Example #1
0
    def do_activate(self):
        # Basic Activation Procedure
        self.shell = self.object
        self.main_window = self.shell.props.window

        # Prepare internal variables
        self.song_duration = 0
        self.cover_pixbuf = None
        self.entry = None

        # Prepare Album Art Displaying
        self.album_art_db = GObject.new(RB.ExtDB, name="album-art")

        # Build up actions.
        self.action_group = ActionGroup(self.shell, 'small window actions')
        action = self.action_group.add_action(func=self.small_window_action,
                                              action_name='SmallWindow',
                                              label='Small Window',
                                              action_type='app')

        self._appshell = ApplicationShell(self.shell)
        self._appshell.insert_action_group(self.action_group)
        self._appshell.add_app_menuitems(ui_string, 'small window actions')

        # Build up small window interface
        builder = Gtk.Builder()
        if is_rb3():
            builder.add_from_file(rb.find_plugin_file(self,
                                                      "interface_rb3.ui"))
        else:
            builder.add_from_file(rb.find_plugin_file(self,
                                                      "interface_rb2.ui"))
        self.load_builder_content(builder)
        self.connect_builder_content(builder)
        restore = builder.get_object('restore button')
        restore.connect('clicked', self.main_window_action)

        # Prepare windows
        for sub_widget in self.small_window:
            sub_widget.show_all()

        geometry = Gdk.Geometry()

        geometry.min_width = 300
        geometry.max_width = 5120
        geometry.min_height = -1
        geometry.max_height = -1

        self.small_window.set_geometry_hints(
            self.small_window, geometry,
            Gdk.WindowHints.MIN_SIZE | Gdk.WindowHints.MAX_SIZE)

        if is_rb3():
            self.shell.props.application.add_window(self.small_window)
            # Bring Builtin Actions to plugin
            for (a, b) in ((self.play_button, "play"), (self.prev_button,
                                                        "play-previous"),
                           (self.next_button,
                            "play-next"), (self.repeat_toggle, "play-repeat"),
                           (self.shuffle_toggle, "play-shuffle")):
                a.set_action_name("app." + b)
                #if b == "play-repeat" or b == "play-shuffle":
                #    a.set_action_target_value(GLib.Variant("b", True))
        else:
            # Bring Builtin Actions to plugin
            for (a,
                 b) in ((self.play_button, "ControlPlay"), (self.prev_button,
                                                            "ControlPrevious"),
                        (self.next_button, "ControlNext"), (self.repeat_toggle,
                                                            "ControlRepeat"),
                        (self.shuffle_toggle, "ControlShuffle")):
                a.set_related_action(
                    self._appshell.lookup_action("MainActions", b).action)

        # Bind needed properites.
        self.bind_title = GObject.Binding(source=self.main_window,
                                          source_property="title",
                                          target=self.small_window,
                                          target_property="title",
                                          flags=GObject.BindingFlags.DEFAULT)

        # Connect signal handlers to rhythmbox
        self.shell_player = self.shell.props.shell_player
        self.sh_psc = self.shell_player.connect("playing-song-changed",
                                                self._sh_on_song_change)

        self.sh_op = self.shell_player.connect("elapsed-changed",
                                               self._sh_on_playing)