def _build_header(channel): v = widgetset.VBox(6) lab = widgetset.Label(clamp_text(channel.name, 60)) lab.set_bold(True) lab.set_size(1.2) v.pack_start(widgetutil.align_left(lab)) lab = widgetset.Label(clamp_text(channel.url, 80)) lab.set_selectable(True) lab.set_size(widgetconst.SIZE_SMALL) lab.set_color(widgetconst.DIALOG_NOTE_COLOR) v.pack_start(widgetutil.align_left(lab)) return v
def test_clamp_text(self): # limit 20 self.assertRaises(TypeError, util.clamp_text, None) self.assertEqual('', util.clamp_text('')) self.assertEqual('1', util.clamp_text('1')) self.assertEqual('12345678901234567890', util.clamp_text('12345678901234567890')) self.assertEqual('12345678901234567...', util.clamp_text('123456789012345678901')) self.assertEqual('12345678901234567...', util.clamp_text('12345678901234567890 1234 1234 1234')) # limit 4 self.assertRaises(TypeError, util.clamp_text, None, 4) self.assertEqual('', util.clamp_text('', 4)) self.assertEqual('1', util.clamp_text('1', 4)) self.assertEqual('1...', util.clamp_text('12345678901234567890', 4)) self.assertEqual('1...', util.clamp_text('123456789012345678901', 4)) self.assertEqual('1...', util.clamp_text('12345678901234567890 1234 1234 1234', 4))
def test_clamp_text(self): # limit 20 self.assertRaises(TypeError, util.clamp_text, None) self.assertEqual('', util.clamp_text('')) self.assertEqual('1', util.clamp_text('1')) self.assertEqual('12345678901234567890', util.clamp_text('12345678901234567890')) self.assertEqual('12345678901234567...', util.clamp_text('123456789012345678901')) self.assertEqual( '12345678901234567...', util.clamp_text('12345678901234567890 1234 1234 1234')) # limit 4 self.assertRaises(TypeError, util.clamp_text, None, 4) self.assertEqual('', util.clamp_text('', 4)) self.assertEqual('1', util.clamp_text('1', 4)) self.assertEqual('1...', util.clamp_text('12345678901234567890', 4)) self.assertEqual('1...', util.clamp_text('123456789012345678901', 4)) self.assertEqual( '1...', util.clamp_text('12345678901234567890 1234 1234 1234', 4))
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()
def run_dialog(channel_infos, downloaded_items, downloading_items, has_watched_feeds): """Displays the remove feeds dialog.""" title = ngettext('Remove Feed', 'Remove Feeds', len(channel_infos)) rc_window = MainDialog(title) try: try: v = widgetset.VBox(spacing=5) lab = widgetset.Label(ngettext( "Are you sure you want to remove this feed:", "Are you sure you want to remove these feeds:", len(channel_infos) )) lab.set_wrap(True) v.pack_start(widgetutil.align_left(lab)) v2 = widgetset.VBox() lab_height = None for mem in channel_infos: lab_mem = widgetset.Label(util.clamp_text(mem.name, 40)) if lab_height is None: dummy, lab_height = lab_mem.get_size_request() v2.pack_start(widgetutil.align_left(lab_mem, left_pad=15)) if len(channel_infos) > 5: scroller = widgetset.Scroller(False, True) scroller.set_has_borders(True) scroller.add(v2) scroller_width, scroller_height = scroller.get_size_request() if scroller_height == 0: scroller.set_size_request(scroller_width, 5 * (lab_height + 1)) v2 = scroller v.pack_start(v2, padding=10) cbx_downloaded = None if downloaded_items: cbx_downloaded = widgetset.Checkbox(_("Keep items that have been downloaded in my library.")) v.pack_start(widgetutil.align_left(cbx_downloaded, bottom_pad=5)) if has_watched_feeds: lab = widgetset.Label(_( "Watched folders will be removed from the sidebar but their contents will " "still appear in your library. You can stop watching watched folders completely " "in the %(appname)s preference panel.", {"appname": app.config.get(prefs.SHORT_APP_NAME)} )) lab.set_wrap(True) lab.set_size_request(390, -1) v.pack_start(widgetutil.align_left(lab, bottom_pad=5)) if downloading_items: lab_downloading = widgetset.Label(ngettext( "Are you sure you want to remove this feed? " "The downloads currently in progress will be canceled.", "Are you sure you want to remove these feeds? " "The downloads currently in progress will be canceled.", len(channel_infos) )) lab_downloading.set_wrap(True) lab_downloading.set_size_request(390, -1) v.pack_start(widgetutil.align_left(lab_downloading)) rc_window.set_extra_widget(v) rc_window.add_button(BUTTON_REMOVE.text) rc_window.add_button(BUTTON_CANCEL.text) ret = rc_window.run() if ret == 0: # this is silly, but it sets us up for adding additional # bits later. ret = {KEEP_ITEMS: False} if downloaded_items: ret[KEEP_ITEMS] = cbx_downloaded.get_checked() return ret except StandardError: logging.exception("removefeeds threw exception.") finally: rc_window.destroy()
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()
def run_dialog(channel_infos, downloaded_items, downloading_items, has_watched_feeds): """Displays the remove feeds dialog. """ title = ngettext('Remove Podcast', 'Remove Podcasts', len(channel_infos)) rc_window = MainDialog(title) try: try: v = widgetset.VBox(spacing=5) lab = widgetset.Label( ngettext("Are you sure you want to remove this podcast:", "Are you sure you want to remove these podcasts:", len(channel_infos))) lab.set_wrap(True) v.pack_start(widgetutil.align_left(lab)) v2 = widgetset.VBox() lab_height = None for mem in channel_infos: lab_mem = widgetset.Label(util.clamp_text(mem.name, 40)) if lab_height is None: dummy, lab_height = lab_mem.get_size_request() v2.pack_start(widgetutil.align_left(lab_mem, left_pad=15)) if len(channel_infos) > 5: scroller = widgetset.Scroller(False, True) scroller.set_has_borders(True) scroller.add(v2) scroller_width, scroller_height = scroller.get_size_request() if scroller_height == 0: scroller.set_size_request(scroller_width, 5 * (lab_height + 1)) v2 = scroller v.pack_start(v2, padding=10) cbx_downloaded = None if downloaded_items: cbx_downloaded = widgetset.Checkbox( _("Keep items that have been downloaded in my library.")) v.pack_start( widgetutil.align_left(cbx_downloaded, bottom_pad=5)) if has_watched_feeds: lab = widgetset.Label( _( "Watched folders will be removed from the sidebar but " "their contents will still appear in your library. " "You can stop watching watched folders completely " "in the %(appname)s preference panel.", {"appname": app.config.get(prefs.SHORT_APP_NAME)})) lab.set_wrap(True) lab.set_size_request(390, -1) v.pack_start(widgetutil.align_left(lab, bottom_pad=5)) if downloading_items: lab_downloading = widgetset.Label( ngettext( "Are you sure you want to remove this podcast? " "The downloads currently in progress will be canceled.", "Are you sure you want to remove these podcasts? " "The downloads currently in progress will be canceled.", len(channel_infos))) lab_downloading.set_wrap(True) lab_downloading.set_size_request(390, -1) v.pack_start(widgetutil.align_left(lab_downloading)) rc_window.set_extra_widget(v) rc_window.add_button(BUTTON_REMOVE.text) rc_window.add_button(BUTTON_CANCEL.text) ret = rc_window.run() if ret == 0: # this is silly, but it sets us up for adding additional # bits later. ret = {KEEP_ITEMS: False} if downloaded_items: ret[KEEP_ITEMS] = cbx_downloaded.get_checked() return ret except StandardError: logging.exception("removefeeds threw exception.") finally: rc_window.destroy()