Example #1
0
 def do_get_value(self, iter_, column):
     """Returns the value for iter and column."""
     if column == 0:
         return self._markup_rownum(iter_.user_data + 1)
     if column >= self._n_columns + 1:
         value_col = column - (self._n_columns * 2) + 1
         if self.result_selection.is_selected(iter_.user_data, value_col):
             return self._col_bg_selected
         else:
             return self._col_bg_normal
     value = self.get_raw_value(iter_, column)
     if value is None:
         return self._markup_none(value)
     elif self.is_blob_value(value):
         return self._markup_blob(value)
     else:
         data = str(value)
         lines = data.splitlines()
         if len(lines) > 1:
             return '{} <span color="{}">[...]</span>'.format(
                 GObject.markup_escape_text(lines[0]),
                 self._col_insensitive_str)
         elif lines:
             return GObject.markup_escape_text(lines[0])
         else:
             return GObject.markup_escape_text(data)
Example #2
0
    def __button_next_cb(self, button):
        self._back_button.set_sensitive(True)
        self._next_button.set_sensitive(True)
        logging.debug('current page %s', self._notebook.get_current_page())
        if self._notebook.get_current_page() < 3:
            errors = self._validate(self._notebook.get_current_page())
            if not errors:
                self._notebook.next_page()
        if self._notebook.get_current_page() == 3:
            self._title_label.set_markup(
                '<span size="x-large" >%s</span>' %
                GObject.markup_escape_text(self._poll.title))
            self._question_label.set_markup(
                '<span size="x-large" >%s</span>' %
                GObject.markup_escape_text(self._poll.question))
            self._maxvoters_label.set_markup(
                '<span size="x-large" >%s</span>' % str(self._poll.maxvoters))

            for choice in self._poll.options.keys():
                self._option_labels[int(choice)].set_markup(
                    '<span size="x-large" >%s</span>' %
                    GObject.markup_escape_text(
                        self._poll.options[int(choice)]))
            self._notebook.next_page()

            # disble next button in the last page
            self._next_button.set_sensitive(False)
 def cell_data_func(self, sidebar_column, renderer, tree_model, iter, data):
     db = self.get_property("shell").get_property("db")
     entry = tree_model.get(iter, 0)[0]
     title = entry[0]
     album = entry[1]
     markup = "<span size=\"smaller\">" + \
              "<b>" + GObject.markup_escape_text(title) + "</b>\n" + \
              "<i>" + GObject.markup_escape_text(album) + "</i></span>"
     renderer.set_property("markup", markup)
Example #4
0
 def _highlight_match(self, match, word):
     pos = 0
     markup = ''
     for offset in self._get_match_offsets(match, word):
         markup += GObject.markup_escape_text(word[pos:offset])
         markup += '<span underline="single">'
         markup += GObject.markup_escape_text(word[offset])
         markup += '</span>'
         pos = offset + 1
     markup += GObject.markup_escape_text(word[pos:])
     return markup
Example #5
0
 def cell_data_func(self, sidebar_column, renderer, tree_model, iter, data):
         db = self.get_property("shell").get_property("db")
         entry = tree_model.get(iter, 0)[0]
         title = entry.get_string(RB.RhythmDBPropType.TITLE)
         artist = entry.get_string(RB.RhythmDBPropType.ARTIST)
         album = entry.get_string(RB.RhythmDBPropType.ALBUM)
         markup = "<span size=\"smaller\">" + \
                 "<b>" + GObject.markup_escape_text(title) + "</b>\n" + \
                 "<i>" + GObject.markup_escape_text(album) + "</i>\n" + \
                 "<i>" + GObject.markup_escape_text(artist) + "</i></span>"
         renderer.set_property("markup", markup)
Example #6
0
    def get_markup(self, doc):
        app = self.db.get_application(doc)

        # the logic is that "apps" are displayed normally
        # but "packages" are displayed with their summary as name
        if app.appname:
            appname = self.get_appname(doc)
            summary = self.db.get_summary(doc)
        else:
            appname = self.db.get_summary(doc)
            summary = self.get_pkgname(doc)

        return "%s\n<small>%s</small>" % (GObject.markup_escape_text(appname), GObject.markup_escape_text(summary))
