def build_media_player_import_page(self): vbox = widgetset.VBox(spacing=5) vbox.pack_start( _build_title_question( _( "Would you like to display your %(player)s music and " "video in %(appname)s?", { "player": self.mp_name, "appname": app.config.get(prefs.SHORT_APP_NAME) }))) rbg = widgetset.RadioButtonGroup() yes_rb = widgetset.RadioButton(_("Yes"), rbg) no_rb = widgetset.RadioButton(_("No"), rbg) yes_rb.set_selected() vbox.pack_start(widgetutil.align_left(yes_rb)) vbox.pack_start(widgetutil.align_left(no_rb)) lab = widgetset.Label( _( "Note: %(appname)s won't move or copy any files on your " "disk. It will just add them to your %(appname)s library.", {"appname": app.config.get(prefs.SHORT_APP_NAME)})) lab.set_size_request(WIDTH - 40, -1) lab.set_wrap(True) vbox.pack_start(widgetutil.align_left(lab)) def handle_next(widget): if rbg.get_selected() == yes_rb: self.import_media_player_stuff = True else: self.import_media_player_stuff = False self.next_page() prev_button = widgetset.Button(_("< Previous")) prev_button.connect('clicked', lambda x: self.prev_page()) next_button = widgetset.Button(_("Next >")) next_button.connect('clicked', handle_next) vbox.pack_start(widgetutil.align_bottom( widgetutil.align_right( widgetutil.build_hbox((prev_button, next_button)))), expand=True) vbox = widgetutil.pad(vbox) return vbox
def set_device(self, device): for child in self.device_choices.children: self.device_choices.remove(child) self.device = device possible_devices = sorted(device.info.devices) rbg = widgetset.RadioButtonGroup() buttons_to_device_name = {} for device_name in possible_devices: button = widgetset.RadioButton(device_name, rbg) self.device_choices.pack_start(button) buttons_to_device_name[button] = device_name def _clicked(*args): selected_button = rbg.get_selected() if selected_button is None: return # user didn't actually select a device messages.SetDeviceType( self.device, buttons_to_device_name[selected_button]).send_to_backend() select = widgetset.Button(_('This is my device')) select.connect('clicked', _clicked) self.device_choices.pack_start(widgetutil.pad(select, top=20))
def _playback_panel(): extras = [] lab = widgetset.Label(_("Renderer options:")) lab.set_bold(True) extras.append(align_left(lab)) grid = dialogwidgets.ControlGrid() note = dialogwidgets.note( _("You must restart %(appname)s for renderer " "changes to take effect.", {"appname": app.config.get(prefs.SHORT_APP_NAME)})) grid.pack(align_left(note, bottom_pad=12), grid.ALIGN_LEFT, span=2) grid.end_line(spacing=12) rbg = widgetset.RadioButtonGroup() radio_map = {} for mem in renderers.get_renderer_list(): radio_map[mem] = widgetset.RadioButton(mem, rbg) buttons = [(v, k) for k, v in radio_map.items()] attach_radio(buttons, options.USE_RENDERER) grid.pack_label(_("Video renderer:"), grid.ALIGN_RIGHT) grid.pack(dialogwidgets.radio_button_list(*radio_map.values())) grid.end_line(spacing=12) extras.append(align_left(grid.make_table())) return extras
def _general_panel(): extras = [] show_cbx = widgetset.Checkbox(_("Enable tray icon")) attach_boolean(show_cbx, options.SHOW_TRAYICON) extras.append(show_cbx) lab = widgetset.Label(_("When I click the red close button:")) extras.append(widgetutil.align_left(lab)) rbg = widgetset.RadioButtonGroup() rad_close = widgetset.RadioButton(_("Close to tray so that downloads can continue."), rbg) rad_quit = widgetset.RadioButton(_("Quit %(appname)s completely.", {'appname': app.config.get(prefs.SHORT_APP_NAME)}), rbg) attach_radio([(rad_close, True), (rad_quit, False)], prefs.MINIMIZE_TO_TRAY) extras.append(widgetutil.align_left(rad_close, left_pad=20)) extras.append(widgetutil.align_left(rad_quit, left_pad=20)) return extras
def build_startup_page(self): vbox = widgetset.VBox(spacing=5) vbox.pack_start( _build_paragraph_text( _( "%(name)s can automatically run when you start your " "computer so that it can resume your downloads " "and update your podcasts.", {'name': app.config.get(prefs.SHORT_APP_NAME)}))) vbox.pack_start( _build_title_question( _("Would you like to run %(name)s on startup?", {'name': app.config.get(prefs.SHORT_APP_NAME)}))) rbg = widgetset.RadioButtonGroup() yes_rb = widgetset.RadioButton(_("Yes"), rbg) no_rb = widgetset.RadioButton(_("No"), rbg) prefpanel.attach_radio([(yes_rb, True), (no_rb, False)], prefs.RUN_AT_STARTUP) vbox.pack_start(widgetutil.align_left(yes_rb, left_pad=10)) vbox.pack_start(widgetutil.align_left(no_rb, left_pad=10)) prev_button = widgetset.Button(_("< Previous")) prev_button.connect('clicked', lambda x: self.prev_page()) next_button = widgetset.Button(_("Next >")) next_button.connect('clicked', lambda x: self.next_page()) vbox.pack_start(self._force_space_label()) vbox.pack_start(widgetutil.align_bottom( widgetutil.align_right( widgetutil.build_hbox((prev_button, next_button)))), expand=True) vbox = widgetutil.pad(vbox) return vbox
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 build_find_files_page(self): vbox = widgetset.VBox(spacing=5) vbox.pack_start( _build_paragraph_text( _( "%(name)s can find music and video on your computer " "and show them in your %(name)s library. No files " "will be copied or duplicated.", {"name": app.config.get(prefs.SHORT_APP_NAME)}))) vbox.pack_start( _build_title_question( _( "Would you like %(name)s to search your computer " "for media files?", {"name": app.config.get(prefs.SHORT_APP_NAME)}))) rbg = widgetset.RadioButtonGroup() no_rb = widgetset.RadioButton(_("No"), rbg) yes_rb = widgetset.RadioButton(_("Yes"), rbg) no_rb.set_selected() vbox.pack_start(widgetutil.align_left(no_rb, left_pad=10)) vbox.pack_start( widgetutil.align_left(yes_rb, left_pad=10, bottom_pad=5)) group_box = widgetset.VBox(spacing=5) rbg2 = widgetset.RadioButtonGroup() restrict_rb = widgetset.RadioButton(_("Search everywhere."), rbg2) search_rb = widgetset.RadioButton(_("Just search in this folder:"), rbg2) restrict_rb.set_selected() group_box.pack_start(widgetutil.align_left(restrict_rb, left_pad=30)) group_box.pack_start(widgetutil.align_left(search_rb, left_pad=30)) search_entry = widgetset.TextEntry( filename_to_unicode(get_default_search_dir())) search_entry.set_width(20) change_button = widgetset.Button(_("Choose...")) hbox = widgetutil.build_hbox((widgetutil.align_middle(search_entry), widgetutil.align_middle(change_button))) group_box.pack_start(widgetutil.align_left(hbox, left_pad=30)) def handle_change_clicked(widget): dir_ = dialogs.ask_for_directory( _("Choose directory to search for media files"), initial_directory=get_default_search_dir(), transient_for=self) if dir_: search_entry.set_text(filename_to_unicode(dir_)) self.search_directory = dir_ else: self.search_directory = get_default_search_dir() # reset the search results if they change the directory self.gathered_media_files = None change_button.connect('clicked', handle_change_clicked) vbox.pack_start(group_box) prev_button = widgetset.Button(_("< Previous")) prev_button.connect('clicked', lambda x: self.prev_page()) def handle_search_finish_clicked(widget): if widget.mode == "search": if rbg2.get_selected() == restrict_rb: self.search_directory = get_default_search_dir() self.next_page() else: self.destroy() search_button = widgetset.Button(_("Search")) search_button.connect('clicked', handle_search_finish_clicked) # FIXME - this is goofy naming search_button.text_faces = {"search": _("Next >"), "next": _("Finish")} search_button.mode = "search" def switch_mode(mode): search_button.set_text(search_button.text_faces[mode]) search_button.mode = mode vbox.pack_start(self._force_space_label()) vbox.pack_start(widgetutil.align_bottom( widgetutil.align_right( widgetutil.build_hbox((prev_button, search_button)))), expand=True) def handle_radio_button_clicked(widget): # Uggh this is a bit messy. if widget is no_rb: group_box.disable() search_entry.disable() change_button.disable() switch_mode("next") self.gathered_media_files = None elif widget is yes_rb: group_box.enable() if rbg2.get_selected() is restrict_rb: search_entry.disable() change_button.disable() else: search_entry.enable() change_button.enable() switch_mode("search") elif widget is restrict_rb: search_entry.disable() change_button.disable() self.gathered_media_files = None elif widget is search_rb: search_entry.enable() change_button.enable() self.gathered_media_files = None if widget is restrict_rb or widget is search_rb: switch_mode("search") no_rb.connect('clicked', handle_radio_button_clicked) yes_rb.connect('clicked', handle_radio_button_clicked) restrict_rb.connect('clicked', handle_radio_button_clicked) search_rb.connect('clicked', handle_radio_button_clicked) handle_radio_button_clicked(restrict_rb) handle_radio_button_clicked(no_rb) vbox = widgetutil.pad(vbox) return vbox
def build_widgets(self): self.window.add_button(BUTTON_CREATE_FEED.text) self.window.add_button(BUTTON_CANCEL.text) extra = widgetset.VBox() hb1 = widgetset.HBox() hb1.pack_start(widgetset.Label(_('Search for:')), padding=5) self.searchterm = widgetset.TextEntry() self.searchterm.set_activates_default(True) hb1.pack_start(self.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) self.choice_table = widgetset.Table(columns=2, rows=3) self.choice_table.set_column_spacing(5) self.choice_table.set_row_spacing(5) self.rbg = widgetset.RadioButtonGroup() self.channel_rb = widgetset.RadioButton(_("Podcast:"), self.rbg) self.channel_option = widgetset.OptionMenu( [ci.name + u" - " + ci.url for ci in self.channels]) self.channel_option.set_size_request(250, -1) self.choice_table.pack(self.channel_rb, 0, 0) self.choice_table.pack(self.channel_option, 1, 0) self.search_engine_rb = widgetset.RadioButton(_("Search engine:"), self.rbg) self.search_engine_option = widgetset.OptionMenu( [se.title for se in self.search_engines]) self.choice_table.pack(self.search_engine_rb, 0, 1) self.choice_table.pack(self.search_engine_option, 1, 1) url_rb = widgetset.RadioButton(_("URL:"), self.rbg) self.url_text = widgetset.TextEntry() self.choice_table.pack(url_rb, 0, 2) self.choice_table.pack(self.url_text, 1, 2) hb2.pack_start(self.choice_table, expand=True) # by default only the channel row is enabled self.enable_choice_table_row(0) def handle_clicked(widget): # this enables and disables the fields in the table # based on which radio button is selected if widget is self.channel_rb: self.enable_choice_table_row(0) elif widget is self.search_engine_rb: self.enable_choice_table_row(1) else: self.enable_choice_table_row(2) self.channel_rb.connect('clicked', handle_clicked) self.search_engine_rb.connect('clicked', handle_clicked) url_rb.connect('clicked', handle_clicked) extra.pack_start(widgetutil.align_top(hb2, top_pad=6)) self.window.set_extra_widget(extra)