Ejemplo n.º 1
0
    def __init__(self):
        logging.debug('STARTUP: Loading the desktop window')
        Gtk.Window.__init__(self)
        self.set_has_resize_grip(False)

        accel_group = Gtk.AccelGroup()
        self.sugar_accel_group = accel_group
        self.add_accel_group(accel_group)

        self._active = False
        self._fully_obscured = True

        screen = self.get_screen()
        screen.connect('size-changed', self.__screen_size_change_cb)
        self.set_default_size(screen.get_width(),
                              screen.get_height())

        self.realize()
        self._busy_count = 0
        self.busy()

        self.set_type_hint(Gdk.WindowTypeHint.DESKTOP)
        self.modify_bg(Gtk.StateType.NORMAL,
                       style.COLOR_WHITE.get_gdk_color())

        self.add_events(Gdk.EventMask.VISIBILITY_NOTIFY_MASK |
                        Gdk.EventMask.BUTTON_PRESS_MASK)
        self.connect('visibility-notify-event',
                     self._visibility_notify_event_cb)
        self.connect('map-event', self.__map_event_cb)
        self.connect('key-press-event', self.__key_press_event_cb)
        self.connect('key-release-event', self.__key_release_event_cb)

        self._box = HomeBackgroundBox()

        self._toolbar = ViewToolbar()
        self._box.pack_start(self._toolbar, False, True, 0)
        self._toolbar.show()

        self._alert = None

        self._home_box = HomeBox(self._toolbar)
        self._box.pack_start(self._home_box, True, True, 0)
        self._home_box.show()
        self._toolbar.show_view_buttons()

        self._group_box = GroupBox(self._toolbar)
        self._mesh_box = MeshBox(self._toolbar)
        self._transition_box = TransitionBox()

        self.add(self._box)
        self._box.show()

        self._transition_box.connect('completed',
                                     self._transition_completed_cb)

        shell.get_model().zoom_level_changed.connect(
            self.__zoom_level_changed_cb)

        self._alt_timeout_sid = None
Ejemplo n.º 2
0
    def __init__(self):
        logging.debug('STARTUP: Loading the desktop window')
        Gtk.Window.__init__(self)
        self.set_has_resize_grip(False)

        accel_group = Gtk.AccelGroup()
        self.sugar_accel_group = accel_group
        self.add_accel_group(accel_group)

        self._active = False
        self._fully_obscured = True

        screen = self.get_screen()
        screen.connect('size-changed', self.__screen_size_change_cb)
        self.set_default_size(screen.get_width(),
                              screen.get_height())

        self.realize()
        self._busy_count = 0
        self.busy()

        self.set_type_hint(Gdk.WindowTypeHint.DESKTOP)
        self.modify_bg(Gtk.StateType.NORMAL,
                       style.COLOR_WHITE.get_gdk_color())

        self.add_events(Gdk.EventMask.VISIBILITY_NOTIFY_MASK |
                        Gdk.EventMask.BUTTON_PRESS_MASK)
        self.connect('visibility-notify-event',
                     self._visibility_notify_event_cb)
        self.connect('map-event', self.__map_event_cb)
        self.connect('key-press-event', self.__key_press_event_cb)
        self.connect('key-release-event', self.__key_release_event_cb)

        self._box = HomeBackgroundBox()

        self._toolbar = ViewToolbar()
        self._box.pack_start(self._toolbar, False, True, 0)
        self._toolbar.show()

        self._alert = None

        self._home_box = HomeBox(self._toolbar)
        self._box.pack_start(self._home_box, True, True, 0)
        self._home_box.show()
        self._toolbar.show_view_buttons()

        self._group_box = GroupBox(self._toolbar)
        self._mesh_box = MeshBox(self._toolbar)
        self._transition_box = TransitionBox()

        self.add(self._box)
        self._box.show()

        self._transition_box.connect('completed',
                                     self._transition_completed_cb)

        shell.get_model().zoom_level_changed.connect(
            self.__zoom_level_changed_cb)

        self._alt_timeout_sid = None
Ejemplo n.º 3
0
    def __init__(self):
        logging.debug('STARTUP: Loading the desktop window')
        gtk.Window.__init__(self)

        accel_group = gtk.AccelGroup()
        self.set_data('sugar-accel-group', accel_group)
        self.add_accel_group(accel_group)

        self._active = False
        self._fully_obscured = True

        screen = self.get_screen()
        screen.connect('size-changed', self.__screen_size_change_cb)
        self.set_default_size(screen.get_width(), screen.get_height())

        self.realize()
        self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)

        self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
        self.connect('visibility-notify-event',
                     self._visibility_notify_event_cb)
        self.connect('map-event', self.__map_event_cb)
        self.connect('key-press-event', self.__key_press_event_cb)
        self.connect('key-release-event', self.__key_release_event_cb)

        self._home_box = HomeBox()
        self._group_box = GroupBox()
        self._mesh_box = MeshBox()
        self._transition_box = TransitionBox()

        self.add(self._home_box)
        self._home_box.show()

        self._transition_box.connect('completed',
                                     self._transition_completed_cb)

        shell.get_model().zoom_level_changed.connect(
            self.__zoom_level_changed_cb)
Ejemplo n.º 4
0
    def __init__(self):
        logging.debug('STARTUP: Loading the desktop window')
        gtk.Window.__init__(self)

        accel_group = gtk.AccelGroup()
        self.set_data('sugar-accel-group', accel_group)
        self.add_accel_group(accel_group)

        self._active = False
        self._fully_obscured = True

        screen = self.get_screen()
        screen.connect('size-changed', self.__screen_size_change_cb)
        self.set_default_size(screen.get_width(),
                              screen.get_height())

        self.realize()
        self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)

        self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
        self.connect('visibility-notify-event',
                     self._visibility_notify_event_cb)
        self.connect('map-event', self.__map_event_cb)
        self.connect('key-press-event', self.__key_press_event_cb)
        self.connect('key-release-event', self.__key_release_event_cb)

        self._home_box = HomeBox()
        self._group_box = GroupBox()
        self._mesh_box = MeshBox()
        self._transition_box = TransitionBox()

        self.add(self._home_box)
        self._home_box.show()

        self._transition_box.connect('completed',
                                     self._transition_completed_cb)

        shell.get_model().zoom_level_changed.connect(
                                     self.__zoom_level_changed_cb)
