mirror of
https://github.com/gryf/pygtktalog.git
synced 2025-12-17 11:30:19 +01:00
* Small improvements.
* Added functionality for adding thumbnails only (without big images).
This commit is contained in:
@@ -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 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:
|
||||
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])
|
||||
@@ -389,6 +412,10 @@ class MainController(Controller):
|
||||
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",
|
||||
|
||||
@@ -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,6 +165,7 @@ class MainModel(ModelMT):
|
||||
res = self.db_cursor.fetchall()
|
||||
if len(res) > 0:
|
||||
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[1]))
|
||||
|
||||
@@ -176,6 +179,7 @@ class MainModel(ModelMT):
|
||||
sql = """select filename, thumbnail from images where id=?"""
|
||||
self.db_cursor.execute(sql, (id,))
|
||||
res = self.db_cursor.fetchone()
|
||||
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]))
|
||||
@@ -537,6 +541,7 @@ class MainModel(ModelMT):
|
||||
res = db_cursor.fetchall()
|
||||
if len(res) > 0:
|
||||
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[1]))
|
||||
|
||||
@@ -654,6 +659,7 @@ class MainModel(ModelMT):
|
||||
self.db_cursor.execute(sql, (img_id,))
|
||||
res = self.db_cursor.fetchone()
|
||||
if res:
|
||||
if res[0]:
|
||||
return os.path.join(self.internal_dirname, res[0])
|
||||
return None
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
x, y = im.size
|
||||
if x > self.x or y > self.y:
|
||||
im.thumbnail((self.x, self.y), Image.ANTIALIAS)
|
||||
return im
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user