def build_results_page(self): # FIXME - this is built just like the search_page. it'd be # better to just change the buttons on the bottom of the # search page. vbox = widgetset.VBox(spacing=5) progress_bar = widgetset.ProgressBar() progress_bar.set_size_request(400, -1) vbox.pack_start(widgetutil.align_center(progress_bar, top_pad=50)) progress_bar.stop_pulsing() progress_bar.set_progress(1.0) self.results_label = widgetset.Label("") vbox.pack_start( widgetutil.align_top( widgetutil.align_center(self.results_label), top_pad=10)) vbox.pack_start(self._force_space_label(), expand=True) cancel_button = widgetset.Button(BUTTON_CANCEL.text) cancel_button.connect('clicked', self.on_cancel) import_button = widgetset.Button(BUTTON_IMPORT_FILES.text) import_button.connect('clicked', lambda x: self.destroy_dialog()) vbox.pack_start(widgetutil.align_right( widgetutil.build_hbox((cancel_button, import_button)))) return vbox
def _build_remember_items(channel, grid): grid.pack_label(_("Outdated Feed Items:"), grid.ALIGN_RIGHT) older_options = [ ("-1", _("Keep %(number)s (Default)", {"number": app.config.get(prefs.MAX_OLD_ITEMS_DEFAULT)})), ("0", _("Keep 0")), ("20", _("Keep 20")), ("50", _("Keep 50")), ("100", _("Keep 100")), ("1000", _("Keep 1000")) ] older_values = [o[0] for o in older_options] older_combo = widgetset.OptionMenu([o[1] for o in older_options]) if channel.max_old_items == u"system": selected = older_values.index("-1") else: try: selected = older_values.index(str(channel.max_old_items)) except ValueError: selected = 0 older_combo.set_selected(selected) def older_changed(widget, index): value = older_options[index][0] if value == u"system": messages.SetFeedMaxOldItems(channel, -1).send_to_backend() else: messages.SetFeedMaxOldItems(channel, int(value)).send_to_backend() older_combo.connect('changed', older_changed) button = widgetset.Button(_("Remove All")) button.set_size(widgetconst.SIZE_SMALL) lab = widgetset.Label("") lab.set_size(widgetconst.SIZE_SMALL) lab.set_color(widgetconst.DIALOG_NOTE_COLOR) def _handle_clicked(widget): messages.CleanFeed(channel.id).send_to_backend() # FIXME - we don't really know if it got cleaned or if it errored out # at this point. but ... we need to give some kind of feedback to # the user and it's not likely that it failed and if it did, it'd # be in the logs. lab.set_text(_("Old items have been removed.")) button.connect('clicked', _handle_clicked) grid.pack(older_combo, grid.ALIGN_LEFT) grid.pack(button, grid.ALIGN_LEFT) grid.end_line(spacing=2) grid.pack_label("") grid.pack(widgetutil.build_hbox((lab, )), grid.ALIGN_LEFT)
def _build_remember_items(channel, grid): grid.pack_label(_("Outdated Podcast Items:"), grid.ALIGN_RIGHT) older_options = [ ("-1", _("Keep %(number)s (Default)", {"number": app.config.get(prefs.MAX_OLD_ITEMS_DEFAULT)})), ("0", _("Keep 0")), ("20", _("Keep 20")), ("50", _("Keep 50")), ("100", _("Keep 100")), ("1000", _("Keep 1000")) ] older_values = [o[0] for o in older_options] older_combo = widgetset.OptionMenu([o[1] for o in older_options]) if channel.max_old_items == u"system": selected = older_values.index("-1") else: try: selected = older_values.index(str(channel.max_old_items)) except ValueError: selected = 0 older_combo.set_selected(selected) def older_changed(widget, index): value = older_options[index][0] if value == u"system": messages.SetFeedMaxOldItems(channel, -1).send_to_backend() else: messages.SetFeedMaxOldItems(channel, int(value)).send_to_backend() older_combo.connect('changed', older_changed) button = widgetset.Button(_("Remove All")) button.set_size(widgetconst.SIZE_SMALL) lab = widgetset.Label("") lab.set_size(widgetconst.SIZE_SMALL) lab.set_color(widgetconst.DIALOG_NOTE_COLOR) def _handle_clicked(widget): messages.CleanFeed(channel.id).send_to_backend() # FIXME - we don't really know if it got cleaned or if it errored out # at this point. but ... we need to give some kind of feedback to # the user and it's not likely that it failed and if it did, it'd # be in the logs. lab.set_text(_("Old items have been removed.")) button.connect('clicked', _handle_clicked) grid.pack(older_combo, grid.ALIGN_LEFT) grid.pack(button, grid.ALIGN_LEFT) grid.end_line(spacing=2) grid.pack_label("") grid.pack(widgetutil.build_hbox((lab, )), grid.ALIGN_LEFT)
def _run_dialog(title, description, default_type): """Creates and launches the New Folder dialog. This dialog waits for the user to press "Create Folder" or "Cancel". Returns a tuple of the (name, section). """ window = MainDialog(title, description) try: try: window.add_button(BUTTON_CREATE_FOLDER.text) window.add_button(BUTTON_CANCEL.text) extra = widgetset.VBox() lab = widgetset.Label(_('Folder name:')) name_entry = widgetset.TextEntry() name_entry.set_activates_default(True) h = widgetset.HBox() h.pack_start(lab, padding=5) h.pack_start(name_entry, expand=True) extra.pack_start(h, padding=5) lab = widgetset.Label(_('Folder should go in this section:')) rbg = widgetset.RadioButtonGroup() video_rb = widgetset.RadioButton(_("video"), rbg) audio_rb = widgetset.RadioButton(_("audio"), rbg) if default_type == 'feed': video_rb.set_selected() else: audio_rb.set_selected() extra.pack_start(widgetutil.build_hbox((lab, video_rb, audio_rb))) window.set_extra_widget(extra) response = window.run() if response == 0: if rbg.get_selected() == video_rb: section = u"video" else: section = u"audio" name = name_entry.get_text() if name: return (name, section) return (None, None) except StandardError: logging.exception("newfeed threw exception.") finally: window.destroy()
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 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 build_second_page(self): vbox = widgetset.VBox(spacing=5) vbox.pack_start(_build_title( _("%(name)s Startup", {'name': app.config.get(prefs.SHORT_APP_NAME)}))) lab = widgetset.Label(_( "We recommend that you have %(name)s launch when your computer " "starts up. This way, downloads in progress can finish " "downloading and new media files can be downloaded in the " "background, ready when you want to watch.", {'name': app.config.get(prefs.SHORT_APP_NAME)})) lab.set_wrap(True) lab.set_size_request(400, -1) vbox.pack_start(widgetutil.align_left(lab)) lab = widgetset.Label(_("Would you like to run %(name)s on startup?", {'name': app.config.get(prefs.SHORT_APP_NAME)})) lab.set_bold(True) vbox.pack_start(widgetutil.align_left(lab)) 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)) vbox.pack_start(widgetutil.align_left(no_rb)) vbox.pack_start(widgetset.Label(" "), expand=True) 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()) hbox = widgetutil.build_hbox((prev_button, next_button)) vbox.pack_start(widgetutil.align_right(hbox)) return vbox
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 build_search_page(self): vbox = widgetset.VBox(spacing=5) self.progress_bar = widgetset.ProgressBar() self.progress_bar.set_size_request(400, -1) vbox.pack_start(widgetutil.align_center( self.progress_bar, top_pad=50)) self.progress_label = widgetset.Label("") vbox.pack_start( widgetutil.align_top( widgetutil.align_center(self.progress_label), top_pad=10)) self.cancel_search_button = widgetset.Button(_("Cancel Search")) self.cancel_search_button.connect( 'clicked', self.handle_search_cancel_clicked) vbox.pack_start(widgetutil.align_right(self.cancel_search_button, right_pad=5)) vbox.pack_start(self._force_space_label(), expand=True) self.search_prev_button = widgetset.Button(_("< Previous")) self.search_prev_button.connect('clicked', lambda x: self.prev_page()) self.search_next_button = widgetset.Button(_("Finish")) self.search_next_button.connect('clicked', lambda x: self.destroy()) vbox.pack_start( widgetutil.align_bottom(widgetutil.align_right( widgetutil.build_hbox((self.search_prev_button, self.search_next_button)))), expand=True) vbox = widgetutil.pad(vbox) vbox.run_me_on_switch = self.start_search return vbox
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 build_search_page(self): vbox = widgetset.VBox(spacing=5) self.progress_bar = widgetset.ProgressBar() self.progress_bar.set_size_request(400, -1) vbox.pack_start(widgetutil.align_center(self.progress_bar, top_pad=50)) self.progress_label = widgetset.Label("") vbox.pack_start( widgetutil.align_top(widgetutil.align_center(self.progress_label), top_pad=10)) self.cancel_search_button = widgetset.Button(_("Cancel Search")) self.cancel_search_button.connect('clicked', self.handle_search_cancel_clicked) vbox.pack_start( widgetutil.align_right(self.cancel_search_button, right_pad=5)) vbox.pack_start(self._force_space_label(), expand=True) self.search_prev_button = widgetset.Button(_("< Previous")) self.search_prev_button.connect('clicked', lambda x: self.prev_page()) self.search_next_button = widgetset.Button(_("Finish")) self.search_next_button.connect('clicked', lambda x: self.destroy()) vbox.pack_start(widgetutil.align_bottom( widgetutil.align_right( widgetutil.build_hbox( (self.search_prev_button, self.search_next_button)))), expand=True) vbox = widgetutil.pad(vbox) vbox.run_me_on_switch = self.start_search return vbox
def build_third_page(self): vbox = widgetset.VBox(spacing=5) vbox.pack_start(_build_title(_("Finding Files"))) lab = widgetset.Label(_( "%(name)s can find all the media files on your computer to help " "you organize your collection.\n" "\n" "Would you like %(name)s to look for media files on your " "computer?", {'name': app.config.get(prefs.SHORT_APP_NAME)})) lab.set_size_request(400, -1) lab.set_wrap(True) vbox.pack_start(widgetutil.align_left(lab)) rbg = widgetset.RadioButtonGroup() no_rb = widgetset.RadioButton(_("No"), rbg) yes_rb = widgetset.RadioButton(_("Yes"), rbg) vbox.pack_start(widgetutil.align_left(no_rb)) vbox.pack_start(widgetutil.align_left(yes_rb, bottom_pad=5)) group_box = widgetset.VBox(spacing=5) rbg2 = widgetset.RadioButtonGroup() restrict_rb = widgetset.RadioButton( _("Restrict to all my personal files."), rbg2) search_rb = widgetset.RadioButton(_("Search custom folders:"), rbg2) group_box.pack_start(widgetutil.align_left(restrict_rb, left_pad=30)) group_box.pack_start(widgetutil.align_left(search_rb, left_pad=30)) # XXX: we can think about providing a list of media players installed # and search through those, but righ tnow the code doesn't handle # a list of search directories to search. (name, path) = get_plat_media_player_name_path() if path: import_rb = widgetset.RadioButton( _("Import from %(player)s as watched folder" % \ dict(player=name)), rbg2) self.search_directory = path group_box.pack_start(widgetutil.align_left(import_rb, left_pad=30)) else: # can't import - import_rb doesn't exist. import_rb = None search_entry = widgetset.TextEntry() search_entry.set_width(20) change_button = widgetset.Button(_("Change")) hbox = widgetutil.build_hbox((search_entry, 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_user_media_directory(), transient_for=self) if dir_: search_entry.set_text(filename_to_unicode(dir_)) self.search_directory = dir_ else: self.search_directory = _get_user_media_directory() change_button.connect('clicked', handle_change_clicked) vbox.pack_start(group_box) vbox.pack_start(widgetset.Label(" "), expand=True) 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_user_media_directory() self.next_page() else: if rbg2.get_selected() == import_rb: # Add watched folder app.watched_folder_manager.add(self.search_directory) self.on_close() search_button = widgetset.Button(_("Search")) search_button.connect('clicked', handle_search_finish_clicked) search_button.text_faces = {"search": _("Search"), "finish": _("Finish")} search_button.mode = "search" def switch_mode(mode): search_button.set_text(search_button.text_faces[mode]) search_button.mode = mode hbox = widgetutil.build_hbox((prev_button, search_button)) vbox.pack_start(widgetutil.align_right(hbox)) 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("finish") elif widget is yes_rb: group_box.enable() if (rbg2.get_selected() is restrict_rb or rbg2.get_selected() is import_rb): search_entry.disable() change_button.disable() else: search_entry.enable() change_button.enable() if rbg2.get_selected() is import_rb: switch_mode("finish") else: switch_mode("search") elif widget is restrict_rb or widget is import_rb: search_entry.disable() change_button.disable() elif widget is search_rb: search_entry.enable() change_button.enable() if widget is restrict_rb or widget is search_rb: switch_mode("search") if widget is import_rb: switch_mode("finish") 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) if import_rb: import_rb.connect('clicked', handle_radio_button_clicked) handle_radio_button_clicked(restrict_rb) handle_radio_button_clicked(no_rb) return vbox
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_language_page(self): vbox = widgetset.VBox(spacing=5) vbox.pack_start( _build_paragraph_text( _( "Welcome to %(name)s! We have a couple of questions " "to help you get started.", {'name': app.config.get(prefs.SHORT_APP_NAME)}))) vbox.pack_start( _build_title_question( _("What language would you like %(name)s to be in?", {'name': app.config.get(prefs.SHORT_APP_NAME)}))) lang_options = gtcache.get_languages() lang_options.insert(0, ("system", _("System default"))) def update_language(widget, index): os.environ["LANGUAGE"] = _SYSTEM_LANGUAGE app.config.set(prefs.LANGUAGE, str(lang_options[index][0])) gtcache.init() # FIXME - this is totally awful and may break at some # point. what happens is that widgetconst translates at # import time, so if someone changes the language, then # the translations have already happened. we reload the # module to force them to happen again. bug 17515 if "miro.frontends.widgets.widgetconst" in sys.modules: reload(sys.modules["miro.frontends.widgets.widgetconst"]) self.this_page(rebuild=True) lang_option_menu = widgetset.OptionMenu([op[1] for op in lang_options]) lang = app.config.get(prefs.LANGUAGE) try: lang_option_menu.set_selected([op[0] for op in lang_options].index(lang)) except ValueError: lang_option_menu.set_selected(1) lang_option_menu.connect('changed', update_language) def next_clicked(widget): os.environ["LANGUAGE"] = _SYSTEM_LANGUAGE app.config.set( prefs.LANGUAGE, str(lang_options[lang_option_menu.get_selected()][0])) gtcache.init() self.next_page(rebuild=True) hbox = widgetset.HBox() hbox.pack_start(widgetset.Label(_("Language:")), padding=0) hbox.pack_start(lang_option_menu, padding=5) vbox.pack_start(widgetutil.align_center(hbox)) vbox.pack_start(self._force_space_label()) next_button = widgetset.Button(_("Next >")) next_button.connect('clicked', next_clicked) vbox.pack_start(widgetutil.align_bottom( widgetutil.align_right(widgetutil.build_hbox((next_button, )))), expand=True) vbox = widgetutil.pad(vbox) return vbox
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 __init__(self): self.device = None widgetset.VBox.__init__(self) self.button_row = segmented.SegmentedButtonsRow() for key, name in (('main', _('Main')), ('podcasts', _('Podcasts')), ('playlists', _('Playlists')), ('settings', _('Settings'))): button = DeviceTabButtonSegment(key, name, self._tab_clicked) self.button_row.add_button(name.lower(), button) self.button_row.set_active('main') tbc = TabButtonContainer() tbc.add( widgetutil.align_center(self.button_row.make_widget(), top_pad=9)) width = tbc.child.get_size_request()[0] tbc.child.set_size_request(-1, 24) self.pack_start(tbc) self.tabs = {} self.tab_container = widgetset.Background() scroller = widgetset.Scroller(False, True) scroller.add(self.tab_container) self.pack_start(scroller, expand=True) vbox = widgetset.VBox() vbox.pack_start( widgetutil.align_left(tabcontroller.ConnectTab.build_header( _("Individual Files")), top_pad=10)) label = tabcontroller.ConnectTab.build_text( _("Drag individual video and audio files onto " "the device in the sidebar to copy them.")) label.set_size_request(width, -1) label.set_wrap(True) vbox.pack_start(widgetutil.align_left(label, top_pad=10)) vbox.pack_start( widgetutil.align_left(tabcontroller.ConnectTab.build_header( _("Syncing")), top_pad=30)) label = tabcontroller.ConnectTab.build_text( _("Use the tabs above and these options for " "automatic syncing.")) label.set_size_request(width, -1) label.set_wrap(True) vbox.pack_start(widgetutil.align_left(label, top_pad=10)) self.auto_sync = widgetset.Checkbox( _("Sync automatically when this " "device is connected")) self.auto_sync.connect('toggled', self._auto_sync_changed) vbox.pack_start(widgetutil.align_left(self.auto_sync, top_pad=10)) max_fill_label = _( "Don't fill more than %(count)i percent of the " "free space when syncing", {'count': id(self)}) checkbox_label, text_label = max_fill_label.split(unicode(id(self)), 1) self.max_fill_enabled = widgetset.Checkbox(checkbox_label) self.max_fill_enabled.connect('toggled', self._max_fill_enabled_changed) self.max_fill_percent = widgetset.TextEntry() self.max_fill_percent.set_size_request(50, -1) self.max_fill_percent.connect('focus-out', self._max_fill_percent_changed) label = widgetset.Label(text_label) vbox.pack_start( widgetutil.align_left(widgetutil.build_hbox( [self.max_fill_enabled, self.max_fill_percent, label], 0), top_pad=10)) rounded_vbox = RoundedVBox() vbox.pack_start( widgetutil.align_left(tabcontroller.ConnectTab.build_header( _("Auto Fill")), top_pad=30, bottom_pad=10)) self.auto_fill = widgetset.Checkbox( _("After syncing my selections in the tabs above, " "fill remaining space with:")) self.auto_fill.connect('toggled', self._auto_fill_changed) rounded_vbox.pack_start( widgetutil.align_left(self.auto_fill, 20, 20, 20, 20)) names = [(_('Newest Music'), u'recent_music'), (_('Random Music'), u'random_music'), (_('Most Played Songs'), u'most_played_music'), (_('New Playlists'), u'new_playlists'), (_('Most Recent Podcasts'), u'recent_podcasts')] longest = max(names, key=lambda x: len(x[0]))[0] width = widgetset.Label(longest).get_width() less_label = widgetset.Label(_('Less').upper()) less_label.set_size(tabcontroller.ConnectTab.TEXT_SIZE / 2) more_label = widgetset.Label(_('More').upper()) more_label.set_size(tabcontroller.ConnectTab.TEXT_SIZE / 2) label_hbox = widgetutil.build_hbox([ less_label, widgetutil.pad( more_label, left=(200 - less_label.get_width() - more_label.get_width())) ], padding=0) label_hbox.set_size_request(200, -1) scrollers = [widgetutil.align_right(label_hbox, right_pad=20)] self.auto_fill_sliders = {} for name, setting in names: label = widgetutil.align_right(widgetset.Label(name)) label.set_size_request(width, -1) dragger = AutoFillSlider() dragger.connect('released', self._auto_fill_slider_changed, setting) self.auto_fill_sliders[setting] = dragger hbox = widgetutil.build_hbox([label, dragger], 20) scrollers.append(hbox) rounded_vbox.pack_start( widgetutil.align_left(widgetutil.build_vbox(scrollers, 10), 20, 20, 20, 20)) vbox.pack_start(widgetutil.align_left(rounded_vbox)) self.device_size = SizeWidget() self.device_size.sync_button.connect('clicked', self.sync_clicked) self.pack_end(self.device_size) self.add_tab('main', widgetutil.align_center(vbox, 20, 20, 20, 20)) self.add_tab( 'podcasts', widgetutil.align_center(PodcastSyncWidget(), 20, 20, 20, 20)) self.add_tab( 'playlists', widgetutil.align_center(PlaylistSyncWidget(), 20, 20, 20, 20)) self.add_tab( 'settings', widgetutil.align_center(DeviceSettingsWidget(), 20, 20, 20, 20))
def build_search_page(self): vbox = widgetset.VBox(spacing=5) vbox.pack_start(_build_title(_("Searching for media files"))) progress_bar = widgetset.ProgressBar() vbox.pack_start(progress_bar) progress_label = widgetset.Label("") progress_label.set_size_request(400, -1) vbox.pack_start(widgetutil.align_left(progress_label)) search_button = widgetset.Button(_("Search")) cancel_button = widgetset.Button(_("Cancel")) hbox = widgetutil.build_hbox((search_button, cancel_button)) vbox.pack_start(widgetutil.align_left(hbox)) vbox.pack_start(widgetset.Label(" "), expand=True) prev_button = widgetset.Button(_("< Previous")) prev_button.connect('clicked', lambda x: self.prev_page()) finish_button = widgetset.Button(_("Finish")) finish_button.connect('clicked', lambda x: self.on_close()) hbox = widgetutil.build_hbox((prev_button, finish_button)) vbox.pack_start(widgetutil.align_right(hbox)) def handle_cancel_clicked(widget): progress_bar.stop_pulsing() progress_bar.set_progress(1.0) search_button.enable() cancel_button.disable() prev_button.enable() finish_button.enable() self.cancelled = True def make_progress(): if self.cancelled: self.gathered_media_files = [] self.finder = None progress_label.set_text("") return try: num_parsed, found = self.finder.next() self.gathered_media_files = found num_found = len(found) num_files = ngettext("parsed %(count)s file", "parsed %(count)s files", num_parsed, {"count": num_parsed}) num_media_files = ngettext("found %(count)s media file", "found %(count)s media files", num_found, {"count": num_found}) progress_label.set_text(u"%s - %s" % (num_files, num_media_files)) threads.call_on_ui_thread(make_progress) except StopIteration: handle_cancel_clicked(None) self.finder = None def handle_search_clicked(widget): self.cancelled = False search_button.disable() cancel_button.enable() prev_button.disable() finish_button.disable() search_directory = FilenameType(self.search_directory) self.finder = util.gather_media_files(search_directory) progress_bar.start_pulsing() threads.call_on_ui_thread(make_progress) search_button.connect('clicked', handle_search_clicked) cancel_button.connect('clicked', handle_cancel_clicked) cancel_button.disable() return vbox
def build_language_page(self): vbox = widgetset.VBox(spacing=5) vbox.pack_start(_build_paragraph_text(_( "Welcome to %(name)s! We have a couple of questions " "to help you get started.", {'name': app.config.get(prefs.SHORT_APP_NAME)}))) vbox.pack_start(_build_title_question(_( "What language would you like %(name)s to be in?", {'name': app.config.get(prefs.SHORT_APP_NAME)}))) lang_options = gtcache.get_languages() lang_options.insert(0, ("system", _("System default"))) def update_language(widget, index): os.environ["LANGUAGE"] = _SYSTEM_LANGUAGE app.config.set(prefs.LANGUAGE, str(lang_options[index][0])) gtcache.init() # FIXME - this is totally awful and may break at some # point. what happens is that widgetconst translates at # import time, so if someone changes the language, then # the translations have already happened. we reload the # module to force them to happen again. bug 17515 if "miro.frontends.widgets.widgetconst" in sys.modules: reload(sys.modules["miro.frontends.widgets.widgetconst"]) self.this_page(rebuild=True) lang_option_menu = widgetset.OptionMenu([op[1] for op in lang_options]) lang = app.config.get(prefs.LANGUAGE) try: lang_option_menu.set_selected([op[0] for op in lang_options].index(lang)) except ValueError: lang_option_menu.set_selected(1) lang_option_menu.connect('changed', update_language) def next_clicked(widget): os.environ["LANGUAGE"] = _SYSTEM_LANGUAGE app.config.set(prefs.LANGUAGE, str(lang_options[lang_option_menu.get_selected()][0])) gtcache.init() self.next_page(rebuild=True) hbox = widgetset.HBox() hbox.pack_start(widgetset.Label(_("Language:")), padding=0) hbox.pack_start(lang_option_menu, padding=5) vbox.pack_start(widgetutil.align_center(hbox)) vbox.pack_start(self._force_space_label()) next_button = widgetset.Button(_("Next >")) next_button.connect('clicked', next_clicked) vbox.pack_start( widgetutil.align_bottom(widgetutil.align_right( widgetutil.build_hbox((next_button,)))), expand=True) vbox = widgetutil.pad(vbox) return vbox
def __init__(self): self.device = None widgetset.VBox.__init__(self) self.button_row = segmented.SegmentedButtonsRow() for key, name in ( ('main', _('Main')), ('podcasts', _('Podcasts')), ('playlists', _('Playlists')), ('settings', _('Settings'))): button = DeviceTabButtonSegment(key, name, self._tab_clicked) self.button_row.add_button(name.lower(), button) self.button_row.set_active('main') tbc = TabButtonContainer() tbc.add(widgetutil.align_center(self.button_row.make_widget(), top_pad=9)) width = tbc.child.get_size_request()[0] tbc.child.set_size_request(-1, 24) self.pack_start(tbc) self.tabs = {} self.tab_container = widgetset.Background() scroller = widgetset.Scroller(False, True) scroller.add(self.tab_container) self.pack_start(scroller, expand=True) vbox = widgetset.VBox() vbox.pack_start(widgetutil.align_left( tabcontroller.ConnectTab.build_header(_("Individual Files")), top_pad=10)) label = tabcontroller.ConnectTab.build_text( _("Drag individual video and audio files onto " "the device in the sidebar to copy them.")) label.set_size_request(width, -1) label.set_wrap(True) vbox.pack_start(widgetutil.align_left(label, top_pad=10)) vbox.pack_start(widgetutil.align_left( tabcontroller.ConnectTab.build_header(_("Syncing")), top_pad=30)) label = tabcontroller.ConnectTab.build_text( _("Use the tabs above and these options for " "automatic syncing.")) label.set_size_request(width, -1) label.set_wrap(True) vbox.pack_start(widgetutil.align_left(label, top_pad=10)) self.auto_sync = widgetset.Checkbox(_("Sync automatically when this " "device is connected")) self.auto_sync.connect('toggled', self._auto_sync_changed) vbox.pack_start(widgetutil.align_left(self.auto_sync, top_pad=10)) max_fill_label = _( "Don't fill more than %(count)i percent of the " "free space when syncing", {'count': id(self)}) checkbox_label, text_label = max_fill_label.split(unicode(id(self)), 1) self.max_fill_enabled = widgetset.Checkbox(checkbox_label) self.max_fill_enabled.connect('toggled', self._max_fill_enabled_changed) self.max_fill_percent = widgetset.TextEntry() self.max_fill_percent.set_size_request(50, -1) self.max_fill_percent.connect('focus-out', self._max_fill_percent_changed) label = widgetset.Label(text_label) vbox.pack_start(widgetutil.align_left( widgetutil.build_hbox([self.max_fill_enabled, self.max_fill_percent, label], 0), top_pad=10)) rounded_vbox = RoundedVBox() vbox.pack_start(widgetutil.align_left( tabcontroller.ConnectTab.build_header(_("Auto Fill")), top_pad=30, bottom_pad=10)) self.auto_fill = widgetset.Checkbox( _("After syncing my selections in the tabs above, " "fill remaining space with:")) self.auto_fill.connect('toggled', self._auto_fill_changed) rounded_vbox.pack_start(widgetutil.align_left(self.auto_fill, 20, 20, 20, 20)) names = [ (_('Newest Music'), u'recent_music'), (_('Random Music'), u'random_music'), (_('Most Played Songs'), u'most_played_music'), (_('New Playlists'), u'new_playlists'), (_('Most Recent Podcasts'), u'recent_podcasts')] longest = max(names, key=lambda x: len(x[0]))[0] width = widgetset.Label(longest).get_width() less_label = widgetset.Label(_('Less').upper()) less_label.set_size(tabcontroller.ConnectTab.TEXT_SIZE / 2) more_label = widgetset.Label(_('More').upper()) more_label.set_size(tabcontroller.ConnectTab.TEXT_SIZE / 2) label_hbox = widgetutil.build_hbox([ less_label, widgetutil.pad(more_label, left=(200 - less_label.get_width() - more_label.get_width()))], padding=0) label_hbox.set_size_request(200, -1) scrollers = [widgetutil.align_right(label_hbox, right_pad=20)] self.auto_fill_sliders = {} for name, setting in names: label = widgetutil.align_right(widgetset.Label(name)) label.set_size_request(width, -1) dragger = AutoFillSlider() dragger.connect('released', self._auto_fill_slider_changed, setting) self.auto_fill_sliders[setting] = dragger hbox = widgetutil.build_hbox([label, dragger], 20) scrollers.append(hbox) rounded_vbox.pack_start(widgetutil.align_left( widgetutil.build_vbox(scrollers, 10), 20, 20, 20, 20)) vbox.pack_start(widgetutil.align_left(rounded_vbox)) self.device_size = SizeWidget() self.device_size.sync_button.connect('clicked', self.sync_clicked) self.pack_end(self.device_size) self.add_tab('main', widgetutil.align_center(vbox, 20, 20, 20, 20)) self.add_tab('podcasts', widgetutil.align_center(PodcastSyncWidget(), 20, 20, 20, 20)) self.add_tab('playlists', widgetutil.align_center(PlaylistSyncWidget(), 20, 20, 20, 20)) self.add_tab('settings', widgetutil.align_center(DeviceSettingsWidget(), 20, 20, 20, 20))