Ejemplo n.º 5
0
class HomeWindow(Gtk.Window):

    def __init__(self):
        logging.debug('STARTUP: Loading the desktop window')
        Gtk.Window.__init__(self)
        self.set_has_resize_grip(False)

        accel_group = Gtk.AccelGroup()
        self.sugar_accel_group = accel_group
        self.add_accel_group(accel_group)

        self._active = False
        self._fully_obscured = True

        screen = self.get_screen()
        screen.connect('size-changed', self.__screen_size_change_cb)
        self.set_default_size(screen.get_width(),
                              screen.get_height())

        self.realize()
        self._busy_count = 0
        self.busy()

        self.set_type_hint(Gdk.WindowTypeHint.DESKTOP)
        self.modify_bg(Gtk.StateType.NORMAL,
                       style.COLOR_WHITE.get_gdk_color())

        self.add_events(Gdk.EventMask.VISIBILITY_NOTIFY_MASK |
                        Gdk.EventMask.BUTTON_PRESS_MASK)
        self.connect('visibility-notify-event',
                     self._visibility_notify_event_cb)
        self.connect('map-event', self.__map_event_cb)
        self.connect('key-press-event', self.__key_press_event_cb)
        self.connect('key-release-event', self.__key_release_event_cb)

        self._box = HomeBackgroundBox()

        self._toolbar = ViewToolbar()
        self._box.pack_start(self._toolbar, False, True, 0)
        self._toolbar.show()

        self._alert = None

        self._home_box = HomeBox(self._toolbar)
        self._box.pack_start(self._home_box, True, True, 0)
        self._home_box.show()
        self._toolbar.show_view_buttons()

        self._group_box = GroupBox(self._toolbar)
        self._mesh_box = MeshBox(self._toolbar)
        self._transition_box = TransitionBox()

        self.add(self._box)
        self._box.show()

        self._transition_box.connect('completed',
                                     self._transition_completed_cb)

        shell.get_model().zoom_level_changed.connect(
            self.__zoom_level_changed_cb)

        self._alt_timeout_sid = None

    def add_alert(self, alert):
        self._alert = alert
        self._show_alert()

    def remove_alert(self, alert):
        if alert == self._alert:
            self._box.remove(self._alert)
            self._alert = None

    def _show_alert(self):
        if self._alert:
            self._box.pack_start(self._alert, False, False, 0)
            self._box.reorder_child(self._alert, 1)

    def _hide_alert(self):
        if self._alert:
            self._box.remove(self._alert)

    def _deactivate_view(self, level):
        group = palettegroup.get_group('default')
        group.popdown()
        if level == ShellModel.ZOOM_HOME:
            self._home_box.suspend()
        elif level == ShellModel.ZOOM_MESH:
            self._mesh_box.suspend()

    def __screen_size_change_cb(self, screen):
        self.resize(screen.get_width(), screen.get_height())

    def _activate_view(self, level):
        if level == ShellModel.ZOOM_HOME:
            self._home_box.resume()
        elif level == ShellModel.ZOOM_MESH:
            self._mesh_box.resume()

    def _visibility_notify_event_cb(self, window, event):
        fully_obscured = (
            event.get_state() == Gdk.VisibilityState.FULLY_OBSCURED)
        if self._fully_obscured == fully_obscured:
            return
        self._fully_obscured = fully_obscured

        if fully_obscured:
            self._deactivate_view(shell.get_model().zoom_level)
        else:
            self._activate_view(shell.get_model().zoom_level)

    def __is_alt(self, event):
        # When shift is on, <ALT> becomes <META>
        shift = (event.state & Gdk.ModifierType.SHIFT_MASK) == 1
        return event.keyval in [Gdk.KEY_Alt_L, Gdk.KEY_Alt_R] or \
            event.keyval in [Gdk.KEY_Meta_L, Gdk.KEY_Meta_R] and shift

    def __key_press_event_cb(self, window, event):
        if self.__is_alt(event) and not self._alt_timeout_sid:
            self._home_box.set_resume_mode(False)
            self._alt_timeout_sid = GObject.timeout_add(100,
                                                        self.__alt_timeout_cb)

        if not self._toolbar.search_entry.props.has_focus:
            self._toolbar.search_entry.grab_focus()

        return False

    def __key_release_event_cb(self, window, event):
        if self.__is_alt(event) and self._alt_timeout_sid:
            self._home_box.set_resume_mode(True)
            GObject.source_remove(self._alt_timeout_sid)
            self._alt_timeout_sid = None

        return False

    def __alt_timeout_cb(self):
        display = Gdk.Display.get_default()
        screen_, x_, y_, modmask = display.get_pointer()
        if modmask & Gdk.ModifierType.MOD1_MASK:
            return True

        self._home_box.set_resume_mode(True)

        if self._alt_timeout_sid:
            GObject.source_remove(self._alt_timeout_sid)
            self._alt_timeout_sid = None

        return False

    def __map_event_cb(self, window, event):
        # have to make the desktop window active
        # since metacity doesn't make it on startup
        timestamp = event.get_time()
        x11_window = self.get_window()
        if not timestamp:
            timestamp = GdkX11.x11_get_server_time(x11_window)
        x11_window.focus(timestamp)

    def __zoom_level_changed_cb(self, **kwargs):
        old_level = kwargs['old_level']
        new_level = kwargs['new_level']

        self._deactivate_view(old_level)
        self._activate_view(new_level)

        if old_level != ShellModel.ZOOM_ACTIVITY and \
           new_level != ShellModel.ZOOM_ACTIVITY:
            self._hide_alert()
            children = self._box.get_children()
            if len(children) >= 2:
                self._box.remove(children[1])
            self._box.pack_start(self._transition_box, True, True, 0)
            self._transition_box.show()

            if new_level == ShellModel.ZOOM_HOME:
                end_size = style.XLARGE_ICON_SIZE
            elif new_level == ShellModel.ZOOM_GROUP:
                end_size = style.LARGE_ICON_SIZE
            elif new_level == ShellModel.ZOOM_MESH:
                end_size = style.STANDARD_ICON_SIZE

            if old_level == ShellModel.ZOOM_HOME:
                start_size = style.XLARGE_ICON_SIZE
            elif old_level == ShellModel.ZOOM_GROUP:
                start_size = style.LARGE_ICON_SIZE
            elif old_level == ShellModel.ZOOM_MESH:
                start_size = style.STANDARD_ICON_SIZE

            self._transition_box.start_transition(start_size, end_size)
        else:
            self._update_view(new_level)

    def _transition_completed_cb(self, transition_box):
        self._update_view(shell.get_model().zoom_level)

    def _update_view(self, level):
        if level == ShellModel.ZOOM_ACTIVITY:
            return

        self._hide_alert()
        children = self._box.get_children()
        if len(children) >= 2:
            self._box.remove(children[1])

        if level == ShellModel.ZOOM_HOME:
            self._box.pack_start(self._home_box, True, True, 0)
            self._home_box.show()
            self._toolbar.clear_query()
            self._toolbar.set_placeholder_text_for_view(_('Home'))
            self._toolbar.show_view_buttons()
        elif level == ShellModel.ZOOM_GROUP:
            self._box.pack_start(self._group_box, True, True, 0)
            self._group_box.show()
            self._toolbar.clear_query()
            self._toolbar.set_placeholder_text_for_view(_('Group'))
            self._toolbar.hide_view_buttons()
        elif level == ShellModel.ZOOM_MESH:
            self._box.pack_start(self._mesh_box, True, True, 0)
            self._mesh_box.show()
            self._toolbar.clear_query()
            self._toolbar.set_placeholder_text_for_view(_('Neighborhood'))
            self._toolbar.hide_view_buttons()
        self._show_alert()

    def get_home_box(self):
        return self._home_box

    def busy(self):
        if self._busy_count == 0:
            self._old_cursor = self.get_window().get_cursor()
            self._set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
        self._busy_count += 1

    def unbusy(self):
        self._busy_count -= 1
        if self._busy_count == 0:
            self._set_cursor(self._old_cursor)

    def _set_cursor(self, cursor):
        self.get_window().set_cursor(cursor)
        Gdk.flush()
