Example #1
0
    def add_pango_attributes(self, attrs, start_index, end_index):
        """Insert attributes for this StyleSpec into a pango.AttrList. Not every
        property of StyleSpec maps into a pango.Attribute - the ones that don't
        map are ignored and need to be handled separately.

        @param attrs: pango.AttrList to insert attributes into.
        @param start_index: byte offset of the start of the range this spec applies to
        @param end_index: byte offset of the ned of the range this spec applies to

        """

        if self.family is not None:
            attrs.insert(pango.AttrFamily(self.family, start_index, end_index))
        if self.foreground is not None:
            color = pango.Color(self.foreground)
            attrs.insert(
                pango.AttrForeground(color.red, color.green, color.blue,
                                     start_index, end_index))
        if self.style is not None:
            attrs.insert(pango.AttrStyle(self.style, start_index, end_index))
        if self.underline is not None:
            attrs.insert(
                pango.AttrUnderline(self.underline, start_index, end_index))
        if self.weight is not None:
            attrs.insert(pango.AttrWeight(self.weight, start_index, end_index))
        if self.weight is not None:
            attrs.insert(pango.AttrWeight(self.weight, start_index, end_index))
Example #2
0
def set_font(widget, tipo, typewidget=""):
    attrlist = pango.AttrList()
    fg_color = pango.AttrForeground(0, 0, 0, 0, -1)
    stype = pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1)
    fontdesc = pango.FontDescription("Monospace 12")
    if tipo == "titulo":
        fontdesc = pango.FontDescription("Monospace 20")
        stype = pango.AttrWeight(pango.WEIGHT_ULTRABOLD, 0, -1)
    elif tipo == "subtitulo1":
        fontdesc = pango.FontDescription("Monospace 16")
    elif tipo == "subtitulo2":
        fontdesc = pango.FontDescription("Monospace 14")
    else:
        fg_color = pango.AttrForeground(0, 27756, 0, 0, -1)
    widget.modify_font(fontdesc)
    attrlist.insert(fg_color)
    attrlist.insert(stype)
    if "Label" in str(type(widget)) or "Label" in typewidget:
        widget.set_attributes(attrlist)
    elif "Frame" in str(type(widget)) or "Frame" in typewidget:
        widget.get_label_widget().set_attributes(attrlist)
    elif "Entry" in str(type(widget)) or "Entry" in typewidget:
        widget.get_layout().set_attributes(attrlist)
    else:
        print str(type(widget))
Example #3
0
    def update_example(self, widget=None):
        start = 0
        end = len(self.example)

        attributes = pango.AttrList()

        attributes.insert(pango.AttrForeground(self.text_color.red, self.text_color.green,
                                               self.text_color.blue, start, end))
        attributes.insert(pango.AttrBackground(self.highlight_color.red,
                                               self.highlight_color.green,
                                               self.highlight_color.blue,
                                               start, end))

        # Bold verification
        if self.bold_tg_button.get_active():
            attributes.insert(pango.AttrWeight(pango.WEIGHT_HEAVY, start, end))
        else:
            attributes.insert(pango.AttrWeight(pango.WEIGHT_NORMAL, start, end))

        # Italic verification
        if self.italic_tg_button.get_active():
            attributes.insert(pango.AttrStyle(pango.STYLE_ITALIC, start, end))
        else:
            attributes.insert(pango.AttrStyle(pango.STYLE_NORMAL, start, end))

        # Underline verification
        if self.underline_tg_button.get_active():
            attributes.insert(pango.AttrUnderline(pango.UNDERLINE_SINGLE, start, end))
        else:
            attributes.insert(pango.AttrUnderline(pango.UNDERLINE_NONE, start, end))

        self.example_label.set_attributes(attributes)
