OptionMenu fixes and API updates.
This commit is contained in:
		
							parent
							
								
									fa4c775bc9
								
							
						
					
					
						commit
						28f10bf142
					
				| @ -46,14 +46,14 @@ class Entry(hippo.CanvasBox, hippo.CanvasItem): | ||||
|         self._buttons = {} | ||||
| 
 | ||||
|         self._round_box = RoundBox() | ||||
|         self._round_box.props.border_color = Color.FRAME_BORDER.get_int() | ||||
|         self._round_box.props.border_color = color.FRAME_BORDER.get_int() | ||||
|         self.append(self._round_box, hippo.PACK_EXPAND) | ||||
| 
 | ||||
|         self._entry = self.create_entry() | ||||
|         self._entry.props.has_frame = False | ||||
|         self._update_colors(focused=False) | ||||
|         self._entry.modify_text(gtk.STATE_SELECTED, | ||||
|                                 Color.BLACK.get_gdk_color()) | ||||
|                                 color.BLACK.get_gdk_color()) | ||||
|         self._entry.connect('focus-in-event', self._entry_focus_in_event_cb) | ||||
|         self._entry.connect('focus-out-event', self._entry_focus_out_event_cb) | ||||
|         self._entry.connect('activate', self._entry_activate_cb) | ||||
|  | ||||
| @ -33,7 +33,7 @@ class Menu(hippo.CanvasBox, hippo.CanvasItem): | ||||
|     __gtype_name__ = 'SugarMenu' | ||||
| 
 | ||||
|     __gsignals__ = { | ||||
|         'action': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([int])) | ||||
|         'action': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([object])) | ||||
|     } | ||||
| 
 | ||||
|     def __init__(self): | ||||
| @ -60,7 +60,8 @@ class Menu(hippo.CanvasBox, hippo.CanvasItem): | ||||
|         canvas_text.props.font_desc = font.DEFAULT.get_pango_desc() | ||||
|         box.append(canvas_text) | ||||
| 
 | ||||
|         box.connect('button-press-event', self._button_press_event_cb, action_id) | ||||
|         box.connect('button-press-event', self._button_press_event_cb, | ||||
|                     [action_id, label]) | ||||
|         self.append(box) | ||||
|      | ||||
|     def add_separator(self): | ||||
| @ -81,8 +82,8 @@ class Menu(hippo.CanvasBox, hippo.CanvasItem): | ||||
|             self._window.destroy() | ||||
|             self._window = None | ||||
| 
 | ||||
|     def _button_press_event_cb(self, item, event, option_id): | ||||
|         self.emit('action', option_id) | ||||
|     def _button_press_event_cb(self, item, event, data): | ||||
|         self.emit('action', data) | ||||
|         self.hide() | ||||
|      | ||||
|     def is_visible(self): | ||||
| @ -119,12 +120,13 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): | ||||
|         button.props.scale = style.small_icon_scale | ||||
|         button.props.yalign = hippo.ALIGNMENT_CENTER | ||||
|         button.props.xalign = hippo.ALIGNMENT_START | ||||
|         button.connect('activated', self._button_activated_cb) | ||||
|         self._round_box.append(button) | ||||
| 
 | ||||
|         self._menu = Menu() | ||||
|         self._menu.connect('action', self._menu_action_cb) | ||||
| 
 | ||||
|         self.connect('button-press-event', self._button_press_event_cb) | ||||
| 
 | ||||
|     def do_set_property(self, pspec, value): | ||||
|         if pspec.name == 'value': | ||||
|             self._value = value | ||||
| @ -134,12 +136,16 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): | ||||
|             return self._value | ||||
| 
 | ||||
|     def add_option(self, action_id, label, icon_name=None, icon_color=None): | ||||
|         if not self._value: | ||||
|             self._value = action_id | ||||
|             self._canvas_text.props.text = label | ||||
| 
 | ||||
|         self._menu.add_item(action_id, label, icon_name, icon_color) | ||||
| 
 | ||||
|     def add_separator(self): | ||||
|         self._menu.add_separator() | ||||
| 
 | ||||
|     def _button_activated_cb(self, button): | ||||
|     def _button_press_event_cb(self, box, event): | ||||
|         if self._menu.is_visible(): | ||||
|             self._menu.hide() | ||||
|         else: | ||||
| @ -149,7 +155,9 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): | ||||
|             self._menu.props.box_width = self.get_width_request() | ||||
|             self._menu.show(x, y + height) | ||||
| 
 | ||||
|     def _menu_action_cb(self, menu, option_id): | ||||
|         if option_id != self._value: | ||||
|             self._value = option_id | ||||
|     def _menu_action_cb(self, menu, data): | ||||
|         [action_id, label] = data | ||||
|         if action_id != self._value: | ||||
|             self._value = action_id | ||||
|             self._canvas_text.props.text = label | ||||
|             self.emit('changed') | ||||
|  | ||||
| @ -6,4 +6,5 @@ class Toolbar(hippo.CanvasBox): | ||||
| 
 | ||||
|     def __init__(self, orientation=hippo.ORIENTATION_HORIZONTAL): | ||||
|         hippo.CanvasBox.__init__(self, orientation=orientation, | ||||
|                                  background_color=0x414141ff) | ||||
|                                  background_color=0x414141ff, | ||||
|                                  spacing=15) | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Tomeu Vizoso
						Tomeu Vizoso