From 1940536a9546a2d76e3aa8815a7d9eead2e14056 Mon Sep 17 00:00:00 2001 From: Felipe Reyes Date: Wed, 9 Jul 2008 16:00:06 -0400 Subject: [PATCH] added locks to handle the threads toavoid segfault on gtk --- marvin/ui/marvin.glade | 382 ++++++++++++++++++++++++++----------------------- marvin/view.py | 24 +++- 2 files changed, 225 insertions(+), 181 deletions(-) diff --git a/marvin/ui/marvin.glade b/marvin/ui/marvin.glade index 7d36e2b..97070e4 100644 --- a/marvin/ui/marvin.glade +++ b/marvin/ui/marvin.glade @@ -1,6 +1,209 @@ + + + + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + + + True + GTK_RESIZE_QUEUE + + + True + gtk-missing-image + + + + + + + + + 400 + 300 + + + + True + + + + + + + + + True + True + + + True + 5 + + + True + + + False + False + + + + + True + + + False + False + 1 + + + + + + + + False + True + + + + + True + + + True + 5 + + + True + Filter + + + False + False + + + + + True + True + + + + False + False + 1 + + + + + True + True + True + gtk-find + True + 0 + + + + False + 2 + + + + + False + 5 + + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + + + True + True + + + + + + + 1 + + + + + True + True + + + + + 2 + + + + + True + + + True + True + + + + + + True + True + True + 0 + + + True + gtk-cancel + + + + + False + False + 1 + + + + + False + False + 3 + + + + + True + 2 + + + False + 4 + + + + + 300 5 @@ -186,183 +389,4 @@ - - 400 - 300 - - - - True - - - - - - - - - True - True - - - True - 5 - - - True - - - False - False - - - - - True - - - False - False - 1 - - - - - - - - False - True - - - - - True - - - True - 5 - - - True - Filter - - - False - False - - - - - True - True - - - - False - False - 1 - - - - - True - True - True - gtk-find - True - 0 - - - - False - 2 - - - - - False - 5 - - - - - True - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - - - True - True - - - - - - - 1 - - - - - True - True - - - - - 2 - - - - - True - True - - - - False - False - 3 - - - - - True - 2 - - - False - 4 - - - - - - - - - - - - True - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - - - True - GTK_RESIZE_QUEUE - - - True - gtk-missing-image - - - - - - - diff --git a/marvin/view.py b/marvin/view.py index 7b8a3c1..23fb804 100644 --- a/marvin/view.py +++ b/marvin/view.py @@ -37,6 +37,7 @@ import os import sys import shutil import time +import datetime try: import EXIF except: @@ -129,8 +130,8 @@ class MainWindow (object): # prepare and launch the thread that fills the iconview model - thread = PhotoListThread(list_photos) - thread.start() + self._thread = PhotoListThread(list_photos) + self._thread.start() def _on_import_clicked(self, menuitem): ImportWindow() @@ -152,6 +153,9 @@ class MainWindow (object): sql_filter = entry.get_text() query = "select id, uri from photos " + sql_filter + + if not self._thread.stop.isSet(): + self._thread.stop.set() thread = PhotoListThread(model, query) thread.start() @@ -329,6 +333,7 @@ class PhotoListThread (threading.Thread): def __init__ (self, model, query=None, use_progressbar=False): super(PhotoListThread, self).__init__() + if query is not None: self._query = query else: @@ -338,16 +343,23 @@ class PhotoListThread (threading.Thread): def run (self): + inicio = datetime.datetime.now() + global wTree + gtk.gdk.threads_enter() progressbar = wTree.get_widget("progressbar1") progressbar.show() self._model.clear() + gtk.gdk.threads_leave() + conn = connect_to_db() c = conn.cursor() c.execute (self._query) i=0 for row in c: + + gtk.gdk.threads_enter() i += 1 try: p = Photo(row[0], row[1]) @@ -358,10 +370,16 @@ class PhotoListThread (threading.Thread): pass progressbar.pulse() + gtk.gdk.threads_leave() + gtk.gdk.threads_enter() Progressbar.push_message(_("%d pictures found.") % (i)) conn.close() progressbar.hide() + gtk.gdk.threads_leave() + + fin = datetime.datetime.now() + print "Took %s load the pictures" % (fin-inicio) class Progressbar(object): @@ -622,7 +640,9 @@ def start(): wnd = MainWindow() + gtk.gdk.threads_enter() gtk.main() + gtk.gdk.threads_leave() if __name__ == '__main__': -- 2.11.4.GIT