From 067f703bfe7787bd4706172f0c56e57874899966 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Sat, 24 Feb 2007 18:18:50 +0100 Subject: [PATCH 1/2] Make OptionMenu grab the pointer on popup. --- sugar/graphics/canvasicon.py | 2 +- sugar/graphics/optionmenu.py | 8 +++++++- sugar/graphics/popup.py | 8 ++++++++ tests/test-option-menu.py | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index 76d29b0b..fe04074f 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -355,7 +355,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): [x, y] = context.translate_to_screen(self) # TODO: Any better place to do this? - popup.props.box_width = max(popup.props.box_width, + popup.props.box_width = max(popup.get_width_request(), self.get_width_request()) [width, height] = self.get_allocation() diff --git a/sugar/graphics/optionmenu.py b/sugar/graphics/optionmenu.py index edd1d39e..f5a44175 100644 --- a/sugar/graphics/optionmenu.py +++ b/sugar/graphics/optionmenu.py @@ -64,6 +64,8 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): self._round_box = RoundBox() self._round_box.props.border_color = color.FRAME_BORDER.get_int() + self._round_box.props.spacing = units.points_to_pixels(3) + self._round_box.props.padding = units.points_to_pixels(1) self.append(self._round_box, hippo.PACK_EXPAND) self._canvas_text = hippo.CanvasText() @@ -111,10 +113,14 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): [x, y] = context.translate_to_screen(self._round_box) # TODO: Any better place to do this? - self._menu.props.box_width = self.get_width_request() + self._menu.props.box_width = max(self.get_width_request(), + self._menu.get_width_request()) [width, height] = self._round_box.get_allocation() self._menu.popup(x, y + height) + + # Grab the pointer so the menu will popdown on mouse click. + self._menu.grab_pointer() def _menu_action_cb(self, menu, menu_item): action_id = menu_item.props.action_id diff --git a/sugar/graphics/popup.py b/sugar/graphics/popup.py index 5c63b6e3..d0bee06e 100644 --- a/sugar/graphics/popup.py +++ b/sugar/graphics/popup.py @@ -46,5 +46,13 @@ class Popup(hippo.CanvasBox, hippo.CanvasItem): self._window.hide() self._visible = False + def grab_pointer(self): + gtk.gdk.pointer_grab(self._window.window, owner_events=False, + event_mask=gtk.gdk.BUTTON_PRESS_MASK | + gtk.gdk.BUTTON_RELEASE_MASK | + gtk.gdk.ENTER_NOTIFY_MASK | + gtk.gdk.LEAVE_NOTIFY_MASK | + gtk.gdk.POINTER_MOTION_MASK) + def _button_press_event_cb(self, menu, event): self.emit('action-completed') diff --git a/tests/test-option-menu.py b/tests/test-option-menu.py index bbcc03a0..f320afcc 100755 --- a/tests/test-option-menu.py +++ b/tests/test-option-menu.py @@ -48,7 +48,7 @@ canvas.set_root(vbox) toolbar = Toolbar() vbox.append(toolbar) -button = IconButton('theme:stock-close') +button = IconButton(icon_name='theme:stock-close') toolbar.append(button) OPTION_ANYTHING = 1 From d7eb3fd73400bef047ba49bf50d8673aa121dab0 Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Sat, 24 Feb 2007 13:28:04 -0500 Subject: [PATCH 2/2] Fix part of bug 853, reposition and resize sugar frame after rotate --- shell/view/frame/PanelWindow.py | 46 +++++++++++++++++++++------------ shell/view/frame/frame.py | 23 ++++++++++++----- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/shell/view/frame/PanelWindow.py b/shell/view/frame/PanelWindow.py index e14f6b4b..6edd4bd7 100644 --- a/shell/view/frame/PanelWindow.py +++ b/shell/view/frame/PanelWindow.py @@ -22,6 +22,7 @@ from sugar.graphics import units class PanelWindow(gtk.Window): def __init__(self, orientation): gtk.Window.__init__(self) + self._orientation = orientation self.set_decorated(False) self.connect('realize', self._realize_cb) @@ -29,35 +30,46 @@ class PanelWindow(gtk.Window): self._canvas = hippo.Canvas() self._bg = hippo.CanvasBox(background_color=0x414141ff, - orientation=orientation) - - padding = units.grid_to_pixels(1) - if orientation == hippo.ORIENTATION_HORIZONTAL: - self._bg.props.padding_left = padding - self._bg.props.padding_right = padding - - width = gtk.gdk.screen_width() - height = units.grid_to_pixels(1) - else: - self._bg.props.padding_top = padding - self._bg.props.padding_bottom = padding - - width = units.grid_to_pixels(1) - height = gtk.gdk.screen_height() + orientation=self._orientation) + self._update_size() self._canvas.set_root(self._bg) self.add(self._canvas) self._canvas.show() - - self.resize(width, height) + + screen = gtk.gdk.screen_get_default() + screen.connect('size-changed', self._size_changed_cb) def get_root(self): return self._bg def get_canvas(self): return self._canvas + + def _update_size(self): + padding = units.grid_to_pixels(1) + if self._orientation == hippo.ORIENTATION_HORIZONTAL: + self._bg.props.padding_left = padding + self._bg.props.padding_right = padding + self._bg.props.padding_top = 0 + self._bg.props.padding_bottom = 0 + + width = gtk.gdk.screen_width() + height = units.grid_to_pixels(1) + else: + self._bg.props.padding_left = 0 + self._bg.props.padding_right = 0 + self._bg.props.padding_top = padding + self._bg.props.padding_bottom = padding + + width = units.grid_to_pixels(1) + height = gtk.gdk.screen_height() + self.resize(width, height) def _realize_cb(self, widget): self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) self.window.set_accept_focus(False) + + def _size_changed_cb(self, screen): + self._update_size() diff --git a/shell/view/frame/frame.py b/shell/view/frame/frame.py index 27658f03..f15bf35f 100644 --- a/shell/view/frame/frame.py +++ b/shell/view/frame/frame.py @@ -50,6 +50,7 @@ class Frame: self._hover_frame = False self._shell = shell self._mode = Frame.INACTIVE + self._current_position = 0 self._timeline = Timeline(self) self._timeline.add_tag('slide_in', 18, 24) @@ -75,6 +76,9 @@ class Frame: shell.get_model().connect('notify::state', self._shell_state_changed_cb) + + screen = gtk.gdk.screen_get_default() + screen.connect('size-changed', self._size_changed_cb) def _create_top_panel(self): panel = self._create_panel(hippo.ORIENTATION_HORIZONTAL) @@ -219,24 +223,28 @@ class Frame: def notify_key_release(self): if self._mode == Frame.TEMPORARY: self._timeline.play('before_slide_out', 'slide_out') - + def _move(self, pos): + self._current_position = pos + self._update_position() + + def _update_position(self): screen_h = gtk.gdk.screen_height() screen_w = gtk.gdk.screen_width() - self._move_panel(self._top_panel, pos, + self._move_panel(self._top_panel, self._current_position, 0, units.grid_to_pixels(-1), 0, 0) - self._move_panel(self._bottom_panel, pos, + self._move_panel(self._bottom_panel, self._current_position, 0, screen_h, 0, screen_h - units.grid_to_pixels(1)) - self._move_panel(self._left_panel, pos, + self._move_panel(self._left_panel, self._current_position, units.grid_to_pixels(-1), 0, 0, 0) - self._move_panel(self._right_panel, pos, + self._move_panel(self._right_panel, self._current_position, screen_w, 0, screen_w - units.grid_to_pixels(1), 0) @@ -255,7 +263,10 @@ class Frame: self._move(0) if not self._event_frame.is_visible(): self._event_frame.show() - + + def _size_changed_cb(self, screen): + self._update_position() + def is_visible(self): return self._top_panel.props.visible