Ejemplo n.º 6
0
class HomeWindow(Gtk.Window):
    def __init__(self):
        logging.debug('STARTUP: Loading the desktop window')
        Gtk.Window.__init__(self)
        self.set_has_resize_grip(False)

        accel_group = Gtk.AccelGroup()
        self.sugar_accel_group = accel_group
        self.add_accel_group(accel_group)

        self._active = False
        self._fully_obscured = True

        screen = self.get_screen()
        screen.connect('size-changed', self.__screen_size_change_cb)
        self.set_default_size(screen.get_width(),
                              screen.get_height())

        self.realize()
        self._busy_count = 0
        self.busy()

        self.set_type_hint(Gdk.WindowTypeHint.DESKTOP)
        self.modify_bg(Gtk.StateType.NORMAL,
                       style.COLOR_WHITE.get_gdk_color())

        self.add_events(Gdk.EventMask.VISIBILITY_NOTIFY_MASK |
                        Gdk.EventMask.BUTTON_PRESS_MASK)
        self.connect('visibility-notify-event',
                     self._visibility_notify_event_cb)
        self.connect('map-event', self.__map_event_cb)
        self.connect('key-press-event', self.__key_press_event_cb)
        self.connect('key-release-event', self.__key_release_event_cb)

        self._box = HomeBackgroundBox()

        self._toolbar = ViewToolbar()
        self._box.pack_start(self._toolbar, False, True, 0)
        self._toolbar.show()

        self._alert = None

        self._home_box = HomeBox(self._toolbar)
        self._box.pack_start(self._home_box, True, True, 0)
        self._home_box.show()
        self._home_box.grab_focus()
        self._toolbar.show_view_buttons()

        self._group_box = GroupBox(self._toolbar)
        self._mesh_box = MeshBox(self._toolbar)
        self._transition_box = TransitionBox()

        self.add(self._box)
        self._box.show()

        self._transition_box.connect('completed',
                                     self._transition_completed_cb)

        shell.get_model().zoom_level_changed.connect(
            self.__zoom_level_changed_cb)

        self._alt_timeout_sid = None

    def add_alert(self, alert):
        self._alert = alert
        self._show_alert()

    def remove_alert(self, alert):
        if alert == self._alert:
            self._box.remove(self._alert)
            self._alert = None

    def _show_alert(self):
        if self._alert:
            self._box.pack_start(self._alert, False, False, 0)
            self._box.reorder_child(self._alert, 1)

    def _hide_alert(self):
        if self._alert:
            self._box.remove(self._alert)

    def _deactivate_view(self, level):
        group = palettegroup.get_group('default')
        group.popdown()
        if level == ShellModel.ZOOM_HOME:
            self._home_box.suspend()
        elif level == ShellModel.ZOOM_MESH:
            self._mesh_box.suspend()

    def __screen_size_change_cb(self, screen):
        self.resize(screen.get_width(), screen.get_height())

    def _activate_view(self, level):
        if level == ShellModel.ZOOM_HOME:
            self._home_box.resume()
        elif level == ShellModel.ZOOM_MESH:
            self._mesh_box.resume()

    def _visibility_notify_event_cb(self, window, event):
        fully_obscured = (
            event.get_state() == Gdk.VisibilityState.FULLY_OBSCURED)
        if self._fully_obscured == fully_obscured:
            return
        self._fully_obscured = fully_obscured

        if fully_obscured:
            self._deactivate_view(shell.get_model().zoom_level)
        else:
            self._activate_view(shell.get_model().zoom_level)

    def __is_alt(self, event):
        # When shift is on, <ALT> becomes <META>
        shift = (event.state & Gdk.ModifierType.SHIFT_MASK) == 1
        return event.keyval in [Gdk.KEY_Alt_L, Gdk.KEY_Alt_R] or \
           event.keyval in [Gdk.KEY_Meta_L, Gdk.KEY_Meta_R] and shift

    def __key_press_event_cb(self, window, event):
        if self.__is_alt(event) and not self._alt_timeout_sid:
            self._home_box.set_resume_mode(False)
            self._alt_timeout_sid = GObject.timeout_add(100,
                                                        self.__alt_timeout_cb)

        return False

    def __key_release_event_cb(self, window, event):
        if self.__is_alt(event) and self._alt_timeout_sid:
            self._home_box.set_resume_mode(True)
            GObject.source_remove(self._alt_timeout_sid)
            self._alt_timeout_sid = None

        return False

    def __alt_timeout_cb(self):
        display = Gdk.Display.get_default()
        screen_, x_, y_, modmask = display.get_pointer()
        if modmask & Gdk.ModifierType.MOD1_MASK:
            return True

        self._home_box.set_resume_mode(True)

        if self._alt_timeout_sid:
            GObject.source_remove(self._alt_timeout_sid)
            self._alt_timeout_sid = None

        return False

    def __map_event_cb(self, window, event):
        # have to make the desktop window active
        # since metacity doesn't make it on startup
        timestamp = event.get_time()
        x11_window = self.get_window()
        if not timestamp:
            timestamp = GdkX11.x11_get_server_time(x11_window)
        x11_window.focus(timestamp)

    def __zoom_level_changed_cb(self, **kwargs):
        old_level = kwargs['old_level']
        new_level = kwargs['new_level']

        self._deactivate_view(old_level)
        self._activate_view(new_level)

        if old_level != ShellModel.ZOOM_ACTIVITY and \
           new_level != ShellModel.ZOOM_ACTIVITY:
            self._hide_alert()
            children = self._box.get_children()
            if len(children) >= 2:
                self._box.remove(children[1])
            self._box.pack_start(self._transition_box, True, True, 0)
            self._transition_box.show()

            if new_level == ShellModel.ZOOM_HOME:
                end_size = style.XLARGE_ICON_SIZE
            elif new_level == ShellModel.ZOOM_GROUP:
                end_size = style.LARGE_ICON_SIZE
            elif new_level == ShellModel.ZOOM_MESH:
                end_size = style.STANDARD_ICON_SIZE

            if old_level == ShellModel.ZOOM_HOME:
                start_size = style.XLARGE_ICON_SIZE
            elif old_level == ShellModel.ZOOM_GROUP:
                start_size = style.LARGE_ICON_SIZE
            elif old_level == ShellModel.ZOOM_MESH:
                start_size = style.STANDARD_ICON_SIZE

            self._transition_box.start_transition(start_size, end_size)
        else:
            self._update_view(new_level)

    def _transition_completed_cb(self, transition_box):
        self._update_view(shell.get_model().zoom_level)

    def _update_view(self, level):
        if level == ShellModel.ZOOM_ACTIVITY:
            return

        self._hide_alert()
        children = self._box.get_children()
        if len(children) >= 2:
            self._box.remove(children[1])

        if level == ShellModel.ZOOM_HOME:
            self._box.pack_start(self._home_box, True, True, 0)
            self._home_box.show()
            self._toolbar.clear_query()
            self._toolbar.set_placeholder_text_for_view(_('Home'))
            self._home_box.grab_focus()
            self._toolbar.show_view_buttons()
        elif level == ShellModel.ZOOM_GROUP:
            self._box.pack_start(self._group_box, True, True, 0)
            self._group_box.show()
            self._toolbar.clear_query()
            self._toolbar.set_placeholder_text_for_view(_('Group'))
            self._group_box.grab_focus()
            self._toolbar.hide_view_buttons()
        elif level == ShellModel.ZOOM_MESH:
            self._box.pack_start(self._mesh_box, True, True, 0)
            self._mesh_box.show()
            self._toolbar.clear_query()
            self._toolbar.set_placeholder_text_for_view(_('Neighborhood'))
            self._mesh_box.grab_focus()
            self._toolbar.hide_view_buttons()
        self._show_alert()

    def get_home_box(self):
        return self._home_box

    def busy(self):
        if self._busy_count == 0:
            self._old_cursor = self.get_window().get_cursor()
            self._set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
        self._busy_count += 1

    def unbusy(self):
        self._busy_count -= 1
        if self._busy_count == 0:
            self._set_cursor(self._old_cursor)

    def _set_cursor(self, cursor):
        self.get_window().set_cursor(cursor)
        Gdk.flush()
