Beispiel #1
0
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)
Beispiel #2
0
def _playback_panel():
    extras = []
    font_infos = [(_('System Default'), None)]
    font_infos.extend((name, name) for name in fontinfo.get_all_font_info())
    subtitle_font_menu = widgetset.OptionMenu(
            [name for (name, path) in font_infos])
    attach_combo(subtitle_font_menu, prefs.SUBTITLE_FONT,
            [path for (name, path) in font_infos])
    lab = widgetset.Label(_("Subtitle font:"))
    extras.append(widgetutil.build_control_line((lab, subtitle_font_menu)))
    return extras
Beispiel #3
0
 def __init__(self, field, items, label, option_map):
     Field.__init__(self, field, items, label)
     labels = dict(option_map)
     labels['_mixed'] = _("(mixed)")
     self.options = [option[0] for option in option_map]
     if self.mixed_values:
         self.options.insert(0, '_mixed')
     option_labels = (labels[option] for option in self.options)
     self.widget = widgetset.OptionMenu(option_labels)
     self.widget.set_width(134)
     if self.common_value is not None:
         self.widget.set_selected(self.options.index(self.common_value))
Beispiel #4
0
def _build_auto_download(channel, grid):
    auto_download_cbx = widgetset.Checkbox(
        _("Pause auto-downloading when this many items are unplayed:"))
    grid.pack(auto_download_cbx, grid.ALIGN_RIGHT)

    max_new_options = [("1", _("1 unplayed item")),
                       ("3", _("3 unplayed items")),
                       ("5", _("5 unplayed items")),
                       ("10", _("10 unplayed items")),
                       ("15", _("15 unplayed items"))]

    max_new_values = [int(e[0]) for e in max_new_options]
    max_new_combo = widgetset.OptionMenu([e[1] for e in max_new_options])

    if channel.max_new == u"unlimited":
        auto_download_cbx.set_checked(False)
        max_new_combo.set_selected(2)
        max_new_combo.disable()
    else:
        auto_download_cbx.set_checked(True)
        value = channel.max_new
        if value < 1:
            value = 1
        else:
            while value not in max_new_values and value > 1:
                value = value - 1
        max_new_combo.set_selected(max_new_values.index(value))

    def max_new_changed(widget, index):
        value = max_new_options[index][0]
        messages.SetFeedMaxNew(channel, int(value)).send_to_backend()

    def checkbox_changed(widget):
        if widget.get_checked():
            max_new_combo.enable()
            max_new_changed(max_new_combo, 2)
        else:
            max_new_combo.disable()
            max_new_changed(max_new_combo, 2)
            messages.SetFeedMaxNew(channel, u"unlimited").send_to_backend()

    grid.pack(max_new_combo, grid.ALIGN_LEFT)

    max_new_combo.connect('changed', max_new_changed)
    auto_download_cbx.connect('toggled', checkbox_changed)
Beispiel #5
0
def _build_video_expires(channel, grid):
    grid.pack_label(_("Auto-Expire Items:"), grid.ALIGN_RIGHT)

    expire_options = [("system",
                       _("Watched %(expiration)s (Default)",
                         {"expiration": get_formatted_default_expiration()})),
                      ("24", _("Watched 1 day ago")),
                      ("72", _("Watched 3 days ago")),
                      ("144", _("Watched 6 days ago")),
                      ("240", _("Watched 10 days ago")),
                      ("720", _("Watched 1 month ago")), ("never", _("never"))]
    expire_values = [e[0] for e in expire_options]
    expire_combo = widgetset.OptionMenu([e[1] for e in expire_options])

    if channel.expire == "system":
        selected = expire_values.index("system")
    elif channel.expire == "never":
        selected = expire_values.index("never")
    else:
        try:
            selected = expire_values.index(str(channel.expire_time))
        except ValueError:
            selected = 0
    expire_combo.set_selected(selected)

    def expire_changed(widget, index):
        value = expire_options[index][0]

        if value == "system":
            expire_type = "system"
            expire_time = app.config.get(prefs.EXPIRE_AFTER_X_DAYS)
        elif value == "never":
            expire_type = "never"
            expire_time = 0
        else:
            expire_type = "feed"
            expire_time = int(value)

        messages.SetFeedExpire(channel, expire_type,
                               expire_time).send_to_backend()

    expire_combo.connect('changed', expire_changed)

    grid.pack(expire_combo, grid.ALIGN_LEFT)
