Exemplo n.º 1
0
 def test_hashable(self):
     for testcase in (None,
                      u'',
                      u'a',
                      u'a1a',
                      u'Episode_100',
                      u'episode_1',
                      ):
         hash(util.name_sort_key(testcase))
Exemplo n.º 2
0
 def test_simple(self):
     for testcase in ((None, 'ZZZZZZZZZZZZZ'),
                      (u'', [u'']),
                      (u'a', [u'a']),
                      (u'a1a', [u'a', 1.0, u'a']),
                      (u'Episode_100', [u'episode_', 100.0, u'']),
                      (u'episode_1', [u'episode_', 1.0, u''])
                      ):
         self.assertEquals(util.name_sort_key(testcase[0]),
                           testcase[1])
Exemplo n.º 3
0
 def test_hashable(self):
     for testcase in (
             None,
             u'',
             u'a',
             u'a1a',
             u'Episode_100',
             u'episode_1',
     ):
         hash(util.name_sort_key(testcase))
Exemplo n.º 4
0
 def test_name_sort(self):
     # Test that name sort does a natural sort on the items, and removes
     # "the" / "a" from the begining
     self.items[0].title = u'Podcast Item A'
     self.items[1].title = u'The Podcast Item B'
     self.items[2].title = u'A Podcast Item C'
     self.items[3].title = u'SeriesItem9'
     self.items[4].title = u'SeriesItem10'
     self.items[5].title = u'SeriesItem11'
     for i in self.items[:6]:
         i.signal_change()
     app.db.finish_transaction()
     # test that the default sort is release date
     self.item_list.set_sort(itemsort.TitleSort(True))
     self.items.sort(key=lambda i: util.name_sort_key(i.title))
     self.check_sort_order(self.items)
Exemplo n.º 5
0
 def test_name_sort(self):
     # Test that name sort does a natural sort on the items, and removes
     # "the" / "a" from the begining
     self.items[0].title = u'Podcast Item A'
     self.items[1].title = u'The Podcast Item B'
     self.items[2].title = u'A Podcast Item C'
     self.items[3].title = u'SeriesItem9'
     self.items[4].title = u'SeriesItem10'
     self.items[5].title = u'SeriesItem11'
     for i in self.items[:6]:
         i.signal_change()
     app.db.finish_transaction()
     # test that the default sort is release date
     self.item_list.set_sort(itemsort.TitleSort(True))
     self.items.sort(key=lambda i: util.name_sort_key(i.title))
     self.check_sort_order(self.items)
Exemplo n.º 6
0
 def title_sort_key(self):
     return util.name_sort_key(self.title)
Exemplo n.º 7
0
def run_dialog():
    """Creates and launches the Add to Playlist dialog.  This dialog
    waits for the user to press "Add" or "Cancel".

    In the case of "Add", returns a tuple of:

    * ("new", playlist_name)
    * ("existing", playlist id)

    In the case of "Cancel", returns None.
    """
    title = _('Add a Playlist')
    description = _('Add items to an existing playlist or a new one.')

    playlists = app.tabs['playlist'].get_playlists()
    playlists = [pi for pi in playlists if not pi.is_folder]
    playlists.sort(key=lambda x: name_sort_key(x.name))

    window = MainDialog(title, description)
    try:
        try:
            window.add_button(BUTTON_ADD.text)
            window.add_button(BUTTON_CANCEL.text)

            extra = widgetset.VBox()

            choice_table = widgetset.Table(columns=2, rows=2)
            choice_table.set_column_spacing(5)
            choice_table.set_row_spacing(5)
            rbg = widgetset.RadioButtonGroup()

            existing_rb = widgetset.RadioButton(_("Existing playlist:"), rbg)
            existing_option = widgetset.OptionMenu(
                [clamp_text(pi.name) for pi in playlists])

            choice_table.pack(existing_rb, 0, 0)
            choice_table.pack(existing_option, 1, 0)

            new_rb = widgetset.RadioButton(_("New playlist:"), rbg)
            new_text = widgetset.TextEntry()
            new_text.set_activates_default(True)
            choice_table.pack(new_rb, 0, 1)
            choice_table.pack(new_text, 1, 1)

            # only the existing row is enabled
            choice_table.disable(row=1, column=1)

            def handle_clicked(widget):
                # this enables and disables the fields in the table
                # based on which radio button is selected
                if widget is existing_rb:
                    choice_table.enable(row=0, column=1)
                    choice_table.disable(row=1, column=1)
                else:
                    choice_table.disable(row=0, column=1)
                    choice_table.enable(row=1, column=1)
                if new_rb.get_selected():
                    new_text.focus()

            existing_rb.connect('clicked', handle_clicked)
            new_rb.connect('clicked', handle_clicked)
            existing_rb.set_selected()

            extra.pack_start(widgetutil.align_top(choice_table, top_pad=6))

            window.set_extra_widget(extra)
            response = window.run()

            if response == 0:
                selected_option = rbg.get_selected()
                if selected_option is existing_rb and len(playlists) > 0:
                    return ("existing",
                            playlists[existing_option.get_selected()])
                elif new_text.get_text():
                    return ("new", new_text.get_text())
        except StandardError:
            logging.exception("addtoplaylistdialog threw exception.")
    finally:
        window.destroy()
