| 
									
										
										
										
											2006-11-15 13:56:19 +01:00
										 |  |  | import hippo | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from sugar.graphics.menu import Menu | 
					
						
							|  |  |  | from sugar.graphics.canvasicon import CanvasIcon | 
					
						
							|  |  |  | from sugar.graphics.ClipboardBubble import ClipboardBubble | 
					
						
							|  |  |  | from sugar.graphics import style | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ClipboardMenuItem(ClipboardBubble): | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-04 20:12:24 +01:00
										 |  |  |     def __init__(self, percent = 0, stylesheet="clipboard.Bubble"): | 
					
						
							| 
									
										
										
										
											2007-01-11 23:57:06 +01:00
										 |  |  |         self._text_item = None | 
					
						
							|  |  |  |         ClipboardBubble.__init__(self, percent=percent) | 
					
						
							| 
									
										
										
										
											2006-12-04 20:12:24 +01:00
										 |  |  |         style.apply_stylesheet(self, stylesheet) | 
					
						
							| 
									
										
										
										
											2007-01-11 23:57:06 +01:00
										 |  |  |                  | 
					
						
							|  |  |  |         self._text_item = hippo.CanvasText(text=str(percent) + ' %') | 
					
						
							|  |  |  |         style.apply_stylesheet(self._text_item, 'clipboard.MenuItem.Title') | 
					
						
							|  |  |  |         self.append(self._text_item) | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |     def do_set_property(self, pspec, value): | 
					
						
							|  |  |  |         if pspec.name == 'percent': | 
					
						
							|  |  |  |             if self._text_item: | 
					
						
							|  |  |  |                 self._text_item.set_property('text', str(value) + ' %') | 
					
						
							| 
									
										
										
										
											2006-11-15 13:56:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-11 23:57:06 +01:00
										 |  |  |         ClipboardBubble.do_set_property(self, pspec, value) | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2006-11-15 13:56:19 +01:00
										 |  |  | class ClipboardMenu(Menu): | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-04 20:12:24 +01:00
										 |  |  |     ACTION_DELETE = 0 | 
					
						
							| 
									
										
										
										
											2007-01-11 23:57:06 +01:00
										 |  |  |     ACTION_OPEN = 1 | 
					
						
							| 
									
										
										
										
											2006-12-04 20:12:24 +01:00
										 |  |  |     ACTION_STOP_DOWNLOAD = 2 | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2007-01-11 23:57:06 +01:00
										 |  |  |     def __init__(self, name, percent, preview, activity): | 
					
						
							| 
									
										
										
										
											2006-12-04 20:12:24 +01:00
										 |  |  |         Menu.__init__(self, name) | 
					
						
							| 
									
										
										
										
											2006-12-14 13:50:42 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if percent < 100:         | 
					
						
							|  |  |  |             self._progress_bar = ClipboardMenuItem(percent) | 
					
						
							|  |  |  |             self._root.append(self._progress_bar) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             self._progress_bar = None | 
					
						
							| 
									
										
										
										
											2006-12-04 20:12:24 +01:00
										 |  |  |          | 
					
						
							|  |  |  |         self._remove_icon = None | 
					
						
							| 
									
										
										
										
											2007-01-11 23:57:06 +01:00
										 |  |  |         self._open_icon = None | 
					
						
							| 
									
										
										
										
											2006-12-04 20:12:24 +01:00
										 |  |  |         self._stop_icon = None | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2007-01-07 23:38:33 +01:00
										 |  |  |         self.add_item(preview, wrap=True) | 
					
						
							| 
									
										
										
										
											2007-01-05 21:13:46 +01:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2007-01-11 23:57:06 +01:00
										 |  |  |         self._update_icons(percent, activity) | 
					
						
							| 
									
										
										
										
											2006-12-04 20:12:24 +01:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2007-01-11 23:57:06 +01:00
										 |  |  |     def _update_icons(self, percent, activity): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if percent == 100 and activity: | 
					
						
							| 
									
										
										
										
											2006-12-04 20:12:24 +01:00
										 |  |  |             if not self._remove_icon: | 
					
						
							| 
									
										
										
										
											2007-01-12 21:35:53 +01:00
										 |  |  |                 self._remove_icon = CanvasIcon(icon_name='theme:stock-remove') | 
					
						
							| 
									
										
										
										
											2006-12-04 20:12:24 +01:00
										 |  |  |                 self.add_action(self._remove_icon, ClipboardMenu.ACTION_DELETE) | 
					
						
							| 
									
										
										
										
											2007-01-11 23:57:06 +01:00
										 |  |  |                              | 
					
						
							|  |  |  |             if not self._open_icon: | 
					
						
							| 
									
										
										
										
											2007-01-16 19:22:50 +01:00
										 |  |  |                 self._open_icon = CanvasIcon(icon_name='theme:stock-keep') | 
					
						
							| 
									
										
										
										
											2007-01-11 23:57:06 +01:00
										 |  |  |                 self.add_action(self._open_icon, ClipboardMenu.ACTION_OPEN) | 
					
						
							|  |  |  |                              | 
					
						
							| 
									
										
										
										
											2006-12-04 20:12:24 +01:00
										 |  |  |             if self._stop_icon: | 
					
						
							|  |  |  |                 self.remove_action(self._stop_icon) | 
					
						
							|  |  |  |                 self._stop_icon = None | 
					
						
							| 
									
										
										
										
											2007-01-11 23:57:06 +01:00
										 |  |  |         elif percent == 100 and not activity: | 
					
						
							|  |  |  |             if not self._remove_icon: | 
					
						
							| 
									
										
										
										
											2007-01-16 19:22:50 +01:00
										 |  |  |                 self._remove_icon = CanvasIcon(icon_name='theme:stock-remove') | 
					
						
							| 
									
										
										
										
											2007-01-11 23:57:06 +01:00
										 |  |  |                 self.add_action(self._remove_icon, ClipboardMenu.ACTION_DELETE) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if self._open_icon: | 
					
						
							|  |  |  |                 self.remove_action(self._open_icon) | 
					
						
							|  |  |  |                 self._open_icon = None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if self._stop_icon: | 
					
						
							|  |  |  |                 self.remove_action(self._stop_icon) | 
					
						
							|  |  |  |                 self._stop_icon = None         | 
					
						
							| 
									
										
										
										
											2006-12-04 20:12:24 +01:00
										 |  |  |         else: | 
					
						
							|  |  |  |             if not self._stop_icon: | 
					
						
							| 
									
										
										
										
											2007-01-12 21:35:53 +01:00
										 |  |  |                 self._stop_icon = CanvasIcon(icon_name='theme:stock-close') | 
					
						
							| 
									
										
										
										
											2006-12-04 20:12:24 +01:00
										 |  |  |                 self.add_action(self._stop_icon, ClipboardMenu.ACTION_STOP_DOWNLOAD) | 
					
						
							| 
									
										
										
										
											2006-11-15 13:56:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-04 20:12:24 +01:00
										 |  |  |             if self._remove_icon: | 
					
						
							|  |  |  |                 self.remove_action(self._remove_icon) | 
					
						
							|  |  |  |                 self._remove_icon = None | 
					
						
							| 
									
										
										
										
											2007-01-11 23:57:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if self._open_icon: | 
					
						
							|  |  |  |                 self.remove_action(self._open_icon) | 
					
						
							|  |  |  |                 self._open_icon = None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def set_state(self, name, percent, preview, activity): | 
					
						
							| 
									
										
										
										
											2007-01-05 21:13:46 +01:00
										 |  |  |         self.set_title(name) | 
					
						
							| 
									
										
										
										
											2006-12-14 13:50:42 +01:00
										 |  |  |         if self._progress_bar: | 
					
						
							|  |  |  |             self._progress_bar.set_property('percent', percent) | 
					
						
							| 
									
										
										
										
											2007-01-11 23:57:06 +01:00
										 |  |  |             self._update_icons(percent, activity) |