Example #7
0
    def get_markup(self, doc):
        appname = doc.get_value(XapianValues.APPNAME)

        if not appname:
            appname = self.db.get_summary(doc)
            summary = self.get_pkgname(doc)
        else:
            if self.db.is_appname_duplicated(appname):
                appname = "%s (%s)" % (appname, self.get_pkgname(doc))

            summary = self.db.get_summary(doc)

        return "%s\n<small>%s</small>" % (
                 GObject.markup_escape_text(appname),
                 GObject.markup_escape_text(summary))
Example #8
0
    def do_get_value(self, iterator, column):
        if self.view_is_resizing:
            return None

        index = iterator.user_data
        if index == self._last_requested_index:
            return self._cached_row[column]

        if index >= self._result_set.length:
            return None

        self._result_set.seek(index)
        metadata = self._result_set.read()

        self._last_requested_index = index
        self._cached_row = []
        self._cached_row.append(metadata['uid'])

        title = GObject.markup_escape_text(metadata.get('title',
                                                        _('Untitled')))
        self._cached_row.append(title)

        self._cached_row.append(metadata.get('preview', ''))

        return self._cached_row[column]
Example #9
0
 def __init__(self, untranslated_name, display_name, subcats, pkg_count):
     self.untranslated_name = untranslated_name
     self.display_name = GObject.markup_escape_text(display_name)
     #self.subcategories = subcats
     self.pkg_count = pkg_count
     self.vis_count = pkg_count
     return
Example #10
0
def run_dialog( text, parent=None, messagetype=Gtk.MessageType.WARNING, buttonstype=Gtk.ButtonsType.OK, extrabuttons=()):
    """Run a dialog with text 'text'.
       Extra buttons are passed as tuples of (button label, response id).
    """
    escaped = GObject.markup_escape_text(text)
    d = Gtk.MessageDialog(
        None,
        Gtk.DialogFlags.DESTROY_WITH_PARENT,
        messagetype,
        buttonstype)
    markup = '<span weight="bold" size="larger">%s</span>' % escaped
    d.set_markup(markup)
    if parent and isinstance(parent, Gtk.Window):
        d.set_transient_for(parent.widget.get_toplevel())
    for b, rid in extrabuttons:
        d.add_button(b, rid)
    d.vbox.set_spacing(12)
    hbox = d.vbox.get_children()[0]
    hbox.set_spacing(12)
    try:
        d.props.image.set_alignment(0.5, 0)
        d.props.image.set_padding(12, 12)
    except AttributeError:
        # FIXME: This is ridiculous. Possibly distribution-specific patches,
        # or just... bad things. This needs to go away.
        pass
    ret = d.run()
    d.destroy()
    return ret
Example #11
0
 def assume_password(self):
     if self.connection is None:
         return False
     result = True
     if self.connection.requires_password():
         result = False
         dlg = Gtk.Dialog('Enter password', self.win,
                          Gtk.DialogFlags.DESTROY_WITH_PARENT |
                          Gtk.DialogFlags.MODAL,
                          use_header_bar=True)
         dlg.add_button('_Cancel', Gtk.ResponseType.CANCEL)
         dlg.add_button('_Ok', Gtk.ResponseType.OK)
         dlg.set_default_response(Gtk.ResponseType.OK)
         box = dlg.get_content_area()
         box.set_border_width(12)
         box.set_spacing(6)
         lbl = Gtk.Label()
         lbl.set_markup('Password required for <b>{}</b>.'.format(
             GObject.markup_escape_text(
                 self.connection.get_label())))
         box.pack_start(lbl, True, True, 0)
         entry = Gtk.Entry()
         entry.set_visibility(False)
         entry.set_invisible_char('*')
         entry.connect(
             'activate', lambda *a: dlg.response(Gtk.ResponseType.OK))
         box.pack_start(entry, True, True, 0)
         box.show_all()
         if dlg.run() == Gtk.ResponseType.OK:
             self.connection.set_session_password(entry.get_text())
             result = True
         dlg.destroy()
     return result
Example #12
0
 def _get_description_widget(self, fact):
     """Return a widget to render ``Fact.description``."""
     description_label = Gtk.Label()
     description_label.set_name("OverviewDescriptionLabel")
     description_label.set_line_wrap(True)
     description_label.set_markup("<small><i>{}</i></small>".format(GObject.markup_escape_text(fact.description)))
     description_label.props.halign = Gtk.Align.START
     return description_label
Example #13
0
 def get_tag_widget(name):
     tag_label = Gtk.Label()
     tag_label.set_markup("<small>{}</small>".format(GObject.markup_escape_text(name)))
     tag_label.set_name("OverviewTagLabel")
     tag_box = Gtk.EventBox()
     tag_box.set_name("OverviewTagBox")
     tag_box.add(tag_label)
     return tag_box
Example #14
0
 def _update_sub_toprated_content(self, category):
     self.toprated.remove_all()
     # FIXME: should this be m = "%s %s" % (_(gettext text), header text) ??
     m = _('Top Rated %s') % GObject.markup_escape_text(self.header)
     self.toprated_frame.set_header_label(m)
     docs = self._get_sub_toprated_content(category)
     self._add_tiles_to_flowgrid(docs, self.toprated, TOP_RATED_CAROUSEL_LIMIT)
     return
Example #15
0
 def refresh_connection_list(self, key=None):
     store = self.conn_list.get_model()
     store.clear()
     for conn in self.app.connection_manager.get_connections():
         lbl = GObject.markup_escape_text(conn.get_label())
         if conn.config.get('description'):
             lbl += '\n<small>{}</small>'.format(
                 GObject.markup_escape_text(conn.config['description']))
         store.append([conn.key, lbl, conn.get_label()])
     if key is not None:
         iter_ = store.get_iter_first()
         while iter_:
             if store.get_value(iter_, 0) == key:
                 selection = self.conn_list.get_selection()
                 selection.select_iter(iter_)
                 break
             iter_ = store.iter_next(iter_)
Example #16
0
 def _finished_updating(self, installed_updates):
     logging.debug('ActivityUpdater._finished_updating')
     top_message = ngettext('%s update was installed',
                            '%s updates were installed', installed_updates)
     top_message = top_message % installed_updates
     top_message = GObject.markup_escape_text(top_message)
     self._top_label.set_markup('<big>%s</big>' % top_message)
     self._clear_center()
Example #17
0
 def _updated(self, packages):
     num_installed = len(packages)
     top_message = ngettext('%s update was installed',
                            '%s updates were installed', num_installed)
     top_message = top_message % num_installed
     top_message = GObject.markup_escape_text(top_message)
     self._top_label.set_markup('<big>%s</big>' % top_message)
     self._clear_center()
Example #18
0
    def _get_header_for_view_state(self, view_state):
        channel = view_state.channel
        category = view_state.category
        subcategory = view_state.subcategory

        line1 = None
        line2 = None
        if channel is not None:
            name = channel.display_name or channel.name
            line1 = GObject.markup_escape_text(name)
        elif subcategory is not None:
            line1 = GObject.markup_escape_text(category.name)
            line2 = GObject.markup_escape_text(subcategory.name)
        elif category is not None:
            line1 = GObject.markup_escape_text(category.name)
        else:
            line1 = _("All Software")
        return line1, line2
Example #19
0
def escape_markup(text):
    """
    Escape markup text to use with GTK3 widgets.
    After escaping, text is converted to raw string
    from unicode. brrr...
    """
    return \
        GObject.markup_escape_text(
            prepare_markup(text))
Example #20
0
 def _get_activity_widget(self, fact):
     """Return widget to render the activity, including its related category."""
     # [FIXME]
     # Once 'preferences/config' is live, we can change this.
     # Most likly we do not actually need to jump through extra hoops as
     # legacy hamster did but just use a i18n'ed string and be done.
     if not fact.category:
         category = "not categorised"
     else:
         category = str(fact.category)
     activity_label = Gtk.Label()
     activity_label.set_markup(
         "{activity} - {category}".format(
             activity=GObject.markup_escape_text(fact.activity.name), category=GObject.markup_escape_text(category)
         )
     )
     activity_label.props.halign = Gtk.Align.START
     return activity_label
Example #21
0
 def set_description(self, raw_desc, pkgname):
     self.clear()
     if type(raw_desc) == str:
         encoded_desc = unicode(raw_desc, "utf8").encode("utf8")
     else:
         encoded_desc = raw_desc.encode("utf8")
     self._text = GObject.markup_escape_text(encoded_desc)
     self._parse_desc(self._text, pkgname)
     self.show_all()
Example #22
0
 def __finished_cb(self, model, installed_updates, failed_updates,
                   cancelled):
     num_installed = len(installed_updates)
     logging.debug('ActivityUpdater.__finished_cb')
     top_message = ngettext('%s update was installed',
                            '%s updates were installed', num_installed)
     top_message = top_message % num_installed
     top_message = GObject.markup_escape_text(top_message)
     self._top_label.set_markup('<big>%s</big>' % top_message)
     self._clear_center()
Example #23
0
 def _markup_blob(self, value):
     mime, _ = Gio.content_type_guess(None, value)
     if mime is not None:
         txt = '{} ({})'.format(
             Gio.content_type_get_description(mime), mime)
     else:
         txt = 'LOB'
     return '<span color="{}">{}</span>'.format(
         self._col_insensitive_str,
         GObject.markup_escape_text(txt))
Example #24
0
    def __init__(self, category_totals):
        """Initialize widget."""
        super(Summary, self).__init__()

        for category, total in category_totals:
            label = Gtk.Label()
            label.set_markup("<b>{}:</b> {} minutes".format(
                GObject.markup_escape_text(text_type(category)),
                int(total.total_seconds() / 60)))
            self.pack_start(label, False, False, 10)
Example #25
0
 def _get_summery_widget(self, category_totals):
     # [FIXME]
     # Change to Grid based layout
     box = Gtk.Box
     for category, total in category_totals:
         label = Gtk.Label()
         label.set_markup("<b>{}:</b> {} minutes".format(GObject.markup_escape_text(category),
                                                         int(total.total_seconds() / 60)))
         box.pack_start(label, False, False, 10)
     return box
Example #26
0
 def set_description(self, raw_desc, pkgname):
     self.clear()
     if type(raw_desc) == str:
         encoded_desc = unicode(raw_desc, 'utf8').encode('utf8')
     else:
         encoded_desc = raw_desc.encode('utf8')
     desc = GObject.markup_escape_text(encoded_desc)
     self._parse_desc(desc, pkgname)
     self.show_all()
     return
Example #27
0
 def addRow(self, grp_id, text, grp_type):
     """ :Description: Takes a player or a channel identified by grp_id and adds
         them to the correct group defined by grp_type
         :return: None
     """
     if grp_id in self.id2iter:
         return
     model = self.sort_model.get_model()
     m_iter = model.append([grp_id, text, grp_type, GObject.markup_escape_text(text)])
     self.id2iter[grp_id] = m_iter
     self.idSet.add(grp_id)
Example #28
0
 def __init__(self, catview, subcategory):
     RecommendationsPanel.__init__(self, catview)
     self.subcategory = subcategory
     if self.subcategory:
         self.set_header_label(GObject.markup_escape_text(utf8(
             _("Recommended For You in %s")) % utf8(self.subcategory.name)))
     self.recommended_for_you_content = None
     if self.recommender_agent.is_opted_in():
         self._update_recommended_for_you_content()
     else:
         self._hide_recommended_for_you_panel()
Example #29
0
 def _update_sub_top_rated_content(self, category):
     self.top_rated.remove_all()
     # FIXME: should this be m = "%s %s" % (_(gettext text), header text) ??
     # TRANSLATORS: %s is a category name, like Internet or Development
     # Tools
     m = _('Top Rated %(category)s') % {
         'category': GObject.markup_escape_text(self.header)}
     self.top_rated_frame.set_header_label(m)
     docs = self._get_sub_top_rated_content(category)
     self._add_tiles_to_flowgrid(docs, self.top_rated,
                                 TOP_RATED_CAROUSEL_LIMIT)
     return
Example #30
0
    def _update_subcat_departments(self, category, num_items):
        self.departments.remove_all()

        # set the subcat header
        m = "<b><big>%s</big></b>"
        self.subcat_label.set_markup(m % GObject.markup_escape_text(
            self.header))

        # sort Category.name's alphabetically
        sorted_cats = categories_sorted_by_name(self.categories)
        enquire = xapian.Enquire(self.db.xapiandb)
        app_filter = AppFilter(self.db, self.cache)
        for cat in sorted_cats:
            # add the subcategory if and only if it is non-empty
            enquire.set_query(cat.query)

            if len(enquire.get_mset(0, 1)):
                tile = CategoryTile(cat.name, cat.iconname)
                tile.connect('clicked', self.on_category_clicked, cat)
                self.departments.add_child(tile)

        # partialy work around a (quite rare) corner case
        if num_items == 0:
            enquire.set_query(xapian.Query(xapian.Query.OP_AND,
                                category.query,
                                xapian.Query("ATapplication")))
            # assuming that we only want apps is not always correct ^^^
            tmp_matches = enquire.get_mset(0, len(self.db), None, app_filter)
            num_items = tmp_matches.get_matches_estimated()

        # append an additional button to show all of the items in the category
        all_cat = Category("All", _("All"), "category-show-all",
            category.query)
        name = GObject.markup_escape_text('%s %s' % (_("All"), num_items))
        tile = CategoryTile(name, "category-show-all")
        tile.connect('clicked', self.on_category_clicked, all_cat)
        self.departments.add_child(tile)
        self.departments.queue_draw()
        return num_items
Example #31
0
 def bold(self) -> None:
     self.set_markup('<b>{}</b>'.format(
         GObject.markup_escape_text(self._label)))
Example #32
0
    def do_get_value(self, iterator, column):
        if self.view_is_resizing:
            return None

        index = iterator.user_data
        if index == self._last_requested_index:
            return self._cached_row[column]

        if index >= self._result_set.length:
            return None

        self._result_set.seek(index)
        metadata = self._result_set.read()

        self._last_requested_index = index
        self._cached_row = []
        self._cached_row.append(metadata['uid'])
        self._cached_row.append(metadata.get('keep', '0') == '1')
        self._cached_row.append(misc.get_icon_name(metadata))

        if misc.is_activity_bundle(metadata):
            xo_color = XoColor('%s,%s' % (style.COLOR_BUTTON_GREY.get_svg(),
                                          style.COLOR_TRANSPARENT.get_svg()))
        else:
            xo_color = misc.get_icon_color(metadata)
        self._cached_row.append(xo_color)

        title = GObject.markup_escape_text(metadata.get('title',
                                           _('Untitled')))
        self._cached_row.append('<b>%s</b>' % (title, ))

        try:
            timestamp = float(metadata.get('timestamp', 0))
        except (TypeError, ValueError):
            timestamp_content = _('Unknown')
        else:
            timestamp_content = util.timestamp_to_elapsed_string(timestamp)
        self._cached_row.append(timestamp_content)

        try:
            creation_time = float(metadata.get('creation_time'))
        except (TypeError, ValueError):
            self._cached_row.append(_('Unknown'))
        else:
            self._cached_row.append(
                util.timestamp_to_elapsed_string(float(creation_time)))

        try:
            size = int(metadata.get('filesize'))
        except (TypeError, ValueError):
            size = None
        self._cached_row.append(util.format_size(size))

        try:
            progress = int(float(metadata.get('progress', 100)))
        except (TypeError, ValueError):
            progress = 100
        self._cached_row.append(progress)

        buddies = []
        if metadata.get('buddies'):
            try:
                buddies = json.loads(metadata['buddies']).values()
            except json.decoder.JSONDecodeError, exception:
                logging.warning('Cannot decode buddies for %r: %s',
                                metadata['uid'], exception)
Example #33
0
 def unbold(self) -> None:
     self.set_markup(GObject.markup_escape_text(self._label))