Пример #1
0
    def onDND(self, list, context, x, y, dragData, dndId, time):
        """ External Drag'n'Drop """
        import urllib.request

        uris = dragData.get_uris()

        if not uris:
            context.finish(False, False, time)
            return

        def get_path(uri):
            if uri.startswith('file://'):
                uri = uri[len('file://'):]
            return urllib.request.url2pathname(uri)

        paths = [get_path(uri) for uri in uris]
        tracks = media.getTracks(paths)

        dropInfo = list.get_dest_row_at_pos(x, y)

        # Insert the tracks, but beware of the AFTER/BEFORE mechanism used by GTK
        if dropInfo is None:
            self.insert(tracks, playNow=False, highlight=True)
        else:
            path, drop_mode = dropInfo
            iter = self.tree.store.get_iter(path)
            self.insert(tracks, iter, drop_mode, playNow=False, highlight=True)

        # We want to allow dropping tracks only when we are sure that no dir is
        # selected. This is needed for dnd from nautilus.
        self.tree.dir_selected = True

        context.finish(True, False, time)
Пример #2
0
 def SetTracks(self, uris, playNow):
     """ Replace the tracklist by the given URIs """
     # uris is a DBus array we want a Python list
     # We add the empty string to convert the uris from DBus.String to unicode
     paths = [uri + '' for uri in uris]
     GObject.idle_add(modules.postMsg, consts.MSG_CMD_TRACKLIST_SET, {
         'tracks': media.getTracks(paths),
         'playNow': playNow
     })
Пример #3
0
 def AddTracks(self, uris, playNow):
     """ Appends multiple URIs to the tracklist """
     # uris is a DBus array we want a Python list
     # We add the empty string to convert the uris from DBus.String to unicode
     paths = [uri + '' for uri in uris]
     GObject.idle_add(modules.postMsg, consts.MSG_CMD_TRACKLIST_ADD, {
         'tracks': media.getTracks(paths),
         'playNow': playNow
     })
Пример #4
0
 def onLoadTracks(self, paths):
     modules.postMsg(consts.MSG_CMD_TRACKLIST_ADD, {
         'tracks': media.getTracks(paths),
         'playNow': True
     })
Пример #5
0
        else:
            action = Gdk.DragAction.COPY
        Gdk.drag_status(context, action, time)

        # Return whether the cursor position is in a drop zone.
        return pos_ok


if __name__ == '__main__':
    from gi.repository import GdkPixbuf
    from gi.repository import GObject

    from pogo.tools import icons
    from pogo.media import getTracks

    tracks = getTracks(['/home/jendrik/Musik/Clearlake - Amber'])

    columns = (
        ('', [(Gtk.CellRendererPixbuf(), GdkPixbuf.Pixbuf), (Gtk.CellRendererText(), GObject.TYPE_STRING)], True),
        (None, [(None, GObject.TYPE_INT)], False),
        (None, [(None, GObject.TYPE_STRING)], False),
        (None, [(None, GObject.TYPE_PYOBJECT)], False),
    )

    tree = TrackTreeView(columns, True)

    track = None

    a = tree.appendRow((icons.nullMenuIcon(), 'a', 1, 'something', track), None)
    b = tree.appendRow((icons.nullMenuIcon(), 'b', 1, 'something', track), a)
    c = tree.appendRow((icons.nullMenuIcon(), 'c', 1, 'something', track), a)
Пример #6
0
    def onAppStarted(self):
        """ This is the real initialization function, called when the module has been loaded """
        wTree = tools.prefs.getWidgetsTree()
        self.playtime = 0
        self.bufferedTrack = None
        # Retrieve widgets
        self.window = wTree.get_object('win-main')

        columns = (('', [(Gtk.CellRendererPixbuf(), GdkPixbuf.Pixbuf), (Gtk.CellRendererText(), GObject.TYPE_STRING)], True),
                   (None, [(None, GObject.TYPE_PYOBJECT)], False),
                   )

        self.tree = TrackTreeView(columns, use_markup=True)

        self.tree.enableDNDReordering()
        target = Gtk.TargetEntry.new(*DND_INTERNAL_TARGET)
        targets = Gtk.TargetList.new([target])
        self.tree.setDNDSources(targets)

        wTree.get_object('scrolled-tracklist').add(self.tree)

        # GTK handlers
        self.tree.connect('exttreeview-button-pressed', self.onMouseButton)
        self.tree.connect('tracktreeview-dnd', self.onDND)
        self.tree.connect('key-press-event', self.onKeyboard)
        self.tree.get_model().connect('row-deleted', self.onRowDeleted)

        _options, args = prefs.getCmdLine()

        self.savedPlaylist = os.path.join(consts.dirCfg, 'saved-playlist')
        self.paused = False

        # Populate the playlist with the saved playlist
        dump = None
        if os.path.exists(self.savedPlaylist):
            try:
                dump = pickleLoad(self.savedPlaylist)
            except (EOFError, ImportError, IOError):
                msg = '[%s] Unable to restore playlist from %s\n\n%s'
                log.logger.error(msg % (MOD_INFO[modules.MODINFO_NAME],
                                        self.savedPlaylist, traceback.format_exc()))

        if dump:
            self.restoreTreeDump(dump)
            log.logger.info('[%s] Restored playlist' % MOD_INFO[modules.MODINFO_NAME])
            self.tree.collapse_all()
            self.select_last_played_track()
            self.onListModified()

        commands, args = tools.separate_commands_and_tracks(args)

        # Add commandline tracks to the playlist
        if args:
            log.logger.info('[%s] Filling playlist with files given on command line' % MOD_INFO[modules.MODINFO_NAME])
            tracks = media.getTracks([os.path.abspath(arg) for arg in args])
            playNow = 'stop' not in commands and 'pause' not in commands
            modules.postMsg(consts.MSG_CMD_TRACKLIST_ADD, {'tracks': tracks, 'playNow': playNow})
        elif 'play' in commands:
            modules.postMsg(consts.MSG_CMD_TOGGLE_PAUSE)

        # Automatically save the content at regular intervals
        GObject.timeout_add_seconds(SAVE_INTERVAL, self.save_track_tree)