diff --git a/src/ctrls/c_main.py b/src/ctrls/c_main.py index 24165e5..d889837 100644 --- a/src/ctrls/c_main.py +++ b/src/ctrls/c_main.py @@ -142,9 +142,11 @@ class MainController(Controller): self.model.rename(id, ret['filename']) self.model.update_desc_and_note(id, ret['description'], ret['note']) 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): - image = Dialogs.LoadImageFile().run() + image, only_thumbs = Dialogs.LoadImageFile().run() if not image: return try: @@ -153,6 +155,8 @@ class MainController(Controller): for path in list_of_paths: id = model.get_value(model.get_iter(path),0) self.model.add_thumbnail(image, id) + self.model.unsaved_project = True + self.__set_title(filepath=self.model.filename, modified=True) except: if __debug__: print "c_main.py: on_add_thumb1_activate(): error on getting selected items or creating thumbnails" return @@ -174,6 +178,9 @@ class MainController(Controller): except: if __debug__: print "c_main.py: on_remove_thumb1_activate(): error on getting selected items or removing thumbnails" return + + self.model.unsaved_project = True + self.__set_title(filepath=self.model.filename, modified=True) self.__get_item_info(id) return @@ -192,6 +199,9 @@ class MainController(Controller): except: if __debug__: print "c_main.py: on_remove_thumb1_activate(): error on getting selected items or removing thumbnails" return + + self.model.unsaved_project = True + self.__set_title(filepath=self.model.filename, modified=True) self.__get_item_info(id) return @@ -200,10 +210,13 @@ class MainController(Controller): iter = model.get_iter(path) id = model.get_value(iter, 0) img = self.model.get_image_path(id) - if self.model.config.confd['imgview'] and len(self.model.config.confd['imgprog'])>0: - popen("%s %s" % (self.model.config.confd['imgprog'], img)) + if img: + if self.model.config.confd['imgview'] and len(self.model.config.confd['imgprog'])>0: + popen("%s %s" % (self.model.config.confd['imgprog'], img)) + else: + ImageView(img) else: - ImageView(img) + Dialogs.Inf("Image view", "No Image", "This item have no real image, only thumbnail.") def on_rename1_activate(self, widget): model, iter = self.view['discs'].get_selection().get_selected() @@ -216,6 +229,8 @@ class MainController(Controller): if new_name != None and new_name != name: self.model.rename(id, new_name) 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): try: @@ -244,6 +259,9 @@ class MainController(Controller): except TypeError: self.model.get_root_entries(1) return + + self.model.unsaved_project = True + self.__set_title(filepath=self.model.filename, modified=True) return def on_tag_cloud_textview_motion_notify_event(self, widget): @@ -374,6 +392,11 @@ class MainController(Controller): return False 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() model = self.view['images'].get_model() iter = model.get_iter(list_of_paths[0]) @@ -388,6 +411,10 @@ class MainController(Controller): self.__get_item_info(id) except: pass + + self.model.unsaved_project = True + self.__set_title(filepath=self.model.filename, modified=True) + return def on_img_add_activate(self, menu_item): self.on_add_image1_activate(menu_item) @@ -545,7 +572,12 @@ class MainController(Controller): print self.view['files'].get_cursor() 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: return @@ -562,7 +594,11 @@ class MainController(Controller): id = model.get_value(iter, 0) except: 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) return @@ -678,6 +714,11 @@ class MainController(Controller): return 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() model = self.view['files'].get_model() iter = model.get_iter(path) @@ -685,6 +726,8 @@ class MainController(Controller): if id: self.model.del_thumbnail(id) self.__get_item_info(id) + self.model.unsaved_project = True + self.__set_title(filepath=self.model.filename, modified=True) return def on_debugbtn_clicked(self, widget): @@ -799,6 +842,8 @@ class MainController(Controller): current_id) self.model.unsaved_project = True self.__set_title(filepath=self.model.filename, modified=True) + else: + deviceHelper.volumount(self.model.config.confd['cd']) return True else: Dialogs.Wrn("Error mounting device - pyGTKtalog", diff --git a/src/models/m_main.py b/src/models/m_main.py index d1b4a04..6461958 100644 --- a/src/models/m_main.py +++ b/src/models/m_main.py @@ -44,7 +44,6 @@ except ImportError: import dummy_threading as _threading from m_config import ConfigModel -from m_details import DetailsModel try: from utils.thumbnail import Thumbnail from utils.img import Img @@ -97,7 +96,6 @@ class MainModel(ModelMT): self.abort = False self.source = self.CD self.config.load() - self.details = DetailsModel() # Directory tree: id, name, icon, type self.discs_tree = gtk.TreeStore(gobject.TYPE_INT, gobject.TYPE_STRING, @@ -135,7 +133,7 @@ class MainModel(ModelMT): ]''' return - def add_image(self, image, id): + def add_image(self, image, id, only_thumbs=False): """add single image to file/directory""" sql = """insert into images(file_id, thumbnail, filename) values(?, null, null)""" @@ -149,8 +147,12 @@ class MainModel(ModelMT): tp, ip, rc = Img(image, self.internal_dirname).save(res[0]) if rc != -1: 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, - (ip.split(self.internal_dirname)[1][1:], + (img, tp.split(self.internal_dirname)[1][1:], res[0])) self.db_connection.commit() @@ -163,7 +165,8 @@ class MainModel(ModelMT): res = self.db_cursor.fetchall() if len(res) > 0: for fn in res: - os.unlink(os.path.join(self.internal_dirname, fn[0])) + if fn[0]: + os.unlink(os.path.join(self.internal_dirname, fn[0])) os.unlink(os.path.join(self.internal_dirname, fn[1])) # remove images records @@ -176,8 +179,9 @@ class MainModel(ModelMT): sql = """select filename, thumbnail from images where id=?""" self.db_cursor.execute(sql, (id,)) res = self.db_cursor.fetchone() - if res[0]: - os.unlink(os.path.join(self.internal_dirname, res[0])) + if res: + if res[0]: + os.unlink(os.path.join(self.internal_dirname, res[0])) os.unlink(os.path.join(self.internal_dirname, res[1])) if __debug__: @@ -537,7 +541,8 @@ class MainModel(ModelMT): res = db_cursor.fetchall() if len(res) > 0: for fn in res: - os.unlink(os.path.join(self.internal_dirname, fn[0])) + if res[0]: + os.unlink(os.path.join(self.internal_dirname, fn[0])) os.unlink(os.path.join(self.internal_dirname, fn[1])) # remove thumbs records @@ -654,7 +659,8 @@ class MainModel(ModelMT): self.db_cursor.execute(sql, (img_id,)) res = self.db_cursor.fetchone() if res: - return os.path.join(self.internal_dirname, res[0]) + if res[0]: + return os.path.join(self.internal_dirname, res[0]) return None def update_desc_and_note(self, id, desc='', note=''): @@ -1072,8 +1078,7 @@ class MainModel(ModelMT): self.delete(self.currentid, db_cursor, db_connection) self.currentid = None - else: - print "new directory/cd" + db_cursor.close() db_connection.commit() db_connection.close() diff --git a/src/utils/img.py b/src/utils/img.py index 80048f2..fed850b 100644 --- a/src/utils/img.py +++ b/src/utils/img.py @@ -32,8 +32,8 @@ import Image class Img(object): def __init__(self, filename=None, base=''): self.root = 'images' - self.x = 96 - self.y = 96 + self.x = 160 + self.y = 160 self.filename = filename self.base = base @@ -101,5 +101,7 @@ class Img(object): im = Image.open(self.filename).convert('RGB') except: return None - im.thumbnail((self.x, self.y), Image.ANTIALIAS) + x, y = im.size + if x > self.x or y > self.y: + im.thumbnail((self.x, self.y), Image.ANTIALIAS) return im diff --git a/src/views/v_dialogs.py b/src/views/v_dialogs.py index 5ba304d..ec7f26b 100644 --- a/src/views/v_dialogs.py +++ b/src/views/v_dialogs.py @@ -354,6 +354,7 @@ class LoadImageFile(object): self.dialog.set_current_folder_uri(self.URI) response = self.dialog.run() filenames = None + only_thumbs = False if response == gtk.RESPONSE_OK: try: @@ -361,12 +362,15 @@ class LoadImageFile(object): filenames = self.dialog.get_filenames() else: filenames = self.dialog.get_filename() + + if self.dialog.get_extra_widget().get_active(): + only_thumbs = True except: pass self.__class__.URI = self.dialog.get_current_folder_uri() self.dialog.destroy() - return filenames + return filenames, only_thumbs def update_preview_cb(self, widget): filename = self.dialog.get_preview_filename() diff --git a/src/views/v_main.py b/src/views/v_main.py index 55b0de6..d88a0db 100644 --- a/src/views/v_main.py +++ b/src/views/v_main.py @@ -25,7 +25,6 @@ import os.path import utils.globals from gtkmvc import View -from v_details import DetailsView class MainView(View): """This handles only the graphical representation of the