Ejemplo n.º 7
0
class HomeWindow(Gtk.Window):
    def __init__(self):
        logging.debug('STARTUP: Loading the desktop window')
        Gtk.Window.__init__(self)
        self.set_has_resize_grip(False)

        accel_group = Gtk.AccelGroup()
        self.sugar_accel_group = accel_group
        self.add_accel_group(accel_group)

        self._active = False
        self._fully_obscured = True

        screen = self.get_screen()
        screen.connect('size-changed', self.__screen_size_change_cb)
        self.set_default_size(screen.get_width(),
                              screen.get_height())

        self.realize()
        self.set_type_hint(Gdk.WindowTypeHint.DESKTOP)
        self.modify_bg(Gtk.StateType.NORMAL,
                       style.COLOR_WHITE.get_gdk_color())

        self.add_events(Gdk.EventMask.VISIBILITY_NOTIFY_MASK |
                        Gdk.EventMask.BUTTON_PRESS_MASK)
        self.connect('visibility-notify-event',
                     self._visibility_notify_event_cb)
        self.connect('map-event', self.__map_event_cb)
        self.connect('key-press-event', self.__key_press_event_cb)
        self.connect('key-release-event', self.__key_release_event_cb)
        self.connect('button-press-event', self.__button_pressed_cb)

        self._box = HomeBackgroundBox()

        self._toolbar = ViewToolbar()
        self._box.pack_start(self._toolbar, False, True, 0)
        self._toolbar.show()

        self._home_box = HomeBox(self._toolbar)
        self._box.pack_start(self._home_box, True, True, 0)
        self._home_box.show()
        self._home_box.grab_focus()
        self._toolbar.show_view_buttons()

        self._group_box = GroupBox(self._toolbar)
        self._mesh_box = MeshBox(self._toolbar)
        self._transition_box = TransitionBox()

        self.add(self._box)
        self._box.show()

        self._transition_box.connect('completed',
                                     self._transition_completed_cb)

        shell.get_model().zoom_level_changed.connect(
            self.__zoom_level_changed_cb)

    def _deactivate_view(self, level):
        group = palettegroup.get_group('default')
        group.popdown()
        if level == ShellModel.ZOOM_HOME:
            self._home_box.suspend()
        elif level == ShellModel.ZOOM_MESH:
            self._mesh_box.suspend()

    def __screen_size_change_cb(self, screen):
        self.resize(screen.get_width(), screen.get_height())

    def _activate_view(self, level):
        if level == ShellModel.ZOOM_HOME:
            self._home_box.resume()
        elif level == ShellModel.ZOOM_MESH:
            self._mesh_box.resume()

    def _visibility_notify_event_cb(self, window, event):
        fully_obscured = (
            event.get_state() == Gdk.VisibilityState.FULLY_OBSCURED)
        if self._fully_obscured == fully_obscured:
            return
        self._fully_obscured = fully_obscured

        if fully_obscured:
            self._deactivate_view(shell.get_model().zoom_level)
        else:
            display = Gdk.Display.get_default()
            screen_, x_, y_, modmask = display.get_pointer()
            if modmask & Gdk.ModifierType.MOD1_MASK:
                self._home_box.set_resume_mode(False)
            else:
                self._home_box.set_resume_mode(True)

            self._activate_view(shell.get_model().zoom_level)

    def __key_press_event_cb(self, window, event):
        if event.keyval in [Gdk.KEY_Alt_L, Gdk.KEY_Alt_R]:
            self._home_box.set_resume_mode(False)
        else:
            if not self._toolbar.search_entry.has_focus():
                self._toolbar.search_entry.grab_focus()
        return False

    def __key_release_event_cb(self, window, event):
        if event.keyval in [Gdk.KEY_Alt_L, Gdk.KEY_Alt_R]:
            self._home_box.set_resume_mode(True)
        return False

    def __button_pressed_cb(self, widget, event):
        current_box = self._box.get_children()[1]
        current_box.grab_focus()
        return False

    def __map_event_cb(self, window, event):
        # have to make the desktop window active
        # since metacity doesn't make it on startup
        timestamp = event.get_time()
        x11_window = self.get_window()
        if not timestamp:
            timestamp = GdkX11.x11_get_server_time(x11_window)
        x11_window.focus(timestamp)

    def __zoom_level_changed_cb(self, **kwargs):
        old_level = kwargs['old_level']
        new_level = kwargs['new_level']

        self._deactivate_view(old_level)
        self._activate_view(new_level)

        if old_level != ShellModel.ZOOM_ACTIVITY and \
           new_level != ShellModel.ZOOM_ACTIVITY:
            children = self._box.get_children()
            if len(children) >= 2:
                self._box.remove(children[1])
            self._box.pack_start(self._transition_box, True, True, 0)
            self._transition_box.show()

            if new_level == ShellModel.ZOOM_HOME:
                end_size = style.XLARGE_ICON_SIZE
            elif new_level == ShellModel.ZOOM_GROUP:
                end_size = style.LARGE_ICON_SIZE
            elif new_level == ShellModel.ZOOM_MESH:
                end_size = style.STANDARD_ICON_SIZE

            if old_level == ShellModel.ZOOM_HOME:
                start_size = style.XLARGE_ICON_SIZE
            elif old_level == ShellModel.ZOOM_GROUP:
                start_size = style.LARGE_ICON_SIZE
            elif old_level == ShellModel.ZOOM_MESH:
                start_size = style.STANDARD_ICON_SIZE

            self._transition_box.start_transition(start_size, end_size)
        else:
            self._update_view(new_level)

    def _transition_completed_cb(self, transition_box):
        self._update_view(shell.get_model().zoom_level)

    def _update_view(self, level):
        if level == ShellModel.ZOOM_ACTIVITY:
            return

        children = self._box.get_children()
        if len(children) >= 2:
            self._box.remove(children[1])

        if level == ShellModel.ZOOM_HOME:
            self._box.pack_start(self._home_box, True, True, 0)
            self._home_box.show()
            self._toolbar.clear_query()
            self._toolbar.set_placeholder_text_for_view(_('Home'))
            self._home_box.grab_focus()
            self._toolbar.show_view_buttons()
        elif level == ShellModel.ZOOM_GROUP:
            self._box.pack_start(self._group_box, True, True, 0)
            self._group_box.show()
            self._toolbar.clear_query()
            self._toolbar.set_placeholder_text_for_view(_('Group'))
            self._group_box.grab_focus()
            self._toolbar.hide_view_buttons()
        elif level == ShellModel.ZOOM_MESH:
            self._box.pack_start(self._mesh_box, True, True, 0)
            self._mesh_box.show()
            self._toolbar.clear_query()
            self._toolbar.set_placeholder_text_for_view(_('Neighborhood'))
            self._mesh_box.grab_focus()
            self._toolbar.hide_view_buttons()

    def get_home_box(self):
        return self._home_box

    def busy_during_delayed_action(self, action):
        """Use busy cursor during execution of action, scheduled via idle_add.
        """
        def action_wrapper(old_cursor):
            try:
                action()
            finally:
                self.get_window().set_cursor(old_cursor)

        old_cursor = self.get_window().get_cursor()
        self.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
        GLib.idle_add(action_wrapper, old_cursor)
