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