Example #4
0
    def __init__(self):
        _path = path.dirname(sys.modules[self.__module__].__file__)

        _conf_filename = '%s/config' %_path
        _conf_dict = {
            'Menu': {'Layer': 'gimp-layer*'},
            'Templates': {'Get first layer': 'layer = image.layers[0]'}
            }
        if not(path.isfile(_conf_filename)):
            self._create_conf_file(_conf_filename, _conf_dict)
        self.config = ConfigParser()
        self.config.read(_conf_filename) 
        self._check_conf(_conf_filename, _conf_dict)       

        self.ui = gtk.Builder()
        self.ui.set_translation_domain('GEB')
        self.ui.add_from_file('%s/batch_ex.ui' %_path)
        self.ui.connect_signals(self)
        self.status = self.ui.get_object('status')

        #Check Gimp version and updade syntax file, if needed
        self._check_syntax('%s/python-fu.xml' %_path)

        add_syntax_path(_path)
        buff = CodeBuffer(lang=SyntaxLoader("python-fu"))
        self.ui.get_object('code').set_buffer(buff)
        buff.connect('changed', self.code_changed)

        self.base = shelve.open('%s/batch_base' %_path)
        self._get_macro_list()
        self._ckey = ""
        self.browse_dlg = None

        # Menu
        self._create_menu()

        # colors
        self.red_color = pango.AttrList()
        self.red_color.insert(pango.AttrForeground(65535, 0, 0, 0, -1))
        self.red_color.insert(pango.AttrWeight(pango.WEIGHT_HEAVY, 0, -1))
        self.green_color = pango.AttrList()
        self.green_color.insert(pango.AttrForeground(0, 65535, 0, 0, -1))        
        self.green_color.insert(pango.AttrWeight(pango.WEIGHT_HEAVY, 0, -1))
        self.blue_color = pango.AttrList()
        self.blue_color.insert(pango.AttrForeground(0, 0, 65535, 0, -1)) 
        self.blue_color.insert(pango.AttrWeight(pango.WEIGHT_HEAVY, 0, -1))

        # Log
        self._log = self.ui.get_object('log').get_buffer()
        self._log.create_tag('alert', foreground='red', weight=700)
        self._log.create_tag('ok', foreground='black')
        self._log.create_tag('done', foreground='blue', weight=700)

        self._set_status(ST_NEW)
        self.format_changed(self.ui.get_object('format_combo'))
        self._add_log(_('GEB started!'), 'done')
Example #5
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)
    def set_shown_window(self, window):
        if self.shown_window != None:
            if self.sw_name_changed_handler != None:
                self.shown_window.disconnect(self.sw_name_changed_handler)
            if self.sw_state_changed_handler != None:
                self.shown_window.disconnect(self.sw_state_changed_handler)
        self.shown_window = window
        self.sw_name_changed_handler = self.shown_window.connect(
            'name-changed', self.on_window_name_changed)
        self.sw_state_changed_handler = self.shown_window.connect(
            'state-changed', self.on_shown_window_state_changed)

        self.container.show_all()
        name = u"" + self.shown_window.get_name()
        self.label.set_tooltip_text(name)
        self.label.set_text(name)
        if self.shown_window == self.active_window \
        and self.window_state == 'passive':
            self.window_state = 'active'
        elif self.shown_window != self.active_window \
        and not self.window_state == 'passive':
            self.window_state = 'passive'

        attr_list = pango.AttrList()
        if settings['%s_bold' % self.window_state]:
            attr_list.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, 300))
        color = settings['%s_color' % self.window_state]
        r = int(color[1:3], 16) * 256
        g = int(color[3:5], 16) * 256
        b = int(color[5:7], 16) * 256
        attr_list.insert(pango.AttrForeground(r, g, b, 0, 300))
        self.label.set_attributes(attr_list)
