Beispiel #1
0
 def make_table(self):
     if self._made_table:
         raise AssertionError("make_table() called twice")
     lines = self._lines[:]
     if self._current_columns > 0:
         lines.append((self._current_line, 0))
     table = widgetset.Table(self.columns, len(lines))
     for i, (line, spacing) in enumerate(lines):
         line.add_to_table(table, i, spacing)
     self._made_table = True
     return table
Beispiel #2
0
 def build_extra_widget(self, window):
     table = widgetset.Table(2, 2)
     table.set_column_spacing(12)
     table.pack(widgetset.Label(_("Username:"******"Password:")), 0, 1)
     self.password_entry = widgetset.SecureTextEntry(
         self.dialog.prefill_password)
     self.password_entry.set_activates_default(True)
     table.pack(self.password_entry, 1, 1)
     window.set_extra_widget(widgetutil.align_center(table))
Beispiel #3
0
    def __init__(self):
        widgetset.SolidBackground.__init__(self, (0, 0, 0))
        vbox = widgetset.VBox()
        label = widgetset.Label(_(
            "%(appname)s can't play this file.  You may "
            "be able to open it with a different program",
            {"appname": app.config.get(prefs.SHORT_APP_NAME)}
            ))
        label.set_color((1, 1, 1))
        vbox.pack_start(label)
        table = widgetset.Table(2, 2)
        table.set_column_spacing(6)
        self.filename_label = self._make_label('')
        self.filetype_label  = self._make_label('')
        table.pack(widgetutil.align_left(self._make_heading(_('Filename:'))),
                0, 0)
        table.pack(widgetutil.align_left(self.filename_label), 1, 0)
        table.pack(widgetutil.align_left(self._make_heading(_('File type:'))),
                0, 1)
        table.pack(widgetutil.align_left(self.filetype_label), 1, 1)
        vbox.pack_start(widgetutil.align_left(table, top_pad=12))
        hbox = widgetset.HBox(spacing=12)
        reveal_button = widgetset.Button(_('Reveal File'))
        self.play_externally_button = widgetset.Button(_('Play Externally'))
        self.play_externally_button.connect('clicked',
                                            self._on_play_externally)
        skip_button = widgetset.Button(_('Skip'))
        reveal_button.connect('clicked', self._on_reveal)
        skip_button.connect('clicked', self._on_skip)

        self.reveal_button_holder = widgetutil.HideableWidget(reveal_button)
        self.play_externally_button_holder = widgetutil.HideableWidget(
                                          self.play_externally_button)

        hbox.pack_start(self.reveal_button_holder)
        hbox.pack_start(self.play_externally_button_holder)
        hbox.pack_start(skip_button)
        vbox.pack_start(widgetutil.align_center(hbox, top_pad=24))
        alignment = widgetset.Alignment(xalign=0.5, yalign=0.5)
        alignment.add(vbox)
        self.add(alignment)
Beispiel #4
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 #5
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 #6
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)
Beispiel #7
0
def run_dialog():
    """Displays a diagnostics windows that tells a user how Miro is set
    up on their machine.
    """
    window = MainDialog(_("Diagnostics"))
    try:
        items = [{
            "label":
            _("Movies location:"),
            "data":
            app.config.get(prefs.MOVIES_DIRECTORY),
            "button_face":
            SHOW,
            "button_fun":
            open_helper(app.config.get(prefs.MOVIES_DIRECTORY))
        }, {
            "label":
            _("Icon cache location:"),
            "data":
            app.config.get(prefs.ICON_CACHE_DIRECTORY),
            "button_face":
            SHOW,
            "button_fun":
            open_helper(app.config.get(prefs.ICON_CACHE_DIRECTORY))
        }, {
            "label": _("Log file location:"),
            "data": app.config.get(prefs.LOG_PATHNAME),
            "button_face": SHOW,
            "button_fun": open_helper(app.config.get(prefs.LOG_PATHNAME))
        }, {
            "label":
            _("Downloader log file location:"),
            "data":
            app.config.get(prefs.DOWNLOADER_LOG_PATHNAME),
            "button_face":
            SHOW,
            "button_fun":
            open_helper(app.config.get(prefs.DOWNLOADER_LOG_PATHNAME))
        }, {
            "label":
            _("Database file location:"),
            "data":
            app.config.get(prefs.SQLITE_PATHNAME),
            "button_face":
            SHOW,
            "button_fun":
            open_helper(app.config.get(prefs.SQLITE_PATHNAME))
        }, {
            "label":
            _("Crash reports location:"),
            "data":
            app.config.get(prefs.CRASH_PATHNAME),
            "button_face":
            SHOW,
            "button_fun":
            open_helper(app.config.get(prefs.CRASH_PATHNAME))
        }, SEPARATOR, {
            "label":
            _("Space free on disk:"),
            "data":
            lambda: util.format_size_for_user(get_available_bytes_for_movies(),
                                              "0B", False)
        }, {
            "label":
            _("Database size:"),
            "data":
            lambda: util.format_size_for_user(get_database_size(), "0B", False)
        }, {
            "label": _("Total db objects in memory:"),
            "data": lambda: "%d" % get_database_object_count()
        }, SEPARATOR, {
            "label":
            _("Total db backups:"),
            "data":
            "",
            "button_face":
            _("%(databasecount)s: Delete",
              {"databasecount": len(app.db.get_backup_databases())}),
            "button_fun":
            delete_backups
        }]

        t = widgetset.Table(3, len(items))
        t.set_column_spacing(10)
        for row_num, item in enumerate(items):
            if item is SEPARATOR:
                t.pack(widgetset.Label(""), 0, row_num)
                continue

            label = item.get("label")
            lab = widgetset.Label(label)
            lab.set_bold(True)
            t.pack(widgetutil.align_left(lab), 0, row_num)

            data = item.get("data")
            if callable(data):
                data = data()
            if not isinstance(data, basestring):
                data = repr(data)
            datalab = widgetset.Label(data)
            t.pack(widgetutil.align_left(datalab), 1, row_num)

            if item.get("button_face"):
                b = widgetset.Button(item["button_face"])
                b.set_size(widgetconst.SIZE_SMALL)
                b.connect('clicked', item["button_fun"])
                t.pack(widgetutil.align_left(b), 2, row_num)

        window.set_extra_widget(t)
        window.add_button(BUTTON_OK.text)
        window.run()
    finally:
        window.destroy()