Ejemplo n.º 8
0
class HomeWindow(Gtk.Window):
    def __init__(self):
        logging.debug('STARTUP: Loading the desktop window')
        Gtk.Window.__init__(self)
        self.set_has_resize_grip(False)

        accel_group = Gtk.AccelGroup()
        self.sugar_accel_group = accel_group
        self.add_accel_group(accel_group)

        self._active = False
        self._fully_obscured = True

        screen = self.get_screen()
        screen.connect('size-changed', self.__screen_size_change_cb)
        self.set_default_size(screen.get_width(),
                              screen.get_height())

        self.realize()
        self.set_type_hint(Gdk.WindowTypeHint.DESKTOP)
        self.modify_bg(Gtk.StateType.NORMAL,
                       style.COLOR_WHITE.get_gdk_color())

        self.add_events(Gdk.EventMask.VISIBILITY_NOTIFY_MASK |
                        Gdk.EventMask.BUTTON_PRESS_MASK)
        self.connect('visibility-notify-event',
                     self._visibility_notify_event_cb)
        self.connect('map-event', self.__map_event_cb)
        self.connect('key-press-event', self.__key_press_event_cb)
        self.connect('key-release-event', self.__key_release_event_cb)
        self.connect('button-press-event', self.__button_pressed_cb)

        self._box = HomeBackgroundBox()

        self._toolbar = ViewToolbar()
        self._box.pack_start(self._toolbar, False, True, 0)
        self._toolbar.show()

        self._alerts = []

        self._home_box = HomeBox(self._toolbar)
        self._box.pack_start(self._home_box, True, True, 0)
        self._home_box.show()
        self._home_box.grab_focus()
        self._toolbar.show_view_buttons()

        self._group_box = GroupBox(self._toolbar)
        self._mesh_box = MeshBox(self._toolbar)
        self._transition_box = TransitionBox()

        self.add(self._box)
        self._box.show()

        self._transition_box.connect('completed',
                                     self._transition_completed_cb)

        shell.get_model().zoom_level_changed.connect(
            self.__zoom_level_changed_cb)

    def add_alert(self, alert):
        self._alerts.append(alert)
        if len(self._alerts) == 1:
            self._display_alert(alert)

    def remove_alert(self, alert):
        if alert in self._alerts:
            self._alerts.remove(alert)
            # if the alert is the visible one on top of the queue
            if alert.get_parent() is not None:
                self._box.remove(alert)
                if len(self._alerts) >= 1:
                    self._display_alert(self._alerts[0])

    def _display_alert(self, alert):
        self._box.pack_start(alert, False, False, 0)
        self._box.reorder_child(alert, 1)

    def _deactivate_view(self, level):
        group = palettegroup.get_group('default')
        group.popdown()
        if level == ShellModel.ZOOM_HOME:
            self._home_box.suspend()
        elif level == ShellModel.ZOOM_MESH:
            self._mesh_box.suspend()

    def __screen_size_change_cb(self, screen):
        self.resize(screen.get_width(), screen.get_height())

    def _activate_view(self, level):
        if level == ShellModel.ZOOM_HOME:
            self._home_box.resume()
        elif level == ShellModel.ZOOM_MESH:
            self._mesh_box.resume()

    def _visibility_notify_event_cb(self, window, event):
        fully_obscured = (
            event.get_state() == Gdk.VisibilityState.FULLY_OBSCURED)
        if self._fully_obscured == fully_obscured:
            return
        self._fully_obscured = fully_obscured

        if fully_obscured:
            self._deactivate_view(shell.get_model().zoom_level)
        else:
            display = Gdk.Display.get_default()
            screen_, x_, y_, modmask = display.get_pointer()
            if modmask & Gdk.ModifierType.MOD1_MASK:
                self._home_box.set_resume_mode(False)
            else:
                self._home_box.set_resume_mode(True)

            self._activate_view(shell.get_model().zoom_level)

    def __key_press_event_cb(self, window, event):
        if event.keyval in [Gdk.KEY_Alt_L, Gdk.KEY_Alt_R]:
            self._home_box.set_resume_mode(False)
        else:
            if not self._toolbar.search_entry.has_focus():
                self._toolbar.search_entry.grab_focus()
        return False

    def __key_release_event_cb(self, window, event):
        if event.keyval in [Gdk.KEY_Alt_L, Gdk.KEY_Alt_R]:
            self._home_box.set_resume_mode(True)
        return False

    def __button_pressed_cb(self, widget, event):
        current_box = self._box.get_children()[1]
        current_box.grab_focus()
        return False

    def __map_event_cb(self, window, event):
        # have to make the desktop window active
        # since metacity doesn't make it on startup
        timestamp = event.get_time()
        x11_window = self.get_window()
        if not timestamp:
            timestamp = GdkX11.x11_get_server_time(x11_window)
        x11_window.focus(timestamp)

    def __zoom_level_changed_cb(self, **kwargs):
        old_level = kwargs['old_level']
        new_level = kwargs['new_level']

        self._deactivate_view(old_level)
        self._activate_view(new_level)

        if old_level != ShellModel.ZOOM_ACTIVITY and \
           new_level != ShellModel.ZOOM_ACTIVITY:
            children = self._box.get_children()
            if len(children) >= 2:
                self._box.remove(children[1])
            self._box.pack_start(self._transition_box, True, True, 0)
            self._transition_box.show()

            if new_level == ShellModel.ZOOM_HOME:
                end_size = style.XLARGE_ICON_SIZE
            elif new_level == ShellModel.ZOOM_GROUP:
                end_size = style.LARGE_ICON_SIZE
            elif new_level == ShellModel.ZOOM_MESH:
                end_size = style.STANDARD_ICON_SIZE

            if old_level == ShellModel.ZOOM_HOME:
                start_size = style.XLARGE_ICON_SIZE
            elif old_level == ShellModel.ZOOM_GROUP:
                start_size = style.LARGE_ICON_SIZE
            elif old_level == ShellModel.ZOOM_MESH:
                start_size = style.STANDARD_ICON_SIZE

            self._transition_box.start_transition(start_size, end_size)
        else:
            self._update_view(new_level)

    def _transition_completed_cb(self, transition_box):
        self._update_view(shell.get_model().zoom_level)

    def _update_view(self, level):
        if level == ShellModel.ZOOM_ACTIVITY:
            return

        children = self._box.get_children()
        if len(children) >= 2:
            self._box.remove(children[1])

        if level == ShellModel.ZOOM_HOME:
            self._box.pack_start(self._home_box, True, True, 0)
            self._home_box.show()
            self._toolbar.clear_query()
            self._toolbar.set_placeholder_text_for_view(_('Home'))
            self._home_box.grab_focus()
            self._toolbar.show_view_buttons()
        elif level == ShellModel.ZOOM_GROUP:
            self._box.pack_start(self._group_box, True, True, 0)
            self._group_box.show()
            self._toolbar.clear_query()
            self._toolbar.set_placeholder_text_for_view(_('Group'))
            self._group_box.grab_focus()
            self._toolbar.hide_view_buttons()
        elif level == ShellModel.ZOOM_MESH:
            self._box.pack_start(self._mesh_box, True, True, 0)
            self._mesh_box.show()
            self._toolbar.clear_query()
            self._toolbar.set_placeholder_text_for_view(_('Neighborhood'))
            self._mesh_box.grab_focus()
            self._toolbar.hide_view_buttons()

    def get_home_box(self):
        return self._home_box

    def busy_during_delayed_action(self, action):
        """Use busy cursor during execution of action, scheduled via idle_add.
        """
        def action_wrapper(old_cursor):
            try:
                action()
            finally:
                self.get_window().set_cursor(old_cursor)

        old_cursor = self.get_window().get_cursor()
        self.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
        GLib.idle_add(action_wrapper, old_cursor)
