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,6 +32,7 @@ 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 = []
|
||||||
|
|
||||||
@@ -104,9 +104,9 @@ class ConfigModel(Model):
|
|||||||
}
|
}
|
||||||
|
|
||||||
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",
|
||||||
@@ -166,7 +166,6 @@ class ConfigModel(Model):
|
|||||||
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)
|
||||||
@@ -182,7 +181,8 @@ class ConfigModel(Model):
|
|||||||
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
|
||||||
@@ -215,7 +215,8 @@ class ConfigModel(Model):
|
|||||||
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()
|
||||||
@@ -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,20 +251,23 @@ 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:
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -42,6 +42,7 @@ def volname(mntp):
|
|||||||
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)
|
||||||
@@ -65,6 +67,7 @@ def volumount(mntp):
|
|||||||
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")
|
||||||
@@ -89,6 +93,7 @@ def mountpoint_to_dev(mntp):
|
|||||||
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:
|
||||||
|
|||||||
@@ -21,13 +21,13 @@
|
|||||||
# 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
|
||||||
@@ -55,21 +55,26 @@ class GthumbCommentParser(object):
|
|||||||
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
|
||||||
|
|||||||
@@ -22,14 +22,13 @@
|
|||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -25,6 +26,7 @@ class ParseExif(object):
|
|||||||
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']
|
||||||
@@ -51,11 +53,13 @@ class ParseExif(object):
|
|||||||
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)
|
||||||
@@ -76,7 +80,8 @@ class ParseExif(object):
|
|||||||
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)
|
||||||
@@ -95,13 +100,18 @@ class ParseExif(object):
|
|||||||
|
|
||||||
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,7 +31,9 @@ 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
|
||||||
@@ -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,10 +80,14 @@ 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')
|
||||||
@@ -169,17 +176,19 @@ 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:
|
||||||
@@ -191,7 +200,8 @@ class Thumbnail(object):
|
|||||||
# 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,6 +31,7 @@ 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,
|
||||||
@@ -40,6 +41,7 @@ class Qst(object):
|
|||||||
)
|
)
|
||||||
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,6 +51,7 @@ 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,
|
||||||
@@ -58,14 +61,17 @@ class Inf(object):
|
|||||||
)
|
)
|
||||||
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,
|
||||||
@@ -75,31 +81,37 @@ class Wrn(object):
|
|||||||
)
|
)
|
||||||
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,11 +119,13 @@ 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 = ""
|
||||||
@@ -131,6 +145,7 @@ class InputDiskLabel(object):
|
|||||||
|
|
||||||
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 = ""
|
||||||
@@ -159,7 +174,9 @@ 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"""
|
||||||
@@ -170,9 +187,7 @@ 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)
|
||||||
@@ -190,8 +205,11 @@ class PointDirectoryToAdd(object):
|
|||||||
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:
|
||||||
@@ -215,9 +233,7 @@ 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)
|
||||||
@@ -255,7 +271,8 @@ class ChooseDBFilename(object):
|
|||||||
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)
|
||||||
|
|
||||||
@@ -267,9 +284,7 @@ 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)
|
||||||
|
|
||||||
@@ -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()
|
||||||
|
|
||||||
@@ -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()
|
||||||
@@ -385,6 +402,7 @@ class LoadImageFile(object):
|
|||||||
|
|
||||||
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
|
||||||
@@ -393,7 +411,7 @@ class StatsDialog(object):
|
|||||||
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:
|
||||||
@@ -402,7 +420,7 @@ class StatsDialog(object):
|
|||||||
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:
|
||||||
@@ -411,11 +429,11 @@ class StatsDialog(object):
|
|||||||
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']))
|
||||||
|
|
||||||
@@ -425,8 +443,28 @@ class StatsDialog(object):
|
|||||||
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
|
||||||
@@ -440,12 +478,12 @@ class EditDialog(object):
|
|||||||
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)
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user