1
0
mirror of https://github.com/gryf/pygtktalog.git synced 2025-12-17 19:40:21 +01:00

* Small improvements.

* Added functionality for adding thumbnails only (without big images).
This commit is contained in:
2008-04-14 18:49:31 +00:00
parent 59db470ffa
commit 81d37ba053
5 changed files with 77 additions and 22 deletions

View File

@@ -142,9 +142,11 @@ class MainController(Controller):
self.model.rename(id, ret['filename']) self.model.rename(id, ret['filename'])
self.model.update_desc_and_note(id, ret['description'], ret['note']) self.model.update_desc_and_note(id, ret['description'], ret['note'])
self.__get_item_info(id) self.__get_item_info(id)
self.model.unsaved_project = True
self.__set_title(filepath=self.model.filename, modified=True)
def on_add_thumb1_activate(self, menu_item): def on_add_thumb1_activate(self, menu_item):
image = Dialogs.LoadImageFile().run() image, only_thumbs = Dialogs.LoadImageFile().run()
if not image: if not image:
return return
try: try:
@@ -153,6 +155,8 @@ class MainController(Controller):
for path in list_of_paths: for path in list_of_paths:
id = model.get_value(model.get_iter(path),0) id = model.get_value(model.get_iter(path),0)
self.model.add_thumbnail(image, id) self.model.add_thumbnail(image, id)
self.model.unsaved_project = True
self.__set_title(filepath=self.model.filename, modified=True)
except: except:
if __debug__: print "c_main.py: on_add_thumb1_activate(): error on getting selected items or creating thumbnails" if __debug__: print "c_main.py: on_add_thumb1_activate(): error on getting selected items or creating thumbnails"
return return
@@ -174,6 +178,9 @@ class MainController(Controller):
except: except:
if __debug__: print "c_main.py: on_remove_thumb1_activate(): error on getting selected items or removing thumbnails" if __debug__: print "c_main.py: on_remove_thumb1_activate(): error on getting selected items or removing thumbnails"
return return
self.model.unsaved_project = True
self.__set_title(filepath=self.model.filename, modified=True)
self.__get_item_info(id) self.__get_item_info(id)
return return
@@ -192,6 +199,9 @@ class MainController(Controller):
except: except:
if __debug__: print "c_main.py: on_remove_thumb1_activate(): error on getting selected items or removing thumbnails" if __debug__: print "c_main.py: on_remove_thumb1_activate(): error on getting selected items or removing thumbnails"
return return
self.model.unsaved_project = True
self.__set_title(filepath=self.model.filename, modified=True)
self.__get_item_info(id) self.__get_item_info(id)
return return
@@ -200,10 +210,13 @@ class MainController(Controller):
iter = model.get_iter(path) iter = model.get_iter(path)
id = model.get_value(iter, 0) id = model.get_value(iter, 0)
img = self.model.get_image_path(id) img = self.model.get_image_path(id)
if img:
if self.model.config.confd['imgview'] and len(self.model.config.confd['imgprog'])>0: if self.model.config.confd['imgview'] and len(self.model.config.confd['imgprog'])>0:
popen("%s %s" % (self.model.config.confd['imgprog'], img)) popen("%s %s" % (self.model.config.confd['imgprog'], img))
else: else:
ImageView(img) ImageView(img)
else:
Dialogs.Inf("Image view", "No Image", "This item have no real image, only thumbnail.")
def on_rename1_activate(self, widget): def on_rename1_activate(self, widget):
model, iter = self.view['discs'].get_selection().get_selected() model, iter = self.view['discs'].get_selection().get_selected()
@@ -216,6 +229,8 @@ class MainController(Controller):
if new_name != None and new_name != name: if new_name != None and new_name != name:
self.model.rename(id, new_name) self.model.rename(id, new_name)
self.__set_title(filepath=self.model.filename, modified=True) self.__set_title(filepath=self.model.filename, modified=True)
self.model.unsaved_project = True
self.__set_title(filepath=self.model.filename, modified=True)
def on_rename2_activate(self, widget): def on_rename2_activate(self, widget):
try: try:
@@ -244,6 +259,9 @@ class MainController(Controller):
except TypeError: except TypeError:
self.model.get_root_entries(1) self.model.get_root_entries(1)
return return
self.model.unsaved_project = True
self.__set_title(filepath=self.model.filename, modified=True)
return return
def on_tag_cloud_textview_motion_notify_event(self, widget): def on_tag_cloud_textview_motion_notify_event(self, widget):
@@ -374,6 +392,11 @@ class MainController(Controller):
return False return False
def on_img_delete_activate(self, menu_item): def on_img_delete_activate(self, menu_item):
if self.model.config.confd['delwarn']:
obj = Dialogs.Qst('Delete image', 'Delete image?',
'Selected image will be permanently removed from catalog.')
if not obj.run():
return
list_of_paths = self.view['images'].get_selected_items() list_of_paths = self.view['images'].get_selected_items()
model = self.view['images'].get_model() model = self.view['images'].get_model()
iter = model.get_iter(list_of_paths[0]) iter = model.get_iter(list_of_paths[0])
@@ -389,6 +412,10 @@ class MainController(Controller):
except: except:
pass pass
self.model.unsaved_project = True
self.__set_title(filepath=self.model.filename, modified=True)
return
def on_img_add_activate(self, menu_item): def on_img_add_activate(self, menu_item):
self.on_add_image1_activate(menu_item) self.on_add_image1_activate(menu_item)
@@ -545,7 +572,12 @@ class MainController(Controller):
print self.view['files'].get_cursor() print self.view['files'].get_cursor()
def on_add_image1_activate(self, menu_item): def on_add_image1_activate(self, menu_item):
images = Dialogs.LoadImageFile(True).run() dialog = Dialogs.LoadImageFile(True)
toggle = gtk.CheckButton("Don't copy images. Generate only thumbnails.")
toggle.show()
dialog.dialog.set_extra_widget(toggle)
images, only_thumbs = dialog.run()
if not images: if not images:
return return
@@ -562,7 +594,11 @@ class MainController(Controller):
id = model.get_value(iter, 0) id = model.get_value(iter, 0)
except: except:
return return
self.model.add_image(image, id) self.model.add_image(image, id, only_thumbs)
self.model.unsaved_project = True
self.__set_title(filepath=self.model.filename, modified=True)
self.__get_item_info(id) self.__get_item_info(id)
return return
@@ -678,6 +714,11 @@ class MainController(Controller):
return return
def on_th_delete_activate(self, menu_item): def on_th_delete_activate(self, menu_item):
if self.model.config.confd['delwarn']:
obj = Dialogs.Qst('Delete thumbnail', 'Delete thumbnail?',
'Current thumbnail will be permanently removed from catalog.')
if not obj.run():
return
path, column = self.view['files'].get_cursor() path, column = self.view['files'].get_cursor()
model = self.view['files'].get_model() model = self.view['files'].get_model()
iter = model.get_iter(path) iter = model.get_iter(path)
@@ -685,6 +726,8 @@ class MainController(Controller):
if id: if id:
self.model.del_thumbnail(id) self.model.del_thumbnail(id)
self.__get_item_info(id) self.__get_item_info(id)
self.model.unsaved_project = True
self.__set_title(filepath=self.model.filename, modified=True)
return return
def on_debugbtn_clicked(self, widget): def on_debugbtn_clicked(self, widget):
@@ -799,6 +842,8 @@ class MainController(Controller):
current_id) current_id)
self.model.unsaved_project = True self.model.unsaved_project = True
self.__set_title(filepath=self.model.filename, modified=True) self.__set_title(filepath=self.model.filename, modified=True)
else:
deviceHelper.volumount(self.model.config.confd['cd'])
return True return True
else: else:
Dialogs.Wrn("Error mounting device - pyGTKtalog", Dialogs.Wrn("Error mounting device - pyGTKtalog",

View File

@@ -44,7 +44,6 @@ except ImportError:
import dummy_threading as _threading import dummy_threading as _threading
from m_config import ConfigModel from m_config import ConfigModel
from m_details import DetailsModel
try: try:
from utils.thumbnail import Thumbnail from utils.thumbnail import Thumbnail
from utils.img import Img from utils.img import Img
@@ -97,7 +96,6 @@ class MainModel(ModelMT):
self.abort = False self.abort = False
self.source = self.CD self.source = self.CD
self.config.load() self.config.load()
self.details = DetailsModel()
# Directory tree: id, name, icon, type # Directory tree: id, name, icon, type
self.discs_tree = gtk.TreeStore(gobject.TYPE_INT, gobject.TYPE_STRING, self.discs_tree = gtk.TreeStore(gobject.TYPE_INT, gobject.TYPE_STRING,
@@ -135,7 +133,7 @@ class MainModel(ModelMT):
]''' ]'''
return return
def add_image(self, image, id): def add_image(self, image, id, only_thumbs=False):
"""add single image to file/directory""" """add single image to file/directory"""
sql = """insert into images(file_id, thumbnail, filename) sql = """insert into images(file_id, thumbnail, filename)
values(?, null, null)""" values(?, null, null)"""
@@ -149,8 +147,12 @@ class MainModel(ModelMT):
tp, ip, rc = Img(image, self.internal_dirname).save(res[0]) tp, ip, rc = Img(image, self.internal_dirname).save(res[0])
if rc != -1: if rc != -1:
sql = """update images set filename=?, thumbnail=? where id=?""" sql = """update images set filename=?, thumbnail=? where id=?"""
if only_thumbs:
img = None
else:
img = ip.split(self.internal_dirname)[1][1:]
self.db_cursor.execute(sql, self.db_cursor.execute(sql,
(ip.split(self.internal_dirname)[1][1:], (img,
tp.split(self.internal_dirname)[1][1:], tp.split(self.internal_dirname)[1][1:],
res[0])) res[0]))
self.db_connection.commit() self.db_connection.commit()
@@ -163,6 +165,7 @@ class MainModel(ModelMT):
res = self.db_cursor.fetchall() res = self.db_cursor.fetchall()
if len(res) > 0: if len(res) > 0:
for fn in res: for fn in res:
if fn[0]:
os.unlink(os.path.join(self.internal_dirname, fn[0])) os.unlink(os.path.join(self.internal_dirname, fn[0]))
os.unlink(os.path.join(self.internal_dirname, fn[1])) os.unlink(os.path.join(self.internal_dirname, fn[1]))
@@ -176,6 +179,7 @@ class MainModel(ModelMT):
sql = """select filename, thumbnail from images where id=?""" sql = """select filename, thumbnail from images where id=?"""
self.db_cursor.execute(sql, (id,)) self.db_cursor.execute(sql, (id,))
res = self.db_cursor.fetchone() res = self.db_cursor.fetchone()
if res:
if res[0]: if res[0]:
os.unlink(os.path.join(self.internal_dirname, res[0])) os.unlink(os.path.join(self.internal_dirname, res[0]))
os.unlink(os.path.join(self.internal_dirname, res[1])) os.unlink(os.path.join(self.internal_dirname, res[1]))
@@ -537,6 +541,7 @@ class MainModel(ModelMT):
res = db_cursor.fetchall() res = db_cursor.fetchall()
if len(res) > 0: if len(res) > 0:
for fn in res: for fn in res:
if res[0]:
os.unlink(os.path.join(self.internal_dirname, fn[0])) os.unlink(os.path.join(self.internal_dirname, fn[0]))
os.unlink(os.path.join(self.internal_dirname, fn[1])) os.unlink(os.path.join(self.internal_dirname, fn[1]))
@@ -654,6 +659,7 @@ class MainModel(ModelMT):
self.db_cursor.execute(sql, (img_id,)) self.db_cursor.execute(sql, (img_id,))
res = self.db_cursor.fetchone() res = self.db_cursor.fetchone()
if res: if res:
if res[0]:
return os.path.join(self.internal_dirname, res[0]) return os.path.join(self.internal_dirname, res[0])
return None return None
@@ -1072,8 +1078,7 @@ class MainModel(ModelMT):
self.delete(self.currentid, db_cursor, db_connection) self.delete(self.currentid, db_cursor, db_connection)
self.currentid = None self.currentid = None
else:
print "new directory/cd"
db_cursor.close() db_cursor.close()
db_connection.commit() db_connection.commit()
db_connection.close() db_connection.close()

View File

@@ -32,8 +32,8 @@ 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 = 96 self.x = 160
self.y = 96 self.y = 160
self.filename = filename self.filename = filename
self.base = base self.base = base
@@ -101,5 +101,7 @@ class Img(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
if x > self.x or y > self.y:
im.thumbnail((self.x, self.y), Image.ANTIALIAS) im.thumbnail((self.x, self.y), Image.ANTIALIAS)
return im return im

View File

@@ -354,6 +354,7 @@ class LoadImageFile(object):
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
if response == gtk.RESPONSE_OK: if response == gtk.RESPONSE_OK:
try: try:
@@ -361,12 +362,15 @@ class LoadImageFile(object):
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():
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 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()

View File

@@ -25,7 +25,6 @@
import os.path import os.path
import utils.globals import utils.globals
from gtkmvc import View from gtkmvc import View
from v_details import DetailsView
class MainView(View): class MainView(View):
"""This handles only the graphical representation of the """This handles only the graphical representation of the