Merge lp:~mvo/software-center/thumbnail-test-fixes into lp:software-center

Proposed by Michael Vogt
Status: Merged
Merged at revision: 3200
Proposed branch: lp:~mvo/software-center/thumbnail-test-fixes
Merge into: lp:software-center
Diff against target: 261 lines (+68/-59)
3 files modified
softwarecenter/ui/gtk3/widgets/thumbnail.py (+21/-18)
tests/gtk3/test_widgets.py (+14/-4)
tests/gtk3/windows.py (+33/-37)
To merge this branch: bzr merge lp:~mvo/software-center/thumbnail-test-fixes
Reviewer Review Type Date Requested Status
Gary Lasker (community) Approve
Review via email: mp+125935@code.launchpad.net

Description of the change

Tiny branch that fixes the get_test_screenshot_thumbnail_window()
function and ensures that its properly used in the automatic test.

This is a drive-by branch while trying to figure out why davmor2 sometimes
gets a "screenshot-unavailable" thumbnail even if there is clearly a
screenshot available

To post a comment you must log in.
3201. By Michael Vogt

add missing disconnect for self._on_screenshot_query_complete)

Revision history for this message
Gary Lasker (gary-lasker) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwarecenter/ui/gtk3/widgets/thumbnail.py'
2--- softwarecenter/ui/gtk3/widgets/thumbnail.py 2012-05-30 18:39:55 +0000
3+++ softwarecenter/ui/gtk3/widgets/thumbnail.py 2012-09-24 07:25:22 +0000
4@@ -162,19 +162,21 @@
5 self.loader.disconnect_by_func(
6 self._on_screenshot_download_complete)
7 self.loader.disconnect_by_func(
8+ self._on_screenshot_query_complete)
9+ self.loader.disconnect_by_func(
10 self._on_screenshot_load_error)
11
12 # overrides
13 def do_get_preferred_width(self):
14 if self.data.get_n_screenshots() <= 1:
15- pb = self.button.image.get_pixbuf()
16+ pb = self.main_screenshot.image.get_pixbuf()
17 if pb:
18 width = pb.get_width() + 20
19 return width, width
20 return 320, 320
21
22 def do_get_preferred_height(self):
23- pb = self.button.image.get_pixbuf()
24+ pb = self.main_screenshot.image.get_pixbuf()
25 if pb:
26 height = pb.get_height()
27 if self.data.get_n_screenshots() <= 1:
28@@ -194,18 +196,18 @@
29 def _build_ui(self):
30 self.set_border_width(3)
31 # the frame around the screenshot (placeholder)
32- self.screenshot = Gtk.VBox()
33- self.pack_start(self.screenshot, True, True, 0)
34+ self.screenshot_frame = Gtk.VBox()
35+ self.pack_start(self.screenshot_frame, True, True, 0)
36
37 self.spinner = Gtk.Spinner()
38 self.spinner.set_size_request(*self.SPINNER_SIZE)
39 self.spinner.set_valign(Gtk.Align.CENTER)
40 self.spinner.set_halign(Gtk.Align.CENTER)
41- self.screenshot.add(self.spinner)
42+ self.screenshot_frame.add(self.spinner)
43
44- # clickable screenshot button
45- self.button = ScreenshotButton()
46- self.screenshot.pack_start(self.button, True, False, 0)
47+ # main big clickable screenshot button
48+ self.main_screenshot = ScreenshotButton()
49+ self.screenshot_frame.pack_start(self.main_screenshot, True, False, 0)
50
51 # unavailable layout
52 self.unavailable = Gtk.Label(label=_(self.NOT_AVAILABLE_STRING))
53@@ -213,7 +215,7 @@
54 # force the label state to INSENSITIVE so we get the nice
55 # subtle etched in look
56 self.unavailable.set_state(Gtk.StateType.INSENSITIVE)
57- self.screenshot.add(self.unavailable)
58+ self.screenshot_frame.add(self.unavailable)
59
60 self.thumbnails = ThumbnailGallery(self)
61 self.thumbnails.set_margin_top(5)
62@@ -221,9 +223,9 @@
63 self.pack_end(self.thumbnails, False, False, 0)
64 self.thumbnails.connect(
65 "thumb-selected", self.on_thumbnail_selected)
66- self.button.connect("clicked", self.on_clicked)
67- self.button.connect('enter-notify-event', self._on_enter)
68- self.button.connect('leave-notify-event', self._on_leave)
69+ self.main_screenshot.connect("clicked", self.on_clicked)
70+ self.main_screenshot.connect('enter-notify-event', self._on_enter)
71+ self.main_screenshot.connect('leave-notify-event', self._on_leave)
72 self.show_all()
73
74 def _on_enter(self, widget, event):
75@@ -261,6 +263,7 @@
76 self.thumbnails.set_thumbnails_from_data(screenshots)
77
78 def _on_screenshot_download_complete(self, loader, screenshot_path):
79+
80 try:
81 self.screenshot_pixbuf = GdkPixbuf.Pixbuf.new_from_file(
82 screenshot_path)
83@@ -269,10 +272,10 @@
84 self.loader.emit('error', GObject.GError, e)
85 return False
86
87- #context = self.button.get_style_context()
88+ #context = self.main_screenshot.get_style_context()
89 tw, th = self.MAX_SIZE_CONSTRAINTS
90 pb = self._downsize_pixbuf(self.screenshot_pixbuf, tw, th)
91- self.button.image.set_from_pixbuf(pb)
92+ self.main_screenshot.image.set_from_pixbuf(pb)
93 self.ready = True
94 self.display_image()
95
96@@ -311,8 +314,8 @@
97 self.display_spinner()
98
99 def display_spinner(self):
100- self.button.image.clear()
101- self.button.hide()
102+ self.main_screenshot.image.clear()
103+ self.main_screenshot.hide()
104 self.unavailable.hide()
105 self.spinner.show()
106 self.spinner.start()
107@@ -321,7 +324,7 @@
108 self.spinner.hide()
109 self.spinner.stop()
110 self.unavailable.show()
111- self.button.hide()
112+ self.main_screenshot.hide()
113 acc = self.get_accessible()
114 acc.set_name(_(self.NOT_AVAILABLE_STRING))
115 acc.set_role(Atk.Role.LABEL)
116@@ -330,7 +333,7 @@
117 self.unavailable.hide()
118 self.spinner.stop()
119 self.spinner.hide()
120- self.button.show_all()
121+ self.main_screenshot.show_all()
122 self.thumbnails.show()
123
124 def get_is_actionable(self):
125
126=== modified file 'tests/gtk3/test_widgets.py'
127--- tests/gtk3/test_widgets.py 2012-09-17 14:46:36 +0000
128+++ tests/gtk3/test_widgets.py 2012-09-24 07:25:22 +0000
129@@ -9,6 +9,7 @@
130 DATA_DIR,
131 setup_test_env,
132 do_events,
133+ do_events_with_sleep,
134 )
135 setup_test_env()
136
137@@ -106,10 +107,6 @@
138 win = get_test_buttons_window()
139 self.addCleanup(win.destroy)
140
141- def test_screenshot_thumbnail(self):
142- win = get_test_screenshot_thumbnail_window()
143- self.addCleanup(win.destroy)
144-
145 def test_videoplayer(self):
146 win = get_test_videoplayer_window()
147 self.addCleanup(win.destroy)
148@@ -118,6 +115,19 @@
149 win = get_test_window_apptreeview()
150 self.addCleanup(win.destroy)
151
152+ def test_screenshot_thumbnail(self):
153+ win = get_test_screenshot_thumbnail_window()
154+ self.addCleanup(win.destroy)
155+ t = win.get_data("screenshot_thumbnail_widget")
156+ b = win.get_data("screenshot_thumbnail_cycle_test_button")
157+ for i in range(5):
158+ b.clicked()
159+ do_events_with_sleep(iterations=5)
160+ # ensure that either the big screeshot is visible or the loading
161+ # spinner
162+ self.assertTrue(t.main_screenshot.get_property("visible") or
163+ t.spinner.get_property("visible"))
164+
165
166
167 class TestHWRequirements(unittest.TestCase):
168
169=== modified file 'tests/gtk3/windows.py'
170--- tests/gtk3/windows.py 2012-09-20 00:53:48 +0000
171+++ tests/gtk3/windows.py 2012-09-24 07:25:22 +0000
172@@ -1038,17 +1038,35 @@
173
174
175 def get_test_screenshot_thumbnail_window():
176+
177+ class CycleState(object):
178+ def __init__(self):
179+ self.app_n = 0
180+ self.apps = [application.Application("Movie Player", "totem"),
181+ application.Application("Comix", "comix"),
182+ application.Application("Gimp", "gimp"),
183+ #application.Application("ACE", "uace"),
184+ ]
185+
186+ def testing_cycle_apps(widget, thumb, db, cycle_state):
187+ d = cycle_state.apps[cycle_state.app_n].get_details(db)
188+
189+ if cycle_state.app_n + 1 < len(cycle_state.apps):
190+ cycle_state.app_n += 1
191+ else:
192+ cycle_state.app_n = 0
193+
194+ thumb.fetch_screenshots(d)
195+ return True
196+
197+ cycle_state = CycleState()
198+
199 vb = Gtk.VBox(spacing=6)
200 win = get_test_window(child=vb)
201
202- icons = Gtk.IconTheme.get_default()
203- icons.append_search_path("/usr/share/app-install/icons/")
204-
205+ icons = get_test_gtk3_icon_cache()
206 distro = softwarecenter.distro.get_distro()
207
208- init_sc_css_provider(win, Gtk.Settings.get_default(),
209- Gdk.Screen.get_default())
210-
211 t = thumbnail.ScreenshotGallery(distro, icons)
212 t.connect('draw', t.draw)
213 frame = containers.FramedBox()
214@@ -1056,39 +1074,17 @@
215
216 win.set_data("screenshot_thumbnail_widget", t)
217
218- b = Gtk.Button('A button for focus testing')
219- vb.pack_start(b, True, True, 0)
220+ b = Gtk.Button('A button for cycle testing')
221+ vb.pack_start(b, False, False, 8)
222 win.set_data("screenshot_button_widget", b)
223 vb.pack_start(frame, True, True, 0)
224-
225- cache = pkginfo.get_pkg_info()
226- cache.open()
227-
228- xapian_base_path = "/var/cache/software-center"
229- pathname = os.path.join(xapian_base_path, "xapian")
230- db = database.StoreDatabase(pathname, cache)
231- db.open()
232-
233- apps = [application.Application("Movie Player", "totem"),
234- application.Application("Comix", "comix"),
235- application.Application("Gimp", "gimp"),
236- application.Application("ACE", "uace")]
237-
238- app_n = 0
239-
240- def testing_cycle_apps(_, thumb, apps, db):
241- global app_n
242- d = apps[app_n].get_details(db)
243-
244- if app_n + 1 < len(apps):
245- app_n += 1
246- else:
247- app_n = 0
248-
249- thumb.fetch_screenshots(d)
250- return True
251-
252- b.connect("clicked", testing_cycle_apps, t, apps, db)
253+ win.set_data("screenshot_thumbnail_cycle_test_button", b)
254+
255+ db = get_test_db()
256+ win.show_all()
257+
258+ testing_cycle_apps(None, t, db, cycle_state)
259+ b.connect("clicked", testing_cycle_apps, t, db, cycle_state)
260
261 return win
262

Subscribers

People subscribed via source and target branches