Ejemplo n.º 9
0
class HomeWindow(gtk.Window):
    def __init__(self):
        logging.debug('STARTUP: Loading the desktop window')
        gtk.Window.__init__(self)

        accel_group = gtk.AccelGroup()
        self.set_data('sugar-accel-group', accel_group)
        self.add_accel_group(accel_group)

        self._active = False
        self._fully_obscured = True

        screen = self.get_screen()
        screen.connect('size-changed', self.__screen_size_change_cb)
        self.set_default_size(screen.get_width(),
                              screen.get_height())

        self.realize()
        self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)

        self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
        self.connect('visibility-notify-event',
                     self._visibility_notify_event_cb)
        self.connect('map-event', self.__map_event_cb)
        self.connect('key-press-event', self.__key_press_event_cb)
        self.connect('key-release-event', self.__key_release_event_cb)

        self._home_box = HomeBox()
        self._group_box = GroupBox()
        self._mesh_box = MeshBox()
        self._transition_box = TransitionBox()

        self.add(self._home_box)
        self._home_box.show()

        self._transition_box.connect('completed',
                                     self._transition_completed_cb)

        shell.get_model().zoom_level_changed.connect(
                                     self.__zoom_level_changed_cb)

    def _deactivate_view(self, level):
        group = palettegroup.get_group('default')
        group.popdown()
        if level == ShellModel.ZOOM_HOME:
            self._home_box.suspend()
        elif level == ShellModel.ZOOM_MESH:
            self._mesh_box.suspend()

    def __screen_size_change_cb(self, screen):
        self.resize(screen.get_width(), screen.get_height())

    def _activate_view(self, level):
        if level == ShellModel.ZOOM_HOME:
            self._home_box.resume()
        elif level == ShellModel.ZOOM_MESH:
            self._mesh_box.resume()

    def _visibility_notify_event_cb(self, window, event):
        fully_obscured = (event.state == gtk.gdk.VISIBILITY_FULLY_OBSCURED)
        if self._fully_obscured == fully_obscured:
            return
        self._fully_obscured = fully_obscured

        if fully_obscured:
            self._deactivate_view(shell.get_model().zoom_level)
        else:
            display = gtk.gdk.display_get_default()
            screen_, x_, y_, modmask = display.get_pointer()
            if modmask & gtk.gdk.MOD1_MASK:
                self._home_box.set_resume_mode(False)
            else:
                self._home_box.set_resume_mode(True)

            self._activate_view(shell.get_model().zoom_level)

    def __key_press_event_cb(self, window, event):
        if event.keyval in [gtk.keysyms.Alt_L, gtk.keysyms.Alt_R]:
            self._home_box.set_resume_mode(False)
        return False

    def __key_release_event_cb(self, window, event):
        if event.keyval in [gtk.keysyms.Alt_L, gtk.keysyms.Alt_R]:
            self._home_box.set_resume_mode(True)
        return False

    def __map_event_cb(self, window, event):
        # have to make the desktop window active
        # since metacity doesn't make it on startup
        timestamp = event.get_time()
        if not timestamp:
            timestamp = gtk.gdk.x11_get_server_time(self.window)
        self.window.focus(timestamp)

    def __zoom_level_changed_cb(self, **kwargs):
        old_level = kwargs['old_level']
        new_level = kwargs['new_level']

        self._deactivate_view(old_level)
        self._activate_view(new_level)

        if old_level != ShellModel.ZOOM_ACTIVITY and \
           new_level != ShellModel.ZOOM_ACTIVITY:
            self.remove(self.get_child())
            self.add(self._transition_box)
            self._transition_box.show()

            if new_level == ShellModel.ZOOM_HOME:
                end_size = style.XLARGE_ICON_SIZE
            elif new_level == ShellModel.ZOOM_GROUP:
                end_size = style.LARGE_ICON_SIZE
            elif new_level == ShellModel.ZOOM_MESH:
                end_size = style.STANDARD_ICON_SIZE

            if old_level == ShellModel.ZOOM_HOME:
                start_size = style.XLARGE_ICON_SIZE
            elif old_level == ShellModel.ZOOM_GROUP:
                start_size = style.LARGE_ICON_SIZE
            elif old_level == ShellModel.ZOOM_MESH:
                start_size = style.STANDARD_ICON_SIZE

            self._transition_box.start_transition(start_size, end_size)
        else:
            self._update_view(new_level)

    def _transition_completed_cb(self, transition_box):
        self._update_view(shell.get_model().zoom_level)

    def _update_view(self, level):
        if level == ShellModel.ZOOM_ACTIVITY:
            return

        current_child = self.get_child()
        self.remove(current_child)

        if level == ShellModel.ZOOM_HOME:
            self.add(self._home_box)
            self._home_box.show()
            self._home_box.focus_search_entry()
        elif level == ShellModel.ZOOM_GROUP:
            self.add(self._group_box)
            self._group_box.show()
        elif level == ShellModel.ZOOM_MESH:
            self.add(self._mesh_box)
            self._mesh_box.show()
            self._mesh_box.focus_search_entry()

    def get_home_box(self):
        return self._home_box

    def busy_during_delayed_action(self, action):
        """Use busy cursor during execution of action, scheduled via idle_add.
        """
        def action_wrapper(old_cursor):
            try:
                action()
            finally:
                self.get_window().set_cursor(old_cursor)

        old_cursor = self.get_window().get_cursor()
        self.get_window().set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
        gobject.idle_add(action_wrapper, old_cursor)
