Do not show the frame when leaving the edge before the time
This commit is contained in:
parent
c982879815
commit
66124465e8
@ -13,15 +13,24 @@ from sugar.canvas.MenuShell import MenuShell
|
|||||||
|
|
||||||
class EventFrame(gobject.GObject):
|
class EventFrame(gobject.GObject):
|
||||||
__gsignals__ = {
|
__gsignals__ = {
|
||||||
'hover-edge': (gobject.SIGNAL_RUN_FIRST,
|
'enter-edge': (gobject.SIGNAL_RUN_FIRST,
|
||||||
gobject.TYPE_NONE, ([])),
|
gobject.TYPE_NONE, ([])),
|
||||||
'hover-corner': (gobject.SIGNAL_RUN_FIRST,
|
'enter-corner': (gobject.SIGNAL_RUN_FIRST,
|
||||||
|
gobject.TYPE_NONE, ([])),
|
||||||
|
'leave': (gobject.SIGNAL_RUN_FIRST,
|
||||||
gobject.TYPE_NONE, ([]))
|
gobject.TYPE_NONE, ([]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HOVER_NONE = 0
|
||||||
|
HOVER_CORNER = 1
|
||||||
|
HOVER_EDGE = 2
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
gobject.GObject.__init__(self)
|
gobject.GObject.__init__(self)
|
||||||
|
|
||||||
self._windows = []
|
self._windows = []
|
||||||
|
self._hover = EventFrame.HOVER_NONE
|
||||||
|
self._active = False
|
||||||
|
|
||||||
invisible = self._create_invisible(0, 0, gtk.gdk.screen_width(), 1)
|
invisible = self._create_invisible(0, 0, gtk.gdk.screen_width(), 1)
|
||||||
self._windows.append(invisible)
|
self._windows.append(invisible)
|
||||||
@ -45,15 +54,17 @@ class EventFrame(gobject.GObject):
|
|||||||
|
|
||||||
def _create_invisible(self, x, y, width, height):
|
def _create_invisible(self, x, y, width, height):
|
||||||
invisible = gtk.Invisible()
|
invisible = gtk.Invisible()
|
||||||
invisible.connect('enter-notify-event', self._enter_notify_cb)
|
invisible.connect('motion-notify-event', self._motion_notify_cb)
|
||||||
|
invisible.connect('leave-notify-event', self._leave_notify_cb)
|
||||||
|
|
||||||
invisible.realize()
|
invisible.realize()
|
||||||
invisible.window.set_events(gtk.gdk.ENTER_NOTIFY_MASK)
|
invisible.window.set_events(gtk.gdk.POINTER_MOTION_MASK |
|
||||||
|
gtk.gdk.LEAVE_NOTIFY_MASK)
|
||||||
invisible.window.move_resize(x, y, width, height)
|
invisible.window.move_resize(x, y, width, height)
|
||||||
|
|
||||||
return invisible
|
return invisible
|
||||||
|
|
||||||
def _enter_notify_cb(self, widget, event):
|
def _motion_notify_cb(self, widget, event):
|
||||||
screen_w = gtk.gdk.screen_width()
|
screen_w = gtk.gdk.screen_width()
|
||||||
screen_h = gtk.gdk.screen_height()
|
screen_h = gtk.gdk.screen_height()
|
||||||
|
|
||||||
@ -61,15 +72,26 @@ class EventFrame(gobject.GObject):
|
|||||||
(event.x == 0 and event.y == screen_h - 1) or \
|
(event.x == 0 and event.y == screen_h - 1) or \
|
||||||
(event.x == screen_w - 1 and event.y == 0) or \
|
(event.x == screen_w - 1 and event.y == 0) or \
|
||||||
(event.x == screen_w - 1 and event.y == screen_h - 1):
|
(event.x == screen_w - 1 and event.y == screen_h - 1):
|
||||||
self.emit('hover-corner')
|
if self._hover != EventFrame.HOVER_CORNER:
|
||||||
|
self._hover = EventFrame.HOVER_CORNER
|
||||||
|
self.emit('enter-corner')
|
||||||
else:
|
else:
|
||||||
self.emit('hover-edge')
|
if self._hover != EventFrame.HOVER_EDGE:
|
||||||
|
self._hover = EventFrame.HOVER_EDGE
|
||||||
|
self.emit('enter-edge')
|
||||||
|
|
||||||
|
def _leave_notify_cb(self, widget, event):
|
||||||
|
self._hover = EventFrame.HOVER_NONE
|
||||||
|
if self._active:
|
||||||
|
self.emit('leave')
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
|
self._active = True
|
||||||
for window in self._windows:
|
for window in self._windows:
|
||||||
window.show()
|
window.show()
|
||||||
|
|
||||||
def hide(self):
|
def hide(self):
|
||||||
|
self._active = False
|
||||||
for window in self._windows:
|
for window in self._windows:
|
||||||
window.hide()
|
window.hide()
|
||||||
|
|
||||||
@ -120,8 +142,9 @@ class Frame:
|
|||||||
self._add_panel(model, 0, 5, 5, 50)
|
self._add_panel(model, 0, 5, 5, 50)
|
||||||
|
|
||||||
self._event_frame = EventFrame()
|
self._event_frame = EventFrame()
|
||||||
self._event_frame.connect('hover-edge', self._hover_edge_cb)
|
self._event_frame.connect('enter-edge', self._enter_edge_cb)
|
||||||
self._event_frame.connect('hover-corner', self._hover_corner_cb)
|
self._event_frame.connect('enter-corner', self._enter_corner_cb)
|
||||||
|
self._event_frame.connect('leave', self._event_frame_leave_cb)
|
||||||
self._event_frame.show()
|
self._event_frame.show()
|
||||||
|
|
||||||
def _add_panel(self, model, x, y, width, height):
|
def _add_panel(self, model, x, y, width, height):
|
||||||
@ -146,12 +169,15 @@ class Frame:
|
|||||||
if not self._menu_shell.is_active():
|
if not self._menu_shell.is_active():
|
||||||
self._timeline.play('before_slide_out', 'slide_out')
|
self._timeline.play('before_slide_out', 'slide_out')
|
||||||
|
|
||||||
def _hover_edge_cb(self, event_frame):
|
def _enter_edge_cb(self, event_frame):
|
||||||
self._timeline.play(None, 'slide_in')
|
self._timeline.play(None, 'slide_in')
|
||||||
|
|
||||||
def _hover_corner_cb(self, event_frame):
|
def _enter_corner_cb(self, event_frame):
|
||||||
self._timeline.play('slide_in', 'slide_in')
|
self._timeline.play('slide_in', 'slide_in')
|
||||||
|
|
||||||
|
def _event_frame_leave_cb(self, event_frame):
|
||||||
|
self._timeline.goto('slide_out', True)
|
||||||
|
|
||||||
def show_and_hide(self, seconds):
|
def show_and_hide(self, seconds):
|
||||||
self._timeline.play()
|
self._timeline.play()
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ class Timeline:
|
|||||||
self._observer.next_frame(tag.name, frame, n_frames)
|
self._observer.next_frame(tag.name, frame, n_frames)
|
||||||
|
|
||||||
def goto(self, tag_name, end_frame=False):
|
def goto(self, tag_name, end_frame=False):
|
||||||
self.stop()
|
self.pause()
|
||||||
|
|
||||||
tag = self._name_to_tag[tag_name]
|
tag = self._name_to_tag[tag_name]
|
||||||
if end_frame:
|
if end_frame:
|
||||||
@ -75,7 +75,7 @@ class Timeline:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def play(self, start_tag=None, stop_tag=None):
|
def play(self, start_tag=None, stop_tag=None):
|
||||||
self.stop()
|
self.pause()
|
||||||
|
|
||||||
if start_tag == None:
|
if start_tag == None:
|
||||||
start = 0
|
start = 0
|
||||||
@ -93,6 +93,6 @@ class Timeline:
|
|||||||
self._timeout_sid = gobject.timeout_add(
|
self._timeout_sid = gobject.timeout_add(
|
||||||
interval, self._timeout_cb, end)
|
interval, self._timeout_cb, end)
|
||||||
|
|
||||||
def stop(self):
|
def pause(self):
|
||||||
if self._timeout_sid > 0:
|
if self._timeout_sid > 0:
|
||||||
gobject.source_remove(self._timeout_sid)
|
gobject.source_remove(self._timeout_sid)
|
||||||
|
Loading…
Reference in New Issue
Block a user