From 49b0db642e7dc04e17b8ff6a054c0c0889153253 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Mon, 12 Mar 2007 16:09:41 +0100 Subject: [PATCH] Fix hover checking logic --- shell/view/frame/PanelWindow.py | 10 +++++ shell/view/frame/frame.py | 71 +++++++++++++++++---------------- 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/shell/view/frame/PanelWindow.py b/shell/view/frame/PanelWindow.py index cf3fc417..7f585b6d 100644 --- a/shell/view/frame/PanelWindow.py +++ b/shell/view/frame/PanelWindow.py @@ -23,10 +23,14 @@ from sugar.graphics.window import Window class PanelWindow(Window): def __init__(self, orientation): Window.__init__(self) + self.hover = False + self._orientation = orientation self.set_decorated(False) self.connect('realize', self._realize_cb) + self.connect('enter-notify-event', self._enter_notify_cb) + self.connect('leave-notify-event', self._leave_notify_cb) self._bg = hippo.CanvasBox(background_color=0x414141ff, orientation=self._orientation) @@ -63,6 +67,12 @@ class PanelWindow(Window): def _realize_cb(self, widget): self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) self.window.set_accept_focus(False) + + def _enter_notify_cb(self, window, event): + self.hover = True + + def _leave_notify_cb(self, window, event): + self.hover = 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 133d4dfa..a8e86e4f 100644 --- a/shell/view/frame/frame.py +++ b/shell/view/frame/frame.py @@ -125,7 +125,6 @@ class Frame(object): self._shell = shell self._current_position = 0.0 self._animator = None - self._hover_frame = False self._event_frame = EventFrame() self._event_frame.connect('enter-corner', self._enter_corner_cb) @@ -151,6 +150,36 @@ class Frame(object): self._key_listener = _KeyListener(self) self._mouse_listener = _MouseListener(self) + def hide(self): + if self.state == STATE_HIDING: + return + if self._animator: + self._animator.stop() + + self._animator = animator.Animator(0.5, 30, animator.EASE_OUT_EXPO) + self._animator.add(_Animation(self, 0.0)) + self._animator.start() + + self._event_frame.show() + + self.state = STATE_HIDING + self.mode = MODE_NONE + + def show(self): + if self.state == STATE_SHOWING: + return + if self._animator: + self._animator.stop() + + self._animator = animator.Animator(0.5, 30, animator.EASE_OUT_EXPO) + self._animator.add(_Animation(self, 1.0)) + self._animator.start() + + self._event_frame.hide() + + self.state = STATE_SHOWING + self.mode = MODE_NOT_INTERACTIVE + def get_popup_context(self): return self._popup_context @@ -161,6 +190,12 @@ class Frame(object): self._current_position = pos self._update_position() + def _is_hover(self): + return (self._top_panel.hover or \ + self._bottom_panel.hover or \ + self._left_panel.hover or \ + self._right_panel.hover) + def _create_top_panel(self): panel = self._create_panel(hippo.ORIENTATION_HORIZONTAL) root = panel.get_root() @@ -244,36 +279,6 @@ class Frame(object): screen_w, 0, screen_w - units.grid_to_pixels(1), 0) - def hide(self): - if self.state == STATE_HIDING: - return - if self._animator: - self._animator.stop() - - self._animator = animator.Animator(0.5, 30, animator.EASE_OUT_EXPO) - self._animator.add(_Animation(self, 0.0)) - self._animator.start() - - self._event_frame.show() - - self.state = STATE_HIDING - self.mode = MODE_NONE - - def show(self): - if self.state == STATE_SHOWING: - return - if self._animator: - self._animator.stop() - - self._animator = animator.Animator(0.5, 30, animator.EASE_OUT_EXPO) - self._animator.add(_Animation(self, 1.0)) - self._animator.start() - - self._event_frame.hide() - - self.state = STATE_SHOWING - self.mode = MODE_NOT_INTERACTIVE - def _size_changed_cb(self, screen): self._update_position() @@ -281,15 +286,13 @@ class Frame(object): self._mouse_listener.mouse_enter() def _popup_context_deactivated_cb(self, popup_context): - if not self._hover_frame: + if not self._is_hover(): self._mouse_listener.mouse_leave() def _enter_notify_cb(self, window, event): - self._hover_frame = True self._mouse_listener.mouse_enter() def _leave_notify_cb(self, window, event): - self._hover_frame = False if not self._popup_context.is_active(): self._mouse_listener.mouse_leave()