2006-10-15 01:24:45 +02:00
|
|
|
# Copyright (C) 2006, Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
import logging
|
2006-08-23 11:52:18 +02:00
|
|
|
import gtk
|
2006-08-29 00:30:19 +02:00
|
|
|
import gobject
|
2006-10-02 01:50:43 +02:00
|
|
|
import hippo
|
2006-09-18 16:51:21 +02:00
|
|
|
import wnck
|
2006-08-23 11:52:18 +02:00
|
|
|
|
2006-10-02 01:50:43 +02:00
|
|
|
from view.frame.ActivitiesBox import ActivitiesBox
|
|
|
|
from view.frame.ZoomBox import ZoomBox
|
2006-10-24 19:44:18 +02:00
|
|
|
from view.frame.overlaybox import OverlayBox
|
2006-10-05 17:09:38 +02:00
|
|
|
from view.frame.FriendsBox import FriendsBox
|
2006-09-15 13:23:21 +02:00
|
|
|
from view.frame.PanelWindow import PanelWindow
|
2006-12-13 22:36:05 +01:00
|
|
|
from view.frame.clipboardpanelwindow import ClipboardPanelWindow
|
2006-10-16 18:43:04 +02:00
|
|
|
from view.frame.notificationtray import NotificationTray
|
2007-01-11 11:43:34 +01:00
|
|
|
from model.ShellModel import ShellModel
|
2006-10-04 00:55:20 +02:00
|
|
|
from sugar.graphics.timeline import Timeline
|
2006-10-02 01:50:43 +02:00
|
|
|
from sugar.graphics.grid import Grid
|
2006-10-18 17:57:41 +02:00
|
|
|
from sugar.graphics.menushell import MenuShell
|
2006-08-23 11:52:18 +02:00
|
|
|
|
2006-09-18 16:51:21 +02:00
|
|
|
class EventFrame(gobject.GObject):
|
2006-12-04 20:12:24 +01:00
|
|
|
__gsignals__ = {
|
|
|
|
'enter-edge': (gobject.SIGNAL_RUN_FIRST,
|
|
|
|
gobject.TYPE_NONE, ([])),
|
|
|
|
'enter-corner': (gobject.SIGNAL_RUN_FIRST,
|
|
|
|
gobject.TYPE_NONE, ([])),
|
|
|
|
'leave': (gobject.SIGNAL_RUN_FIRST,
|
|
|
|
gobject.TYPE_NONE, ([]))
|
|
|
|
}
|
|
|
|
|
|
|
|
HOVER_NONE = 0
|
|
|
|
HOVER_CORNER = 1
|
|
|
|
HOVER_EDGE = 2
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
gobject.GObject.__init__(self)
|
|
|
|
|
|
|
|
self._windows = []
|
|
|
|
self._hover = EventFrame.HOVER_NONE
|
|
|
|
self._active = False
|
|
|
|
|
2007-01-11 23:57:06 +01:00
|
|
|
invisible = self._create_invisible(0, 0, gtk.gdk.screen_width(), 6)
|
2006-12-04 20:12:24 +01:00
|
|
|
self._windows.append(invisible)
|
|
|
|
|
2007-01-11 23:57:06 +01:00
|
|
|
invisible = self._create_invisible(0, 0, 6, gtk.gdk.screen_height())
|
2006-12-04 20:12:24 +01:00
|
|
|
self._windows.append(invisible)
|
|
|
|
|
2007-01-11 23:57:06 +01:00
|
|
|
invisible = self._create_invisible(gtk.gdk.screen_width() - 6, 0,
|
2006-12-04 20:12:24 +01:00
|
|
|
gtk.gdk.screen_width(),
|
|
|
|
gtk.gdk.screen_height())
|
|
|
|
self._windows.append(invisible)
|
|
|
|
|
2007-01-11 23:57:06 +01:00
|
|
|
invisible = self._create_invisible(0, gtk.gdk.screen_height() - 6,
|
2006-12-04 20:12:24 +01:00
|
|
|
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()
|
|
|
|
invisible.connect('motion-notify-event', self._motion_notify_cb)
|
|
|
|
invisible.connect('enter-notify-event', self._enter_notify_cb)
|
|
|
|
invisible.connect('leave-notify-event', self._leave_notify_cb)
|
2006-12-16 23:55:22 +01:00
|
|
|
|
|
|
|
invisible.drag_dest_set(0, [], 0)
|
|
|
|
invisible.connect('drag_motion', self._drag_motion_cb)
|
|
|
|
invisible.connect('drag_leave', self._drag_leave_cb)
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
invisible.realize()
|
|
|
|
invisible.window.set_events(gtk.gdk.POINTER_MOTION_MASK |
|
|
|
|
gtk.gdk.ENTER_NOTIFY_MASK |
|
|
|
|
gtk.gdk.LEAVE_NOTIFY_MASK)
|
|
|
|
invisible.window.move_resize(x, y, width, height)
|
|
|
|
|
|
|
|
return invisible
|
|
|
|
|
|
|
|
def _enter_notify_cb(self, widget, event):
|
|
|
|
self._notify_enter(event.x, event.y)
|
2006-12-16 23:55:22 +01:00
|
|
|
logging.debug('EventFrame._enter_notify_cb ' + str(self._hover))
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
def _motion_notify_cb(self, widget, event):
|
|
|
|
self._notify_enter(event.x, event.y)
|
2006-12-16 23:55:22 +01:00
|
|
|
logging.debug('EventFrame._motion_notify_cb ' + str(self._hover))
|
|
|
|
|
|
|
|
def _drag_motion_cb(self, widget, drag_context, x, y, timestamp):
|
|
|
|
drag_context.drag_status(0, timestamp);
|
|
|
|
self._notify_enter(x, y)
|
|
|
|
logging.debug('EventFrame._drag_motion_cb ' + str(self._hover))
|
|
|
|
return True
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
def _notify_enter(self, x, y):
|
|
|
|
screen_w = gtk.gdk.screen_width()
|
|
|
|
screen_h = gtk.gdk.screen_height()
|
|
|
|
|
|
|
|
if (x == 0 and y == 0) or \
|
|
|
|
(x == 0 and y == screen_h - 1) or \
|
|
|
|
(x == screen_w - 1 and y == 0) or \
|
|
|
|
(x == screen_w - 1 and y == screen_h - 1):
|
|
|
|
if self._hover != EventFrame.HOVER_CORNER:
|
|
|
|
self._hover = EventFrame.HOVER_CORNER
|
|
|
|
self.emit('enter-corner')
|
|
|
|
else:
|
|
|
|
if self._hover != EventFrame.HOVER_EDGE:
|
|
|
|
self._hover = EventFrame.HOVER_EDGE
|
|
|
|
self.emit('enter-edge')
|
|
|
|
|
|
|
|
def _leave_notify_cb(self, widget, event):
|
2006-12-16 23:55:22 +01:00
|
|
|
self._notify_leave()
|
|
|
|
logging.debug('EventFrame._leave_notify_cb ' + str(self._hover))
|
|
|
|
|
|
|
|
def _drag_leave_cb(self, widget, drag_context, timestamp):
|
|
|
|
self._notify_leave()
|
|
|
|
logging.debug('EventFrame._drag_leave_cb ' + str(self._hover))
|
|
|
|
return True
|
|
|
|
|
|
|
|
def _notify_leave(self):
|
2006-12-04 20:12:24 +01:00
|
|
|
self._hover = EventFrame.HOVER_NONE
|
|
|
|
if self._active:
|
|
|
|
self.emit('leave')
|
|
|
|
|
|
|
|
def show(self):
|
|
|
|
self._active = True
|
|
|
|
for window in self._windows:
|
|
|
|
window.show()
|
|
|
|
|
|
|
|
def hide(self):
|
|
|
|
self._active = False
|
|
|
|
for window in self._windows:
|
|
|
|
window.hide()
|
|
|
|
|
|
|
|
def _active_window_changed_cb(self, screen):
|
|
|
|
for window in self._windows:
|
|
|
|
window.window.raise_()
|
2006-09-18 16:51:21 +02:00
|
|
|
|
2006-09-01 15:11:52 +02:00
|
|
|
class Frame:
|
2006-12-04 20:12:24 +01:00
|
|
|
INACTIVE = 0
|
|
|
|
TEMPORARY = 1
|
|
|
|
STICKY = 2
|
|
|
|
HIDE_ON_LEAVE = 3
|
|
|
|
AUTOMATIC = 4
|
2006-09-22 11:14:33 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def __init__(self, shell):
|
|
|
|
self._windows = []
|
2007-01-09 20:15:18 +01:00
|
|
|
self._hover_frame = False
|
2006-12-04 20:12:24 +01:00
|
|
|
self._shell = shell
|
|
|
|
self._mode = Frame.INACTIVE
|
2006-09-21 14:08:10 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
self._timeline = Timeline(self)
|
2007-01-16 14:38:51 +01:00
|
|
|
self._timeline.add_tag('slide_in', 18, 24)
|
|
|
|
self._timeline.add_tag('before_slide_out', 48, 48)
|
|
|
|
self._timeline.add_tag('slide_out', 49, 54)
|
2006-09-07 15:11:51 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
self._event_frame = EventFrame()
|
|
|
|
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)
|
|
|
|
self._event_frame.show()
|
2006-10-02 01:50:43 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
grid = Grid()
|
2006-09-07 15:11:51 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
# Top panel
|
2006-12-13 22:36:05 +01:00
|
|
|
panel = self._create_panel(grid, 0, 0, 16, 1)
|
|
|
|
menu_shell = panel.get_menu_shell()
|
|
|
|
root = panel.get_root()
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
menu_shell.set_position(MenuShell.BOTTOM)
|
2006-08-23 11:52:18 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
box = ZoomBox(self._shell, menu_shell)
|
2006-09-07 15:11:51 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
[x, y] = grid.point(1, 0)
|
|
|
|
root.append(box, hippo.PACK_FIXED)
|
|
|
|
root.move(box, x, y)
|
2006-09-08 01:13:42 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
tray = NotificationTray()
|
|
|
|
tray_box = hippo.CanvasBox(box_width=grid.dimension(1),
|
|
|
|
box_height=grid.dimension(1),
|
|
|
|
xalign=hippo.ALIGNMENT_END)
|
2006-10-16 18:43:04 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
tray_widget = hippo.CanvasWidget()
|
|
|
|
tray_widget.props.widget = tray
|
|
|
|
tray_box.append(tray_widget, gtk.EXPAND)
|
2006-10-16 18:43:04 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
[x, y] = grid.point(13, 0)
|
|
|
|
root.append(tray_box, hippo.PACK_FIXED)
|
|
|
|
root.move(tray_box, x, y)
|
2006-10-16 18:43:04 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
box = OverlayBox(self._shell)
|
2006-10-24 19:44:18 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
[x, y] = grid.point(14, 0)
|
|
|
|
root.append(box, hippo.PACK_FIXED)
|
|
|
|
root.move(box, x, y)
|
2006-10-24 19:44:18 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
# Bottom panel
|
2006-12-13 22:36:05 +01:00
|
|
|
panel = self._create_panel(grid, 0, 11, 16, 1)
|
|
|
|
menu_shell = panel.get_menu_shell()
|
|
|
|
root = panel.get_root()
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
menu_shell.set_position(MenuShell.TOP)
|
2006-09-08 01:13:42 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
box = ActivitiesBox(self._shell)
|
|
|
|
root.append(box, hippo.PACK_FIXED)
|
2006-09-07 15:11:51 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
[x, y] = grid.point(1, 0)
|
|
|
|
root.move(box, x, y)
|
2006-09-18 16:51:21 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
# Right panel
|
2006-12-13 22:36:05 +01:00
|
|
|
panel = self._create_panel(grid, 15, 1, 1, 10)
|
|
|
|
menu_shell = panel.get_menu_shell()
|
|
|
|
root = panel.get_root()
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
menu_shell.set_position(MenuShell.LEFT)
|
2006-10-02 01:50:43 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
box = FriendsBox(self._shell, menu_shell)
|
|
|
|
root.append(box)
|
2006-10-05 17:09:38 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
# Left panel
|
2006-12-13 22:36:05 +01:00
|
|
|
panel = self._create_clipboard_panel(grid, 0, 1, 1, 10)
|
2007-01-11 11:43:34 +01:00
|
|
|
|
|
|
|
shell.get_model().connect('notify::state',
|
|
|
|
self._shell_state_changed_cb)
|
|
|
|
|
|
|
|
def _shell_state_changed_cb(self, model, pspec):
|
|
|
|
if model.props.state == ShellModel.STATE_SHUTDOWN:
|
|
|
|
self._timeline.goto('slide_out', True)
|
2006-12-13 22:36:05 +01:00
|
|
|
|
|
|
|
def _create_clipboard_panel(self, grid, x, y, width, height):
|
|
|
|
[x, y, width, height] = grid.rectangle(x, y, width, height)
|
2006-12-16 23:55:22 +01:00
|
|
|
panel = ClipboardPanelWindow(self, x, y, width, height)
|
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
self._connect_to_panel(panel)
|
2006-12-16 23:55:22 +01:00
|
|
|
panel.connect('drag-motion', self._drag_motion_cb)
|
|
|
|
panel.connect('drag-leave', self._drag_leave_cb)
|
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
self._windows.append(panel)
|
2006-11-15 13:56:19 +01:00
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
return panel
|
2006-10-05 17:09:38 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _create_panel(self, grid, x, y, width, height):
|
2006-12-13 22:36:05 +01:00
|
|
|
[x, y, width, height] = grid.rectangle(x, y, width, height)
|
|
|
|
panel = PanelWindow(x, y, width, height)
|
|
|
|
self._connect_to_panel(panel)
|
|
|
|
self._windows.append(panel)
|
|
|
|
|
|
|
|
return panel
|
2006-10-02 01:50:43 +02:00
|
|
|
|
2006-12-13 22:36:05 +01:00
|
|
|
def _connect_to_panel(self, panel):
|
2006-12-04 20:12:24 +01:00
|
|
|
panel.connect('enter-notify-event', self._enter_notify_cb)
|
|
|
|
panel.connect('leave-notify-event', self._leave_notify_cb)
|
2006-10-02 01:50:43 +02:00
|
|
|
|
2007-01-09 20:15:18 +01:00
|
|
|
self._menu_shell = panel.get_menu_shell()
|
|
|
|
self._menu_shell.connect('activated',
|
|
|
|
self._menu_shell_activated_cb)
|
|
|
|
self._menu_shell.connect('deactivated',
|
|
|
|
self._menu_shell_deactivated_cb)
|
2006-10-18 16:23:06 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _menu_shell_activated_cb(self, menu_shell):
|
|
|
|
self._timeline.goto('slide_in', True)
|
2006-09-19 14:43:42 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _menu_shell_deactivated_cb(self, menu_shell):
|
2007-01-09 20:15:18 +01:00
|
|
|
if self._mode != Frame.STICKY and not self._hover_frame:
|
2006-12-04 20:12:24 +01:00
|
|
|
self._timeline.play('before_slide_out', 'slide_out')
|
2006-09-19 14:43:42 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _enter_notify_cb(self, window, event):
|
2007-01-09 20:15:18 +01:00
|
|
|
self._enter_notify()
|
2006-12-16 23:55:22 +01:00
|
|
|
logging.debug('Frame._enter_notify_cb ' + str(self._mode))
|
|
|
|
|
|
|
|
def _drag_motion_cb(self, window, context, x, y, time):
|
2007-01-09 20:15:18 +01:00
|
|
|
self._enter_notify()
|
2006-12-16 23:55:22 +01:00
|
|
|
logging.debug('Frame._drag_motion_cb ' + str(self._mode))
|
|
|
|
return True
|
|
|
|
|
|
|
|
def _drag_leave_cb(self, window, drag_context, timestamp):
|
|
|
|
self._leave_notify()
|
|
|
|
logging.debug('Frame._drag_leave_cb ' + str(self._mode))
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _leave_notify_cb(self, window, event):
|
|
|
|
# FIXME for some reason every click cause also a leave-notify
|
|
|
|
if event.state == gtk.gdk.BUTTON1_MASK:
|
|
|
|
return
|
2006-09-22 11:14:33 +02:00
|
|
|
|
2006-12-16 23:55:22 +01:00
|
|
|
self._leave_notify()
|
|
|
|
logging.debug('Frame._leave_notify_cb ' + str(self._mode))
|
2007-01-09 20:15:18 +01:00
|
|
|
|
|
|
|
def _enter_notify(self):
|
|
|
|
self._hover_frame = True
|
|
|
|
self._timeline.goto('slide_in', True)
|
|
|
|
|
2006-12-16 23:55:22 +01:00
|
|
|
def _leave_notify(self):
|
2007-01-09 20:15:18 +01:00
|
|
|
self._hover_frame = False
|
|
|
|
if not self._menu_shell.is_active() and \
|
2006-12-04 20:12:24 +01:00
|
|
|
(self._mode == Frame.HIDE_ON_LEAVE or \
|
|
|
|
self._mode == Frame.AUTOMATIC):
|
|
|
|
self._timeline.play('before_slide_out', 'slide_out')
|
2006-09-21 14:45:36 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _enter_edge_cb(self, event_frame):
|
|
|
|
self._mode = Frame.HIDE_ON_LEAVE
|
|
|
|
self._timeline.play(None, 'slide_in')
|
2006-12-16 23:55:22 +01:00
|
|
|
logging.debug('Frame._enter_edge_cb ' + str(self._mode))
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _enter_corner_cb(self, event_frame):
|
|
|
|
self._mode = Frame.HIDE_ON_LEAVE
|
|
|
|
self._timeline.play('slide_in', 'slide_in')
|
2006-12-16 23:55:22 +01:00
|
|
|
logging.debug('Frame._enter_corner_cb ' + str(self._mode))
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _event_frame_leave_cb(self, event_frame):
|
|
|
|
if self._mode != Frame.STICKY:
|
|
|
|
self._timeline.goto('slide_out', True)
|
2006-12-16 23:55:22 +01:00
|
|
|
logging.debug('Frame._event_frame_leave_cb ' + str(self._mode))
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def show_and_hide(self, seconds):
|
|
|
|
self._mode = Frame.AUTOMATIC
|
|
|
|
self._timeline.play()
|
2006-08-23 11:52:18 +02:00
|
|
|
|
2006-12-04 20:12:24 +01: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._mode = Frame.TEMPORARY
|
|
|
|
else:
|
|
|
|
self._mode = Frame.STICKY
|
|
|
|
self._timeline.play('slide_in', 'slide_in')
|
2006-09-21 14:08:10 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def notify_key_release(self):
|
|
|
|
if self._mode == Frame.TEMPORARY:
|
|
|
|
self._timeline.play('before_slide_out', 'slide_out')
|
2006-09-21 14:08:10 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def do_slide_in(self, current=0, n_frames=0):
|
|
|
|
if not self._windows[0].props.visible:
|
|
|
|
for panel in self._windows:
|
|
|
|
panel.show()
|
|
|
|
self._event_frame.hide()
|
2006-09-21 14:08:10 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def do_slide_out(self, current=0, n_frames=0):
|
|
|
|
if self._windows[0].props.visible:
|
|
|
|
for panel in self._windows:
|
|
|
|
panel.hide()
|
|
|
|
self._event_frame.show()
|
2006-09-28 22:11:29 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def is_visible(self):
|
|
|
|
if self._windows[0].props.visible:
|
|
|
|
return True
|
|
|
|
return False
|