Exemplo n.º 8
0
 def album_artist_sort_key(self):
     if self.album_artist:
         return util.name_sort_key(self.album_artist)
     else:
         return self.artist_sort_key
Exemplo n.º 9
0
 def album_sort_key(self):
     return util.name_sort_key(self.album)
Exemplo n.º 10
0
 def artist_sort_key(self):
     return util.name_sort_key(self.artist)
Exemplo n.º 11
0
 def title_sort_key(self):
     return util.name_sort_key(self.title)
Exemplo n.º 12
0
 def sort_key(self, item):
     return [int(item.track),
             util.name_sort_key(item.artist),
             util.name_sort_key(item.album)]
Exemplo n.º 13
0
 def sort_key(self, item):
     return util.name_sort_key(item.name)
Exemplo n.º 14
0
 def artist_sort_key(self):
     return util.name_sort_key(self.artist)
Exemplo n.º 15
0
 def album_sort_key(self):
     return util.name_sort_key(self.album)
Exemplo n.º 16
0
 def get_channel_info(self):
     self.channels = [ci for ci in app.tabs['feed'].get_feeds()
             if not (ci.is_folder or ci.is_directory_feed)]
     self.channels.sort(key=lambda x: util.name_sort_key(x.name))
Exemplo n.º 17
0
def run_dialog():
    """Creates and launches the Add to Playlist dialog.  This dialog
    waits for the user to press "Add" or "Cancel".

    In the case of "Add", returns a tuple of:

    * ("new", playlist_name)
    * ("existing", playlist id)

    In the case of "Cancel", returns None.
    """
    title = _('Add a Playlist')
    description = _('Add items to an existing playlist or a new one.')

    playlists = app.tab_list_manager.playlist_list.get_playlists()
    playlists = [pi for pi in playlists if not pi.is_folder]
    playlists.sort(key=lambda x: name_sort_key(x.name))

    window = MainDialog(title, description)
    try:
        try:
            window.add_button(BUTTON_ADD.text)
            window.add_button(BUTTON_CANCEL.text)

            extra = widgetset.VBox()

            choice_table = widgetset.Table(columns=2, rows=2)
            choice_table.set_column_spacing(5)
            choice_table.set_row_spacing(5)
            rbg = widgetset.RadioButtonGroup()

            existing_rb = widgetset.RadioButton(_("Existing playlist:"), rbg)
            existing_option = widgetset.OptionMenu([clamp_text(pi.name) for pi in playlists])

            choice_table.pack(existing_rb, 0, 0)
            choice_table.pack(existing_option, 1, 0)

            new_rb = widgetset.RadioButton(_("New playlist:"), rbg)
            new_text = widgetset.TextEntry()
            new_text.set_activates_default(True)
            choice_table.pack(new_rb, 0, 1)
            choice_table.pack(new_text, 1, 1)

            # only the existing row is enabled
            choice_table.disable(row=1, column=1)

            def handle_clicked(widget):
                # this enables and disables the fields in the table
                # based on which radio button is selected
                if widget is existing_rb:
                    choice_table.enable(row=0, column=1)
                    choice_table.disable(row=1, column=1)
                else:
                    choice_table.disable(row=0, column=1)
                    choice_table.enable(row=1, column=1)
                if new_rb.get_selected():
                    new_text.focus()

            existing_rb.connect('clicked', handle_clicked)
            new_rb.connect('clicked', handle_clicked)

            extra.pack_start(widgetutil.align_top(choice_table, top_pad=6))

            window.set_extra_widget(extra)
            response = window.run()

            if response == 0:
                selected_option = rbg.get_selected()
                if selected_option is existing_rb and len(playlists) > 0:
                    return ("existing", playlists[existing_option.get_selected()])
                elif new_text.get_text():
                    return ("new", new_text.get_text())
        except StandardError:
            logging.exception("addtoplaylistdialog threw exception.")
    finally:
        window.destroy()
