mirror of
https://github.com/gryf/pygtktalog.git
synced 2025-12-17 11:30:19 +01:00
* Code clean up.
* Removed unnecessary imports. * Adapted to PEP8.
This commit is contained in:
@@ -24,7 +24,6 @@
|
||||
|
||||
from gtkmvc import Model
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
import gtk
|
||||
@@ -33,18 +32,19 @@ import gobject
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
class Ini(object):
|
||||
|
||||
def __init__(self):
|
||||
self.ini = []
|
||||
|
||||
|
||||
def add_section(self, section):
|
||||
self.ini.append("[%s]" % section)
|
||||
|
||||
|
||||
def add_key(self, key, value):
|
||||
self.ini.append("%s=%s" % (key, value))
|
||||
|
||||
|
||||
def add_comment(self, comment):
|
||||
self.ini.append(";%s" % comment)
|
||||
|
||||
|
||||
def add_verb(self, verb):
|
||||
self.ini.append(verb)
|
||||
|
||||
@@ -53,11 +53,11 @@ class Ini(object):
|
||||
|
||||
class ConfigModel(Model):
|
||||
ini = Ini()
|
||||
|
||||
|
||||
__properties__ = {}
|
||||
|
||||
|
||||
filetype_list = ['Images', 'Movies']
|
||||
|
||||
|
||||
confd = {
|
||||
'savewin': True,
|
||||
'savepan': True,
|
||||
@@ -67,26 +67,26 @@ class ConfigModel(Model):
|
||||
'v': 300,
|
||||
'eject': True,
|
||||
'compress': True,
|
||||
|
||||
|
||||
'exportxls': False,
|
||||
|
||||
|
||||
'confirmquit': True,
|
||||
'confirmabandon': True,
|
||||
'mntwarn': True,
|
||||
'delwarn': True,
|
||||
|
||||
|
||||
'cd': '/mnt/cdrom',
|
||||
'ejectapp': 'eject -r',
|
||||
|
||||
|
||||
'imgview': False,
|
||||
'imgprog': 'gqview',
|
||||
|
||||
|
||||
'retrive': False,
|
||||
|
||||
|
||||
'thumbs': True,
|
||||
'exif': True,
|
||||
'gthumb': False,
|
||||
|
||||
|
||||
'extensions': {'bmp':'identify %s',
|
||||
'gif':'identify "%s"',
|
||||
'jpg':'identify "%s"',
|
||||
@@ -98,15 +98,15 @@ class ConfigModel(Model):
|
||||
'mpeg':'midentify "%s"',
|
||||
'wmv':'midentify "%s"',
|
||||
},
|
||||
|
||||
|
||||
'showtoolbar':True,
|
||||
'showstatusbar':True,
|
||||
}
|
||||
|
||||
|
||||
dictconf = {
|
||||
"save main window size" : "savewin",
|
||||
"save panes size" : "savepan",
|
||||
"main window width" : "wx",
|
||||
"save main window size": "savewin",
|
||||
"save panes size": "savepan",
|
||||
"main window width": "wx",
|
||||
"main window height": "wy",
|
||||
"horizontal panes": "h",
|
||||
"vertical panes":"v",
|
||||
@@ -128,7 +128,7 @@ class ConfigModel(Model):
|
||||
'use external image viewer':'imgview',
|
||||
'external image viewer program':'imgprog',
|
||||
}
|
||||
|
||||
|
||||
dbool = (
|
||||
'exportxls',
|
||||
'thumbs',
|
||||
@@ -148,25 +148,24 @@ class ConfigModel(Model):
|
||||
'retrive',
|
||||
'imgview',
|
||||
)
|
||||
|
||||
|
||||
recent = []
|
||||
RECENT_MAX = 10
|
||||
|
||||
|
||||
dstring = ('cd','ejectapp','imgprog')
|
||||
|
||||
|
||||
try:
|
||||
path = os.environ['HOME']
|
||||
except:
|
||||
path = "/tmp"
|
||||
|
||||
|
||||
def __init__(self):
|
||||
Model.__init__(self)
|
||||
self.category_tree = gtk.ListStore(gobject.TYPE_STRING)
|
||||
|
||||
|
||||
self.refresh_ext()
|
||||
return
|
||||
|
||||
|
||||
|
||||
def refresh_ext(self):
|
||||
self.ext_tree = gtk.ListStore(gobject.TYPE_STRING,
|
||||
gobject.TYPE_STRING)
|
||||
@@ -175,24 +174,25 @@ class ConfigModel(Model):
|
||||
myiter = self.ext_tree.insert_before(None,None)
|
||||
self.ext_tree.set_value(myiter, 0, i)
|
||||
self.ext_tree.set_value(myiter, 1, self.confd['extensions'][i])
|
||||
|
||||
|
||||
def save(self):
|
||||
try:
|
||||
os.lstat("%s/.pygtktalog" % self.path)
|
||||
except:
|
||||
print "Saving preferences to %s/.pygtktalog" % self.path
|
||||
if __debug__:
|
||||
print "m_config.py: save() Saving preferences to %s/.pygtktalog" % self.path
|
||||
print "m_config.py: save() Saving preferences to",
|
||||
print "%s/.pygtktalog" % self.path
|
||||
newIni = Ini()
|
||||
|
||||
|
||||
# main section
|
||||
newIni.add_section("pyGTKtalog conf")
|
||||
for opt in self.dictconf:
|
||||
newIni.add_key(opt,self.confd[self.dictconf[opt]])
|
||||
|
||||
|
||||
# recent section
|
||||
newIni.add_section("pyGTKtalog recent")
|
||||
|
||||
|
||||
count = 1
|
||||
max_count = self.RECENT_MAX + 1
|
||||
for opt in self.recent:
|
||||
@@ -201,26 +201,27 @@ class ConfigModel(Model):
|
||||
else:
|
||||
break
|
||||
count+=1
|
||||
|
||||
|
||||
# extensions sections
|
||||
newIni.add_section("extensions")
|
||||
count = 1
|
||||
for i in self.confd['extensions']:
|
||||
newIni.add_key(i, self.confd['extensions'][i])
|
||||
count+=1
|
||||
|
||||
|
||||
# write config
|
||||
try:
|
||||
f = open("%s/.pygtktalog" % self.path,"w")
|
||||
success = True
|
||||
except:
|
||||
if __debug__:
|
||||
print "m_config.py: save() Cannot open config file %s for writing." % (self.path, "/.pygtktalog")
|
||||
print "m_config.py: save() Cannot open config file",
|
||||
print "%s for writing." % (self.path, "/.pygtktalog")
|
||||
success = False
|
||||
f.write(newIni.show())
|
||||
f.close()
|
||||
return success
|
||||
|
||||
|
||||
def load(self):
|
||||
try:
|
||||
# try to read config file
|
||||
@@ -231,16 +232,18 @@ class ConfigModel(Model):
|
||||
for sec in parser.sections():
|
||||
if sec == 'pyGTKtalog conf':
|
||||
for opt in parser.options(sec):
|
||||
i = self.dictconf[opt]
|
||||
try:
|
||||
if self.dictconf[opt] in self.dbool:
|
||||
self.confd[self.dictconf[opt]] = parser.getboolean(sec,opt)
|
||||
self.confd[i] = parser.getboolean(sec,opt)
|
||||
elif self.dictconf[opt] in self.dstring:
|
||||
self.confd[self.dictconf[opt]] = parser.get(sec,opt)
|
||||
self.confd[i] = parser.get(sec,opt)
|
||||
else:
|
||||
self.confd[self.dictconf[opt]] = parser.getint(sec,opt)
|
||||
self.confd[i] = parser.getint(sec,opt)
|
||||
except:
|
||||
if __debug__:
|
||||
print "m_config.py: load() failed to parse option:", opt
|
||||
print "m_config.py: load() failed to parse",
|
||||
print "option:", opt
|
||||
pass
|
||||
elif sec == 'pyGTKtalog recent':
|
||||
for opt in parser.options(sec):
|
||||
@@ -248,22 +251,25 @@ class ConfigModel(Model):
|
||||
r[int(opt)] = parser.get(sec,opt)
|
||||
except:
|
||||
if __debug__:
|
||||
print "m_config.py: load() failed to parse option:", opt
|
||||
print "m_config.py: load() failed to parse",
|
||||
print "option:", opt
|
||||
pass
|
||||
elif sec == 'extensions':
|
||||
self.confd['extensions'] = {}
|
||||
for opt in parser.options(sec):
|
||||
try:
|
||||
self.confd['extensions'][opt] = parser.get(sec, opt)
|
||||
self.confd['extensions'][opt] = parser.get(sec,
|
||||
opt)
|
||||
except:
|
||||
if __debug__:
|
||||
print "m_config.py: load() failed to parse option:", opt
|
||||
print "m_config.py: load() failed to parse",
|
||||
print "option:", opt
|
||||
pass
|
||||
|
||||
|
||||
for i in range(1, self.RECENT_MAX + 1):
|
||||
if r.has_key(i):
|
||||
if i in r:
|
||||
self.recent.append(r[i])
|
||||
|
||||
|
||||
except:
|
||||
if __debug__:
|
||||
print "m_config.py: load() load config file failed"
|
||||
@@ -272,17 +278,17 @@ class ConfigModel(Model):
|
||||
def add_recent(self, path):
|
||||
if not path:
|
||||
return
|
||||
|
||||
|
||||
if path in self.recent:
|
||||
self.recent.remove(path)
|
||||
self.recent.insert(0,path)
|
||||
return
|
||||
|
||||
|
||||
self.recent.insert(0,path)
|
||||
if len(self.recent) > self.RECENT_MAX:
|
||||
self.recent = self.recent[:self.RECENT_MAX]
|
||||
return
|
||||
|
||||
|
||||
def __str__(self):
|
||||
"""show prefs in string way"""
|
||||
string = "[varname]\tvalue\n"
|
||||
|
||||
@@ -101,7 +101,7 @@ FIELD_TYPES=(
|
||||
(2, 'SS', 'Signed Short'),
|
||||
(4, 'SL', 'Signed Long'),
|
||||
(8, 'SR', 'Signed Ratio')
|
||||
)
|
||||
)
|
||||
|
||||
# dictionary of main EXIF tag names
|
||||
# first element of tuple is tag name, optional second element is
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
device (cd, dvd) helper
|
||||
"""
|
||||
|
||||
import string
|
||||
import os
|
||||
|
||||
|
||||
def volname(mntp):
|
||||
"""read volume name from cd/dvd"""
|
||||
dev = mountpoint_to_dev(mntp)
|
||||
@@ -41,7 +41,8 @@ def volname(mntp):
|
||||
return None
|
||||
return b
|
||||
return None
|
||||
|
||||
|
||||
|
||||
def volmount(mntp):
|
||||
"""mount device, return 'ok' or error message"""
|
||||
_in,_out,_err = os.popen3("mount %s" % mntp)
|
||||
@@ -53,6 +54,7 @@ def volmount(mntp):
|
||||
else:
|
||||
return 'ok'
|
||||
|
||||
|
||||
def volumount(mntp):
|
||||
"""mount device, return 'ok' or error message"""
|
||||
_in,_out,_err = os.popen3("umount %s" % mntp)
|
||||
@@ -60,11 +62,12 @@ def volumount(mntp):
|
||||
if len(inf) > 0:
|
||||
for error in inf:
|
||||
error.strip()
|
||||
|
||||
|
||||
if error.strip()[:7] == 'umount:':
|
||||
return error.strip()
|
||||
return 'ok'
|
||||
|
||||
|
||||
|
||||
def check_mount(dev):
|
||||
"""Refresh the entries from fstab or mount."""
|
||||
mounts = os.popen('mount')
|
||||
@@ -75,6 +78,7 @@ def check_mount(dev):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def mountpoint_to_dev(mntp):
|
||||
"""guess mountpoint from fstab"""
|
||||
fstab = open("/etc/fstab")
|
||||
@@ -88,20 +92,21 @@ def mountpoint_to_dev(mntp):
|
||||
pass
|
||||
fstab.close()
|
||||
return None
|
||||
|
||||
|
||||
|
||||
def eject_cd(eject_app, cd):
|
||||
"""mount device, return 'ok' or error message"""
|
||||
if len(eject_app) > 0:
|
||||
_in,_out,_err = os.popen3("%s %s" % (eject_app, cd))
|
||||
inf = _err.readlines()
|
||||
error = ''
|
||||
|
||||
|
||||
for error in inf:
|
||||
error.strip()
|
||||
|
||||
|
||||
if error !='':
|
||||
return error
|
||||
|
||||
|
||||
return 'ok'
|
||||
return "Eject program not specified"
|
||||
|
||||
|
||||
|
||||
@@ -21,17 +21,17 @@
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
from xml.dom.minidom import Node
|
||||
from xml.dom import minidom
|
||||
import gzip
|
||||
import os
|
||||
from datetime import date
|
||||
|
||||
class GthumbCommentParser(object):
|
||||
|
||||
def __init__(self, image_path, image_filename):
|
||||
self.path = image_path
|
||||
self.filename = image_filename
|
||||
|
||||
|
||||
def parse(self):
|
||||
"""Return dictionary with apropriate fields, or None if no comment
|
||||
available"""
|
||||
@@ -40,38 +40,43 @@ class GthumbCommentParser(object):
|
||||
'.comments', self.filename + '.xml'))
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
try:
|
||||
xml = gf.read()
|
||||
gf.close()
|
||||
except:
|
||||
gf.close()
|
||||
return None
|
||||
|
||||
|
||||
if not xml:
|
||||
return None
|
||||
|
||||
retval = {}
|
||||
doc = minidom.parseString(xml)
|
||||
|
||||
|
||||
try:
|
||||
retval['note'] = doc.getElementsByTagName('Note').item(0).childNodes.item(0).data
|
||||
retval['note'] = doc.getElementsByTagName('Note').item(0)
|
||||
retval['note'] = retval['note'].childNodes.item(0).data
|
||||
except: retval['note'] = None
|
||||
|
||||
|
||||
try:
|
||||
retval['place'] = doc.getElementsByTagName('Place').item(0).childNodes.item(0).data
|
||||
retval['place'] = doc.getElementsByTagName('Place').item(0)
|
||||
retval['place'] = retval['place'].childNodes.item(0).data
|
||||
except: retval['place'] = None
|
||||
|
||||
|
||||
try:
|
||||
d = doc.getElementsByTagName('Time').item(0).childNodes.item(0).data
|
||||
d = doc.getElementsByTagName('Time').item(0).childNodes
|
||||
d = d.item(0).data
|
||||
if int(d) > 0: retval['date'] = date.fromtimestamp(int(d))
|
||||
else: retval['date'] = None
|
||||
except: retval['date'] = None
|
||||
|
||||
|
||||
try:
|
||||
retval['keywords'] = doc.getElementsByTagName('Keywords').item(0).childNodes.item(0).data.split(',')
|
||||
retval['keywords'] = doc.getElementsByTagName('Keywords').item(0)
|
||||
retval['keywords'] = retval['keywords'].childNodes.item(0)
|
||||
retval['keywords'] = retval['keywords'].data.split(',')
|
||||
except: pass
|
||||
|
||||
|
||||
if len(retval) > 0: return retval
|
||||
else: return None
|
||||
|
||||
|
||||
|
||||
@@ -22,44 +22,43 @@
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
from tempfile import gettempdir
|
||||
from shutil import move, copy
|
||||
from shutil import copy
|
||||
from os import path, mkdir
|
||||
from datetime import datetime
|
||||
|
||||
import Image
|
||||
|
||||
class Img(object):
|
||||
|
||||
def __init__(self, filename=None, base=''):
|
||||
self.root = 'images'
|
||||
self.x = 160
|
||||
self.y = 160
|
||||
self.filename = filename
|
||||
self.base = base
|
||||
|
||||
|
||||
def save(self, image_id):
|
||||
"""Save image and asociated thumbnail into specific directory structure
|
||||
return full path to the file and thumbnail or None"""
|
||||
|
||||
|
||||
base_path = self.__get_and_make_path(image_id)
|
||||
ext = self.filename.split('.')[-1].lower()
|
||||
image_filename = path.join(self.base, base_path + "." + ext)
|
||||
|
||||
|
||||
thumbnail = path.join(self.base, base_path + "_t.jpg")
|
||||
|
||||
|
||||
returncode = -1
|
||||
|
||||
im = self.__scale_image()
|
||||
if im:
|
||||
im.save(thumbnail, "JPEG")
|
||||
returncode = 1
|
||||
|
||||
|
||||
if returncode != -1:
|
||||
# copy image
|
||||
copy(self.filename, image_filename)
|
||||
|
||||
|
||||
return thumbnail, image_filename, returncode
|
||||
|
||||
|
||||
# private class functions
|
||||
def __get_and_make_path(self, img_id):
|
||||
"""Make directory structure regards of id
|
||||
@@ -67,7 +66,7 @@ class Img(object):
|
||||
t = path.join(self.base, self.root)
|
||||
try: mkdir(t)
|
||||
except: pass
|
||||
|
||||
|
||||
h = hex(img_id)
|
||||
if len(h[2:])>6:
|
||||
try: mkdir(path.join(t, h[2:4]))
|
||||
@@ -94,7 +93,7 @@ class Img(object):
|
||||
fpath = ''
|
||||
img = "%s" % h[2:]
|
||||
return(path.join(t, fpath, img))
|
||||
|
||||
|
||||
def __scale_image(self):
|
||||
"""create thumbnail. returns image object or None"""
|
||||
try:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import re
|
||||
import EXIF
|
||||
class ParseExif(object):
|
||||
|
||||
def __init__(self, exif_dict=None, exif_file=None):
|
||||
self.camera = None
|
||||
self.date = None
|
||||
@@ -21,10 +22,11 @@ class ParseExif(object):
|
||||
f = open(exif_file, 'rb')
|
||||
e = EXIF.process_file(f)
|
||||
if len(e.keys()) >0:
|
||||
self.exif_dict = e
|
||||
self.exif_dict = e
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
def parse(self):
|
||||
try:
|
||||
self.camera = "%s" % self.exif_dict['Image Make']
|
||||
@@ -34,14 +36,14 @@ class ParseExif(object):
|
||||
model = "%s" % self.exif_dict['Image Model']
|
||||
self.camera += ", " + model.strip()
|
||||
except: pass
|
||||
|
||||
|
||||
try:
|
||||
self.date = "%s" % self.exif_dict['EXIF DateTimeOriginal']
|
||||
p = re.compile('[\d,:]+')
|
||||
if not p.match(self.date):
|
||||
self.date = None
|
||||
except: pass
|
||||
|
||||
|
||||
try:
|
||||
self.aperture = "%s" % self.exif_dict['EXIF FNumber']
|
||||
if len(self.aperture.split("/")) == 2:
|
||||
@@ -50,22 +52,24 @@ class ParseExif(object):
|
||||
self.aperture = "f/%.1f" % float(self.aperture)
|
||||
self.aperture = self.aperture.replace('.',',')
|
||||
except: pass
|
||||
|
||||
try: self.exposure_program = "%s" % self.exif_dict['EXIF ExposureProgram']
|
||||
|
||||
try: self.exposure_program = "%s" % \
|
||||
self.exif_dict['EXIF ExposureProgram']
|
||||
except: pass
|
||||
|
||||
|
||||
try:
|
||||
self.exposure_bias = "%s" % self.exif_dict['EXIF ExposureBiasValue']
|
||||
self.exposure_bias = "%s" % \
|
||||
self.exif_dict['EXIF ExposureBiasValue']
|
||||
if len(self.exposure_bias.split("/")) == 2:
|
||||
self.exposure_bias += '.'
|
||||
self.exposure_bias = "%.1f" % eval(self.exposure_bias)
|
||||
self.exposure_bias = "%.1f" % float(self.exposure_bias)
|
||||
self.exposure_bias = self.exposure_bias.replace('.',',')
|
||||
except: pass
|
||||
|
||||
|
||||
try: self.iso = "%s" % self.exif_dict['EXIF ISOSpeedRatings']
|
||||
except: pass
|
||||
|
||||
|
||||
try:
|
||||
self.focal_length = "%s" % self.exif_dict['EXIF FocalLength']
|
||||
if len(self.focal_length.split("/")) == 2:
|
||||
@@ -74,34 +78,40 @@ class ParseExif(object):
|
||||
self.focal_length = "%.2f mm" % float(self.focal_length)
|
||||
self.focal_length = self.focal_length.replace('.',',')
|
||||
except: pass
|
||||
|
||||
|
||||
try:
|
||||
self.subject_distance = "%s" % self.exif_dict['EXIF SubjectDistance']
|
||||
self.subject_distance = "%s" % \
|
||||
self.exif_dict['EXIF SubjectDistance']
|
||||
if len(self.subject_distance.split("/")) == 2:
|
||||
self.subject_distance += '.'
|
||||
self.subject_distance = "%.3f" % eval(self.subject_distance)
|
||||
self.subject_distance = "%.3f m" % float(self.subject_distance)
|
||||
self.subject_distance = self.subject_distance.replace('.',',')
|
||||
except: pass
|
||||
|
||||
|
||||
try: self.metering_mode = "%s" % self.exif_dict['EXIF MeteringMode']
|
||||
except: pass
|
||||
|
||||
|
||||
try: self.flash = "%s" % self.exif_dict['EXIF Flash']
|
||||
except: pass
|
||||
|
||||
|
||||
try: self.light_source = "%s" % self.exif_dict['EXIF LightSource']
|
||||
except: pass
|
||||
|
||||
|
||||
try: self.resolution = "%s" % self.exif_dict['Image XResolution']
|
||||
except: pass
|
||||
try: self.resolution = self.resolution + " x %s" % self.exif_dict['Image YResolution']
|
||||
try: self.resolution = self.resolution + " x %s" % \
|
||||
self.exif_dict['Image YResolution']
|
||||
except: pass
|
||||
try: self.resolution = self.resolution + " (%s)" % self.exif_dict['Image ResolutionUnit']
|
||||
try: self.resolution = self.resolution + " (%s)" % \
|
||||
self.exif_dict['Image ResolutionUnit']
|
||||
except: pass
|
||||
|
||||
|
||||
try: self.orientation = "%s" % self.exif_dict['Image Orientation']
|
||||
except: pass
|
||||
|
||||
return (self.camera, self.date, self.aperture, self.exposure_program, self.exposure_bias, self.iso, self.focal_length, self.subject_distance, self.metering_mode, self.flash, self.light_source, self.resolution, self.orientation)
|
||||
#print self.date #self.camera, self.date, self.aperture, self.exposure_program, self.exposure_bias, self.iso, self.focal_length, self.subject_distance, self.metering_mode, self.flash, self.light_source, self.resolution, self.flash, self.orientation
|
||||
|
||||
return (self.camera, self.date, self.aperture, self.exposure_program,
|
||||
self.exposure_bias, self.iso, self.focal_length,
|
||||
self.subject_distance, self.metering_mode, self.flash,
|
||||
self.light_source, self.resolution, self.orientation)
|
||||
|
||||
|
||||
@@ -31,13 +31,15 @@ from utils import EXIF
|
||||
import Image
|
||||
|
||||
class Thumbnail(object):
|
||||
def __init__(self, filename=None, x=160, y=160, root='thumbnails', base=''):
|
||||
|
||||
def __init__(self, filename=None, x=160, y=160,
|
||||
root='thumbnails', base=''):
|
||||
self.root = root
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.filename = filename
|
||||
self.base = base
|
||||
|
||||
|
||||
def save(self, image_id):
|
||||
"""Save thumbnail into specific directory structure
|
||||
return full path to the file and exif object or None"""
|
||||
@@ -48,16 +50,17 @@ class Thumbnail(object):
|
||||
try:
|
||||
exif = EXIF.process_file(f)
|
||||
f.close()
|
||||
if exif.has_key('JPEGThumbnail'):
|
||||
if 'JPEGThumbnail' in exif:
|
||||
thumbnail = exif['JPEGThumbnail']
|
||||
f = open(filepath,'wb')
|
||||
f.write(thumbnail)
|
||||
f.close()
|
||||
if exif.has_key('Image Orientation'):
|
||||
if 'Image Orientation' in exif:
|
||||
orientation = exif['Image Orientation'].values[0]
|
||||
if orientation > 1:
|
||||
# TODO: replace silly datetime function with tempfile
|
||||
t = path.join(gettempdir(), "thumb%d.jpg" % datetime.now().microsecond)
|
||||
ms = datetime.now().microsecond
|
||||
t = path.join(gettempdir(), "thumb%d.jpg" % ms)
|
||||
im_in = Image.open(filepath)
|
||||
im_out = None
|
||||
if orientation == 8:
|
||||
@@ -77,11 +80,15 @@ class Thumbnail(object):
|
||||
im_out = im_in.transpose(Image.FLIP_TOP_BOTTOM)
|
||||
elif orientation == 5:
|
||||
# Mirrored horizontal then rotated 90 CCW
|
||||
im_out = im_in.transpose(Image.FLIP_LEFT_RIGHT).transpose(Image.ROTATE_90)
|
||||
op = Image.FLIP_LEFT_RIGHT
|
||||
rot = Image.ROTATE_90
|
||||
im_out = im_in.transpose(op).transpose(rot)
|
||||
elif orientation == 7:
|
||||
# Mirrored horizontal then rotated 90 CW
|
||||
im_out = im_in.transpose(Image.FLIP_LEFT_RIGHT).transpose(Image.ROTATE_270)
|
||||
|
||||
op = Image.FLIP_LEFT_RIGHT
|
||||
rot = Image.ROTATE_270
|
||||
im_out = im_in.transpose(op).transpose(rot)
|
||||
|
||||
if im_out:
|
||||
im_out.save(t, 'JPEG')
|
||||
move(t, filepath)
|
||||
@@ -100,7 +107,7 @@ class Thumbnail(object):
|
||||
im.save(filepath, "JPEG")
|
||||
returncode = 2
|
||||
return filepath, exif, returncode
|
||||
|
||||
|
||||
# private class functions
|
||||
def __get_and_make_path(self, img_id):
|
||||
"""Make directory structure regards of id
|
||||
@@ -134,7 +141,7 @@ class Thumbnail(object):
|
||||
fpath = ''
|
||||
img = "%s.%s" %(h[2:], 'jpg')
|
||||
return(path.join(t, fpath, img))
|
||||
|
||||
|
||||
def __scale_image(self, factor=True):
|
||||
"""create thumbnail. returns image object or None"""
|
||||
try:
|
||||
@@ -143,7 +150,7 @@ class Thumbnail(object):
|
||||
return None
|
||||
im.thumbnail((self.x, self.y), Image.ANTIALIAS)
|
||||
return im
|
||||
|
||||
|
||||
def __scale_image_deprecated(self, factor=True):
|
||||
"""generate scaled Image object for given file
|
||||
args:
|
||||
@@ -155,9 +162,9 @@ class Thumbnail(object):
|
||||
im = Image.open(self.filename).convert('RGB')
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
x, y = im.size
|
||||
|
||||
|
||||
if x > self.x or y > self.y:
|
||||
if x==y:
|
||||
# square
|
||||
@@ -169,30 +176,33 @@ class Thumbnail(object):
|
||||
self.x1 = int(float(self.y) * self.y / self.x)
|
||||
if float(self.y) * self.y / self.x - self.x1 > 0.49:
|
||||
self.x1 += 1
|
||||
imt = im.resize(((int(x/(y/float(self.y))),self.y)),Image.ANTIALIAS)
|
||||
imt = im.resize(((int(x/(y/float(self.y))), self.y)),
|
||||
Image.ANTIALIAS)
|
||||
elif x/self.x==y/self.y:
|
||||
# aspect ratio ok
|
||||
imt = im.resize((self.x, self.y), Image.ANTIALIAS)
|
||||
else:
|
||||
imt = im.resize((self.x,int(y/(x/float(self.x)))), 1)
|
||||
imt = im.resize((self.x, int(y/(x/float(self.x)))), 1)
|
||||
else:
|
||||
# portrait
|
||||
if factor:
|
||||
if y>self.x:
|
||||
imt = im.resize(((int(x/(y/float(self.x))),self.x)),Image.ANTIALIAS)
|
||||
imt = im.resize(((int(x/(y/float(self.x))),self.x)),
|
||||
Image.ANTIALIAS)
|
||||
else:
|
||||
imt = im
|
||||
else:
|
||||
self.x1 = int(float(self.y) * self.y / self.x)
|
||||
if float(self.y) * self.y / self.x - self.x1 > 0.49:
|
||||
self.x1 += 1
|
||||
|
||||
|
||||
if x/self.x1==y/self.y:
|
||||
# aspect ratio ok
|
||||
imt = im.resize((self.x1,self.y),Image.ANTIALIAS)
|
||||
else:
|
||||
imt = im.resize(((int(x/(y/float(self.y))),self.y)),Image.ANTIALIAS)
|
||||
imt = im.resize(((int(x/(y/float(self.y))), self.y)),
|
||||
Image.ANTIALIAS)
|
||||
return imt
|
||||
else:
|
||||
return im
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import utils.globals
|
||||
class ConfigView(View):
|
||||
"""Preferences window from glade file """
|
||||
GLADE = os.path.join(utils.globals.GLADE_DIR, "config.glade")
|
||||
|
||||
def __init__(self, ctrl):
|
||||
View.__init__(self, ctrl, self.GLADE)
|
||||
return
|
||||
|
||||
@@ -31,15 +31,17 @@ class Qst(object):
|
||||
if "OK" button pressed, return "True"
|
||||
"Cancel" button return "False"
|
||||
"""
|
||||
|
||||
def __init__(self, title="", message="", secondarymsg=""):
|
||||
self.dialog = gtk.MessageDialog(
|
||||
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||
type = gtk.MESSAGE_QUESTION,
|
||||
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||
type = gtk.MESSAGE_QUESTION,
|
||||
buttons = gtk.BUTTONS_OK_CANCEL,
|
||||
message_format = message,
|
||||
)
|
||||
self.dialog.set_title(title)
|
||||
self.dialog.format_secondary_text(secondarymsg)
|
||||
|
||||
def run(self):
|
||||
retval = self.dialog.run()
|
||||
self.dialog.destroy()
|
||||
@@ -49,57 +51,67 @@ class Qst(object):
|
||||
|
||||
class Inf(object):
|
||||
"""Show simple dialog for notices"""
|
||||
|
||||
def __init__(self, title="", message="", secondarymsg=""):
|
||||
self.dialog = gtk.MessageDialog(
|
||||
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||
type = gtk.MESSAGE_INFO,
|
||||
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||
type = gtk.MESSAGE_INFO,
|
||||
buttons = gtk.BUTTONS_OK,
|
||||
message_format = message,
|
||||
)
|
||||
self.dialog.set_title(title)
|
||||
self.dialog.format_secondary_text(secondarymsg)
|
||||
self.dialog.connect('response', lambda dialog, response: self.ret(response))
|
||||
self.dialog.connect('response',
|
||||
lambda dialog, response: self.ret(response))
|
||||
self.dialog.show()
|
||||
|
||||
def ret(self,result):
|
||||
self.dialog.destroy()
|
||||
return True
|
||||
|
||||
|
||||
class Wrn(object):
|
||||
"""Show simple dialog for warnings"""
|
||||
|
||||
def __init__(self, title="", message="", secondarymsg=""):
|
||||
self.dialog = gtk.MessageDialog(
|
||||
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||
type = gtk.MESSAGE_WARNING,
|
||||
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||
type = gtk.MESSAGE_WARNING,
|
||||
buttons = gtk.BUTTONS_CLOSE,
|
||||
message_format = message,
|
||||
)
|
||||
self.dialog.set_title(title)
|
||||
self.dialog.format_secondary_text(secondarymsg)
|
||||
self.dialog.connect('response', lambda dialog, response: self.ret(response))
|
||||
self.dialog.connect('response',
|
||||
lambda dialog, response: self.ret(response))
|
||||
self.dialog.show()
|
||||
|
||||
def ret(self,result):
|
||||
self.dialog.destroy()
|
||||
return True
|
||||
|
||||
|
||||
class Err(object):
|
||||
"""Show simple dialog for errors"""
|
||||
|
||||
def __init__(self, title="", message="", secondarymsg=""):
|
||||
self.dialog = gtk.MessageDialog(
|
||||
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||
type = gtk.MESSAGE_ERROR,
|
||||
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||
type = gtk.MESSAGE_ERROR,
|
||||
buttons = gtk.BUTTONS_CLOSE,
|
||||
message_format = message,
|
||||
)
|
||||
message_format = message)
|
||||
|
||||
self.dialog.set_title(title)
|
||||
self.dialog.format_secondary_text(secondarymsg)
|
||||
self.dialog.connect('response', lambda dialog, response: self.ret(response))
|
||||
self.dialog.connect('response',
|
||||
lambda dialog, response: self.ret(response))
|
||||
self.dialog.run()
|
||||
|
||||
def ret(self,result):
|
||||
self.dialog.destroy()
|
||||
return True
|
||||
|
||||
class Abt(object):
|
||||
"""Show simple about dialog"""
|
||||
|
||||
def __init__(self, name=None, ver="", title="", authors=[],licence=""):
|
||||
self.dialog = gtk.AboutDialog()
|
||||
self.dialog.set_title(title)
|
||||
@@ -107,17 +119,19 @@ class Abt(object):
|
||||
self.dialog.set_license(licence)
|
||||
self.dialog.set_name(name)
|
||||
self.dialog.set_authors(authors)
|
||||
self.dialog.connect('response', lambda dialog, response: self.dialog.destroy())
|
||||
self.dialog.connect('response',
|
||||
lambda dialog, response: self.dialog.destroy())
|
||||
self.dialog.show()
|
||||
|
||||
class InputDiskLabel(object):
|
||||
"""Sepcific dialog for quering user for a disc label"""
|
||||
|
||||
def __init__(self, label=""):
|
||||
self.gladefile = os.path.join(utils.globals.GLADE_DIR, "dialogs.glade")
|
||||
self.label = ""
|
||||
if label!= None:
|
||||
self.label = label
|
||||
|
||||
|
||||
def run(self):
|
||||
gladexml = gtk.glade.XML(self.gladefile, "inputDialog")
|
||||
dialog = gladexml.get_widget("inputDialog")
|
||||
@@ -128,14 +142,15 @@ class InputDiskLabel(object):
|
||||
if result == gtk.RESPONSE_OK:
|
||||
return entry.get_text()
|
||||
return None
|
||||
|
||||
|
||||
class InputNewName(object):
|
||||
"""Sepcific dialog for quering user for a disc label"""
|
||||
|
||||
def __init__(self, name=""):
|
||||
self.gladefile = os.path.join(utils.globals.GLADE_DIR, "dialogs.glade")
|
||||
self.label = ""
|
||||
self.name = name
|
||||
|
||||
|
||||
def run(self):
|
||||
gladexml = gtk.glade.XML(self.gladefile, "renameDialog")
|
||||
dialog = gladexml.get_widget("renameDialog")
|
||||
@@ -149,9 +164,9 @@ class InputNewName(object):
|
||||
|
||||
class PointDirectoryToAdd(object):
|
||||
"""Sepcific dialog for quering user for selecting directory to add"""
|
||||
|
||||
|
||||
URI="file://"+os.path.abspath(os.path.curdir)
|
||||
|
||||
|
||||
def __init__(self,volname='',dirname=''):
|
||||
self.gladefile = os.path.join(utils.globals.GLADE_DIR, "dialogs.glade")
|
||||
self.gladexml = gtk.glade.XML(self.gladefile, "addDirDialog")
|
||||
@@ -159,8 +174,10 @@ class PointDirectoryToAdd(object):
|
||||
self.volname.set_text(volname)
|
||||
self.directory = self.gladexml.get_widget("directory")
|
||||
self.directory.set_text(dirname)
|
||||
self.gladexml.signal_autoconnect({"on_browse_activate":self.show_dirchooser,"on_browse_clicked":self.show_dirchooser})
|
||||
|
||||
sigs = {"on_browse_activate":self.show_dirchooser,
|
||||
"on_browse_clicked":self.show_dirchooser}
|
||||
self.gladexml.signal_autoconnect(sigs)
|
||||
|
||||
def show_dirchooser(self,widget):
|
||||
"""dialog for point the mountpoint"""
|
||||
dialog = gtk.FileChooserDialog(
|
||||
@@ -170,13 +187,11 @@ class PointDirectoryToAdd(object):
|
||||
gtk.STOCK_CANCEL,
|
||||
gtk.RESPONSE_CANCEL,
|
||||
gtk.STOCK_OPEN,
|
||||
gtk.RESPONSE_OK
|
||||
)
|
||||
)
|
||||
|
||||
gtk.RESPONSE_OK))
|
||||
|
||||
dialog.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
||||
dialog.set_default_response(gtk.RESPONSE_OK)
|
||||
|
||||
|
||||
if self.URI:
|
||||
dialog.set_current_folder_uri(self.URI)
|
||||
response = dialog.run()
|
||||
@@ -184,14 +199,17 @@ class PointDirectoryToAdd(object):
|
||||
self.directory.set_text(dialog.get_filename())
|
||||
self.__class__.URI = dialog.get_current_folder_uri()
|
||||
dialog.destroy()
|
||||
|
||||
|
||||
def run(self):
|
||||
dialog = self.gladexml.get_widget("addDirDialog")
|
||||
ch = True
|
||||
result = dialog.run()
|
||||
while ch:
|
||||
if result == gtk.RESPONSE_OK and (self.volname.get_text()=='' or self.directory.get_text() == ''):
|
||||
a = Err("Error - pyGTKtalog","There are fields needed to be filled.","Cannot add directory without path and disc label.")
|
||||
if result == gtk.RESPONSE_OK and (self.volname.get_text()=='' or \
|
||||
self.directory.get_text() == ''):
|
||||
a = Err("Error - pyGTKtalog",
|
||||
"There are fields needed to be filled.",
|
||||
"Cannot add directory without path and disc label.")
|
||||
ch = True
|
||||
result = dialog.run()
|
||||
else:
|
||||
@@ -204,9 +222,9 @@ class PointDirectoryToAdd(object):
|
||||
|
||||
class ChooseDBFilename(object):
|
||||
"""Sepcific dialog for quering user for selecting filename for database"""
|
||||
|
||||
|
||||
URI="file://"+os.path.abspath(os.path.curdir)
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.dialog = gtk.FileChooserDialog(
|
||||
title="Save catalog as...",
|
||||
@@ -215,15 +233,13 @@ class ChooseDBFilename(object):
|
||||
gtk.STOCK_CANCEL,
|
||||
gtk.RESPONSE_CANCEL,
|
||||
gtk.STOCK_SAVE,
|
||||
gtk.RESPONSE_OK
|
||||
)
|
||||
)
|
||||
|
||||
gtk.RESPONSE_OK))
|
||||
|
||||
self.dialog.set_action(gtk.FILE_CHOOSER_ACTION_SAVE)
|
||||
self.dialog.set_default_response(gtk.RESPONSE_OK)
|
||||
self.dialog.set_do_overwrite_confirmation(True)
|
||||
self.dialog.set_title('Save catalog to file...')
|
||||
|
||||
|
||||
f = gtk.FileFilter()
|
||||
f.set_name("Catalog files")
|
||||
f.add_pattern("*.pgt")
|
||||
@@ -232,7 +248,7 @@ class ChooseDBFilename(object):
|
||||
f.set_name("All files")
|
||||
f.add_pattern("*.*")
|
||||
self.dialog.add_filter(f)
|
||||
|
||||
|
||||
def run(self):
|
||||
if self.URI:
|
||||
self.dialog.set_current_folder_uri(self.URI)
|
||||
@@ -253,12 +269,13 @@ class ChooseDBFilename(object):
|
||||
self.dialog.destroy()
|
||||
return None
|
||||
pass
|
||||
|
||||
|
||||
class LoadDBFile(object):
|
||||
"""Specific class for displaying openFile dialog. It has veryfication for file existence."""
|
||||
|
||||
"""Specific class for displaying openFile dialog. It has veryfication
|
||||
for file existence."""
|
||||
|
||||
URI="file://"+os.path.abspath(os.path.curdir)
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.dialog = gtk.FileChooserDialog(
|
||||
title="Open catalog",
|
||||
@@ -267,12 +284,10 @@ class LoadDBFile(object):
|
||||
gtk.STOCK_CANCEL,
|
||||
gtk.RESPONSE_CANCEL,
|
||||
gtk.STOCK_OPEN,
|
||||
gtk.RESPONSE_OK
|
||||
)
|
||||
)
|
||||
|
||||
gtk.RESPONSE_OK))
|
||||
|
||||
self.dialog.set_default_response(gtk.RESPONSE_OK)
|
||||
|
||||
|
||||
f = gtk.FileFilter()
|
||||
f.set_name("Catalog files")
|
||||
f.add_pattern("*.pgt")
|
||||
@@ -281,7 +296,7 @@ class LoadDBFile(object):
|
||||
f.set_name("All files")
|
||||
f.add_pattern("*.*")
|
||||
self.dialog.add_filter(f)
|
||||
|
||||
|
||||
def show_dialog(self):
|
||||
response = self.dialog.run()
|
||||
filename = None
|
||||
@@ -294,7 +309,7 @@ class LoadDBFile(object):
|
||||
return 'ok',filename
|
||||
else:
|
||||
return 'cancel',None
|
||||
|
||||
|
||||
def run(self):
|
||||
if self.URI:
|
||||
self.dialog.set_current_folder_uri(self.URI)
|
||||
@@ -310,7 +325,9 @@ class LoadDBFile(object):
|
||||
self.dialog.destroy()
|
||||
return filename
|
||||
except:
|
||||
a = Err("Error - pyGTKtalog","File doesn't exist.","The file that you choose does not exist. Choose another one, or cancel operation.")
|
||||
a = Err("Error - pyGTKtalog","File doesn't exist.",
|
||||
"The file that you choose does not exist." + \
|
||||
" Choose another one, or cancel operation.")
|
||||
ch = True
|
||||
res, filename = self.show_dialog()
|
||||
|
||||
@@ -318,9 +335,9 @@ class LoadDBFile(object):
|
||||
class LoadImageFile(object):
|
||||
"""class for displaying openFile dialog. It have possibility of multiple
|
||||
selection."""
|
||||
|
||||
|
||||
URI="file://"+os.path.abspath(os.path.curdir)
|
||||
|
||||
|
||||
def __init__(self, multiple=False):
|
||||
self.dialog = gtk.FileChooserDialog(
|
||||
title="Select image",
|
||||
@@ -329,15 +346,15 @@ class LoadImageFile(object):
|
||||
gtk.STOCK_CANCEL,
|
||||
gtk.RESPONSE_CANCEL,
|
||||
gtk.STOCK_OPEN,
|
||||
gtk.RESPONSE_OK
|
||||
)
|
||||
)
|
||||
gtk.RESPONSE_OK))
|
||||
self.dialog.set_select_multiple(multiple)
|
||||
self.dialog.set_default_response(gtk.RESPONSE_OK)
|
||||
|
||||
|
||||
f = gtk.FileFilter()
|
||||
f.set_name("All Images")
|
||||
for i in ['*.jpg', '*.jpeg', '*.gif', '*.png', '*.tif', '*.tiff', '*.tga', '*.pcx', '*.bmp', '*.xbm', '*.xpm', '*.jp2', '*.jpx', '*.pnm']:
|
||||
for i in ['*.jpg', '*.jpeg', '*.gif', '*.png', '*.tif', '*.tiff',
|
||||
'*.tga', '*.pcx', '*.bmp', '*.xbm', '*.xpm', '*.jp2',
|
||||
'*.jpx', '*.pnm']:
|
||||
f.add_pattern(i)
|
||||
self.dialog.add_filter(f)
|
||||
f = gtk.FileFilter()
|
||||
@@ -345,33 +362,33 @@ class LoadImageFile(object):
|
||||
f.add_pattern("*.*")
|
||||
self.dialog.add_filter(f)
|
||||
self.preview = gtk.Image()
|
||||
|
||||
|
||||
self.dialog.set_preview_widget(self.preview)
|
||||
self.dialog.connect("update-preview", self.update_preview_cb)
|
||||
|
||||
|
||||
def run(self):
|
||||
if self.URI:
|
||||
self.dialog.set_current_folder_uri(self.URI)
|
||||
response = self.dialog.run()
|
||||
filenames = None
|
||||
only_thumbs = False
|
||||
|
||||
|
||||
if response == gtk.RESPONSE_OK:
|
||||
try:
|
||||
if self.dialog.get_select_multiple():
|
||||
filenames = self.dialog.get_filenames()
|
||||
else:
|
||||
filenames = self.dialog.get_filename()
|
||||
|
||||
|
||||
if self.dialog.get_extra_widget().get_active():
|
||||
only_thumbs = True
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
self.__class__.URI = self.dialog.get_current_folder_uri()
|
||||
self.dialog.destroy()
|
||||
return filenames, only_thumbs
|
||||
|
||||
|
||||
def update_preview_cb(self, widget):
|
||||
filename = self.dialog.get_preview_filename()
|
||||
try:
|
||||
@@ -382,18 +399,19 @@ class LoadImageFile(object):
|
||||
have_preview = False
|
||||
self.dialog.set_preview_widget_active(have_preview)
|
||||
return
|
||||
|
||||
|
||||
class StatsDialog(object):
|
||||
"""Sepcific dialog for display stats"""
|
||||
|
||||
def __init__(self, values={}):
|
||||
self.gladefile = os.path.join(utils.globals.GLADE_DIR, "dialogs.glade")
|
||||
self.values = values
|
||||
|
||||
|
||||
def run(self):
|
||||
gladexml = gtk.glade.XML(self.gladefile, "statDialog")
|
||||
dialog = gladexml.get_widget("statDialog")
|
||||
|
||||
if self.values.has_key('discs'):
|
||||
|
||||
if 'discs' in self.values:
|
||||
entry = gladexml.get_widget("discs_entry")
|
||||
entry.set_text(str(self.values['discs']))
|
||||
else:
|
||||
@@ -401,8 +419,8 @@ class StatsDialog(object):
|
||||
entry = gladexml.get_widget("discs_entry")
|
||||
label.hide()
|
||||
entry.hide()
|
||||
|
||||
if self.values.has_key('dirs'):
|
||||
|
||||
if 'dirs' in self.values:
|
||||
entry = gladexml.get_widget("dirs_entry")
|
||||
entry.set_text(str(self.values['dirs']))
|
||||
else:
|
||||
@@ -410,46 +428,66 @@ class StatsDialog(object):
|
||||
entry = gladexml.get_widget("dirs_entry")
|
||||
label.hide()
|
||||
entry.hide()
|
||||
|
||||
if self.values.has_key('files'):
|
||||
|
||||
if 'files' in self.values:
|
||||
entry = gladexml.get_widget("files_entry")
|
||||
entry.set_text(str(self.values['files']))
|
||||
|
||||
if self.values.has_key('size'):
|
||||
|
||||
if 'size' in self.values:
|
||||
entry = gladexml.get_widget("size_entry")
|
||||
entry.set_text(str(self.values['size']))
|
||||
|
||||
|
||||
result = dialog.run()
|
||||
dialog.destroy()
|
||||
if result == gtk.RESPONSE_OK:
|
||||
return entry.get_text()
|
||||
return None
|
||||
|
||||
class TagsDialog(object):
|
||||
"""Sepcific dialog for display stats"""
|
||||
|
||||
def __init__(self):
|
||||
self.gladefile = os.path.join(utils.globals.GLADE_DIR, "dialogs.glade")
|
||||
|
||||
def run(self):
|
||||
gladexml = gtk.glade.XML(self.gladefile, "tagsDialog")
|
||||
dialog = gladexml.get_widget("tagsDialog")
|
||||
|
||||
entry = gladexml.get_widget("tag_entry1")
|
||||
|
||||
result = dialog.run()
|
||||
|
||||
dialog.destroy()
|
||||
if result == gtk.RESPONSE_OK:
|
||||
return entry.get_text()
|
||||
return None
|
||||
|
||||
class EditDialog(object):
|
||||
"""Sepcific dialog for display stats"""
|
||||
|
||||
def __init__(self, values={}):
|
||||
self.gladefile = os.path.join(utils.globals.GLADE_DIR, "dialogs.glade")
|
||||
self.values = values
|
||||
|
||||
|
||||
def run(self):
|
||||
gladexml = gtk.glade.XML(self.gladefile, "file_editDialog")
|
||||
dialog = gladexml.get_widget("file_editDialog")
|
||||
|
||||
|
||||
filename = gladexml.get_widget("filename_entry")
|
||||
filename.set_text(str(self.values['filename']))
|
||||
description = gladexml.get_widget("description_text")
|
||||
note = gladexml.get_widget("note_text")
|
||||
|
||||
if self.values.has_key('description'):
|
||||
|
||||
if 'description' in self.values:
|
||||
buff = gtk.TextBuffer()
|
||||
buff.set_text(str(self.values['description']))
|
||||
description.set_buffer(buff)
|
||||
|
||||
if self.values.has_key('note'):
|
||||
|
||||
if 'note' in self.values:
|
||||
buff = gtk.TextBuffer()
|
||||
buff.set_text(str(self.values['note']))
|
||||
note.set_buffer(buff)
|
||||
|
||||
|
||||
result = dialog.run()
|
||||
if result == gtk.RESPONSE_OK:
|
||||
d = description.get_buffer()
|
||||
|
||||
@@ -22,15 +22,12 @@
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
import os.path
|
||||
|
||||
import gtk
|
||||
|
||||
import utils.globals
|
||||
|
||||
class ImageView(object):
|
||||
"""simple image viewer. no scaling, no zooming, no rotating.
|
||||
simply show stupid image"""
|
||||
|
||||
def __init__(self, image_filename):
|
||||
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||
image = gtk.Image()
|
||||
@@ -39,5 +36,5 @@ class ImageView(object):
|
||||
image.show()
|
||||
window.show()
|
||||
return
|
||||
|
||||
|
||||
pass # end of class
|
||||
|
||||
Reference in New Issue
Block a user