Beispiel #6
0
def ask_for_choice(title, description, choices):
    """Ask the user to enter a string in a TextEntry box.

    :param title: title for the window
    :param description: textual description with newlines
    :param choices: list of labels for choices
    Returns the index of the value chosen, or None if the user clicked cancel
    """
    window = MainDialog(title, description)
    try:
        window.add_button(BUTTON_OK.text)
        window.add_button(BUTTON_CANCEL.text)
        menu = widgetset.OptionMenu(choices)
        window.set_extra_widget(menu)
        response = window.run()
        if response == 0:
            return menu.get_selected()
        else:
            return None
    finally:
        window.destroy()
Beispiel #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()
Beispiel #8
0
    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
Beispiel #9
0
    def create_table(self):
        self._background.remove()

        def _get_conversion_name(id_):
            if id_ == 'copy':
                return _('Copy')
            else:
                return conversion_manager.lookup_converter(id_).name

        conversion_details = {
            'audio': _get_conversion_name(self.device.info.audio_conversion),
            'video': _get_conversion_name(self.device.info.video_conversion)
        }
        audio_conversion_names = [
            _('Device Default (%(audio)s)', conversion_details),
            _('Copy')
        ]
        self.audio_conversion_values = [None, 'copy']
        video_conversion_names = [
            _('Device Default (%(video)s)', conversion_details),
            _('Copy')
        ]
        self.video_conversion_values = [None, 'copy']
        for section_name, converters in conversion_manager.get_converters():
            for converter in converters:
                if converter.mediatype == 'video':
                    video_conversion_names.append(converter.name)
                    self.video_conversion_values.append(converter.identifier)
                elif converter.mediatype == 'audio':
                    audio_conversion_names.append(converter.name)
                    self.audio_conversion_values.append(converter.identifier)
        widgets = []
        for text, setting, type_ in (
            (_("Name of Device"), u'name', 'text'),
            (_("Video Conversion"), u'video_conversion', 'video_conversion'),
            (_("Audio Conversion"), u'audio_conversion', 'audio_conversion'),
            (_("Store video in this directory"), u'video_path',
             'text'), (_("Store audio in this directory"), u'audio_path',
                       'text'), (_("Always show this device, even if "
                                   "'show all devices' is turned off"),
                                 u'always_show', 'bool'),
            (_("Always convert videos before copying to this device, even "
               "if the video can play without conversion\n(may reduce video "
               "file sizes, but makes syncing much slower)"),
             u"always_sync_videos", 'bool')):
            if type_ == 'text':
                widget = widgetset.TextEntry()
                widget.set_size_request(260, -1)
            elif type_.endswith('conversion'):
                if type_ == 'video_conversion':
                    options = video_conversion_names
                elif type_ == 'audio_conversion':
                    options = audio_conversion_names
                widget = widgetset.OptionMenu(options)
                widget.set_size_request(260, -1)
            elif type_ == 'bool':
                widget = widgetset.Checkbox(text)
                widget.set_size_request(400, -1)
            else:
                raise RuntimeError('unknown settings widget: %r' % type_)
            self.boxes[setting] = widget
            if type_ != 'bool':  # has a label already
                widgets.append((widgetset.Label(text), widget))
                if type_ == 'text':
                    widget.connect('focus-out', self.setting_changed, setting)
                else:
                    widget.connect('changed', self.setting_changed, setting)
            else:
                widgets.append((widget, ))
                widget.connect('toggled', self.setting_changed, setting)
        table = widgetset.Table(2, len(widgets))
        for row, widget in enumerate(widgets):
            if len(widget) == 1:  # checkbox
                table.pack(widget[0], 0, row, column_span=2)
            else:
                table.pack(widgetutil.align_right(widget[0]), 0, row)
                table.pack(widgetutil.align_left(widget[1]), 1, row)
        table.set_column_spacing(20)
        table.set_row_spacing(20)
        self._background.set_child(
            widgetutil.align_center(table, 20, 20, 20, 20))
Beispiel #10
0
    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)