Example #1
0
    def plugin_song(self, song):
        self._window = window = \
            Dialog(title=_("Tap BPM"), parent=self.plugin_window)

        window.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
        window.add_icon_button(_("_Save"), Icons.DOCUMENT_SAVE,
                             Gtk.ResponseType.OK)

        window.set_default_size(300, 100)
        window.set_border_width(6)
        self.__resp_sig = window.connect('response', self.response)

        self._panel = TapBpmPanel(window, song)
        window.vbox.pack_start(self._panel, False, True, 0)

        window.vbox.show_all()
        window.present()
Example #2
0
 def test_add_icon_button(self):
     d = Dialog()
     w = d.add_icon_button("foo", "bar", 100)
     self.assertEqual(d.get_widget_for_response(100), w)
Example #3
0
 def test_add_icon_button(self):
     d = Dialog()
     w = d.add_icon_button("foo", "bar", 100)
     self.assertEqual(d.get_widget_for_response(100), w)
Example #4
0
    def plugin_songs(self, songs):
        global songinfo

        # Create a dialog.
        dlg = Dialog(title=_("Migrate Metadata"),
                     transient_for=self.plugin_window,
                     flags=(Gtk.DialogFlags.MODAL |
                            Gtk.DialogFlags.DESTROY_WITH_PARENT))
        dlg.set_border_width(4)
        dlg.vbox.set_spacing(4)

        dlg.add_icon_button(_("_Copy"), Icons.EDIT_COPY, Gtk.ResponseType.OK)
        dlg.add_icon_button(
            _("_Paste"), Icons.EDIT_PASTE, Gtk.ResponseType.APPLY)

        # Default to the "Copy" button when the songsinfo
        # list is empty, default to "Paste" button otherwise.
        if len(songinfo) == 0:
            dlg.set_default_response(Gtk.ResponseType.OK)
        else:
            dlg.set_default_response(Gtk.ResponseType.APPLY)

        # Create the tag table.
        frame = Gtk.Frame(label=_("Information to copy/paste"))
        # Try to make a nice even square-ish table.
        bias = 3  # Columns count for 3 rows, due to label text using space.
        columns = int(max(1, math.ceil(math.sqrt(len(MIGRATE) / bias))))
        rows = int(max(1, math.ceil(len(MIGRATE) / columns)))
        table = Gtk.Table(rows=rows, columns=columns, homogeneous=True)
        table.set_border_width(4)
        table.set_row_spacings(4)
        table.set_col_spacings(4)

        # Create check boxes.
        tags = {}
        for ctr, tag in enumerate(sorted(MIGRATE)):
            tags[tag] = Gtk.CheckButton(label=readable(tag).capitalize())
            tags[tag].set_active(True)

            # These floors and casts make sure we don't get floats.
            col = int(math.floor(ctr % columns))
            row = int(math.floor(ctr / columns))
            table.attach(tags[tag], col, col + 1, row, row + 1)

        # Create the indexing box.
        index = Gtk.CheckButton(label=_("Map tracks by disc and track number"))
        index.set_tooltip_markup(_("Enable this when you want to migrate "
                                   "metadata from one album to another while "
                                   "matching the disc and track numbers."
                                   "\n\n"
                                   "<b>Note:</b> this must be enabled when "
                                   "metadata is copied for track information "
                                   "to be stored."))
        # Automatically check when there is more
        # than one song in the songs or songinfo lists.
        if len(songs) > 1 or len(songinfo) > 1:
            index.set_active(True)

        # Assemble the window.
        frame.add(table)
        dlg.vbox.add(frame)
        dlg.vbox.add(index)
        dlg.vbox.add(Gtk.Label(ngettext("There is %d stored track.",
                                        "There are %d stored tracks.",
                                        len(songinfo)) % len(songinfo)))
        dlg.show_all()
        response = dlg.run()

        # Only accept expected responses.
        if response not in [Gtk.ResponseType.OK, Gtk.ResponseType.APPLY]:
            dlg.destroy()
            return

        # If copying, erase the currently stored metadata.
        if response == Gtk.ResponseType.OK:
            songinfo = {}

        # Go through the songs list and process it.
        for tid, song in enumerate(songs):
            # This tid will be what we index all of our tracks by,
            # so they will be easier to find when pasting metadata.
            if index.get_active() is True:
                tid = "%d-%d" % (self.get_number(song, 'discnumber'),
                                 self.get_number(song, 'tracknumber'))

            # Erase track info if copying.
            if response == Gtk.ResponseType.OK:
                songinfo[tid] = {}

            for tag in tags.keys():
                if tags[tag].get_active() is False:
                    continue  # Skip unchecked tags.

                try:
                    if response == Gtk.ResponseType.OK:
                        # Copy information.
                        songinfo[tid][tag] = song[tag]
                    elif response == Gtk.ResponseType.APPLY:
                        # Paste information.
                        song[tag] = songinfo[tid][tag]
                except KeyError:
                    continue  # Just leave out tags that aren't present.

        # Erase songinfo after pasting.
        if response == Gtk.ResponseType.APPLY:
            songinfo = {}

        # Aaaaaand we're done.
        dlg.destroy()
        return
