diff options
author | Benjamin Berg <benjamin@sipsolutions.net> | 2011-10-30 11:20:41 (GMT) |
---|---|---|
committer | Benjamin Berg <benjamin@sipsolutions.net> | 2011-10-30 11:24:32 (GMT) |
commit | 40a7094c0ad037bc3ff920e6005d956bbbbf5555 (patch) | |
tree | 481588489c29f36981bee768dc6b92ab9a1245aa | |
parent | 31b8d49ce4d66057eb05c2a531dfe75d75bbe187 (diff) |
A lot of small changes for GTK+ 3 support. This removes menu support.
-rw-r--r-- | src/sugar3/graphics/alert.py | 2 | ||||
-rw-r--r-- | src/sugar3/graphics/icon.py | 44 | ||||
-rw-r--r-- | src/sugar3/graphics/palette.py | 97 | ||||
-rw-r--r-- | src/sugar3/graphics/palettewindow.py | 81 | ||||
-rw-r--r-- | src/sugar3/wm.py | 3 |
5 files changed, 72 insertions, 155 deletions
diff --git a/src/sugar3/graphics/alert.py b/src/sugar3/graphics/alert.py index a404273..f2dd3b9 100644 --- a/src/sugar3/graphics/alert.py +++ b/src/sugar3/graphics/alert.py @@ -354,7 +354,7 @@ class _TimeoutIcon(Gtk.Alignment): self.connect("expose_event", self.__expose_cb) def __expose_cb(self, widget, event): - context = widget.window.cairo_create() + context = widget.get_window().cairo_create() self._draw(context) return False diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py index 6e95ce3..c7fc0d4 100644 --- a/src/sugar3/graphics/icon.py +++ b/src/sugar3/graphics/icon.py @@ -348,7 +348,7 @@ class Icon(Gtk.Image): self._buffer.file_name = self.props.file if self.props.pixel_size == -1: - width, height = Gtk.icon_size_lookup(self.props.icon_size) + res, width, height = Gtk.icon_size_lookup(self.props.icon_size) else: width = height = self.props.pixel_size if self._buffer.width != width or self._buffer.height != height: @@ -364,29 +364,29 @@ class Icon(Gtk.Image): def _file_changed_cb(self, image, pspec): self._buffer.file_name = self.props.file - def do_size_request(self, requisition): - """ - Parameters - ---------- - requisition : - - Returns - ------- - None - - """ + def do_get_preferred_height(self): self._sync_image_properties() surface = self._buffer.get_surface() if surface: - requisition[0] = surface.get_width() - requisition[1] = surface.get_height() + height = surface.get_height() elif self._buffer.width and self._buffer.height: - requisition[0] = self._buffer.width - requisition[1] = self._buffer.width + height = self._buffer.width else: - requisition[0] = requisition[1] = 0 + height = 0 + return (height, height) - def do_expose_event(self, event): + def do_get_preferred_height(self): + self._sync_image_properties() + surface = self._buffer.get_surface() + if surface: + width = surface.get_width() + elif self._buffer.width and self._buffer.width: + width = self._buffer.width + else: + width = 0 + return (width, width) + + def do_draw(self, cr): """ Parameters ---------- @@ -398,7 +398,7 @@ class Icon(Gtk.Image): """ self._sync_image_properties() - sensitive = (self.state != Gtk.StateType.INSENSITIVE) + sensitive = self.is_sensitive() surface = self._buffer.get_surface(sensitive, self) if surface is None: return @@ -411,11 +411,9 @@ class Icon(Gtk.Image): allocation = self.get_allocation() x = math.floor(allocation.x + xpad + - (allocation.width - requisition[0]) * xalign) + (allocation.width - requisition.width) * xalign) y = math.floor(allocation.y + ypad + - (allocation.height - requisition[1]) * yalign) - - cr = self.window.cairo_create() + (allocation.height - requisition.height) * yalign) if self._scale != 1.0: cr.scale(self._scale, self._scale) diff --git a/src/sugar3/graphics/palette.py b/src/sugar3/graphics/palette.py index 6f6355e..4e9ee71 100644 --- a/src/sugar3/graphics/palette.py +++ b/src/sugar3/graphics/palette.py @@ -43,11 +43,10 @@ class Palette(PaletteWindow): __gtype_name__ = 'SugarPalette' - def __init__(self, label=None, accel_path=None, menu_after_content=False, + def __init__(self, label=None, accel_path=None, text_maxlen=60, **kwargs): # DEPRECATED: label is passed with the primary-text property, - # accel_path is set via the invoker property, and menu_after_content - # is not used + # accel_path is set via the invoker property self._primary_text = None self._secondary_text = None @@ -97,8 +96,6 @@ class Palette(PaletteWindow): self._separator = Gtk.HSeparator() self._secondary_box.pack_start(self._separator, True, True, 0) - self._menu_content_separator = Gtk.HSeparator() - self._secondary_anim = animator.Animator(2.0, 10) self._secondary_anim.add(_SecondaryAnimation(self)) @@ -109,15 +106,12 @@ class Palette(PaletteWindow): - 2 * self.get_border_width()) self._full_request = [0, 0] - self._menu_box = None self._content = None # we set these for backward compatibility if label is not None: self.props.primary_text = label - self._add_menu() - self._secondary_box.pack_start(self._menu_content_separator, True, True, 0) self._add_content() self.action_bar = PaletteActionBar() @@ -127,12 +121,7 @@ class Palette(PaletteWindow): self.add(palette_box) palette_box.show() - # The menu is not shown here until an item is added - self.menu = _Menu(self) - self.menu.connect('item-inserted', self.__menu_item_inserted_cb) - self.connect('realize', self.__realize_cb) - self.connect('show', self.__show_cb) self.connect('hide', self.__hide_cb) self.connect('notify::invoker', self.__notify_invoker_cb) self.connect('destroy', self.__destroy_cb) @@ -146,23 +135,11 @@ class Palette(PaletteWindow): Gtk.Window.do_style_set(self, previous_style) self.set_border_width(self.get_style().xthickness) - def __menu_item_inserted_cb(self, menu): - self._update_separators() - def __destroy_cb(self, palette): self._secondary_anim.stop() self.popdown(immediate=True) - # Break the reference cycle. It looks like the gc is not able to free - # it, possibly because Gtk.Menu memory handling is very special. - self.menu.disconnect_by_func(self.__menu_item_inserted_cb) - self.menu = None - - def __show_cb(self, widget): - self.menu.set_active(True) def __hide_cb(self, widget): - self.menu.set_active(False) - self.menu.cancel() self._secondary_anim.stop() def __notify_invoker_cb(self, palette, pspec): @@ -196,28 +173,14 @@ class Palette(PaletteWindow): def popdown(self, immediate=False): if immediate: self._secondary_anim.stop() - self._popdown_submenus() # to suppress glitches while later re-opening self.set_palette_state(self.PRIMARY) PaletteWindow.popdown(self, immediate) - def _popdown_submenus(self): - # TODO explicit hiding of subitems - # should be removed after fixing #1301 - if self.menu is not None: - for menu_item in self.menu.get_children(): - if menu_item.props.submenu is not None: - menu_item.props.submenu.popdown() - def on_enter(self, event): PaletteWindow.on_enter(self, event) self._secondary_anim.start() - def _add_menu(self): - self._menu_box = Gtk.VBox() - self._secondary_box.pack_start(self._menu_box, True, True, 0) - self._menu_box.show() - def _add_content(self): # The content is not shown until a widget is added self._content = Gtk.VBox() @@ -338,14 +301,9 @@ class Palette(PaletteWindow): self._full_request[0]) def _update_separators(self): - visible = self.menu.get_children() or \ - self._content.get_children() + visible = self._content.get_children() self._separator.props.visible = visible - visible = self.menu.get_children() and \ - self._content.get_children() - self._menu_content_separator.props.visible = visible - def _update_accept_focus(self): accept_focus = len(self._content.get_children()) win = self.get_window() @@ -357,13 +315,11 @@ class Palette(PaletteWindow): def _update_full_request(self): if self._palette_state == self.PRIMARY: - self.menu.embed(self._menu_box) self._secondary_box.show() self._full_request = self.size_request() if self._palette_state == self.PRIMARY: - self.menu.unembed() self._secondary_box.hide() def _set_palette_state(self, state): @@ -371,10 +327,8 @@ class Palette(PaletteWindow): return if state == self.PRIMARY: - self.menu.unembed() self._secondary_box.hide() elif state == self.SECONDARY: - self.menu.embed(self._menu_box) self._secondary_box.show() self.update_position() @@ -394,51 +348,6 @@ class PaletteActionBar(Gtk.HButtonBox): self.pack_start(button, True, True, 0) button.show() - -class _Menu(Gtk.Menu): - - __gtype_name__ = 'SugarPaletteMenu' - - __gsignals__ = { - 'item-inserted': (GObject.SignalFlags.RUN_FIRST, None, ([])), - } - - def __init__(self, palette): - Gtk.Menu.__init__(self) - self._palette = palette - - def embed(self, *args): - pass - - def unembed(self, *args): - pass - - def do_insert(self, item, position): - Gtk.Menu.do_insert(self, item, position) - self.emit('item-inserted') - self.show() - - def attach(self, child, left_attach, right_attach, - top_attach, bottom_attach): - Gtk.Menu.attach(self, child, left_attach, right_attach, - top_attach, bottom_attach) - self.emit('item-inserted') - self.show() - - def do_expose_event(self, event): - # Ignore the Menu expose, just do the MenuShell expose to prevent any - # border from being drawn here. A border is drawn by the palette object - # around everything. - Gtk.MenuShell.do_expose_event(self, event) - - def do_grab_notify(self, was_grabbed): - # Ignore grab_notify as the menu would close otherwise - pass - - def do_deactivate(self): - self._palette.hide() - - class _SecondaryAnimation(animator.Animation): def __init__(self, palette): diff --git a/src/sugar3/graphics/palettewindow.py b/src/sugar3/graphics/palettewindow.py index 82c434a..f500d12 100644 --- a/src/sugar3/graphics/palettewindow.py +++ b/src/sugar3/graphics/palettewindow.py @@ -101,8 +101,11 @@ class MouseSpeedDetector(GObject.GObject): self._state = None def _get_mouse_position(self): - display = Gdk.Display.get_default() - screen_, x, y, mask_ = display.get_pointer() + display = self._parent.get_display() + manager = display.get_device_manager() + pointer_device = manager.get_client_pointer() + screen, x, y = pointer_device.get_position() + return (x, y) def _detect_motion(self): @@ -159,6 +162,7 @@ class PaletteWindow(Gtk.Window): self.set_decorated(False) self.set_resizable(False) + self.set_position(Gtk.WindowPosition.NONE) # Just assume xthickness and ythickness are the same self.set_border_width(self.get_style().xthickness) @@ -362,14 +366,10 @@ class PaletteWindow(Gtk.Window): self.popup(immediate=True) def __enter_notify_event_cb(self, widget, event): - if event.detail != Gdk.NOTIFY_INFERIOR and \ - event.mode == Gdk.CROSSING_NORMAL: - self.on_enter(event) + self.on_enter(event) def __leave_notify_event_cb(self, widget, event): - if event.detail != Gdk.NOTIFY_INFERIOR and \ - event.mode == Gdk.CROSSING_NORMAL: - self.on_leave(event) + self.on_leave(event) def __show_cb(self, widget): if self._invoker is not None: @@ -386,7 +386,7 @@ class PaletteWindow(Gtk.Window): self.emit('popdown') def get_rect(self): - win_x, win_y = self.get_window().get_origin() + res, win_x, win_y = self.get_window().get_origin() rectangle = self.get_allocation() x = win_x + rectangle.x @@ -453,8 +453,9 @@ class Invoker(GObject.GObject): self.parent = None - self._screen_area = (0, 0, Gdk.Screen.width(), - Gdk.Screen.height()) + self._screen_area = Gdk.Rectangle() + self._screen_area.x, self._screen_area.y, self._screen_area.width, self._screen_area.height = \ + (0, 0, Gdk.Screen.width(), Gdk.Screen.height()) self._position_hint = self.ANCHORED self._cursor_x = -1 self._cursor_y = -1 @@ -477,8 +478,11 @@ class Invoker(GObject.GObject): invoker_valign = alignment[3] if self._cursor_x == -1 or self._cursor_y == -1: - display = Gdk.Display.get_default() - screen_, x, y, mask_ = display.get_pointer() + display = self.parent.get_display() + manager = display.get_device_manager() + pointer_device = manager.get_client_pointer() + screen, x, y = pointer_device.get_position() + self._cursor_x = x self._cursor_y = y @@ -486,11 +490,12 @@ class Invoker(GObject.GObject): rect = self.get_rect() else: dist = style.PALETTE_CURSOR_DISTANCE - rect = (self._cursor_x - dist, + rect = Gdk.Rectangle() + rect.x, rect.y, rect.width, rect.height = (self._cursor_x - dist, self._cursor_y - dist, dist * 2, dist * 2) - palette_width, palette_height = palette_dim + palette_width, palette_height = palette_dim.width, palette_dim.height x = rect.x + rect.width * invoker_halign + \ palette_width * palette_halign @@ -498,8 +503,11 @@ class Invoker(GObject.GObject): y = rect.y + rect.height * invoker_valign + \ palette_height * palette_valign - return (int(x), int(y), - palette_width, palette_height) + rect = Gdk.Rectangle() + rect.x, rect.y, rect.width, rect.height = (int(x), int(y), + palette_width, palette_height) + + return rect def _in_screen(self, rect): return rect.x >= self._screen_area.x and \ @@ -582,12 +590,12 @@ class Invoker(GObject.GObject): # Set palette_valign to align to screen on the top if dtop > dbottom: - pv = -float(dtop) / palette_dim[1] + pv = -float(dtop) / palette_dim.height # Set palette_valign to align to screen on the bottom else: - pv = -float(palette_dim[1] - dbottom - rect.height) \ - / palette_dim[1] + pv = -float(palette_dim.height - dbottom - rect.height) \ + / palette_dim.height elif best_alignment in self.TOP or best_alignment in self.BOTTOM: dleft = rect.x - screen_area.x @@ -597,12 +605,12 @@ class Invoker(GObject.GObject): # Set palette_halign to align to screen on left if dleft > dright: - ph = -float(dleft) / palette_dim[0] + ph = -float(dleft) / palette_dim.width # Set palette_halign to align to screen on right else: - ph = -float(palette_dim[0] - dright - rect.width) \ - / palette_dim[0] + ph = -float(palette_dim.width - dright - rect.width) \ + / palette_dim.width return (ph, pv, ih, iv) @@ -716,30 +724,32 @@ class WidgetInvoker(Invoker): def get_rect(self): allocation = self._widget.get_allocation() if self._widget.get_window() is not None: - x, y = self._widget.get_window().get_origin() + res, x, y = self._widget.get_window().get_origin() else: logging.warning( "Trying to position palette with invoker that's not realized.") x = 0 y = 0 - if self._widget.flags() & Gtk.NO_WINDOW: - x += allocation.x - y += allocation.y + x += allocation.x + y += allocation.y width = allocation.width height = allocation.height - return (x, y, width, height) + rect = Gdk.Rectangle() + rect.x = x + rect.y = y + rect.width = width + rect.height = height + + return rect def has_rectangle_gap(self): return True def draw_rectangle(self, event, palette): - if self._widget.flags() & Gtk.NO_WINDOW: - x, y = self._widget.allocation.x, self._widget.allocation.y - else: - x = y = 0 + x, y = self._widget.allocation.x, self._widget.allocation.y wstyle = self._widget.get_style() gap = _calculate_gap(self.get_rect(), palette.get_rect()) @@ -897,16 +907,15 @@ class CellRendererInvoker(Invoker): def get_rect(self): allocation = self._tree_view.get_allocation() if self._tree_view.get_window() is not None: - x, y = self._tree_view.get_window().get_origin() + res, x, y = self._tree_view.get_window().get_origin() else: logging.warning( "Trying to position palette with invoker that's not realized.") x = 0 y = 0 - if self._tree_view.flags() & Gtk.NO_WINDOW: - x += allocation.x - y += allocation.y + x += allocation.x + y += allocation.y width = allocation.width height = allocation.height diff --git a/src/sugar3/wm.py b/src/sugar3/wm.py index 87eaf2f..a1df61d 100644 --- a/src/sugar3/wm.py +++ b/src/sugar3/wm.py @@ -19,7 +19,8 @@ UNSTABLE. Used only internally by Activity and jarabe. """ -from gi.repository import Gtk, Gdk +from gi.repository import Gtk +from gi.repository import Gdk import logging |