Ejemplo n.º 10
0
class HomeWindow(gtk.Window):
    def __init__(self):
        logging.debug('STARTUP: Loading the desktop window')
        gtk.Window.__init__(self)

        accel_group = gtk.AccelGroup()
        self.set_data('sugar-accel-group', accel_group)
        self.add_accel_group(accel_group)

        self._active = False
        self._fully_obscured = True

        screen = self.get_screen()
        screen.connect('size-changed', self.__screen_size_change_cb)
        self.set_default_size(screen.get_width(), screen.get_height())

        self.realize()
        self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)

        self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
        self.connect('visibility-notify-event',
                     self._visibility_notify_event_cb)
        self.connect('map-event', self.__map_event_cb)
        self.connect('key-press-event', self.__key_press_event_cb)
        self.connect('key-release-event', self.__key_release_event_cb)

        self._home_box = HomeBox()
        self._group_box = GroupBox()
        self._mesh_box = MeshBox()
        self._transition_box = TransitionBox()

        self.add(self._home_box)
        self._home_box.show()

        self._transition_box.connect('completed',
                                     self._transition_completed_cb)

        shell.get_model().zoom_level_changed.connect(
            self.__zoom_level_changed_cb)

    def _deactivate_view(self, level):
        group = palettegroup.get_group('default')
        group.popdown()
        if level == ShellModel.ZOOM_HOME:
            self._home_box.suspend()
        elif level == ShellModel.ZOOM_MESH:
            self._mesh_box.suspend()

    def __screen_size_change_cb(self, screen):
        self.resize(screen.get_width(), screen.get_height())

    def _activate_view(self, level):
        if level == ShellModel.ZOOM_HOME:
            self._home_box.resume()
        elif level == ShellModel.ZOOM_MESH:
            self._mesh_box.resume()

    def _visibility_notify_event_cb(self, window, event):
        fully_obscured = (event.state == gtk.gdk.VISIBILITY_FULLY_OBSCURED)
        if self._fully_obscured == fully_obscured:
            return
        self._fully_obscured = fully_obscured

        if fully_obscured:
            self._deactivate_view(shell.get_model().zoom_level)
        else:
            display = gtk.gdk.display_get_default()
            screen_, x_, y_, modmask = display.get_pointer()
            if modmask & gtk.gdk.MOD1_MASK:
                self._home_box.set_resume_mode(False)
            else:
                self._home_box.set_resume_mode(True)

            self._activate_view(shell.get_model().zoom_level)

    def __key_press_event_cb(self, window, event):
        if event.keyval in [gtk.keysyms.Alt_L, gtk.keysyms.Alt_R]:
            self._home_box.set_resume_mode(False)
        return False

    def __key_release_event_cb(self, window, event):
        if event.keyval in [gtk.keysyms.Alt_L, gtk.keysyms.Alt_R]:
            self._home_box.set_resume_mode(True)
        return False

    def __map_event_cb(self, window, event):
        # have to make the desktop window active
        # since metacity doesn't make it on startup
        timestamp = event.get_time()
        if not timestamp:
            timestamp = gtk.gdk.x11_get_server_time(self.window)
        self.window.focus(timestamp)

    def __zoom_level_changed_cb(self, **kwargs):
        old_level = kwargs['old_level']
        new_level = kwargs['new_level']

        self._deactivate_view(old_level)
        self._activate_view(new_level)

        if old_level != ShellModel.ZOOM_ACTIVITY and \
           new_level != ShellModel.ZOOM_ACTIVITY:
            self.remove(self.get_child())
            self.add(self._transition_box)
            self._transition_box.show()

            if new_level == ShellModel.ZOOM_HOME:
                end_size = style.XLARGE_ICON_SIZE
            elif new_level == ShellModel.ZOOM_GROUP:
                end_size = style.LARGE_ICON_SIZE
            elif new_level == ShellModel.ZOOM_MESH:
                end_size = style.STANDARD_ICON_SIZE

            if old_level == ShellModel.ZOOM_HOME:
                start_size = style.XLARGE_ICON_SIZE
            elif old_level == ShellModel.ZOOM_GROUP:
                start_size = style.LARGE_ICON_SIZE
            elif old_level == ShellModel.ZOOM_MESH:
                start_size = style.STANDARD_ICON_SIZE

            self._transition_box.start_transition(start_size, end_size)
        else:
            self._update_view(new_level)

    def _transition_completed_cb(self, transition_box):
        self._update_view(shell.get_model().zoom_level)

    def _update_view(self, level):
        if level == ShellModel.ZOOM_ACTIVITY:
            return

        current_child = self.get_child()
        self.remove(current_child)

        if level == ShellModel.ZOOM_HOME:
            self.add(self._home_box)
            self._home_box.show()
            self._home_box.focus_search_entry()
        elif level == ShellModel.ZOOM_GROUP:
            self.add(self._group_box)
            self._group_box.show()
        elif level == ShellModel.ZOOM_MESH:
            self.add(self._mesh_box)
            self._mesh_box.show()
            self._mesh_box.focus_search_entry()

    def get_home_box(self):
        return self._home_box

    def busy_during_delayed_action(self, action):
        """Use busy cursor during execution of action, scheduled via idle_add.
        """
        def action_wrapper(old_cursor):
            try:
                action()
            finally:
                self.get_window().set_cursor(old_cursor)

        old_cursor = self.get_window().get_cursor()
        self.get_window().set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
        gobject.idle_add(action_wrapper, old_cursor)