Example #7
0
 def state_set(self, record):
     super(Label, self).state_set(record)
     if 'name' in self.attrs and record:
         field = record.group.fields[self.attrs['name']]
     else:
         field = None
     if not self.attrs.get('string', True) and field:
         if record:
             text = field.get_client(record) or ''
         else:
             text = ''
         self.set_text(text)
     if record:
         state_changes = record.expr_eval(self.attrs.get('states', {}))
     else:
         state_changes = {}
     if ((field and field.attrs.get('required'))
             or state_changes.get('required')):
         weight = pango.WEIGHT_BOLD
     else:
         weight = pango.WEIGHT_NORMAL
     if ((field and field.attrs.get('readonly'))
             or state_changes.get('readonly')):
         style = pango.STYLE_NORMAL
         weight = pango.WEIGHT_NORMAL
     else:
         style = pango.STYLE_ITALIC
     attrlist = pango.AttrList()
     attrlist.change(pango.AttrWeight(weight, 0, -1))
     attrlist.change(pango.AttrStyle(style, 0, -1))
     if field is not None:
         self._format_set(record, field, attrlist)
     self.set_attributes(attrlist)
 def create_attribute(self, attribute, start, end):
     if attribute == 'bold':
         return pango.AttrWeight(pango.WEIGHT_BOLD, start, end)
     elif attribute == 'italic':
         return pango.AttrStyle(pango.STYLE_ITALIC, start, end)
     elif attribute == 'underline':
         return pango.AttrUnderline(pango.UNDERLINE_SINGLE, start, end)
Example #9
0
 def create_attribute(self, attribute, start, end, value):
     if attribute == 'bold':
         return pango.AttrWeight(value, start, end)
     elif attribute == 'italic':
         return pango.AttrStyle(value, start, end)
     elif attribute == 'underline':
         return pango.AttrUnderline(value, start, end)
Example #10
0
 def setStep(self, step):
     if self.icontheme.rescan_if_needed():
         logging.debug("icon theme changed, re-reading")
     # first update the "previous" step as completed
     size = gtk.ICON_SIZE_MENU
     attrlist = pango.AttrList()
     if self.prev_step:
         image = getattr(self, "image_step%i" % self.prev_step)
         label = getattr(self, "label_step%i" % self.prev_step)
         arrow = getattr(self, "arrow_step%i" % self.prev_step)
         label.set_property("attributes", attrlist)
         image.set_from_stock(gtk.STOCK_APPLY, size)
         image.show()
         arrow.hide()
     self.prev_step = step
     # show the an arrow for the current step and make the label bold
     image = getattr(self, "image_step%i" % step)
     label = getattr(self, "label_step%i" % step)
     arrow = getattr(self, "arrow_step%i" % step)
     # check if that step was not hidden with hideStep()
     if not label.get_property("visible"):
         return
     arrow.show()
     image.hide()
     attr = pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1)
     attrlist.insert(attr)
     label.set_property("attributes", attrlist)
Example #11
0
	def set_message(self, message):
		import pango
		self.comment.set_text(message)
		attrs = pango.AttrList()
		attrs.insert(pango.AttrWeight(pango.WEIGHT_BOLD, end_index = len(message)))
		self.comment.set_attributes(attrs)
		self.comment.show()
    def _update_widgets(self):

        # set title in bold
        self.title = self.builder.get_object(self._Label_preferences)
        attrs = pango.AttrList()
        attrs.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1))
        self.title.set_attributes(attrs)

        # Change Title background colour
        viewport = self.builder.get_object(self._Viewport_title)
        map = viewport.get_colormap()
        colour = map.alloc_color("#9DDDC8")  # firefly grey
        style = viewport.get_style().copy()
        style.bg[gtk.STATE_NORMAL] = colour
        viewport.set_style(style)

        # Theme Combo box
        combo = self.builder.get_object(self._Combobox_theme)
        combo.set_active(self._Combo_Table.index(
            self.conf_options['Theme']))  # Tropical Theme active by default
        self.wdg_dict['Theme'] = combo

        # Trash Check Box
        checkBox = self.builder.get_object(self._Checkbox_trash)
        if (self.conf_options['CaptureTrashDisplay'] == 'yes'):
            checkBox.set_active(True)
        else:
            checkBox.set_active(False)

        self.wdg_dict['CaptureTrashDisplay'] = checkBox
