Merge lp:~mblayman/entertainer/preview-problem into lp:entertainer

Proposed by Matt Layman
Status: Merged
Approved by: Matt Layman
Approved revision: 360
Merged at revision: not available
Proposed branch: lp:~mblayman/entertainer/preview-problem
Merge into: lp:entertainer
Diff against target: None lines
To merge this branch: bzr merge lp:~mblayman/entertainer/preview-problem
Reviewer Review Type Date Requested Status
Jamie Bennett (community) Approve
Samuel Buffet (community) Approve
Review via email: mp+5325@code.launchpad.net

Commit message

The main menu now keeps focus appropriately for left and right directions and all previews now fade in. (Matt Layman)

To post a comment you must log in.
Revision history for this message
Matt Layman (mblayman) wrote :

I was reviewing Samuel's branch on the main menu focus issue (Bug 357056) and thought the problem was bigger than branch submitted. I decided to hack on it because my brain was having some trouble spelling out the problems with the branch (aside from how to break the patch).

I was left with two results:
1) A fix for the problem that doesn't break. Samuel, it turns out you just had the item.get_name() check in the wrong if statement.
2) The preview menu code on the main screen has been cleaned up quite a bit. Now the preview will fade in for either the RSS or the Now Playing preview.

A note on the second point. I changed some method names because they were fairly deceptive. I changed the "show_playing_preview" and "show_rss_preview" because they weren't really showing those previews. They actually recreate the menus and display them again. I changed "show" to "_create" so that it's clear what they are doing. Maybe someone will want to change them in the future to save calls to the feed library or prevent recreating a video texture, but it will at least be clear what they'll have to change.

In summary, I probably went way overboard to fix the bug in the branch that I was supposed to be reviewing for Samuel, but I think that the result is quite nice anyway.

Revision history for this message
Samuel Buffet (samuel-buffet) wrote :

Good Matt,

I approve those changes.

FYI, I've found the idea so good that I've merged those changes in *new-scrollmenu* to be able to continue modifications/improvements to take care of this issue in the context of the new signal based menu.

Thanks

Samuel-

review: Approve
Revision history for this message
Jamie Bennett (jamiebennett) wrote :

Good work Matt. Thorough and good code reuse.

 review approve

On Wed, 2009-04-08 at 02:55 +0000, Matt Layman wrote:
> Matt Layman has proposed merging lp:~laymansterms/entertainer/preview-problem into lp:entertainer.
>
> Requested reviews:
> Entertainer Release Team (entertainer-releases)
>
> I was reviewing Samuel's branch on the main menu focus issue (Bug 357056) and thought the problem was bigger than branch submitted. I decided to hack on it because my brain was having some trouble spelling out the problems with the branch (aside from how to break the patch).
>
> I was left with two results:
> 1) A fix for the problem that doesn't break. Samuel, it turns out you just had the item.get_name() check in the wrong if statement.
> 2) The preview menu code on the main screen has been cleaned up quite a bit. Now the preview will fade in for either the RSS or the Now Playing preview.
>
> A note on the second point. I changed some method names because they were fairly deceptive. I changed the "show_playing_preview" and "show_rss_preview" because they weren't really showing those previews. They actually recreate the menus and display them again. I changed "show" to "_create" so that it's clear what they are doing. Maybe someone will want to change them in the future to save calls to the feed library or prevent recreating a video texture, but it will at least be clear what they'll have to change.
>
> In summary, I probably went way overboard to fix the bug in the branch that I was supposed to be reviewing for Samuel, but I think that the result is quite nice anyway.

review: Approve
Revision history for this message
Matt Layman (mblayman) wrote :