Example #5
0
    def plugin_album(self, album):
        discid = calculate_discid(album)

        try:
            stat, discs = CDDB.query(discid, **CLIENTINFO)
        except IOError:
            ErrorMessage(None, _("Timeout"), _(
                "Query could not be executed, connection timed out")).run()
            return

        if stat in (200, 211):
            xcode = 'utf8:utf8'
            dlg = Dialog(title=_('Select an album'))
            dlg.set_border_width(6)
            dlg.set_resizable(False)
            dlg.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
            dlg.add_icon_button(_("_Save"), Icons.DOCUMENT_SAVE,
                                Gtk.ResponseType.OK)
            dlg.vbox.set_spacing(6)
            dlg.set_default_response(Gtk.ResponseType.CANCEL)
            model = Gtk.ListStore(str, str, str, str, str, str)
            for disc in discs:
                model.append(
                    [disc[s] for s in ('title', 'category', 'disc_id')] * 2)
            box = Gtk.ComboBox(model=model)
            box.set_active(0)
            for i in range(3):
                crt = Gtk.CellRendererText()
                box.pack_start(crt, True)
                box.add_attribute(crt, "text", i)
            discinfo = Gtk.Label()
            crosscode = Gtk.ListStore(str)
            crosscode.append(['utf8:utf8'])
            crosscode.append(['latin1:latin2'])
            crosscode.append(['latin1:cp1251'])
            crosscode.append(['latin1:sjis'])
            crosscode.append(['latin1:euc-jp'])
            cbo = Gtk.ComboBox(
                model=crosscode, entry_text_column=0, has_entry=True)
            cbo.set_active(0)

            def update_discinfo(combo):
                xcode = cbo.get_child().get_text()
                model = combo.get_model()
                t, c, d, title, cat, discid = model[box.get_active()]
                info = query(cat, discid, xcode=xcode)
                discinfo.set_markup(
                    make_info_label(info, album, discs[0]['disc_id']))

            def crosscode_cddbinfo(combo):
                try:
                    xf, xt = combo.get_child().get_text().split(':')
                    for row in model:
                        for show, store in zip(range(0, 3), range(3, 6)):
                            row[show] = row[store].encode(
                                xf, 'replace').decode(xt, 'replace')
                except:
                    for row in model:
                        for show, store in zip(range(0, 3), range(3, 6)):
                            row[show] = row[store]
                update_discinfo(box)

            cbo.connect('changed', crosscode_cddbinfo)
            box.connect('changed', update_discinfo)
            update_discinfo(box)
            dlg.vbox.pack_start(Gtk.Label(
                _("Select the album you wish to retrieve.")), True, True, 0)
            dlg.vbox.pack_start(box, True, True, 0)
            dlg.vbox.pack_start(discinfo, True, True, 0)
            dlg.vbox.pack_start(cbo, True, True, 0)
            dlg.vbox.show_all()
            resp = dlg.run()

            xcode = cbo.get_child().get_text()
            if resp == Gtk.ResponseType.OK:
                t, c, d, title, cat, discid = model[box.get_active()]
                (disc, track) = query(cat, discid, xcode=xcode)
                keys = track.keys()
                keys.sort()
                for key, song in zip(keys, album):
                    if 'artist' in disc:
                        song['artist'] = disc['artist']
                    if 'title' in disc:
                        song['album'] = disc['title']
                    if 'year' in disc:
                        song['date'] = disc['year']
                    if 'genre' in disc:
                        song['genre'] = disc['genre']
                    s = track[key].split("/")
                    if len(s) == 2:
                        song['artist'] = s[0]
                        song['title'] = s[1]
                    else:
                        song['title'] = track[key]
                    song['tracknumber'] = '%d/%d' % (key + 1, len(album))
            dlg.destroy()
        else:
            n = len(album)
            albumname = album[0]('album')
            if not albumname:
                albumname = ngettext('%d track', '%d tracks', n) % n
            ErrorMessage(None, _("CDDB lookup failed (%s)" % stat),
                    ngettext(u"%(title)s and %(count)d more…",
                        u"%(title)s and %(count)d more…", n - 1) % {
                        'title': album[0]('~basename'), 'count':
                        n - 1}).run()