mirror of
https://github.com/gryf/pygtktalog.git
synced 2025-12-18 12:00:21 +01:00
* Code refactoring.
* Small changes in assumptions. * TODO supplement. * Moved minor features into future versions. * Added extensions configuration editor.
This commit is contained in:
@@ -75,7 +75,7 @@ class ConfigModel(Model):
|
||||
'mntwarn': True,
|
||||
'delwarn': True,
|
||||
|
||||
'cd': '/cdrom',
|
||||
'cd': '/mnt/cdrom',
|
||||
'ejectapp': 'eject -r',
|
||||
|
||||
'retrive': False,
|
||||
@@ -84,8 +84,17 @@ class ConfigModel(Model):
|
||||
'exif': True,
|
||||
'gthumb': False,
|
||||
|
||||
'mov_ext': ['avi', 'mkv', 'mpg', 'mpeg', 'wmv'],
|
||||
'img_ext': ['bmp', 'gif', 'jpg', 'jpeg', 'png'],
|
||||
'extensions': {'bmp':'identify %s',
|
||||
'gif':'identify "%s"',
|
||||
'jpg':'identify "%s"',
|
||||
'jpeg':'identify "%s"',
|
||||
'png':'identify "%s"',
|
||||
'avi':'midentify "%s"',
|
||||
'mkv':'midentify "%s"',
|
||||
'mpg':'midentify "%s"',
|
||||
'mpeg':'midentify "%s"',
|
||||
'wmv':'midentify "%s"',
|
||||
},
|
||||
|
||||
'showtoolbar':True,
|
||||
'showstatusbar':True,
|
||||
@@ -147,21 +156,19 @@ class ConfigModel(Model):
|
||||
def __init__(self):
|
||||
Model.__init__(self)
|
||||
self.category_tree = gtk.ListStore(gobject.TYPE_STRING)
|
||||
self.ext_list = gtk.ListStore(gobject.TYPE_STRING)
|
||||
for i in self.filetype_list:
|
||||
myiter = self.ext_list.insert_before(None,None)
|
||||
self.ext_list.set_value(myiter,0,i)
|
||||
|
||||
self.refresh_ext('img_ext')
|
||||
|
||||
self.refresh_ext()
|
||||
return
|
||||
|
||||
|
||||
def refresh_ext(self, key):
|
||||
self.ext_tree = gtk.ListStore(gobject.TYPE_STRING)
|
||||
self.confd[key].sort()
|
||||
for i in self.confd[key]:
|
||||
def refresh_ext(self):
|
||||
self.ext_tree = gtk.ListStore(gobject.TYPE_STRING,
|
||||
gobject.TYPE_STRING)
|
||||
keys = sorted(self.confd['extensions'].keys())
|
||||
for i in keys:
|
||||
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])
|
||||
|
||||
def save(self):
|
||||
try:
|
||||
@@ -190,16 +197,10 @@ class ConfigModel(Model):
|
||||
count+=1
|
||||
|
||||
# extensions sections
|
||||
newIni.add_section("images extensions")
|
||||
newIni.add_section("extensions")
|
||||
count = 1
|
||||
for i in self.confd['img_ext']:
|
||||
newIni.add_key(count, i)
|
||||
count+=1
|
||||
|
||||
newIni.add_section("movies extensions")
|
||||
count = 1
|
||||
for i in self.confd['mov_ext']:
|
||||
newIni.add_key(count, i)
|
||||
for i in self.confd['extensions']:
|
||||
newIni.add_key(i, self.confd['extensions'][i])
|
||||
count+=1
|
||||
|
||||
# write config
|
||||
@@ -243,26 +244,16 @@ class ConfigModel(Model):
|
||||
if __debug__:
|
||||
print "m_config.py: load() failed to parse option:", opt
|
||||
pass
|
||||
elif sec == 'images extensions':
|
||||
self.confd['img_ext'] = []
|
||||
elif sec == 'extensions':
|
||||
self.confd['extensions'] = {}
|
||||
for opt in parser.options(sec):
|
||||
try:
|
||||
self.confd['img_ext'].append(parser.get(sec,opt))
|
||||
self.confd['extensions'][opt] = parser.get(sec, opt)
|
||||
except:
|
||||
if __debug__:
|
||||
print "m_config.py: load() failed to parse option:", opt
|
||||
pass
|
||||
|
||||
elif sec == 'movies extensions':
|
||||
self.confd['mov_ext'] = []
|
||||
for opt in parser.options(sec):
|
||||
try:
|
||||
self.confd['mov_ext'].append(parser.get(sec,opt))
|
||||
except:
|
||||
if __debug__:
|
||||
print "m_config.py: load() failed to parse option:", opt
|
||||
pass
|
||||
|
||||
for i in range(1, self.RECENT_MAX + 1):
|
||||
if r.has_key(i):
|
||||
self.recent.append(r[i])
|
||||
|
||||
@@ -28,6 +28,7 @@ import base64
|
||||
import shutil
|
||||
import tarfile
|
||||
import tempfile
|
||||
import string
|
||||
|
||||
import gtk
|
||||
import gobject
|
||||
@@ -58,17 +59,13 @@ class MainModel(ModelMT):
|
||||
FIL = 2 # file
|
||||
LIN = 3 # symbolic link
|
||||
|
||||
# filetype kind of
|
||||
F_UNK = 0 # unknown - default
|
||||
F_IMG = 1 # images - jpg, gif, tiff itd
|
||||
F_MOV = 2 # movies and clips - mpg, ogm, mkv, avi, asf, wmv itd
|
||||
F_MUS = 4 # music - flac, mp3, mpc, ogg itd
|
||||
F_APP = 5 # applications
|
||||
F_DOC = 6 # all kind of documents txt/pdf/doc/odf itd
|
||||
|
||||
CD = 1 # sorce: cd/dvd
|
||||
DR = 2 # source: filesystem
|
||||
|
||||
# images extensions - only for PIL and EXIF
|
||||
IMG = ['jpg', 'jpeg', 'gif', 'png', 'tif', 'tiff', 'tga', 'pcx', 'bmp',
|
||||
'xbm', 'xpm', 'jp2', 'jpx', 'pnm']
|
||||
|
||||
def __init__(self):
|
||||
ModelMT.__init__(self)
|
||||
self.config = ConfigModel()
|
||||
@@ -255,9 +252,7 @@ class MainModel(ModelMT):
|
||||
|
||||
# all the rest
|
||||
self.db_cursor.execute("SELECT f.id, f.filename, f.size, f.date, \
|
||||
f.type, f.filetype, t.filename \
|
||||
FROM files f \
|
||||
LEFT JOIN thumbnails t ON f.id = t.file_id \
|
||||
f.type FROM files f \
|
||||
WHERE f.parent_id=? AND f.type!=1 \
|
||||
ORDER BY f.filename", (id,))
|
||||
data = self.db_cursor.fetchall()
|
||||
@@ -270,14 +265,11 @@ class MainModel(ModelMT):
|
||||
self.files_list.set_value(myiter, 4, ch[4])
|
||||
self.files_list.set_value(myiter, 5, 'kategoria srategoria')
|
||||
if ch[4] == self.FIL:
|
||||
if ch[6] != None:
|
||||
# TODO: change icon to thumbnail
|
||||
self.files_list.set_value(myiter, 6, gtk.STOCK_FILE)
|
||||
else:
|
||||
self.files_list.set_value(myiter, 6, gtk.STOCK_FILE)
|
||||
self.files_list.set_value(myiter, 6, gtk.STOCK_FILE)
|
||||
elif ch[4] == self.LIN:
|
||||
self.files_list.set_value(myiter, 6, gtk.STOCK_INDEX)
|
||||
return
|
||||
|
||||
def get_parent_discs_value(self, child_id):
|
||||
if child_id:
|
||||
self.db_cursor.execute("SELECT parent_id FROM files where id=?", (child_id,))
|
||||
@@ -290,7 +282,7 @@ class MainModel(ModelMT):
|
||||
"""get file info from database"""
|
||||
retval = {}
|
||||
self.db_cursor.execute("SELECT f.filename, f.date, f.size, f.type, \
|
||||
t.filename \
|
||||
t.filename, f.description \
|
||||
FROM files f \
|
||||
LEFT JOIN thumbnails t ON t.file_id = f.id \
|
||||
WHERE f.id = ?", (id,))
|
||||
@@ -298,7 +290,9 @@ class MainModel(ModelMT):
|
||||
if set:
|
||||
string = "ID: %d\nFilename: %s\nDate: %s\nSize: %s\ntype: %s" % \
|
||||
(id, set[0], datetime.fromtimestamp(set[1]), set[2], set[3])
|
||||
retval['description'] = string
|
||||
retval['file_info'] = string
|
||||
if set[5]:
|
||||
retval['description'] = set[5]
|
||||
|
||||
if set[4]:
|
||||
retval['thumbnail'] = os.path.join(self.internal_dirname, set[4])
|
||||
@@ -408,22 +402,11 @@ class MainModel(ModelMT):
|
||||
size_x integer,
|
||||
size_y integer,
|
||||
filetype integer,
|
||||
note TEXT);""")
|
||||
description TEXT);""")
|
||||
self.db_cursor.execute("""create table
|
||||
tags(id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
file_id INTEGER,
|
||||
tag TEXT);""")
|
||||
self.db_cursor.execute("""create table
|
||||
descriptions(id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
file_id INTEGER,
|
||||
desc TEXT,
|
||||
image TEXT,
|
||||
image_x INTEGER,
|
||||
image_y INTEGER,
|
||||
thumb TEXT,
|
||||
thumb_x INTEGER,
|
||||
thumb_y INTEGER,
|
||||
thumb_mode TEXT);""")
|
||||
self.db_cursor.execute("""create table
|
||||
thumbnails(id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
file_id INTEGER,
|
||||
@@ -586,16 +569,34 @@ class MainModel(ModelMT):
|
||||
update = True
|
||||
sql = """select seq FROM sqlite_sequence WHERE name='files'"""
|
||||
db_cursor.execute(sql)
|
||||
fileid=db_cursor.fetchone()[0]
|
||||
if i.split('.')[-1].lower() in self.config.confd['img_ext']:
|
||||
sql = """UPDATE files set filetype = ? where id = ?"""
|
||||
db_cursor.execute(sql, (self.F_IMG, fileid))
|
||||
if self.config.confd['thumbs']:
|
||||
path, exif, ret_code = Thumbnail(current_path, base=self.internal_dirname).save(fileid)
|
||||
if ret_code != -1:
|
||||
sql = """insert into thumbnails(file_id, filename) values (?, ?)"""
|
||||
db_cursor.execute(sql, (fileid, path.split(self.internal_dirname)[1][1:]))
|
||||
fileid = db_cursor.fetchone()[0]
|
||||
|
||||
ext = i.split('.')[-1].lower()
|
||||
|
||||
# Images - thumbnails and exif data
|
||||
if self.config.confd['thumbs'] and ext in self.IMG:
|
||||
path, exif, ret_code = Thumbnail(current_path, base=self.internal_dirname).save(fileid)
|
||||
if ret_code != -1:
|
||||
sql = """insert into thumbnails(file_id, filename) values (?, ?)"""
|
||||
db_cursor.execute(sql, (fileid,
|
||||
path.split(self.internal_dirname)[1][1:]))
|
||||
|
||||
if self.config.confd['exif']:
|
||||
# TODO: exif implementation
|
||||
pass
|
||||
|
||||
# Extensions - user defined actions
|
||||
if ext in self.config.confd['extensions'].keys():
|
||||
cmd = self.config.confd['extensions'][ext]
|
||||
arg = string.replace(current_path, '"', '\\"')
|
||||
output = os.popen(cmd % arg).readlines()
|
||||
desc = ''
|
||||
for line in output:
|
||||
desc += line
|
||||
#desc = string.replace(desc, "\n", "\\n")
|
||||
sql = """update files set description=? where id=?"""
|
||||
db_cursor.execute(sql, (desc, fileid))
|
||||
|
||||
#if i.split('.').[-1].lower() in mov_ext:
|
||||
# # video only
|
||||
# info = filetypeHelper.guess_video(os.path.join(root,i))
|
||||
|
||||
Reference in New Issue
Block a user