Commit Message: The main menu now keeps focus appropriately for left and right directions and all previews now fade in. (Matt Layman)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'entertainerlib/frontend/gui/screens/main.py'
2--- entertainerlib/frontend/gui/screens/main.py 2009-03-02 03:11:24 +0000
3+++ entertainerlib/frontend/gui/screens/main.py 2009-04-08 02:31:06 +0000
4@@ -44,10 +44,12 @@
5 self.preview = clutter.Group() # Group that contains preview actors
6 self.preview.set_position(self.get_abs_x(0.07), self.get_abs_y(0.1))
7 self.preview.show()
8+ self.preview.set_opacity(0x00)
9 self.add(self.preview)
10
11 self.active_menu = "main"
12- self.rss_preview_menu = None # Pointer to the current preview menu
13+ self.rss_preview_menu = self._create_rss_preview_menu()
14+ self.preview.add(self.rss_preview_menu)
15
16 self.menu = None
17 self.playing_item = None
18@@ -56,6 +58,32 @@
19 clock = ClockLabel(0.13, "screentitle", 0, 0.87)
20 self.add(clock)
21
22+ def _create_rss_preview_menu(self):
23+ '''Create the RSS preview menu that will show feed highlights. An
24+ uninitialized menu will be returned to prevent move errors if there
25+ is nothing in the feed library.'''
26+ menu = TextMenu(self.theme, self.config.show_effects())
27+
28+ if self.feed_library.is_empty() is False:
29+ menu.set_row_count(1)
30+ menu.set_position(self.get_abs_x(0.035), self.get_abs_y(0.12))
31+ menu.set_item_size(self.get_abs_x(0.549), self.get_abs_y(0.078))
32+
33+ # List of latest entries. pack = (Feed object, Entry object)
34+ entries = self.feed_library.get_latest_entries(5)
35+ for pack in entries:
36+ text = pack[0].get_title() + " - " + pack[1].get_title()
37+ item = TextMenuItem(0.549, 0.078,
38+ FeedEntryParser().strip_tags(text),
39+ pack[1].get_date())
40+ kwargs = { 'feed' : pack[0], 'entry' : pack[1] }
41+ item.set_userdata(kwargs)
42+ menu.add_actor(item)
43+
44+ menu.set_active(False)
45+
46+ return menu
47+
48 def create_main_menu(self):
49 """Create main menu of the home screen"""
50 self.menu = ScrollMenu(10, 60, self.config.show_effects())
51@@ -101,8 +129,10 @@
52
53 self.add(self.menu)
54
55- def show_playing_preview(self):
56- """Create a group that displays information on current media."""
57+ def _create_playing_preview(self):
58+ '''Create the Now Playing preview sidebar.'''
59+ preview = clutter.Group()
60+
61 # Video preview of current media
62 video_texture = self.media_player.get_texture()
63 if video_texture == None:
64@@ -141,67 +171,40 @@
65 rect.set_size(int(new_width + 6), int(new_height + 6))
66 rect.set_position(rect_x, rect_y)
67 rect.set_color((128, 128, 128, 192))
68- self.preview.add(rect)
69+ preview.add(rect)
70
71- self.preview.add(video_texture)
72+ preview.add(video_texture)
73
74 title_text = _("Now Playing: %(title)s") % \
75 {'title': self.media_player.get_media_title()}
76 title = Label(0.03, "text", 0.03, 0.74, title_text)
77- self.preview.add(title)
78-
79- def show_rss_preview(self):
80- """Rss preview"""
81+ preview.add(title)
82+
83+ return preview
84+
85+ def _create_rss_preview(self):
86+ '''Create the RSS preview sidebar.'''
87+ preview = clutter.Group()
88+
89+ # RSS Icon
90+ icon = Texture(self.theme.getImage("rss_icon"), 0, 0.04)
91+ icon.set_scale(0.6, 0.6)
92+ preview.add(icon)
93+
94+ # RSS Feed Title
95+ title = Label(0.075, "title", 0.045, 0.03, _("Recent headlines"))
96+ preview.add(title)
97
98 if self.feed_library.is_empty() is False:
99- # RSS Icon
100- icon = Texture(self.theme.getImage("rss_icon"), 0, 0.04)
101- icon.set_scale(0.6, 0.6)
102-
103- # RSS Feed Title
104- title = Label(0.075, "title", 0.045, 0.03, _("Recent headlines"))
105-
106- menu = TextMenu(self.theme, self.config.show_effects())
107- menu.set_row_count(1)
108- menu.set_position(self.get_abs_x(0.035), self.get_abs_y(0.12))
109- menu.set_item_size(self.get_abs_x(0.549), self.get_abs_y(0.078))
110-
111- # List of latest entries. pack = (Feed object, Entry object)
112- entries = self.feed_library.get_latest_entries(5)
113- for pack in entries:
114- text = pack[0].get_title() + " - " + pack[1].get_title()
115- item = TextMenuItem(0.549, 0.078,
116- FeedEntryParser().strip_tags(text),
117- pack[1].get_date())
118- kwargs = { 'feed' : pack[0], 'entry' : pack[1] }
119- item.set_userdata(kwargs)
120- menu.add_actor(item)
121-
122- menu.set_active(False)
123-
124- # Fade in timeline
125- fade_in = clutter.Timeline(20, 60)
126- alpha_in = clutter.Alpha(fade_in, clutter.smoothstep_inc_func)
127- self.in_behaviour = clutter.BehaviourOpacity(0x00, 0xff, alpha_in)
128- self.in_behaviour.apply(menu)
129- self.in_behaviour.apply(title)
130- self.in_behaviour.apply(icon)
131-
132- self.preview.add(icon)
133- self.preview.add(title)
134+ menu = self._create_rss_preview_menu()
135+ preview.add(menu)
136 self.rss_preview_menu = menu
137- self.preview.add(menu)
138-
139- menu.set_opacity(0x00)
140- icon.set_opacity(0x00)
141- title.set_opacity(0x00)
142-
143- fade_in.start()
144-
145 else:
146 # No headlines available in the library
147- info = Label(0.07, "title", 0.1, 0.35, _("No headlines available"))
148- self.preview.add(info)
149+ info = Label(0.05, "title", 0.1, 0.35, _("No headlines available"))
150+ preview.add(info)
151+
152+ return preview
153
154 def get_type(self):
155 """Return screen type."""
156@@ -227,20 +230,28 @@
157
158 self.menu.update()
159
160- self.update_preview_area(self.menu.get_selected())
161+ self._update_preview_area(self.menu.get_selected())
162
163- def update_preview_area(self, item):
164- """
165- Update preview area. This area displayes information of currently
166- selected menuitem.
167- @param item: Menuitem (clutter.Actor)
168- """
169+ def _update_preview_area(self, item):
170+ '''Update the preview area to display the current menu item.'''
171 self.preview.remove_all()
172+ self.preview.set_opacity(0x00)
173+
174+ update = True
175 if item.get_name() == "playing":
176- self.show_playing_preview()
177- #only show the rss menu if it has entries
178+ self.preview.add(self._create_playing_preview())
179 elif item.get_name() == "rss":
180- self.show_rss_preview()
181+ self.preview.add(self._create_rss_preview())
182+ else:
183+ update = False
184+
185+ # If the preview was updated fade it in
186+ if update:
187+ fade_in = clutter.Timeline(20, 60)
188+ alpha_in = clutter.Alpha(fade_in, clutter.smoothstep_inc_func)
189+ self.behaviour = clutter.BehaviourOpacity(0x00, 0xff, alpha_in)
190+ self.behaviour.apply(self.preview)
191+ fade_in.start()
192
193 def _move_menu(self, menu_direction):
194 '''Move the menu in the given direction.'''
195@@ -258,7 +269,7 @@
196 if selected.get_name() == None:
197 scroll_direction()
198 selected = self.menu.get_selected()
199- self.update_preview_area(selected)
200+ self._update_preview_area(selected)
201 else:
202 self.rss_preview_menu.move(preview_direction)
203
204@@ -270,9 +281,17 @@
205 '''Handle UserEvent.NAVIGATE_DOWN.'''
206 self._move_menu(self.DOWN)
207
208+ def _can_move_horizontally(self):
209+ '''Return a boolean indicating if horizontal movement is allowed.'''
210+ item = self.menu.get_selected()
211+ if self.feed_library.is_empty() or item.get_name() != 'rss':
212+ return False
213+ else:
214+ return True
215+
216 def _handle_left(self):
217 '''Handle UserEvent.NAVIGATE_LEFT.'''
218- if self.feed_library.is_empty():
219+ if not self._can_move_horizontally():
220 return
221
222 if self.active_menu == "main":
223@@ -282,7 +301,7 @@
224
225 def _handle_right(self):
226 '''Handle UserEvent.NAVIGATE_RIGHT.'''
227- if self.feed_library.is_empty():
228+ if not self._can_move_horizontally():
229 return
230
231 if self.active_menu == "preview":

Subscribers

People subscribed via source and target branches