2006-08-23 11:52:18 +02:00
|
|
|
import gtk
|
2006-08-29 00:30:19 +02:00
|
|
|
import gobject
|
2006-09-07 15:11:51 +02:00
|
|
|
import goocanvas
|
2006-09-18 16:51:21 +02:00
|
|
|
import wnck
|
2006-08-23 11:52:18 +02:00
|
|
|
|
2006-09-15 13:23:21 +02:00
|
|
|
from view.frame.BottomPanel import BottomPanel
|
|
|
|
from view.frame.RightPanel import RightPanel
|
|
|
|
from view.frame.TopPanel import TopPanel
|
|
|
|
from view.frame.PanelWindow import PanelWindow
|
2006-09-13 13:50:00 +02:00
|
|
|
from sugar.canvas.Grid import Grid
|
2006-09-21 14:08:10 +02:00
|
|
|
from sugar.canvas.Timeline import Timeline
|
2006-09-19 14:04:11 +02:00
|
|
|
from sugar.canvas.MenuShell import MenuShell
|
2006-08-23 11:52:18 +02:00
|
|
|
|
2006-09-18 16:51:21 +02:00
|
|
|
class EventFrame(gobject.GObject):
|
|
|
|
__gsignals__ = {
|
2006-09-21 18:04:37 +02:00
|
|
|
'enter-edge': (gobject.SIGNAL_RUN_FIRST,
|
2006-09-21 14:45:36 +02:00
|
|
|
gobject.TYPE_NONE, ([])),
|
2006-09-21 18:04:37 +02:00
|
|
|
'enter-corner': (gobject.SIGNAL_RUN_FIRST,
|
|
|
|
gobject.TYPE_NONE, ([])),
|
|
|
|
'leave': (gobject.SIGNAL_RUN_FIRST,
|
2006-09-21 14:45:36 +02:00
|
|
|
gobject.TYPE_NONE, ([]))
|
2006-09-18 16:51:21 +02:00
|
|
|
}
|
2006-09-21 18:04:37 +02:00
|
|
|
|
|
|
|
HOVER_NONE = 0
|
|
|
|
HOVER_CORNER = 1
|
|
|
|
HOVER_EDGE = 2
|
|
|
|
|
2006-09-18 16:51:21 +02:00
|
|
|
def __init__(self):
|
|
|
|
gobject.GObject.__init__(self)
|
|
|
|
|
|
|
|
self._windows = []
|
2006-09-21 18:04:37 +02:00
|
|
|
self._hover = EventFrame.HOVER_NONE
|
|
|
|
self._active = False
|
2006-09-18 16:51:21 +02:00
|
|
|
|
|
|
|
invisible = self._create_invisible(0, 0, gtk.gdk.screen_width(), 1)
|
|
|
|
self._windows.append(invisible)
|
|
|
|
|
|
|
|
invisible = self._create_invisible(0, 0, 1, gtk.gdk.screen_height())
|
|
|
|
self._windows.append(invisible)
|
|
|
|
|
|
|
|
invisible = self._create_invisible(gtk.gdk.screen_width() - 1, 0,
|
|
|
|
gtk.gdk.screen_width(),
|
|
|
|
gtk.gdk.screen_height())
|
|
|
|
self._windows.append(invisible)
|
|
|
|
|
|
|
|
invisible = self._create_invisible(0, gtk.gdk.screen_height() - 1,
|
|
|
|
gtk.gdk.screen_width(),
|
|
|
|
gtk.gdk.screen_height())
|
|
|
|
self._windows.append(invisible)
|
|
|
|
|
|
|
|
screen = wnck.screen_get_default()
|
|
|
|
screen.connect('active-window-changed',
|
|
|
|
self._active_window_changed_cb)
|
|
|
|
|
|
|
|
def _create_invisible(self, x, y, width, height):
|
|
|
|
invisible = gtk.Invisible()
|
2006-09-21 18:04:37 +02:00
|
|
|
invisible.connect('motion-notify-event', self._motion_notify_cb)
|
|
|
|
invisible.connect('leave-notify-event', self._leave_notify_cb)
|
2006-09-18 16:51:21 +02:00
|
|
|
|
|
|
|
invisible.realize()
|
2006-09-21 18:04:37 +02:00
|
|
|
invisible.window.set_events(gtk.gdk.POINTER_MOTION_MASK |
|
|
|
|
gtk.gdk.LEAVE_NOTIFY_MASK)
|
2006-09-18 16:51:21 +02:00
|
|
|
invisible.window.move_resize(x, y, width, height)
|
|
|
|
|
|
|
|
return invisible
|
|
|
|
|
2006-09-21 18:04:37 +02:00
|
|
|
def _motion_notify_cb(self, widget, event):
|
2006-09-21 14:45:36 +02:00
|
|
|
screen_w = gtk.gdk.screen_width()
|
|
|
|
screen_h = gtk.gdk.screen_height()
|
|
|
|
|
|
|
|
if (event.x == 0 and event.y == 0) 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 == screen_h - 1):
|
2006-09-21 18:04:37 +02:00
|
|
|
if self._hover != EventFrame.HOVER_CORNER:
|
|
|
|
self._hover = EventFrame.HOVER_CORNER
|
|
|
|
self.emit('enter-corner')
|
2006-09-21 14:45:36 +02:00
|
|
|
else:
|
2006-09-21 18:04:37 +02:00
|
|
|
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')
|
2006-09-18 16:51:21 +02:00
|
|
|
|
|
|
|
def show(self):
|
2006-09-21 18:04:37 +02:00
|
|
|
self._active = True
|
2006-09-18 16:51:21 +02:00
|
|
|
for window in self._windows:
|
|
|
|
window.show()
|
|
|
|
|
|
|
|
def hide(self):
|
2006-09-21 18:04:37 +02:00
|
|
|
self._active = False
|
2006-09-18 16:51:21 +02:00
|
|
|
for window in self._windows:
|
|
|
|
window.hide()
|
|
|
|
|
|
|
|
def _active_window_changed_cb(self, screen):
|
|
|
|
for window in self._windows:
|
|
|
|
window.window.raise_()
|
|
|
|
|
2006-09-01 15:11:52 +02:00
|
|
|
class Frame:
|
2006-09-15 12:40:22 +02:00
|
|
|
def __init__(self, shell):
|
2006-09-07 15:11:51 +02:00
|
|
|
self._windows = []
|
2006-09-18 16:51:21 +02:00
|
|
|
self._shell = shell
|
2006-09-21 14:08:10 +02:00
|
|
|
self._sticky = False
|
|
|
|
|
|
|
|
self._timeline = Timeline(self)
|
|
|
|
self._timeline.add_tag('slide_in', 6, 12)
|
|
|
|
self._timeline.add_tag('before_slide_out', 36, 36)
|
|
|
|
self._timeline.add_tag('slide_out', 37, 42)
|
2006-09-07 15:11:51 +02:00
|
|
|
|
2006-09-13 13:50:00 +02:00
|
|
|
model = goocanvas.CanvasModelSimple()
|
|
|
|
root = model.get_root_item()
|
2006-09-07 15:11:51 +02:00
|
|
|
|
2006-09-15 14:24:26 +02:00
|
|
|
grid = shell.get_grid()
|
2006-09-19 14:43:42 +02:00
|
|
|
self._menu_shell = MenuShell(grid)
|
|
|
|
self._menu_shell.connect('activated', self._menu_shell_activated_cb)
|
|
|
|
self._menu_shell.connect('deactivated', self._menu_shell_deactivated_cb)
|
2006-08-23 11:52:18 +02:00
|
|
|
|
2006-09-14 15:07:22 +02:00
|
|
|
bg = goocanvas.Rect(fill_color="#4f4f4f", line_width=0)
|
2006-09-13 13:50:00 +02:00
|
|
|
grid.set_constraints(bg, 0, 0, 80, 60)
|
|
|
|
root.add_child(bg)
|
2006-09-01 15:33:55 +02:00
|
|
|
|
2006-09-15 14:24:26 +02:00
|
|
|
panel = BottomPanel(shell)
|
2006-09-13 13:50:00 +02:00
|
|
|
grid.set_constraints(panel, 5, 55)
|
|
|
|
root.add_child(panel)
|
2006-09-07 15:11:51 +02:00
|
|
|
|
2006-09-18 16:51:21 +02:00
|
|
|
self._add_panel(model, 0, 55, 80, 5)
|
2006-09-08 01:13:42 +02:00
|
|
|
|
2006-09-19 14:43:42 +02:00
|
|
|
panel = TopPanel(shell, self._menu_shell)
|
2006-09-13 13:50:00 +02:00
|
|
|
root.add_child(panel)
|
2006-09-08 01:13:42 +02:00
|
|
|
|
2006-09-18 16:51:21 +02:00
|
|
|
self._add_panel(model, 0, 0, 80, 5)
|
2006-09-13 13:50:00 +02:00
|
|
|
|
2006-09-19 14:43:42 +02:00
|
|
|
panel = RightPanel(shell, self._menu_shell)
|
2006-09-13 13:50:00 +02:00
|
|
|
grid.set_constraints(panel, 75, 5)
|
|
|
|
root.add_child(panel)
|
2006-09-07 15:11:51 +02:00
|
|
|
|
2006-09-18 16:51:21 +02:00
|
|
|
self._add_panel(model, 75, 5, 5, 50)
|
|
|
|
|
|
|
|
self._add_panel(model, 0, 5, 5, 50)
|
|
|
|
|
|
|
|
self._event_frame = EventFrame()
|
2006-09-21 18:04:37 +02:00
|
|
|
self._event_frame.connect('enter-edge', self._enter_edge_cb)
|
|
|
|
self._event_frame.connect('enter-corner', self._enter_corner_cb)
|
|
|
|
self._event_frame.connect('leave', self._event_frame_leave_cb)
|
2006-09-18 16:51:21 +02:00
|
|
|
self._event_frame.show()
|
|
|
|
|
|
|
|
def _add_panel(self, model, x, y, width, height):
|
|
|
|
grid = self._shell.get_grid()
|
|
|
|
|
|
|
|
panel_window = PanelWindow(grid, model, x, y, width, height)
|
|
|
|
panel_window.connect('enter-notify-event', self._enter_notify_cb)
|
|
|
|
panel_window.connect('leave-notify-event', self._leave_notify_cb)
|
2006-09-08 00:51:45 +02:00
|
|
|
|
2006-09-13 13:50:00 +02:00
|
|
|
self._windows.append(panel_window)
|
2006-08-28 16:53:29 +02:00
|
|
|
|
2006-09-19 14:43:42 +02:00
|
|
|
def _menu_shell_activated_cb(self, menu_shell):
|
2006-09-21 14:45:36 +02:00
|
|
|
self._timeline.goto('slide_in', True)
|
2006-09-19 14:43:42 +02:00
|
|
|
|
|
|
|
def _menu_shell_deactivated_cb(self, menu_shell):
|
2006-09-21 14:45:36 +02:00
|
|
|
self._timeline.play('before_slide_out', 'slide_out')
|
2006-09-19 14:43:42 +02:00
|
|
|
|
2006-09-18 16:51:21 +02:00
|
|
|
def _enter_notify_cb(self, window, event):
|
2006-09-21 14:45:36 +02:00
|
|
|
self._timeline.goto('slide_in', True)
|
2006-09-18 16:51:21 +02:00
|
|
|
|
|
|
|
def _leave_notify_cb(self, window, event):
|
2006-09-21 14:45:36 +02:00
|
|
|
if not self._menu_shell.is_active():
|
|
|
|
self._timeline.play('before_slide_out', 'slide_out')
|
|
|
|
|
2006-09-21 18:04:37 +02:00
|
|
|
def _enter_edge_cb(self, event_frame):
|
2006-09-21 14:45:36 +02:00
|
|
|
self._timeline.play(None, 'slide_in')
|
2006-09-18 16:51:21 +02:00
|
|
|
|
2006-09-21 18:04:37 +02:00
|
|
|
def _enter_corner_cb(self, event_frame):
|
2006-09-21 14:45:36 +02:00
|
|
|
self._timeline.play('slide_in', 'slide_in')
|
2006-09-18 16:51:21 +02:00
|
|
|
|
2006-09-21 18:04:37 +02:00
|
|
|
def _event_frame_leave_cb(self, event_frame):
|
|
|
|
self._timeline.goto('slide_out', True)
|
|
|
|
|
2006-08-29 00:30:19 +02:00
|
|
|
def show_and_hide(self, seconds):
|
2006-09-21 14:08:10 +02:00
|
|
|
self._timeline.play()
|
2006-08-23 11:52:18 +02:00
|
|
|
|
2006-09-21 14:08:10 +02:00
|
|
|
def notify_key_press(self):
|
|
|
|
if self._timeline.on_tag('slide_in'):
|
|
|
|
self._timeline.play('before_slide_out', 'slide_out')
|
|
|
|
elif self._timeline.on_tag('before_slide_out'):
|
|
|
|
self._sticky = True
|
2006-09-18 16:51:21 +02:00
|
|
|
else:
|
2006-09-21 14:08:10 +02:00
|
|
|
self._sticky = False
|
|
|
|
self._timeline.play('slide_in', 'slide_in')
|
|
|
|
|
|
|
|
def notify_key_release(self):
|
|
|
|
if self._sticky:
|
|
|
|
self._timeline.play('before_slide_out', 'slide_out')
|
|
|
|
|
|
|
|
def do_slide_in(self, current, n_frames):
|
2006-09-21 14:45:36 +02:00
|
|
|
if not self._windows[0].props.visible:
|
2006-09-21 14:08:10 +02:00
|
|
|
for panel in self._windows:
|
|
|
|
panel.show()
|
|
|
|
self._event_frame.hide()
|
|
|
|
|
|
|
|
def do_slide_out(self, current, n_frames):
|
2006-09-21 14:45:36 +02:00
|
|
|
if self._windows[0].props.visible:
|
2006-09-21 14:08:10 +02:00
|
|
|
for panel in self._windows:
|
|
|
|
panel.hide()
|
|
|
|
self._event_frame.show()
|