Example #13
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)
Example #14
0
 def set_column_widget(self, column, field, attributes, arrow=True):
     tooltips = Tooltips()
     hbox = gtk.HBox(False, 2)
     label = gtk.Label(attributes['string'])
     if field and self.editable:
         required = field.attrs.get('required')
         readonly = field.attrs.get('readonly')
         if required or not readonly:
             attrlist = pango.AttrList()
             if required:
                 attrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1))
             if not readonly:
                 attrlist.change(pango.AttrStyle(pango.STYLE_ITALIC, 0, -1))
             label.set_attributes(attrlist)
     label.show()
     help = attributes['string']
     if field and field.attrs.get('help'):
         help += '\n' + field.attrs['help']
     elif attributes.get('help'):
         help += '\n' + attributes['help']
     tooltips.set_tip(label, help)
     tooltips.enable()
     if arrow:
         arrow_widget = gtk.Arrow(gtk.ARROW_NONE, gtk.SHADOW_NONE)
         arrow_widget.show()
         column.arrow = arrow_widget
     hbox.pack_start(label, True, True, 0)
     if arrow:
         hbox.pack_start(arrow_widget, False, False, 0)
         column.set_clickable(True)
     hbox.show()
     column.set_widget(hbox)
     column.set_alignment(0.5)
Example #15
0
    def setup_columns (self):
        """
        Setup tree columns
        """
        renderer = gtk.CellRendererText ()
        attributes = pango.AttrList ()
        attributes.insert (pango.AttrWeight (pango.WEIGHT_BOLD, 0, -1))
        renderer.set_property ("attributes", attributes)
        renderer.set_property ('ellipsize', pango.ELLIPSIZE_MIDDLE)
        column = gtk.TreeViewColumn (_("Translation"), renderer,
                                     text=self.COL_TRANSLATION)
        column.set_resizable (True)
        self.append_column (column)

        renderer = gtk.CellRendererText ()
        renderer.set_property ('ellipsize', pango.ELLIPSIZE_MIDDLE)
        column = gtk.TreeViewColumn (_("Original"), renderer,
                                     text=self.COL_ORIGINAL)
        column.set_resizable (True)
        self.append_column (column)

        renderer = gtk.CellRendererPixbuf ()
        column = gtk.TreeViewColumn (_("Application"), None)
        column.pack_start (renderer, expand=False)
        column.add_attribute (renderer, 'pixbuf', self.COL_PIXBUF)
        renderer = gtk.CellRendererText ()
        renderer.set_property ('ellipsize', pango.ELLIPSIZE_END)
        column.pack_start (renderer)
        column.add_attribute (renderer, 'text', self.COL_APPLICATION)
        self.append_column (column)
Example #16
0
 def setup_default_tags(self):
     self.italics = self.get_tags_from_attrs(None, None,
                                             [pango.AttrStyle('italic')])[0]
     self.bold = self.get_tags_from_attrs(None, None,
                                          [pango.AttrWeight('bold')])[0]
     self.underline = self.get_tags_from_attrs(
         None, None, [pango.AttrUnderline('single')])[0]
Example #17
0
 def setupLabels(self):
     if self.appGenericName:
         if self.swapGeneric:
             self.addLabel(self.appName,
                           [pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1)])
             self.addLabel(self.appGenericName)
         else:
             self.addLabel(self.appGenericName,
                           [pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1)])
             self.addLabel(self.appName)
     else:
         if self.appComment != "":
             self.addLabel(self.appName,
                           [pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1)])
             self.addLabel(self.appComment)
         else:
             self.addLabel(self.appName)