Exemplo n.º 18
0
def run_dialog():
    """Creates and launches the New Search Feed dialog.  This dialog waits
    for the user to press "Create Feed" or "Cancel".

    In the case of "Create Feed", returns a tuple of:

    * ("feed", ChannelInfo, search_term str, section str)
    * ("search_engine", SearchEngineInfo, search_term str, section str)
    * ("url", url str, search_term str, section str)

    In the case of "Cancel", returns None.
    """
    title = _('New Search Feed')
    description = _('A search feed contains items that match a search term.')

    channels = app.tab_list_manager.feed_list.get_feeds()
    channels += app.tab_list_manager.audio_feed_list.get_feeds()
    channels = [ci for ci in channels if not ci.is_folder]
    channels.sort(key=lambda x: util.name_sort_key(x.name))

    window = MainDialog(title, description)
    try:
        try:
            window.add_button(BUTTON_CREATE_FEED.text)
            window.add_button(BUTTON_CANCEL.text)

            extra = widgetset.VBox()

            hb1 = widgetset.HBox()
            hb1.pack_start(widgetset.Label(_('Search for:')), padding=5)
            searchterm = widgetset.TextEntry()
            searchterm.set_activates_default(True)
            hb1.pack_start(searchterm, expand=True)
            extra.pack_start(hb1)

            hb2 = widgetset.HBox()
            hb2.pack_start(widgetutil.align_top(widgetset.Label(_('In this:')), top_pad=3), padding=5)

            choice_table = widgetset.Table(columns=2, rows=3)
            choice_table.set_column_spacing(5)
            choice_table.set_row_spacing(5)
            rbg = widgetset.RadioButtonGroup()

            channel_rb = widgetset.RadioButton(_("Feed:"), rbg)
            channel_option = widgetset.OptionMenu(
                [ci.name + u" - " + ci.url for ci in channels])
            channel_option.set_size_request(250, -1)
            choice_table.pack(channel_rb, 0, 0)
            choice_table.pack(channel_option, 1, 0)

            search_engine_rb = widgetset.RadioButton(_("Search engine:"), rbg)
            search_engines = searchengines.get_search_engines()
            search_engine_option = widgetset.OptionMenu([se.title for se in search_engines])
            choice_table.pack(search_engine_rb, 0, 1)
            choice_table.pack(search_engine_option, 1, 1)

            url_rb = widgetset.RadioButton(_("URL:"), rbg)
            url_text = widgetset.TextEntry()
            choice_table.pack(url_rb, 0, 2)
            choice_table.pack(url_text, 1, 2)

            hb2.pack_start(choice_table, expand=True)

            # only the channel row is enabled
            choice_table.disable(row=1, column=1)
            choice_table.disable(row=2, column=1)

            def handle_clicked(widget):
                # this enables and disables the fields in the table
                # based on which radio button is selected
                if widget is channel_rb:
                    choice_table.enable(row=0, column=1)
                    choice_table.disable(row=1, column=1)
                    choice_table.disable(row=2, column=1)
                elif widget is search_engine_rb:
                    choice_table.disable(row=0, column=1)
                    choice_table.enable(row=1, column=1)
                    choice_table.disable(row=2, column=1)
                else:
                    choice_table.disable(row=0, column=1)
                    choice_table.disable(row=1, column=1)
                    choice_table.enable(row=2, column=1)

            channel_rb.connect('clicked', handle_clicked)
            search_engine_rb.connect('clicked', handle_clicked)
            url_rb.connect('clicked', handle_clicked)

            extra.pack_start(widgetutil.align_top(hb2, top_pad=6))

            hb3 = widgetset.HBox()
            hb3.pack_start(widgetutil.align_top(widgetset.Label(_('Add new feed to this section:')), top_pad=3), padding=5)

            rbg_section = widgetset.RadioButtonGroup()
            video_rb = widgetset.RadioButton(_("video"), rbg_section)
            audio_rb = widgetset.RadioButton(_("audio"), rbg_section)
            hb3.pack_start(video_rb)
            hb3.pack_start(audio_rb)
            extra.pack_start(widgetutil.align_top(hb3, top_pad=6))

            window.set_extra_widget(extra)
            response = window.run()

            if response == 0 and searchterm.get_text():
                term = searchterm.get_text()
                selected_option = rbg.get_selected()
                if rbg_section.get_selected() == video_rb:
                    section = u"video"
                else:
                    section = u"audio"
                if selected_option is channel_rb:
                    return ("feed",
                            channels[channel_option.get_selected()],
                            term,
                            section)
                elif selected_option is search_engine_rb:
                    return ("search_engine",
                            search_engines[search_engine_option.get_selected()],
                            term,
                            section)
                else:
                    return ("url",
                            url_text.get_text(),
                            term,
                            section)
        except StandardError:
            logging.exception("newsearchfeed threw exception.")
    finally:
        window.destroy()
Exemplo n.º 19
0
 def album_artist_sort_key(self):
     if self.album_artist:
         return util.name_sort_key(self.album_artist)
     else:
         return self.artist_sort_key