def __init__(self): logging.debug('STARTUP: Loading the frame') self._palette_group = palettegroup.get_group('frame') self._left_panel = None self._right_panel = None self._top_panel = None self._bottom_panel = None self.current_position = 0.0 self._animator = None self._event_area = EventArea() self._event_area.connect('enter', self._enter_corner_cb) self._event_area.show() 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() screen = Gdk.Screen.get_default() screen.connect('size-changed', self._size_changed_cb) self._key_listener = _KeyListener(self) self._notif_by_icon = {} notification_service = notifications.get_service() notification_service.notification_received.connect( self.__notification_received_cb) notification_service.notification_cancelled.connect( self.__notification_cancelled_cb)
def __init__(self): logging.debug('STARTUP: Loading the frame') self.settings = Gio.Settings('org.sugarlabs.frame') self._palette_group = palettegroup.get_group('frame') self._left_panel = None self._right_panel = None self._top_panel = None self._bottom_panel = None self._wanted = False self.current_position = 0.0 self._animator = None self._event_area = EventArea(self.settings) self._event_area.connect('enter', self._enter_corner_cb) self._event_area.show() 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() screen = Gdk.Screen.get_default() screen.connect('size-changed', self._size_changed_cb) self._notif_by_icon = {} notification_service = notifications.get_service() notification_service.notification_received.connect( self.__notification_received_cb) notification_service.notification_cancelled.connect( self.__notification_cancelled_cb)
def __init__(self): logging.debug('STARTUP: Loading the frame') self.mode = None self._palette_group = palettegroup.get_group('frame') self._palette_group.connect('popdown', self._palette_group_popdown_cb) self._left_panel = None self._right_panel = None self._top_panel = None self._bottom_panel = None self.current_position = 0.0 self._animator = None self._event_area = EventArea() self._event_area.connect('enter', self._enter_corner_cb) self._event_area.show() 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() screen = gtk.gdk.screen_get_default() screen.connect('size-changed', self._size_changed_cb) self._key_listener = _KeyListener(self) self._mouse_listener = _MouseListener(self) self._notif_by_icon = {} notification_service = notifications.get_service() notification_service.notification_received.connect( self.__notification_received_cb) notification_service.notification_cancelled.connect( self.__notification_cancelled_cb)
class Frame(object): MODE_MOUSE = 0 MODE_KEYBOARD = 1 MODE_NON_INTERACTIVE = 2 def __init__(self): logging.debug('STARTUP: Loading the frame') self.mode = None self._palette_group = palettegroup.get_group('frame') self._palette_group.connect('popdown', self._palette_group_popdown_cb) self._left_panel = None self._right_panel = None self._top_panel = None self._bottom_panel = None self.current_position = 0.0 self._animator = None self._event_area = EventArea() self._event_area.connect('enter', self._enter_corner_cb) self._event_area.show() 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() screen = gtk.gdk.screen_get_default() screen.connect('size-changed', self._size_changed_cb) self._key_listener = _KeyListener(self) self._mouse_listener = _MouseListener(self) self._notif_by_icon = {} notification_service = notifications.get_service() notification_service.notification_received.connect( self.__notification_received_cb) notification_service.notification_cancelled.connect( self.__notification_cancelled_cb) def is_visible(self): return self.current_position != 0.0 visible = property(is_visible, None) def hide(self): if self._animator: self._animator.stop() self._animator = animator.Animator(0.5) self._animator.add(_Animation(self, 0.0)) self._animator.start() self.mode = None def show(self, mode): if self.visible: return if self._animator: self._animator.stop() self.mode = mode self._animator = animator.Animator(0.5) self._animator.add(_Animation(self, 1.0)) self._animator.start() def move(self, pos): 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(gtk.POS_TOP) zoom_toolbar = ZoomToolbar() panel.append(zoom_toolbar, expand=False) zoom_toolbar.show() activities_tray = ActivitiesTray() panel.append(activities_tray) activities_tray.show() return panel def _create_bottom_panel(self): panel = self._create_panel(gtk.POS_BOTTOM) devices_tray = DevicesTray() panel.append(devices_tray) devices_tray.show() return panel def _create_right_panel(self): panel = self._create_panel(gtk.POS_RIGHT) tray = FriendsTray() panel.append(tray) tray.show() return panel def _create_left_panel(self): panel = ClipboardPanelWindow(self, gtk.POS_LEFT) self._connect_to_panel(panel) panel.connect('drag-motion', self._drag_motion_cb) panel.connect('drag-leave', self._drag_leave_cb) return panel def _create_panel(self, orientation): panel = FrameWindow(orientation) self._connect_to_panel(panel) return panel def _move_panel(self, panel, pos, x1, y1, x2, y2): x = (x2 - x1) * pos + x1 y = (y2 - y1) * pos + y1 panel.move(int(x), int(y)) # FIXME we should hide and show as necessary to free memory if not panel.props.visible: panel.show() def _connect_to_panel(self, panel): panel.connect('enter-notify-event', self._enter_notify_cb) panel.connect('leave-notify-event', self._leave_notify_cb) def _update_position(self): screen_h = gtk.gdk.screen_height() screen_w = gtk.gdk.screen_width() self._move_panel(self._top_panel, self.current_position, 0, - self._top_panel.size, 0, 0) self._move_panel(self._bottom_panel, self.current_position, 0, screen_h, 0, screen_h - self._bottom_panel.size) self._move_panel(self._left_panel, self.current_position, - self._left_panel.size, 0, 0, 0) self._move_panel(self._right_panel, self.current_position, screen_w, 0, screen_w - self._right_panel.size, 0) def _size_changed_cb(self, screen): self._update_position() def _enter_notify_cb(self, window, event): if event.detail != gtk.gdk.NOTIFY_INFERIOR: self._mouse_listener.mouse_enter() def _leave_notify_cb(self, window, event): if event.detail == gtk.gdk.NOTIFY_INFERIOR: return if not self._is_hover() and not self._palette_group.is_up(): self._mouse_listener.mouse_leave() def _palette_group_popdown_cb(self, group): if not self._is_hover(): self._mouse_listener.mouse_leave() def _drag_motion_cb(self, window, context, x, y, time): self._mouse_listener.mouse_enter() def _drag_leave_cb(self, window, drag_context, timestamp): self._mouse_listener.mouse_leave() def _enter_corner_cb(self, event_area): self._mouse_listener.mouse_enter() def notify_key_press(self): self._key_listener.key_press() def add_notification(self, icon, corner=gtk.CORNER_TOP_LEFT, duration=_NOTIFICATION_DURATION): if not isinstance(icon, NotificationIcon): raise TypeError('icon must be a NotificationIcon.') window = NotificationWindow() screen = gtk.gdk.screen_get_default() if corner == gtk.CORNER_TOP_LEFT: window.move(0, 0) elif corner == gtk.CORNER_TOP_RIGHT: window.move(screen.get_width() - style.GRID_CELL_SIZE, 0) elif corner == gtk.CORNER_BOTTOM_LEFT: window.move(0, screen.get_height() - style.GRID_CELL_SIZE) elif corner == gtk.CORNER_BOTTOM_RIGHT: window.move(screen.get_width() - style.GRID_CELL_SIZE, screen.get_height() - style.GRID_CELL_SIZE) else: raise ValueError('Inalid corner: %r' % corner) window.add(icon) icon.show() window.show() self._notif_by_icon[icon] = window gobject.timeout_add(duration, lambda: self.remove_notification(icon)) def remove_notification(self, icon): if icon not in self._notif_by_icon: logging.debug('icon %r not in list of notifications.', icon) return window = self._notif_by_icon[icon] window.destroy() del self._notif_by_icon[icon] def __notification_received_cb(self, **kwargs): logging.debug('__notification_received_cb') icon = NotificationIcon() hints = kwargs['hints'] icon_file_name = hints.get('x-sugar-icon-file-name', '') if icon_file_name: icon.props.icon_filename = icon_file_name else: icon.props.icon_name = 'application-octet-stream' icon_colors = hints.get('x-sugar-icon-colors', '') if not icon_colors: icon_colors = profile.get_color() icon.props.xo_color = icon_colors duration = kwargs.get('expire_timeout', -1) if duration == -1: duration = _NOTIFICATION_DURATION self.add_notification(icon, gtk.CORNER_TOP_RIGHT, duration) def __notification_cancelled_cb(self, **kwargs): # Do nothing for now. Our notification UI is so simple, there's no # point yet. pass
class Frame(object): def __init__(self): logging.debug('STARTUP: Loading the frame') self.settings = Gio.Settings('org.sugarlabs.frame') self._palette_group = palettegroup.get_group('frame') self._left_panel = None self._right_panel = None self._top_panel = None self._bottom_panel = None self._wanted = False self.current_position = 0.0 self._animator = None self._event_area = EventArea(self.settings) self._event_area.connect('enter', self._enter_corner_cb) self._event_area.show() 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() screen = Gdk.Screen.get_default() screen.connect('size-changed', self._size_changed_cb) self._notif_by_icon = {} notification_service = notifications.get_service() notification_service.notification_received.connect( self.__notification_received_cb) notification_service.notification_cancelled.connect( self.__notification_cancelled_cb) def is_visible(self): return self.current_position != 0.0 visible = property(is_visible, None) def toggle(self): if not self._wanted: self.show() else: self.hide() def hide(self): if not self._wanted: return self._wanted = False if self._animator: self._animator.stop() palettegroup.popdown_all() self._animator = animator.Animator(0.5, widget=self._top_panel) self._animator.add(_Animation(self, 0.0)) self._animator.start() def show(self): if self._wanted: return self._wanted = True if self._animator: self._animator.stop() self._animator = animator.Animator(0.5, widget=self._top_panel) self._animator.add(_Animation(self, 1.0)) self._animator.start() def move(self, pos): self.current_position = pos self._update_position() def _create_top_panel(self): panel = self._create_panel(Gtk.PositionType.TOP) zoom_toolbar = ZoomToolbar() panel.append(zoom_toolbar, expand=False) zoom_toolbar.show() zoom_toolbar.connect('level-clicked', self._level_clicked_cb) activities_tray = ActivitiesTray() panel.append(activities_tray) activities_tray.show() return panel def _create_bottom_panel(self): panel = self._create_panel(Gtk.PositionType.BOTTOM) devices_tray = DevicesTray() panel.append(devices_tray) devices_tray.show() return panel def _create_right_panel(self): panel = self._create_panel(Gtk.PositionType.RIGHT) tray = FriendsTray() panel.append(tray) tray.show() return panel def _create_left_panel(self): panel = ClipboardPanelWindow(self, Gtk.PositionType.LEFT) return panel def _create_panel(self, orientation): panel = FrameWindow(orientation) return panel def _move_panel(self, panel, pos, x1, y1, x2, y2): x = (x2 - x1) * pos + x1 y = (y2 - y1) * pos + y1 panel.move(int(x), int(y)) # FIXME we should hide and show as necessary to free memory if not panel.props.visible: panel.show() def _level_clicked_cb(self, zoom_toolbar): self.hide() def _update_position(self): screen_h = Gdk.Screen.height() screen_w = Gdk.Screen.width() self._move_panel(self._top_panel, self.current_position, 0, - self._top_panel.size, 0, 0) self._move_panel(self._bottom_panel, self.current_position, 0, screen_h, 0, screen_h - self._bottom_panel.size) self._move_panel(self._left_panel, self.current_position, - self._left_panel.size, 0, 0, 0) self._move_panel(self._right_panel, self.current_position, screen_w, 0, screen_w - self._right_panel.size, 0) def _size_changed_cb(self, screen): self._update_position() def _enter_corner_cb(self, event_area): self.toggle() def notify_key_press(self): self.toggle() ''' The function adds a notification and returns the id of the timeout signal after which the notification will dissapear. ''' def add_notification(self, icon, corner=Gtk.CornerType.TOP_LEFT, duration=NOTIFICATION_DURATION): if not isinstance(icon, NotificationIcon): raise TypeError('icon must be a NotificationIcon.') window = NotificationWindow() screen = Gdk.Screen.get_default() if corner == Gtk.CornerType.TOP_LEFT: window.move(0, 0) elif corner == Gtk.CornerType.TOP_RIGHT: window.move(screen.get_width() - style.GRID_CELL_SIZE, 0) elif corner == Gtk.CornerType.BOTTOM_LEFT: window.move(0, screen.get_height() - style.GRID_CELL_SIZE) elif corner == Gtk.CornerType.BOTTOM_RIGHT: window.move(screen.get_width() - style.GRID_CELL_SIZE, screen.get_height() - style.GRID_CELL_SIZE) else: raise ValueError('Inalid corner: %r' % corner) window.add(icon) icon.show() window.show() self._notif_by_icon[icon] = window timeout_id = GLib.timeout_add( duration, lambda: self.remove_notification(icon)) return timeout_id def remove_notification(self, icon): if icon not in self._notif_by_icon: logging.debug('icon %r not in list of notifications.', icon) return window = self._notif_by_icon[icon] window.destroy() del self._notif_by_icon[icon] def __button_release_event_cb(self, icon, data=None): self.remove_notification(icon) self.show() def __notification_received_cb(self, **kwargs): logging.debug('__notification_received_cb') icon = NotificationIcon() icon.show_badge() icon.connect('button-release-event', self.__button_release_event_cb) hints = kwargs['hints'] icon_file_name = hints.get('x-sugar-icon-file-name', '') icon_name = hints.get('x-sugar-icon-name', '') if icon_file_name: icon.props.icon_filename = icon_file_name elif icon_name: icon.props.icon_name = icon_name else: icon.props.icon_name = 'application-octet-stream' icon_colors = hints.get('x-sugar-icon-colors', '') if not icon_colors: icon_colors = profile.get_color() icon.props.xo_color = icon_colors duration = kwargs.get('expire_timeout', -1) if duration == -1: duration = NOTIFICATION_DURATION self.add_notification(icon, Gtk.CornerType.TOP_LEFT, duration) def __notification_cancelled_cb(self, **kwargs): # Do nothing for now. Our notification UI is so simple, there's no # point yet. pass
class Frame(object): def __init__(self): logging.debug('STARTUP: Loading the frame') self._palette_group = palettegroup.get_group('frame') self._left_panel = None self._right_panel = None self._top_panel = None self._bottom_panel = None self.current_position = 0.0 self._animator = None self._event_area = EventArea() self._event_area.connect('enter', self._enter_corner_cb) self._event_area.show() 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() screen = Gdk.Screen.get_default() screen.connect('size-changed', self._size_changed_cb) self._key_listener = _KeyListener(self) self._notif_by_icon = {} notification_service = notifications.get_service() notification_service.notification_received.connect( self.__notification_received_cb) notification_service.notification_cancelled.connect( self.__notification_cancelled_cb) def is_visible(self): return self.current_position != 0.0 visible = property(is_visible, None) def hide(self): if not self.visible: return if self._animator: self._animator.stop() palettegroup.popdown_all() self._animator = animator.Animator(0.5) self._animator.add(_Animation(self, 0.0)) self._animator.start() def show(self): if self.visible: return if self._animator: self._animator.stop() self._animator = animator.Animator(0.5) self._animator.add(_Animation(self, 1.0)) self._animator.start() def move(self, pos): self.current_position = pos self._update_position() def _create_top_panel(self): panel = self._create_panel(Gtk.PositionType.TOP) zoom_toolbar = ZoomToolbar() panel.append(zoom_toolbar, expand=False) zoom_toolbar.show() zoom_toolbar.connect('level-clicked', self._level_clicked_cb) activities_tray = ActivitiesTray() panel.append(activities_tray) activities_tray.show() return panel def _create_bottom_panel(self): panel = self._create_panel(Gtk.PositionType.BOTTOM) devices_tray = DevicesTray() panel.append(devices_tray) devices_tray.show() return panel def _create_right_panel(self): panel = self._create_panel(Gtk.PositionType.RIGHT) tray = FriendsTray() panel.append(tray) tray.show() return panel def _create_left_panel(self): panel = ClipboardPanelWindow(self, Gtk.PositionType.LEFT) return panel def _create_panel(self, orientation): panel = FrameWindow(orientation) return panel def _move_panel(self, panel, pos, x1, y1, x2, y2): x = (x2 - x1) * pos + x1 y = (y2 - y1) * pos + y1 panel.move(int(x), int(y)) # FIXME we should hide and show as necessary to free memory if not panel.props.visible: panel.show() def _level_clicked_cb(self, zoom_toolbar): self.hide() def _update_position(self): screen_h = Gdk.Screen.height() screen_w = Gdk.Screen.width() self._move_panel(self._top_panel, self.current_position, 0, -self._top_panel.size, 0, 0) self._move_panel(self._bottom_panel, self.current_position, 0, screen_h, 0, screen_h - self._bottom_panel.size) self._move_panel(self._left_panel, self.current_position, -self._left_panel.size, 0, 0, 0) self._move_panel(self._right_panel, self.current_position, screen_w, 0, screen_w - self._right_panel.size, 0) def _size_changed_cb(self, screen): self._update_position() def _enter_corner_cb(self, event_area): if self.visible: self.hide() else: self.show() def notify_key_press(self): self._key_listener.key_press() def add_notification(self, icon, corner=Gtk.CornerType.TOP_LEFT, duration=_NOTIFICATION_DURATION): if not isinstance(icon, NotificationIcon): raise TypeError('icon must be a NotificationIcon.') window = NotificationWindow() screen = Gdk.Screen.get_default() if corner == Gtk.CornerType.TOP_LEFT: window.move(0, 0) elif corner == Gtk.CornerType.TOP_RIGHT: window.move(screen.get_width() - style.GRID_CELL_SIZE, 0) elif corner == Gtk.CornerType.BOTTOM_LEFT: window.move(0, screen.get_height() - style.GRID_CELL_SIZE) elif corner == Gtk.CornerType.BOTTOM_RIGHT: window.move(screen.get_width() - style.GRID_CELL_SIZE, screen.get_height() - style.GRID_CELL_SIZE) else: raise ValueError('Inalid corner: %r' % corner) window.add(icon) icon.show() window.show() self._notif_by_icon[icon] = window GObject.timeout_add(duration, lambda: self.remove_notification(icon)) def remove_notification(self, icon): if icon not in self._notif_by_icon: logging.debug('icon %r not in list of notifications.', icon) return window = self._notif_by_icon[icon] window.destroy() del self._notif_by_icon[icon] def __button_release_event_cb(self, icon, data=None): self.remove_notification(icon) self.show() def __notification_received_cb(self, **kwargs): logging.debug('__notification_received_cb') icon = NotificationIcon() icon.show_badge() icon.connect('button-release-event', self.__button_release_event_cb) hints = kwargs['hints'] icon_file_name = hints.get('x-sugar-icon-file-name', '') icon_name = hints.get('x-sugar-icon-name', '') if icon_file_name: icon.props.icon_filename = icon_file_name elif icon_name: icon.props.icon_name = icon_name else: icon.props.icon_name = 'application-octet-stream' icon_colors = hints.get('x-sugar-icon-colors', '') if not icon_colors: icon_colors = profile.get_color() icon.props.xo_color = icon_colors duration = kwargs.get('expire_timeout', -1) if duration == -1: duration = _NOTIFICATION_DURATION self.add_notification(icon, Gtk.CornerType.TOP_LEFT, duration) def __notification_cancelled_cb(self, **kwargs): # Do nothing for now. Our notification UI is so simple, there's no # point yet. pass