Example #18
0
 def override_font_attributes(self, attr, text):
     window_width, window_height = self.get_size()
     lines = text.count('\n') + 1
     attr.insert(
         pango.AttrSizeAbsolute((50 * window_height // lines // 100) * 1000,
                                0, -1))
     attr.insert(pango.AttrFamily(self.font.get_family(), 0, -1))
     attr.insert(pango.AttrWeight(self.font.get_weight(), 0, -1))
class StoredQueriesPresenter(editor.GenericEditorPresenter):

    widget_to_field_map = {
        'stqr_label_entry': 'label',
        'stqr_tooltip_entry': 'tooltip',
        'stqr_query_textbuffer': 'query'
    }

    weight = {False: pango.AttrList(), True: pango.AttrList()}
    weight[True].insert(pango.AttrWeight(pango.WEIGHT_HEAVY, 0, 50))

    view_accept_buttons = [
        'stqr_ok_button',
    ]

    def __init__(self, *args, **kwargs):
        super(StoredQueriesPresenter, self).__init__(*args, **kwargs)
        for self.model.page in range(1, 11):
            name = 'stqr_%02d_label' % self.model.page
            self.view.widget_set_text(name, self.model.label or _('<empty>'))
        self.model.page = 1

    def refresh_toggles(self):
        for i in range(1, 11):
            bname = 'stqr_%02d_button' % i
            lname = 'stqr_%02d_label' % i
            self.view.widget_set_active(bname, i == self.model.page)
            self.view.widget_set_attributes(lname,
                                            self.weight[i == self.model.page])

    def refresh_view(self):
        super(StoredQueriesPresenter, self).refresh_view()
        self.refresh_toggles()

    def on_button_clicked(self, widget, *args):
        if self.view.widget_get_active(widget) is False:
            return
        widget_name = self.widget_get_name(widget)
        self.model.page = int(widget_name[5:7])
        self.refresh_view()

    def on_next_button_clicked(self, widget, *args):
        self.model.page = self.model.page % 10 + 1
        self.refresh_view()

    def on_prev_button_clicked(self, widget, *args):
        self.model.page = (self.model.page - 2) % 10 + 1
        self.refresh_view()

    def on_label_entry_changed(self, widget, *args):
        self.on_text_entry_changed(widget, *args)
        page_label_name = 'stqr_%02d_label' % self.model.page
        value = self.view.widget_get_text(widget)
        self.view.widget_set_text(page_label_name, value or _('<empty>'))

    def on_stqr_query_textbuffer_changed(self, widget, value=None, attr=None):
        return self.on_textbuffer_changed(widget, value, attr='query')
Example #20
0
 def callback(text, bold):
     if isinstance(text, unicode):
         text = text.encode("UTF-8")
     si.write(text)
     end_index = index[0] + len(text)
     if bold:
         attrs.insert(
             pango.AttrWeight(pango.WEIGHT_BOLD, index[0],
                              end_index))
     index[0] = end_index
Example #21
0
 def __init__(self):
     gtk.Alignment.__init__(self, 0, 0, 1, 1)
     self.set_app_paintable(True)
     self._text = gtk.Label()
     self._text.set_alignment(0.5, 0.5)
     attrlist = pango.AttrList()
     attrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD))
     self._text.set_attributes(attrlist)
     self.add(self._text)
     self._text.show()
     self.connect("expose_event", self.__expose_cb)
