Merge lp:~ahayzen/cappella/cappella10_properties_load_in_thread into lp:cappella

Proposed by Andrew Hayzen
Status: Merged
Approved by: Andrew Hayzen
Approved revision: 100
Merged at revision: 100
Proposed branch: lp:~ahayzen/cappella/cappella10_properties_load_in_thread
Merge into: lp:cappella
Diff against target: 118 lines (+39/-28)
1 file modified
cappella/gui/widget/properties.py (+39/-28)
To merge this branch: bzr merge lp:~ahayzen/cappella/cappella10_properties_load_in_thread
Reviewer Review Type Date Requested Status
Andrew Hayzen Approve
Review via email: mp+161440@code.launchpad.net

Description of the change

* Properties data is now loaded in separate thread

To post a comment you must log in.
Revision history for this message
Andrew Hayzen (ahayzen) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cappella/gui/widget/properties.py'
2--- cappella/gui/widget/properties.py 2013-04-02 22:48:35 +0000
3+++ cappella/gui/widget/properties.py 2013-04-29 15:18:26 +0000
4@@ -20,6 +20,7 @@
5
6 from gi.repository import GdkPixbuf, GObject, Gtk
7 from os.path import getsize
8+from threading import current_thread, Lock, Thread
9 from urllib.request import urlopen
10
11 from ...config.cappella import settings
12@@ -37,6 +38,7 @@
13 def __init__(self, uri, library):
14 self.album_art_helper = AlbumArtHelper()
15 self.library = library
16+ self.lock = Lock()
17 self.uri = uri
18 self.ids = []
19
20@@ -50,13 +52,9 @@
21 if is_media(uri):
22 self.do_build_window()
23
24- self.do_load_box_top()
25-
26- self.do_load_box_bottom()
27-
28- self.do_load_read_only()
29-
30- self.on_changed_change()
31+ self.thread = Thread(target=self.load)
32+ self.thread.daemon = True
33+ self.thread.start()
34
35 #-------------------------------------------------- Connect signals
36 idn = signal.connect("_musicengine_start_int_",
37@@ -442,15 +440,36 @@
38 signal.emit("_library_change_", self.library, self.uri, info)
39
40 # Reload properties window
41- self.do_load_box_top()
42-
43- self.do_load_box_bottom()
44-
45- self.do_load_read_only()
46-
47 self.changed = False # reset changed
48
49- self.on_changed_change() # Update save button
50+ self.thread = Thread(target=self.load)
51+ self.thread.daemon = True
52+ self.thread.start()
53+
54+ return True
55+
56+ def load(self):
57+ """
58+ Load the data into the view
59+ Only run next stage if previous passes
60+ """
61+
62+ self.lock.acquire()
63+
64+ if self.load_safe(self.do_load_box_top):
65+ if self.load_safe(self.do_load_box_bottom):
66+ if self.load_safe(self.do_load_read_only):
67+ if self.load_safe(self.on_changed_change):
68+ self.lock.release()
69+
70+ def load_safe(self, method):
71+ """ Load the section but stop if a new thread has been started """
72+
73+ if self.thread != current_thread():
74+ self.lock.release()
75+ return False
76+
77+ method()
78
79 return True
80
81@@ -477,15 +496,11 @@
82 self.uri, self.library = data # Set new data
83
84 # Reload properties window
85- self.do_load_box_top()
86-
87- self.do_load_box_bottom()
88-
89- self.do_load_read_only()
90-
91 self.changed = False # reset changed
92
93- self.on_changed_change() # update save button
94+ self.thread = Thread(target=self.load)
95+ self.thread.daemon = True
96+ self.thread.start()
97
98 def on_button_previous(self, *args):
99 """ Select previous file for properties window """
100@@ -510,15 +525,11 @@
101 self.uri, self.library = data # Set new data
102
103 # Reload properties window
104- self.do_load_box_top()
105-
106- self.do_load_box_bottom()
107-
108- self.do_load_read_only()
109-
110 self.changed = False # reset changed
111
112- self.on_changed_change() # update save button
113+ self.thread = Thread(target=self.load)
114+ self.thread.daemon = True
115+ self.thread.start()
116
117 def on_changed_change(self):
118 """ Update saved button state """

Subscribers

People subscribed via source and target branches

to all changes: