Exemple #1
0
class MenuApplicationLauncher(ApplicationLauncher):
    def __init__(self,
                 desktopFile,
                 iconSize,
                 category,
                 showComment,
                 highlight=False):

        self.showComment = showComment
        self.appCategory = category
        self.highlight = highlight

        ApplicationLauncher.__init__(self, desktopFile, iconSize)

    def filterCategory(self, category):
        if self.appCategory == category or category == "":
            self.show()
        else:
            self.hide()

    def setupLabels(self):
        appName = self.appName
        appComment = self.appComment
        if self.highlight:
            try:
                #color = self.labelBox.rc_get_style().fg[ gtk.STATE_SELECTED ].to_string()
                #if len(color) > 0 and color[0] == "#":
                #appName = "<span foreground=\"%s\"><b>%s</b></span>" % (color, appName);
                #appComment = "<span foreground=\"%s\"><b>%s</b></span>" % (color, appComment);
                #appName = "<b>%s</b>" % (appName);
                #appComment = "<b>%s</b>" % (appComment);
                #else:
                #appName = "<b>%s</b>" % (appName);
                #appComment = "<b>%s</b>" % (appComment);
                appName = "<b>%s</b>" % (appName)
                appComment = "<b>%s</b>" % (appComment)
            except Exception, detail:
                print detail
                pass

        if self.showComment and self.appComment != "":
            if self.iconSize <= 2:
                self.addLabel(appName,
                              [pango.AttrScale(pango.SCALE_SMALL, 0, -1)])
                self.addLabel(appComment,
                              [pango.AttrScale(pango.SCALE_X_SMALL, 0, -1)])
            else:
                self.addLabel(appName)
                self.addLabel(appComment,
                              [pango.AttrScale(pango.SCALE_SMALL, 0, -1)])
        else:
            self.addLabel(appName)
Exemple #2
0
 def _format(self):
     text_len = len(self.get_text())
     attrlist = pango.AttrList()
     attrlist.insert(pango.AttrWeight(self._weight, 0, text_len))
     attrlist.insert(pango.AttrStyle(self._style, 0, text_len))
     attrlist.insert(pango.AttrScale(self._scale, 0, text_len))
     self.set_attributes(attrlist)
Exemple #3
0
 def pangoLabel(self, label, fg, scale):
     atr = pango.AttrList()
     foreg = pango.AttrForeground(fg[0], fg[1], fg[2],0, 100)
     scale = pango.AttrScale(scale, 0, 100)
     atr.insert(foreg)
     atr.insert(scale)
     label.set_attributes(atr)
Exemple #4
0
    def draw_individual(self, indi, x, y):
        '''
        Parameter:
            - indi: the individual
            - x,y : the center top of the individual node
        '''
        top_left = (x - self.WIDTH_FOR_INDI / 2, y)
        #self.drawing_area.window.draw_rectangle(self.gc, False, top_left[0], top_left[1], self.WIDTH_FOR_INDI, self.HEIGHT_FOR_INDI)
        # Name
        self.pangolayout_name.set_text(str(indi))
        self.drawing_area.window.draw_layout(self.gc, top_left[0] + 1,
                                             top_left[1] + 1,
                                             self.pangolayout_name)
        # gender picture if available
        pixbuf = get_gender_pixbuf(indi)
        if pixbuf:
            pixbuf.render_to_drawable(
                self.drawing_area.window, self.gc, 0, 0, top_left[0],
                top_left[1] + 1 + self.HEIGHT_FOR_INDI / 2, -1, -1)
            IMAGE_WIDTH = 13
            IMAGE_HEIGTH = 13

        # date life
        life_str = get_life_date_str(indi)
        self.pangolayout_life.set_text(life_str)
        attrs = pango.AttrList()
        attrs.insert(pango.AttrScale(pango.SCALE_X_SMALL, 0, len(life_str)))
        self.pangolayout_life.set_attributes(attrs)
        self.drawing_area.window.draw_layout(
            self.gc, x, top_left[1] + 1 + self.HEIGHT_FOR_INDI / 2,
            self.pangolayout_life)
Exemple #5
0
def font_attrs(fontsize, widget=None):
    attr = pango.AttrScale(fontscalefactors[fontsize], 0, -1)
    if widget:
        attrs = widget.get_attributes()
        attrs.insert(attr)
    else:
        attrs = pango.AttrList()
        attrs.change(attr)
    return attrs
Exemple #6
0
    def translate_widget(self, widget, lang):
        if isinstance(widget, gtk.Button) and widget.get_use_stock():
            widget.set_label(widget.get_label())

        text = self.get_string(widget.get_name(), lang)
        if text is None:
            return
        name = widget.get_name()

        if isinstance(widget, gtk.Label):
            if name == 'step_label':
                curstep = '?'
                if self.current_page is not None:
                    # TODO cjwatson 2009-01-20: This is a compromise. It
                    # doesn't work with multi-page steps (e.g. partitioning
                    # in ubiquity), but it simplifies page configuration
                    # quite a bit.
                    curstep = str(self.current_page + 1)
                text = text.replace('${INDEX}', curstep)
                text = text.replace('${TOTAL}', str(self.steps.get_n_pages()))
            widget.set_text(text)

            # Ideally, these attributes would be in the glade file somehow ...
            textlen = len(text.encode("UTF-8"))
            if 'heading_label' in name:
                attrs = pango.AttrList()
                attrs.insert(pango.AttrScale(pango.SCALE_LARGE, 0, textlen))
                attrs.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, textlen))
                widget.set_attributes(attrs)
            elif 'extra_label' in name:
                attrs = pango.AttrList()
                attrs.insert(pango.AttrStyle(pango.STYLE_ITALIC, 0, textlen))
                widget.set_attributes(attrs)
            elif 'warning_label' in name:
                attrs = pango.AttrList()
                attrs.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, textlen))
                widget.set_attributes(attrs)

        elif isinstance(widget, gtk.Button):
            # TODO evand 2007-06-26: LP #122141 causes a crash unless we keep a
            # reference to the button image.
            tempref = widget.get_image()

            question = i18n.map_widget_name(widget.get_name())
            widget.set_label(text)
            if question.startswith('oem-config/imported/'):
                stock_id = question[18:]
                widget.set_use_stock(False)
                widget.set_image(
                    gtk.image_new_from_stock('gtk-%s' % stock_id,
                                             gtk.ICON_SIZE_BUTTON))

        elif isinstance(widget, gtk.Window):
            widget.set_title(text)
Exemple #7
0
 def create_tab_widget(self):
   self.tab_box = gtk.HBox()
   self.tab_box.set_spacing(1)
   self.icon = resources.load_icon('application_xp_terminal.png')
   self.tab_box.pack_start(self.icon, expand=False)
   self.label = gtk.Label('Terminal')
   self.label.set_ellipsize(pango.ELLIPSIZE_START)
   small = pango.AttrScale(pango.SCALE_X_SMALL, 0, -1)
   self.label_attributes = pango.AttrList()
   self.label_attributes.insert(small)
   self.label.set_attributes(self.label_attributes)
   self.label.set_width_chars(9)
   self.tab_box.pack_start(self.label)
   self.tab_box.show_all()
   return self.tab_box
Exemple #8
0
    def __init__(self, display_tracklist=False):
        """
            :param display_tracklist: Whether to display
                a short list of tracks
        """
        gtk.Alignment.__init__(self)

        builder = gtk.Builder()
        builder.add_from_file(
            xdg.get_data_path('ui', 'widgets', 'tracklist_info.ui'))

        info_box = builder.get_object('info_box')
        info_box.reparent(self)

        self._display_tracklist = display_tracklist

        self.cover = cover.CoverWidget(builder.get_object('cover_image'))
        self.album_label = builder.get_object('album_label')
        self.artist_label = builder.get_object('artist_label')

        if self._display_tracklist:
            self.tracklist_table = builder.get_object('tracklist_table')
            self.tracklist_table.set_no_show_all(False)
            self.tracklist_table.set_property('visible', True)

            self.total_label = builder.get_object('total_label')
            self.total_label.set_no_show_all(False)
            self.total_label.set_property('visible', True)

            self.rownumber = 1
            self.pango_attributes = pango.AttrList()
            self.pango_attributes.insert(
                pango.AttrScale(pango.SCALE_SMALL, end_index=-1))
            self.pango_attributes.insert(
                pango.AttrStyle(pango.STYLE_ITALIC, end_index=-1))
            self.ellipse_pango_attributes = pango.AttrList()
            self.ellipse_pango_attributes.insert(
                pango.AttrWeight(pango.WEIGHT_BOLD, end_index=-1))
Exemple #9
0
    def __init__(self, parent=None, type=gtk.MESSAGE_INFO,
                 buttons=gtk.BUTTONS_NONE, text=None):
        """
            Report important messages to the user

            :param parent: the parent container box
            :type parent: :class:`gtk.Box`
            :param type: the type of message: gtk.MESSAGE_INFO,
                gtk.MESSAGE_WARNING, gtk.MESSAGE_QUESTION or
                gtk.MESSAGE_ERROR.
            :param buttons: the predefined set of buttons to
                use: gtk.BUTTONS_NONE, gtk.BUTTONS_OK,
                gtk.BUTTONS_CLOSE, gtk.BUTTONS_CANCEL,
                gtk.BUTTONS_YES_NO, gtk.BUTTONS_OK_CANCEL
            :param text: a string containing the message
                text or None
        """
        if parent is not None and not isinstance(parent, gtk.Box):
            raise TypeError('Parent needs to be of type gtk.Box')

        gtk.InfoBar.__init__(self)
        self.set_no_show_all(True)

        if parent is not None:
            parent.add(self)
            parent.reorder_child(self, 0)
            parent.child_set_property(self, 'expand', False)

        self.image = gtk.Image()
        self.image.set_property('yalign', 0)
        self.set_message_type(type)

        self.primary_text = gtk.Label(text)
        self.primary_text.set_property('xalign', 0)
        self.primary_text.set_line_wrap(True)
        self.secondary_text = gtk.Label()
        self.secondary_text.set_property('xalign', 0)
        self.secondary_text.set_line_wrap(True)
        self.secondary_text.set_no_show_all(True)
        self.secondary_text.set_selectable(True)

        self.message_area = gtk.VBox(spacing=12)
        self.message_area.pack_start(self.primary_text, False, False)
        self.message_area.pack_start(self.secondary_text, False, False)

        box = gtk.HBox(spacing=6)
        box.pack_start(self.image, False)
        box.pack_start(self.message_area)

        content_area = self.get_content_area()
        content_area.add(box)
        content_area.show_all()

        self.action_area = self.get_action_area()
        self.action_area.set_property('layout-style',
            gtk.BUTTONBOX_START)

        if buttons != gtk.BUTTONS_NONE:
            for text, response in self.buttons_map[buttons]:
                self.add_button(text, response)

        self.primary_text_attributes = pango.AttrList()
        self.primary_text_attributes.insert(
            pango.AttrWeight(pango.WEIGHT_NORMAL, 0, -1))
        self.primary_text_attributes.insert(
            pango.AttrScale(pango.SCALE_MEDIUM, 0, -1))

        self.primary_text_emphasized_attributes = pango.AttrList()
        self.primary_text_emphasized_attributes.insert(
            pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1))
        self.primary_text_emphasized_attributes.insert(
            pango.AttrScale(pango.SCALE_LARGE, 0, -1))

        self.connect('response', self.on_response)
Exemple #10
0
    def __init__(self, window):
        self._num_thumbs = 0
        gtk.Dialog.__init__(self, _('Thumbnail maintenance'), window, 0,
                            (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))
        button = self.add_button(_('Cleanup'), gtk.RESPONSE_OK)
        button.set_image(
            gtk.image_new_from_stock(gtk.STOCK_CLEAR, gtk.ICON_SIZE_BUTTON))
        self.set_has_separator(False)
        self.set_resizable(False)
        self.set_border_width(4)
        self.connect('response', self._response)
        self.set_default_response(gtk.RESPONSE_OK)
        main_box = gtk.VBox(False, 5)
        main_box.set_border_width(6)
        self.vbox.pack_start(main_box, False, False)

        label = labels.BoldLabel(_('Cleanup thumbnails'))
        label.set_alignment(0, 0.5)
        attrlist = label.get_attributes()
        attrlist.insert(
            pango.AttrScale(pango.SCALE_LARGE, 0, len(label.get_text())))
        label.set_attributes(attrlist)
        main_box.pack_start(label, False, False, 2)
        main_box.pack_start(gtk.HSeparator(), False, False, 5)

        label = labels.ItalicLabel(
            _('Thumbnails for files (such as image files and comic book archives) are stored in your home directory. Many different applications use and create these thumbnails, but sometimes thumbnails remain even though the original files have been removed - wasting space. This dialog can cleanup your stored thumbnails by removing orphaned and outdated thumbnails.'
              ))
        label.set_alignment(0, 0.5)
        label.set_line_wrap(True)
        main_box.pack_start(label, False, False, 10)

        hbox = gtk.HBox(False, 10)
        main_box.pack_start(hbox, False, False)
        left_box = gtk.VBox(True, 5)
        right_box = gtk.VBox(True, 5)
        hbox.pack_start(left_box, False, False)
        hbox.pack_start(right_box, False, False)

        label = labels.BoldLabel('%s:' % _('Thumbnail directory'))
        label.set_alignment(1.0, 1.0)
        left_box.pack_start(label, True, True)
        label = gtk.Label('%s' % encoding.to_unicode(_thumb_base))
        label.set_alignment(0, 1.0)
        right_box.pack_start(label, True, True)

        label = labels.BoldLabel('%s:' % _('Total number of thumbnails'))
        label.set_alignment(1.0, 1.0)
        left_box.pack_start(label, True, True)
        self._num_thumbs_label = gtk.Label(_('Calculating...'))
        self._num_thumbs_label.set_alignment(0, 1.0)
        right_box.pack_start(self._num_thumbs_label, True, True)

        label = labels.BoldLabel('%s:' % _('Total size of thumbnails'))
        label.set_alignment(1.0, 1.0)
        left_box.pack_start(label, True, True)
        self._size_thumbs_label = gtk.Label(_('Calculating...'))
        self._size_thumbs_label.set_alignment(0, 1.0)
        right_box.pack_start(self._size_thumbs_label, True, True)

        label = labels.ItalicLabel(
            _('Do you want to cleanup orphaned and outdated thumbnails now?'))
        label.set_alignment(0, 0.5)
        main_box.pack_start(label, False, False, 10)

        self.show_all()
        while gtk.events_pending():
            gtk.main_iteration(False)
        self._update_num_and_size()
    def __init__(self, datadir=None, logdir=None):
        DistUpgradeView.__init__(self)
        self.logdir = logdir
        if not datadir or datadir == '.':
            localedir = os.path.join(os.getcwd(), "mo")
            gladedir = os.getcwd()
        else:
            localedir = "/usr/share/locale/"
            gladedir = os.path.join(datadir, "gtkbuilder")

        # check if we have a display etc
        gtk.init_check()

        try:
            locale.bindtextdomain("ubuntu-release-upgrader", localedir)
            gettext.textdomain("ubuntu-release-upgrader")
        except Exception as e:
            logging.warning("Error setting locales (%s)" % e)

        icons = gtk.icon_theme_get_default()
        try:
            gtk.window_set_default_icon(
                icons.load_icon("system-software-update", 32, 0))
        except gobject.GError as e:
            logging.debug("error setting default icon, ignoring (%s)" % e)
            pass
        SimpleGtkbuilderApp.__init__(self, gladedir + "/DistUpgrade.ui",
                                     "ubuntu-release-upgrader")
        # terminal stuff
        self.create_terminal()

        self.prev_step = 0  # keep a record of the latest step
        # we don't use this currently
        #self.window_main.set_keep_above(True)
        self.icontheme = gtk.icon_theme_get_default()
        # we keep a reference pngloader around so that its in memory
        # -> this avoid the issue that during the dapper->edgy upgrade
        #    the loaders move from /usr/lib/gtk/2.4.0/loaders to 2.10.0
        self.pngloader = gtk.gdk.PixbufLoader("png")
        try:
            self.svgloader = gtk.gdk.PixbufLoader("svg")
            self.svgloader.close()
        except gobject.GError as e:
            logging.debug("svg pixbuf loader failed (%s)" % e)
            pass
        try:
            import webkit
            self._webkit_view = webkit.WebView()
            self.vbox_main.pack_end(self._webkit_view)
        except:
            logging.exception("html widget")
            self._webkit_view = None
        self.window_main.realize()
        self.window_main.window.set_functions(gtk.gdk.FUNC_MOVE)
        self._opCacheProgress = GtkOpProgress(self.progressbar_cache)
        self._acquireProgress = GtkAcquireProgressAdapter(self)
        self._cdromProgress = GtkCdromProgressAdapter(self)
        self._installProgress = GtkInstallProgressAdapter(self)
        # details dialog
        self.details_list = gtk.TreeStore(gobject.TYPE_STRING)
        column = gtk.TreeViewColumn("")
        render = gtk.CellRendererText()
        column.pack_start(render, True)
        column.add_attribute(render, "markup", 0)
        self.treeview_details.append_column(column)
        self.details_list.set_sort_column_id(0, gtk.SORT_ASCENDING)
        self.treeview_details.set_model(self.details_list)
        # Use italic style in the status labels
        attrlist = pango.AttrList()
        #attr = pango.AttrStyle(pango.STYLE_ITALIC, 0, -1)
        attr = pango.AttrScale(pango.SCALE_SMALL, 0, -1)
        attrlist.insert(attr)
        self.label_status.set_property("attributes", attrlist)
        # reasonable fault handler
        sys.excepthook = self._handleException