Example #22
0
    def load(self, node):
        self.index = int(node.getAttribute("cursor"))
        if node.hasAttribute("selection_end"):
            self.end_index = int(node.getAttribute("selection_end"))
        else:
            self.end_index = self.index
        tmp = node.getAttribute("ul-coords")
        self.ul = utils.parse_coords(tmp)
        tmp = node.getAttribute("lr-coords")
        self.lr = utils.parse_coords(tmp)
        self.identity = int(node.getAttribute("identity"))
        try:
            tmp = node.getAttribute("background-color")
            self.background_color = gtk.gdk.color_parse(tmp)
            tmp = node.getAttribute("foreground-color")
            self.foreground_color = gtk.gdk.color_parse(tmp)
        except ValueError:
            pass

        if node.hasAttribute("edit"):
            self.editing = True
        else:
            self.editing = False
            self.end_index = self.index

        self.am_selected = node.hasAttribute("current_root")
        self.am_primary = node.hasAttribute("primary_root")

        for n in node.childNodes:
            if n.nodeType == n.TEXT_NODE:
                self.text = n.data
            elif n.nodeName == "Extended":
                self.extended_buffer.load(n)
            elif n.nodeName == "attribute":
                attrType = n.getAttribute("type")
                start = int(n.getAttribute("start"))
                end = int(n.getAttribute("end"))

                if attrType == "bold":
                    attr = pango.AttrWeight(pango.WEIGHT_BOLD, start, end)
                elif attrType == "italics":
                    attr = pango.AttrStyle(pango.STYLE_ITALIC, start, end)
                elif attrType == "underline":
                    attr = pango.AttrUnderline(pango.UNDERLINE_SINGLE, start,
                                               end)
                elif attrType == "font":
                    font_name = str(n.getAttribute("value"))
                    pango_font = pango.FontDescription(font_name)
                    attr = pango.AttrFontDesc(pango_font, start, end)
                self.attributes.change(attr)
            else:
                print "Unknown: " + n.nodeName
        self.rebuild_byte_table()
        self.recalc_edges()
Example #23
0
 def __init__(self, lbl, is_active=False):
     gtk.ImageMenuItem.__init__(self)
     self.label = gtk.Label(lbl)
     if is_active:
         atrlist = pango.AttrList()
         atrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, 50))
         self.label.set_attributes(atrlist)
     self.label.set_justify(gtk.JUSTIFY_LEFT)
     self.label.set_alignment(0, 0)
     self.add(self.label)
     self.label.show()
Example #24
0
 def _set_attributes(self, bgcolor, fgcolor, size, weight):
     attr = pango.AttrList()
     bg_color = pango.AttrBackground(bgcolor[0], bgcolor[1], bgcolor[2], 0, -1)
     attr.insert(bg_color)
     size_attr = pango.AttrSize(size[0], size[1], size[2])
     attr.insert(size_attr)
     weight_attr = pango.AttrWeight(weight[0], weight[1], weight[2])
     attr.insert(weight_attr)
     fg_color = pango.AttrForeground(fgcolor[0], fgcolor[1], fgcolor[2], 0, 13)
     attr.insert(fg_color)
     return attr
Example #25
0
    def make_title_label(self, text):
        """ set a title label (i.e 1st column of table): play wiyh pango"""
        label = gtk.Label()
        label.set_text("%s" % text)
        attrs = pango.AttrList()
        attrs.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1))
        label.set_attributes(attrs)

        # positionning of label
        label.set_alignment(xalign=0.0,
                            yalign=0.5)  # left justification of label
        # Insert label into the upper left quadrant of the table
        label.show()
        return label
Example #26
0
    def make_table_title(self, title):
        """ set a Table title : play with pango"""
        label = gtk.Label()
        label.set_text(title)
        attrs = pango.AttrList()
        attrs.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1))
        attrs.insert(pango.AttrSize(18000, 0, -1))
        label.set_attributes(attrs)

        # positionning of label
        label.set_alignment(xalign=0.5, yalign=0.5)  # center
        # Insert label into the upper left quadrant of the table
        label.show()
        return label
