2007-06-24 14:45:05 +02:00
|
|
|
# Copyright (C) 2006-2007 Red Hat, Inc.
|
2006-10-15 01:24:45 +02:00
|
|
|
#
|
|
|
|
# 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
|
2007-07-02 10:21:58 +02:00
|
|
|
|
2007-03-17 14:30:23 +01:00
|
|
|
import logging
|
2006-10-15 01:24:45 +02:00
|
|
|
|
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-08-23 11:52:18 +02:00
|
|
|
|
2007-07-06 14:36:59 +02:00
|
|
|
from sugar.graphics import animator
|
2007-07-31 15:21:09 +02:00
|
|
|
from sugar.graphics import style
|
2007-07-06 14:36:59 +02:00
|
|
|
from sugar.graphics import palettegroup
|
|
|
|
from sugar.clipboard import clipboardservice
|
|
|
|
|
2007-04-05 12:44:03 +02:00
|
|
|
from view.frame.eventarea import EventArea
|
2007-09-03 23:28:49 +02:00
|
|
|
from view.frame.activitiestray import ActivitiesTray
|
2007-09-03 00:20:53 +02:00
|
|
|
from view.frame.zoomtoolbar import ZoomToolbar
|
2007-09-03 01:48:03 +02:00
|
|
|
from view.frame.friendstray import FriendsTray
|
2007-05-01 18:26:26 +02:00
|
|
|
from view.frame.framewindow import FrameWindow
|
2006-12-13 22:36:05 +01:00
|
|
|
from view.frame.clipboardpanelwindow import ClipboardPanelWindow
|
2007-07-02 14:34:41 +02:00
|
|
|
from model.shellmodel import ShellModel
|
2006-08-23 11:52:18 +02:00
|
|
|
|
2007-03-12 14:05:50 +01:00
|
|
|
_FRAME_HIDING_DELAY = 500
|
|
|
|
|
2007-03-12 12:39:29 +01:00
|
|
|
class _Animation(animator.Animation):
|
|
|
|
def __init__(self, frame, end):
|
2007-10-29 15:49:17 +01:00
|
|
|
start = frame.current_position
|
2007-03-12 12:39:29 +01:00
|
|
|
animator.Animation.__init__(self, start, end)
|
|
|
|
self._frame = frame
|
2007-01-25 17:37:27 +01:00
|
|
|
|
2007-03-12 12:39:29 +01:00
|
|
|
def next_frame(self, current):
|
|
|
|
self._frame.move(current)
|
2006-09-22 11:14:33 +02:00
|
|
|
|
2007-03-12 14:05:50 +01:00
|
|
|
class _MouseListener(object):
|
|
|
|
def __init__(self, frame):
|
|
|
|
self._frame = frame
|
|
|
|
self._hide_sid = 0
|
|
|
|
|
|
|
|
def mouse_enter(self):
|
2007-10-29 15:49:17 +01:00
|
|
|
self._show_frame()
|
2007-03-12 14:05:50 +01:00
|
|
|
|
|
|
|
def mouse_leave(self):
|
2007-10-29 15:49:17 +01:00
|
|
|
if self._frame.mode == Frame.MODE_MOUSE:
|
2007-03-12 14:48:02 +01:00
|
|
|
self._hide_frame()
|
2007-03-12 14:05:50 +01:00
|
|
|
|
|
|
|
def _show_frame(self):
|
|
|
|
if self._hide_sid != 0:
|
|
|
|
gobject.source_remove(self._hide_sid)
|
2007-10-29 15:49:17 +01:00
|
|
|
self._frame.show(Frame.MODE_MOUSE)
|
2007-03-12 14:05:50 +01:00
|
|
|
|
|
|
|
def _hide_frame_timeout_cb(self):
|
|
|
|
self._frame.hide()
|
|
|
|
return False
|
|
|
|
|
|
|
|
def _hide_frame(self):
|
|
|
|
if self._hide_sid != 0:
|
|
|
|
gobject.source_remove(self._hide_sid)
|
|
|
|
self._hide_sid = gobject.timeout_add(
|
|
|
|
_FRAME_HIDING_DELAY, self._hide_frame_timeout_cb)
|
|
|
|
|
2007-03-12 12:39:29 +01:00
|
|
|
class _KeyListener(object):
|
|
|
|
def __init__(self, frame):
|
|
|
|
self._frame = frame
|
|
|
|
|
|
|
|
def key_press(self):
|
2007-03-17 20:46:44 +01:00
|
|
|
if self._frame.visible:
|
2007-10-29 15:49:17 +01:00
|
|
|
if self._frame.mode == Frame.MODE_KEYBOARD:
|
|
|
|
self._frame.hide()
|
2007-03-17 20:46:44 +01:00
|
|
|
else:
|
2007-10-29 15:49:17 +01:00
|
|
|
self._frame.show(Frame.MODE_KEYBOARD)
|
2007-03-12 12:39:29 +01:00
|
|
|
|
|
|
|
class Frame(object):
|
2007-10-29 15:49:17 +01:00
|
|
|
MODE_MOUSE = 0
|
|
|
|
MODE_KEYBOARD = 1
|
2007-11-24 15:58:53 +01:00
|
|
|
MODE_NON_INTERACTIVE = 2
|
2007-10-29 15:49:17 +01:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def __init__(self, shell):
|
2007-10-29 15:49:17 +01:00
|
|
|
self.mode = None
|
2007-03-12 14:48:02 +01:00
|
|
|
|
2007-07-06 14:36:59 +02:00
|
|
|
self._palette_group = palettegroup.get_group('frame')
|
|
|
|
self._palette_group.connect('popdown', self._palette_group_popdown_cb)
|
|
|
|
|
2007-01-25 12:39:44 +01:00
|
|
|
self._left_panel = None
|
|
|
|
self._right_panel = None
|
|
|
|
self._top_panel = None
|
|
|
|
self._bottom_panel = None
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
self._shell = shell
|
2007-10-29 15:49:17 +01:00
|
|
|
self.current_position = 0.0
|
2007-03-12 14:48:02 +01:00
|
|
|
self._animator = None
|
2006-09-07 15:11:51 +02:00
|
|
|
|
2007-04-05 12:44:03 +02:00
|
|
|
self._event_area = EventArea()
|
|
|
|
self._event_area.connect('enter', self._enter_corner_cb)
|
|
|
|
self._event_area.show()
|
2006-10-02 01:50:43 +02:00
|
|
|
|
2007-02-20 16:23:49 +01:00
|
|
|
self._top_panel = self._create_top_panel()
|
|
|
|
self._bottom_panel = self._create_bottom_panel()
|
|
|
|
self._left_panel = self._create_left_panel()
|
|
|
|
self._right_panel = self._create_right_panel()
|
2006-09-07 15:11:51 +02:00
|
|
|
|
2007-02-24 19:28:04 +01:00
|
|
|
screen = gtk.gdk.screen_get_default()
|
|
|
|
screen.connect('size-changed', self._size_changed_cb)
|
2007-01-25 12:39:44 +01:00
|
|
|
|
2007-03-18 12:56:11 +01:00
|
|
|
cb_service = clipboardservice.get_instance()
|
|
|
|
cb_service.connect_after('object-added', self._clipboard_object_added_cb)
|
|
|
|
|
2007-03-12 12:39:29 +01:00
|
|
|
self._key_listener = _KeyListener(self)
|
2007-03-12 14:05:50 +01:00
|
|
|
self._mouse_listener = _MouseListener(self)
|
2007-03-12 12:39:29 +01:00
|
|
|
|
2007-10-29 15:49:17 +01:00
|
|
|
self.move(1.0)
|
|
|
|
|
|
|
|
def is_visible(self):
|
|
|
|
return self.current_position != 0.0
|
|
|
|
|
|
|
|
def hide(self):
|
2007-03-12 16:09:41 +01:00
|
|
|
if self._animator:
|
|
|
|
self._animator.stop()
|
|
|
|
|
2007-04-16 12:26:17 +02:00
|
|
|
self._animator = animator.Animator(0.5)
|
2007-03-12 16:09:41 +01:00
|
|
|
self._animator.add(_Animation(self, 0.0))
|
|
|
|
self._animator.start()
|
|
|
|
|
2007-04-05 12:44:03 +02:00
|
|
|
self._event_area.show()
|
2007-03-12 16:09:41 +01:00
|
|
|
|
2007-10-29 15:49:17 +01:00
|
|
|
self.mode = None
|
2007-06-13 14:39:16 +02:00
|
|
|
|
2007-10-29 15:49:17 +01:00
|
|
|
def show(self, mode):
|
2007-03-12 19:13:09 +01:00
|
|
|
if self.visible:
|
2007-03-12 16:09:41 +01:00
|
|
|
return
|
|
|
|
if self._animator:
|
|
|
|
self._animator.stop()
|
|
|
|
|
2007-10-23 15:49:19 +02:00
|
|
|
self._shell.take_activity_screenshot()
|
|
|
|
|
2007-10-29 15:49:17 +01:00
|
|
|
self.mode = mode
|
|
|
|
|
2007-04-16 12:26:17 +02:00
|
|
|
self._animator = animator.Animator(0.5)
|
2007-03-12 16:09:41 +01:00
|
|
|
self._animator.add(_Animation(self, 1.0))
|
|
|
|
self._animator.start()
|
|
|
|
|
2007-04-05 12:44:03 +02:00
|
|
|
self._event_area.hide()
|
2007-03-12 16:09:41 +01:00
|
|
|
|
2007-03-12 12:39:29 +01:00
|
|
|
def move(self, pos):
|
2007-10-29 15:49:17 +01:00
|
|
|
self.current_position = pos
|
2007-03-12 12:39:29 +01:00
|
|
|
self._update_position()
|
|
|
|
|
2007-03-12 16:09:41 +01:00
|
|
|
def _is_hover(self):
|
|
|
|
return (self._top_panel.hover or \
|
|
|
|
self._bottom_panel.hover or \
|
|
|
|
self._left_panel.hover or \
|
|
|
|
self._right_panel.hover)
|
|
|
|
|
2007-01-25 12:39:44 +01:00
|
|
|
def _create_top_panel(self):
|
2007-08-16 16:46:21 +02:00
|
|
|
panel = self._create_panel(gtk.POS_TOP)
|
2006-12-13 22:36:05 +01:00
|
|
|
|
2007-09-03 00:20:53 +02:00
|
|
|
toolbar = ZoomToolbar(self._shell)
|
|
|
|
panel.append(hippo.CanvasWidget(widget=toolbar))
|
|
|
|
toolbar.show()
|
2007-02-20 16:23:49 +01:00
|
|
|
|
2007-02-20 16:35:07 +01:00
|
|
|
return panel
|
2006-10-24 19:44:18 +02:00
|
|
|
|
2007-01-25 12:39:44 +01:00
|
|
|
def _create_bottom_panel(self):
|
2007-08-16 16:46:21 +02:00
|
|
|
panel = self._create_panel(gtk.POS_BOTTOM)
|
2006-12-13 22:36:05 +01:00
|
|
|
|
2007-09-03 23:28:49 +02:00
|
|
|
box = ActivitiesTray(self._shell)
|
2007-08-29 14:04:46 +02:00
|
|
|
panel.append(box, hippo.PACK_EXPAND)
|
2006-09-07 15:11:51 +02:00
|
|
|
|
2007-02-20 16:35:07 +01:00
|
|
|
return panel
|
2006-09-18 16:51:21 +02:00
|
|
|
|
2007-01-25 12:39:44 +01:00
|
|
|
def _create_right_panel(self):
|
2007-08-16 16:46:21 +02:00
|
|
|
panel = self._create_panel(gtk.POS_RIGHT)
|
2006-12-13 22:36:05 +01:00
|
|
|
|
2007-09-03 01:48:03 +02:00
|
|
|
tray = FriendsTray(self._shell)
|
|
|
|
panel.append(hippo.CanvasWidget(widget=tray), hippo.PACK_EXPAND)
|
|
|
|
tray.show()
|
2006-10-05 17:09:38 +02:00
|
|
|
|
2007-02-20 16:35:07 +01:00
|
|
|
return panel
|
2007-02-20 16:23:49 +01:00
|
|
|
|
2007-01-25 12:39:44 +01:00
|
|
|
def _create_left_panel(self):
|
2007-08-16 16:46:21 +02:00
|
|
|
panel = ClipboardPanelWindow(self, gtk.POS_LEFT)
|
2007-02-20 16:23:49 +01:00
|
|
|
|
2007-02-20 16:35:07 +01:00
|
|
|
self._connect_to_panel(panel)
|
|
|
|
panel.connect('drag-motion', self._drag_motion_cb)
|
|
|
|
panel.connect('drag-leave', self._drag_leave_cb)
|
2007-01-11 11:43:34 +01:00
|
|
|
|
2007-02-20 16:35:07 +01:00
|
|
|
return panel
|
2007-01-11 11:43:34 +01:00
|
|
|
|
2007-02-20 16:35:07 +01:00
|
|
|
def _create_panel(self, orientation):
|
2007-05-01 18:26:26 +02:00
|
|
|
panel = FrameWindow(orientation)
|
2006-12-13 22:36:05 +01:00
|
|
|
self._connect_to_panel(panel)
|
|
|
|
|
|
|
|
return panel
|
2006-10-02 01:50:43 +02:00
|
|
|
|
2007-02-20 16:23:49 +01:00
|
|
|
def _move_panel(self, panel, pos, x1, y1, x2, y2):
|
|
|
|
x = (x2 - x1) * pos + x1
|
|
|
|
y = (y2 - y1) * pos + y1
|
2007-01-25 17:37:27 +01:00
|
|
|
|
2007-02-27 17:04:15 +01:00
|
|
|
panel.move(int(x), int(y))
|
2007-01-25 17:37:27 +01:00
|
|
|
|
|
|
|
# FIXME we should hide and show as necessary to free memory
|
|
|
|
if not panel.props.visible:
|
|
|
|
panel.show()
|
|
|
|
|
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)
|
2007-07-02 15:55:30 +02:00
|
|
|
panel.connect('leave-notify-event', self._leave_notify_cb)
|
2006-10-02 01:50:43 +02:00
|
|
|
|
2007-02-24 19:28:04 +01:00
|
|
|
def _update_position(self):
|
2007-02-20 16:23:49 +01:00
|
|
|
screen_h = gtk.gdk.screen_height()
|
|
|
|
screen_w = gtk.gdk.screen_width()
|
|
|
|
|
2007-10-29 15:49:17 +01:00
|
|
|
self._move_panel(self._top_panel, self.current_position,
|
2007-08-17 16:18:57 +02:00
|
|
|
0, - self._top_panel.size, 0, 0)
|
2007-02-20 16:23:49 +01:00
|
|
|
|
2007-10-29 15:49:17 +01:00
|
|
|
self._move_panel(self._bottom_panel, self.current_position,
|
2007-08-17 16:18:57 +02:00
|
|
|
0, screen_h, 0, screen_h - self._bottom_panel.size)
|
2007-02-20 16:23:49 +01:00
|
|
|
|
2007-10-29 15:49:17 +01:00
|
|
|
self._move_panel(self._left_panel, self.current_position,
|
2007-08-17 16:18:57 +02:00
|
|
|
- self._left_panel.size, 0, 0, 0)
|
2007-02-20 16:23:49 +01:00
|
|
|
|
2007-10-29 15:49:17 +01:00
|
|
|
self._move_panel(self._right_panel, self.current_position,
|
2007-08-17 16:18:57 +02:00
|
|
|
screen_w, 0, screen_w - self._right_panel.size, 0)
|
2007-01-25 12:39:44 +01:00
|
|
|
|
2007-02-24 19:28:04 +01:00
|
|
|
def _size_changed_cb(self, screen):
|
|
|
|
self._update_position()
|
2007-03-18 12:56:11 +01:00
|
|
|
|
|
|
|
def _clipboard_object_added_cb(self, cb_service, object_id, name):
|
|
|
|
if not self.visible:
|
2007-11-24 15:58:53 +01:00
|
|
|
self.show(self.MODE_NON_INTERACTIVE)
|
2007-03-18 12:56:11 +01:00
|
|
|
gobject.timeout_add(2000, lambda: self.hide())
|
|
|
|
|
2007-03-12 12:39:29 +01:00
|
|
|
def _enter_notify_cb(self, window, event):
|
2007-09-24 23:37:26 +02:00
|
|
|
if event.detail != gtk.gdk.NOTIFY_INFERIOR:
|
|
|
|
self._mouse_listener.mouse_enter()
|
2007-07-02 15:55:30 +02:00
|
|
|
|
|
|
|
def _leave_notify_cb(self, window, event):
|
2007-09-24 23:37:26 +02:00
|
|
|
if event.detail == gtk.gdk.NOTIFY_INFERIOR:
|
2007-07-02 15:55:30 +02:00
|
|
|
return
|
|
|
|
|
2007-07-06 14:36:59 +02:00
|
|
|
if not self._is_hover() and not self._palette_group.is_up():
|
2007-07-02 15:55:30 +02:00
|
|
|
self._mouse_listener.mouse_leave()
|
|
|
|
|
2007-07-06 14:36:59 +02:00
|
|
|
def _palette_group_popdown_cb(self, group):
|
|
|
|
if not self._is_hover():
|
|
|
|
self._mouse_listener.mouse_leave()
|
|
|
|
|
2007-03-12 12:39:29 +01:00
|
|
|
def _drag_motion_cb(self, window, context, x, y, time):
|
2007-03-12 14:05:50 +01:00
|
|
|
self._mouse_listener.mouse_enter()
|
2007-03-12 12:39:29 +01:00
|
|
|
|
|
|
|
def _drag_leave_cb(self, window, drag_context, timestamp):
|
2007-03-12 14:05:50 +01:00
|
|
|
self._mouse_listener.mouse_leave()
|
2007-03-12 12:39:29 +01:00
|
|
|
|
2007-04-05 12:44:03 +02:00
|
|
|
def _enter_corner_cb(self, event_area):
|
2007-03-12 14:05:50 +01:00
|
|
|
self._mouse_listener.mouse_enter()
|
2007-03-12 12:39:29 +01:00
|
|
|
|
|
|
|
def notify_key_press(self):
|
|
|
|
self._key_listener.key_press()
|
|
|
|
|
2007-10-29 15:49:17 +01:00
|
|
|
visible = property(is_visible, None)
|