Example #27
0
    def set_font(self, pango_layout):
        """Sets the font for draw_text"""

        wx2pango_weights = {
            wx.FONTWEIGHT_BOLD: pango.WEIGHT_BOLD,
            wx.FONTWEIGHT_LIGHT: pango.WEIGHT_LIGHT,
            wx.FONTWEIGHT_NORMAL: None,  # Do not set a weight by default
        }

        wx2pango_styles = {
            wx.FONTSTYLE_NORMAL: None,  # Do not set a style by default
            wx.FONTSTYLE_SLANT: pango.STYLE_OBLIQUE,
            wx.FONTSTYLE_ITALIC: pango.STYLE_ITALIC,
        }

        cell_attributes = self.code_array.cell_attributes[self.key]

        # Text font attributes
        textfont = cell_attributes["textfont"]
        pointsize = cell_attributes["pointsize"]
        fontweight = cell_attributes["fontweight"]
        fontstyle = cell_attributes["fontstyle"]
        underline = cell_attributes["underline"]
        strikethrough = cell_attributes["strikethrough"]

        # Now construct the pango font
        font_description = pango.FontDescription(" ".join(
            [textfont, str(pointsize)]))
        pango_layout.set_font_description(font_description)

        attrs = pango.AttrList()

        # Underline
        attrs.insert(pango.AttrUnderline(underline, 0, MAX_RESULT_LENGTH))

        # Weight
        weight = wx2pango_weights[fontweight]
        if weight is not None:
            attrs.insert(pango.AttrWeight(weight, 0, MAX_RESULT_LENGTH))

        # Style
        style = wx2pango_styles[fontstyle]
        if style is not None:
            attrs.insert(pango.AttrStyle(style, 0, MAX_RESULT_LENGTH))

        # Strikethrough
        attrs.insert(
            pango.AttrStrikethrough(strikethrough, 0, MAX_RESULT_LENGTH))

        pango_layout.set_attributes(attrs)
Example #28
0
    def set_window_size(self, setting):
        """Set window and label size."""
        window_width = self.screen_width
        window_height = -1

        window_height = setting * self.screen_height / 100

        attr = pango.AttrList()
        attr.change(pango.AttrSize((50 * window_height / 100) * 1000, 0, -1))
        attr.change(pango.AttrFamily(self.options['font'], 0, -1))
        attr.change(pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1))
        attr.change(pango.AttrForeground(*self.options['color']))

        self.label.set_attributes(attr)
        self.resize(window_width, window_height)
Example #29
0
    def paint_frame(self, cr):
        self.shown_scale = self.tdw.scale
        text = _("Zoom: %.01f%%") % (100 * self.shown_scale)
        layout = self.tdw.create_pango_layout(text)

        # Set a bold font
        if gtk2compat.USE_GTK3:
            font = layout.get_font_description()
            if font is None:  # inherited from context
                font = layout.get_context().get_font_description()
                font = font.copy()
            font.set_weight(pango.Weight.BOLD)
            layout.set_font_description(font)
        else:
            attrs = pango.AttrList()
            attrs.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1))
            layout.set_attributes(attrs)

        # General dimensions
        alloc = self.tdw.get_allocation()
        lw, lh = layout.get_pixel_size()

        # Background rectangle
        hm = self.hmargin
        vm = self.hmargin
        w = alloc.width
        h = alloc.height
        p = self.padding
        area = bx, by, bw, bh = w - lw - hm - p - p, vm, lw + p + p, lh + p + p
        rounded_box(cr, bx, by, bw, bh, p)
        #cr.rectangle(*area)
        rgba = self.background_rgba[:]
        rgba[3] *= self.alpha
        cr.set_source_rgba(*rgba)
        cr.fill()

        # Text
        cr.translate(w - lw - hm - p, vm + p)
        rgba = self.text_rgba[:]
        rgba[3] *= self.alpha
        cr.set_source_rgba(*rgba)
        if gtk2compat.USE_GTK3:
            PangoCairo.show_layout(cr, layout)
        else:
            cr.show_layout(layout)

        # Where to invalidate
        return area
Example #30
0
def get_label_attributes(readonly, required):
    "Return the pango attributes applied to a label according to its state"
    if readonly:
        style = pango.STYLE_NORMAL
        weight = pango.WEIGHT_NORMAL
    else:
        style = pango.STYLE_ITALIC
        if required:
            weight = pango.WEIGHT_BOLD
        else:
            weight = pango.WEIGHT_NORMAL
    attrlist = pango.AttrList()
    if hasattr(pango, 'AttrWeight'):
        attrlist.change(pango.AttrWeight(weight, 0, -1))
    if hasattr(pango, 'AttrStyle'):
        attrlist.change(pango.AttrStyle(style, 0, -1))
    return attrlist