Example #1
0
    def _update_attrlists(self):
        clr = self._color
        oclr = self._override_color
        norm_forground = pango.AttrForeground(clr.red, clr.green, clr.blue, 0,
                                              len(self.get_text()))
        override_forground = pango.AttrForeground(oclr.red, oclr.green,
                                                  oclr.blue, 0,
                                                  len(self.get_text()))
        self._attrlist = pango.AttrList()
        self._attrlist.insert(norm_forground)
        self._override_attrlist = pango.AttrList()
        self._override_attrlist.insert(override_forground)
        itter = self._base_attrlist.get_iterator()

        while True:
            attrs = itter.get_attrs()

            for attr in attrs:
                self._attrlist.insert(attr.copy())

                if not (attr.type
                        in (pango.ATTR_FOREGROUND, pango.ATTR_BACKGROUND)):
                    self._override_attrlist.insert(attr.copy())

            if not itter.next():
                break

        self._update_attributes()
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 check_net(self, origin, status=None):
        """Update the value of the network status"""
        attr1 = pango.AttrList()
        attr2 = pango.AttrList()
        attr3 = pango.AttrList()
        attr4 = pango.AttrList()
        gray = pango.AttrForeground(20000, 20000, 20000, 0, -1)
        red = pango.AttrForeground(65535, 0, 0, 0, -1)
        green = pango.AttrForeground(0, 65535, 0, 0, -1)
        black = pango.AttrForeground(5000, 5000, 5000, 0, -1)
        attr1.insert(gray)
        attr2.insert(green)
        attr3.insert(red)
        attr4.insert(black)

        s3 = self.gui.get_object("status3")
        if not self.net_activity:
            s3.set_text("Disabled")
            s3.set_attributes(attr1)
        else:
            net = status or context.get_state().net
            try:
                if net:
                    s3.set_text("Up")
                    s3.set_attributes(attr2)
                else:
                    s3.set_text("Down")
                    s3.set_attributes(attr3)
            except KeyError:
                s3.set_text("Connecting")
                s3.set_attributes(attr4)
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 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 #6
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 #7
0
File: _gtk.py Project: zhou0/ibus
 def __init__(self, attrs, unistr):
     super(PangoAttrList, self).__init__()
     if attrs == None:
         return
     offsets = []
     offset = 0
     for c in unistr:
         offsets.append(offset)
         offset += len(c.encode("utf8"))
     offsets.append(offset)
     for attr in attrs:
         pango_attr = None
         start_index = attr.start_index if attr.start_index >= 0 else 0
         end_index = attr.end_index if attr.end_index >= 0 else 0
         start_index = offsets[start_index] if start_index < len(
             offsets) else offsets[-1]
         end_index = offsets[end_index] if end_index < len(
             offsets) else offsets[-1]
         if attr.type == ibus.ATTR_TYPE_FOREGROUND:
             r = (attr.value & 0x00ff0000) >> 8
             g = (attr.value & 0x0000ff00)
             b = (attr.value & 0x000000ff) << 8
             pango_attr = pango.AttrForeground(r, g, b, start_index,
                                               end_index)
         elif attr.type == ibus.ATTR_TYPE_BACKGROUND:
             r = (attr.value & 0x00ff0000) >> 8
             g = (attr.value & 0x0000ff00)
             b = (attr.value & 0x000000ff) << 8
             pango_attr = pango.AttrBackground(r, g, b, start_index,
                                               end_index)
         elif attr.type == ibus.ATTR_TYPE_UNDERLINE:
             pango_attr = pango.AttrUnderline(int(attr.value), start_index,
                                              end_index)
         if pango_attr != None:
             self.insert(pango_attr)
Example #8
0
    def __init__(self):
        super(PyApp, self).__init__()

        self.connect("destroy", gtk.main_quit)
        self.set_title("Pango Example")

        label = gtk.Label(quotes)
        gtk.gdk.beep()

        fontdesc = pango.FontDescription("Serif bold 16")
        label.modify_font(fontdesc)

        attlist = pango.AttrList()
        offset = pango.AttrForeground(65535, 0, 0, start_index=0, end_index=40)
        attlist.insert(offset)

        gtk.Label.set_attributes(label, attlist)

        fix = gtk.Fixed()

        fix.put(label, 5, 5)

        self.add(fix)
        self.set_position(gtk.WIN_POS_CENTER)
        self.show_all()
Example #9
0
    def __init__(self):
        gtk.Toolbar.__init__(self)
        self._back = ToolButton('go-previous')
        self._back.set_tooltip(_('Back'))
        self._back.props.sensitive = False
        self._back.connect('clicked', self._go_back_cb)
        self.insert(self._back, -1)
        self._back.show()

        self._forward = ToolButton('go-next')
        self._forward.set_tooltip(_('Forward'))
        self._forward.props.sensitive = False
        self._forward.connect('clicked', self._go_forward_cb)
        self.insert(self._forward, -1)
        self._forward.show()

        num_page_item = gtk.ToolItem()

        self._num_page_entry = gtk.Entry()
        self._num_page_entry.set_text('0')
        self._num_page_entry.set_alignment(1)
        self._num_page_entry.connect('insert-text',
                                     self._num_page_entry_insert_text_cb)
        self._num_page_entry.connect('activate',
                                     self._num_page_entry_activate_cb)

        self._num_page_entry.set_width_chars(4)

        num_page_item.add(self._num_page_entry)
        self._num_page_entry.show()

        self.insert(num_page_item, -1)
        num_page_item.show()

        total_page_item = gtk.ToolItem()

        self._total_page_label = gtk.Label()

        label_attributes = pango.AttrList()
        label_attributes.insert(pango.AttrSize(14000, 0, -1))
        label_attributes.insert(pango.AttrForeground(65535, 65535, 65535, 0, -1))
        self._total_page_label.set_attributes(label_attributes)

        self._total_page_label.set_text(' / 0')
        total_page_item.add(self._total_page_label)
        self._total_page_label.show()

        self.insert(total_page_item, -1)
        total_page_item.show()

        downloaded_item = gtk.ToolItem()
        self._downloaded_label = gtk.Label()
        self._downloaded_label.set_attributes(label_attributes)

        self._downloaded_label.set_text('')
        downloaded_item.add(self._downloaded_label)
        self._downloaded_label.show()

        self.insert(downloaded_item, -1)
        downloaded_item.show()
Example #10
0
    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 #11
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)
    def __init__(self):
        gtk.Toolbar.__init__(self)
        self.back = ToolButton('go-previous')
        self.back.set_tooltip(_('Back'))
        self.back.props.sensitive = False
        palette = self.back.get_palette()
        self.prev_page = MenuItem(text_label=_("Previous page"))
        palette.menu.append(self.prev_page)
        self.prev_page.show_all()
        self.back.connect('clicked', self.go_back_cb)
        self.prev_page.connect('activate', self.go_back_cb)
        self.insert(self.back, -1)
        self.back.show()

        self.forward = ToolButton('go-next')
        self.forward.set_tooltip(_('Forward'))
        self.forward.props.sensitive = False
        palette = self.forward.get_palette()
        self.next_page = MenuItem(text_label=_("Next page"))
        palette.menu.append(self.next_page)
        self.next_page.show_all()
        self.forward.connect('clicked', self.go_forward_cb)
        self.next_page.connect('activate', self.go_forward_cb)
        self.insert(self.forward, -1)
        self.forward.show()

        num_page_item = gtk.ToolItem()

        self._num_page_entry = gtk.Entry()
        self._num_page_entry.set_text('0')
        self._num_page_entry.set_alignment(1)
        self._num_page_entry.connect('insert-text',
                                     self._num_page_entry_insert_text_cb)
        self._num_page_entry.connect('activate',
                                     self._num_page_entry_activate_cb)

        self._num_page_entry.set_width_chars(4)

        num_page_item.add(self._num_page_entry)
        self._num_page_entry.show()

        self.insert(num_page_item, -1)
        num_page_item.show()

        total_page_item = gtk.ToolItem()

        self._total_page_label = gtk.Label()

        label_attributes = pango.AttrList()
        label_attributes.insert(pango.AttrSize(14000, 0, -1))
        label_attributes.insert(
            pango.AttrForeground(65535, 65535, 65535, 0, -1))
        self._total_page_label.set_attributes(label_attributes)

        self._total_page_label.set_text(' / 0')
        total_page_item.add(self._total_page_label)
        self._total_page_label.show()

        self.insert(total_page_item, -1)
        total_page_item.show()
Example #13
0
 def _set_foreground(self, value, attrlist):
     if value not in common.COLOR_RGB:
         logging.getLogger(__name__).info('This color is not supported' +
             '=> %s' % value)
     color = common.COLOR_RGB.get(value, common.COLOR_RGB['black'])
     attrlist.change(pango.AttrForeground(color[0], color[1],
             color[2], 0, -1))
Example #14
0
 def update(self):
     for label, color in zip(self.labels, self.colors):
         attrs = label.get_attributes()
         attrs.change(
             pango.AttrForeground(int(color.r / 255.0 * 65535),
                                  int(color.g / 255.0 * 65535),
                                  int(color.b / 255.0 * 65535)))
         label.set_attributes(attrs)
Example #15
0
 def cluster_toggled(self, widget):
     self.clustered = not self.clustered
     if self.clustered:
         attr = pango.AttrList()
         fg_color = pango.AttrForeground(65535, 0, 0, 0, -1)
         attr.insert(fg_color)
         self._label.set_attributes(attr)
     else:
         self._label.set_attributes(pango.AttrList())
Example #16
0
    def __init__(self,handle):
        activity.Activity.__init__(self,handle)
        
        self.set_title("Ecomundo")
        print "Init activity Ecomundo"
        #print os.path.abspath(__file__)

        self.createToolbox()
        
        hBox = gtk.HBox(False, 0)
        self.set_canvas(hBox)
        
        self.drawingarea1 = gtk.DrawingArea()
        self.drawingarea1.set_size_request(World.SIZE_WORLD,World.SIZE_WORLD)
        self.drawingarea1.show()

        hBox.pack_start(self.drawingarea1, False, False, 0)
        
        notebook = gtk.Notebook()
        
        print hBox.get_screen().get_width()
        #
        
        notebook.set_size_request(hBox.get_screen().get_width() - World.SIZE_WORLD,-1)
        hBox.pack_start(notebook, False, False, 0)

        label_attributes = pango.AttrList()
        label_attributes.insert(pango.AttrSize(10000, 0, -1))
        label_attributes.insert(pango.AttrForeground(65535, 65535, 65535, 0, -1))
        
        # En la primera pagina del notebook pongo los datos del experimento
        icon_experiment = Icon(icon_name="experiment", icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR)
        self.createExperimentControls(notebook,icon_experiment,label_attributes)
        
        # En la segunda pagina del notebook pongo los datos de los conejos
        icon_rabbit = Icon(icon_name="rabbit", icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR)
        self.createAnimalControls(notebook,_('Rabbit features'), icon_rabbit,world.rabbit_data,label_attributes)

        # En la tercera pagina del notebook pongo los datos de los zorros
        icon_fox = Icon(icon_name="fox", icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR)
        self.createAnimalControls(notebook,_('Fox features'), icon_fox,world.fox_data,label_attributes)

        # En la cuarta ponemos los parametros de clima
        icon_rain = Icon(icon_name="rain", icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR)
        self.createRainControls(notebook,icon_rain,label_attributes)

        print "antes de initWorld"
        initWorld()
        print "antes de init Green"
        initGreen()
        print "antes de init Animals"
        initAnimals()

        hBox.resize_children()
        hBox.show_all()

        self.drawingarea1.connect('expose-event', self.onDrawingAreaExposed)
 def on_dtg_colorbutton_color_set(self, widget):
     self.gscreen.set_dtg_color()
     color = self.data.dtg_color
     fg_color = pango.AttrForeground(color[0], color[1], color[2], 0, 11)
     for i in self.data.axis_list:
         axis = "dro_%s3" % i
         attr = self.widgets[axis].get_attributes()
         attr.insert(fg_color)
         self.widgets[axis].set_attributes(attr)
Example #18
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 #19
0
    def _new_attr(self, atype, colorcode, start, end):
        def get_gdk_color(ccolor):
            bg_color = self.get_style().base[gtk.STATE_NORMAL]
            return contrast.contrast_render_foreground_color(bg_color, ccolor)

        gcolor = get_gdk_color(colorcode)
        if atype == "fg":
            return pango.AttrForeground(gcolor.red, gcolor.green, gcolor.blue,
                                        start, end)
        elif atype == "bg":
            return pango.AttrBackground(gcolor.red, gcolor.green, gcolor.blue,
                                        start, end)
Example #20
0
 def update(self):
     for label, color in zip(self.labels, self.colors):
         attrs = label.get_attributes()
         b = (color & 0x000000FF)
         g = (color & 0x0000FF00) >> 8
         r = (color & 0x00FF0000) >> 16
         a = (color & 0xFF000000) >> 24
         attrs.change(
             pango.AttrForeground(int(r / 255.0 * 65535),
                                  int(g / 255.0 * 65535),
                                  int(b / 255.0 * 65535)))
         label.set_attributes(attrs)
Example #21
0
    def __init__(self, weh):
        super(GTKstrip, self).__init__()
        self.label = "GTKstrip"

        chars = "ESKISTLFÜNFZEHNZWANZIGDREIVIERTELTGNACHVORJMHALBQZWÖLFPZWEINSIEBENKDREIRHFÜNFELFNEUNVIERWACHTZEHNRSBSECHSFMUHR...."
        #chars = chars + "------------------------------------------------------------"
        #chars = chars + "------------------------------------------------------------"

        self.labels = []
        self.colors = []
        self.brightness = 180

        self.weh = weh

        self.win = gtk.Window(gtk.WINDOW_TOPLEVEL)

        self.win.connect("delete_event", self.delete_event)
        self.win.connect("destroy", self.destroy)
        self.win.connect("key_press_event", self.key_press_event)

        table = gtk.Table(11, 11, True)

        x = 0
        y = 0
        for i in unicode(chars):
            label = gtk.Label(i)
            self.labels.append(label)
            self.colors.append(Color(0, 0, 0))

            table.attach(label, x, x + 1, y, y + 1, FILL, FILL)

            x += 1
            if x == 11:
                x = 0
                y += 1

            attrs = pango.AttrList()
            # attrs.insert(pango.AttrLanguage("de"))
            attrs.insert(pango.AttrForeground(0, 0, 0))
            FONTSIZE = 15
            attrs.insert(pango.AttrSize(FONTSIZE * 1000))
            attrs.insert(pango.AttrBackground(0, 0, 0))
            label.set_attributes(attrs)

            label.show()

        color = gtk.gdk.color_parse('#000000')
        self.win.modify_bg(gtk.STATE_NORMAL, color)
        self.win.add(table)
        self.win.show_all()
Example #22
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 #23
0
 def setup(self):
     if self.gui:
         import pango
         self.core.register_ui("opengl_window",
                               "Dimension",
                               self.gui.get_object("DimensionTable"),
                               weight=20)
         self.core.get("register_display_item")("show_dimensions",
                                                "Show Dimensions", 60),
         # Color the dimension value according to the axes.
         # For "y" axis: 100% green is too bright on light background - we
         # reduce it a bit.
         for color, names in ((pango.AttrForeground(65535, 0, 0, 0, 100),
                               ("model_dim_x_label", "model_dim_x",
                                "ModelCornerXMax", "ModelCornerXMin",
                                "ModelCornerXSpaces")),
                              (pango.AttrForeground(0, 50000, 0, 0, 100),
                               ("model_dim_y_label", "model_dim_y",
                                "ModelCornerYMax", "ModelCornerYMin",
                                "ModelCornerYSpaces")),
                              (pango.AttrForeground(0, 0, 65535, 0, 100),
                               ("model_dim_z_label", "model_dim_z",
                                "ModelCornerZMax", "ModelCornerZMin",
                                "ModelCornerZSpaces"))):
             attributes = pango.AttrList()
             attributes.insert(color)
             for name in names:
                 self.gui.get_object(name).set_attributes(attributes)
         self._event_handlers = (("model-change-after",
                                  self.update_model_dimensions),
                                 ("visual-item-updated",
                                  self.update_model_dimensions),
                                 ("model-list-chaned",
                                  self.update_model_dimensions))
         self.register_event_handlers(self._event_handlers)
     return True
 def set_attr(layout):
     attr = pango.AttrList()
     size = pango.AttrSize(int(11.5 * pango.SCALE), 0, -1)
     attr.insert(size)
     if customAttr and customAttr.attributes_dict:
         attributes_dict = customAttr.attributes_dict
      
         if attributes_dict.has_key("regex_include_match"):
             start, end = attributes_dict["regex_include_match"]
             pango_color = pango.AttrBackground(self.include_color.red, self.include_color.green, 
                                                self.include_color.blue, start, end)
             attr.insert(pango_color)
         if attributes_dict.has_key("regex_exclude_match"):
             start, end = attributes_dict["regex_exclude_match"]
             pango_color = pango.AttrForeground(self.exclude_color.red, self.exclude_color.green, 
                                                self.exclude_color.blue, start, end)
             attr.insert(pango_color)
     layout.set_attributes(attr)
Example #25
0
 def append_text(self, text, font=None, color=None, underline=False):
     if text == None:
         text = u""
     startpos = self.text_length
     self.text_chunks.append(text)
     endpos = self.text_length = self.text_length + len(text)
     if font is not None:
         attr = pango.AttrFontDesc(font.description, startpos, endpos)
         self.attributes.append(attr)
     if underline:
         self.underlines.append((startpos, endpos))
     if color:
         def convert(value):
             return int(round(value * 65535))
         attr = pango.AttrForeground(convert(color[0]), convert(color[1]),
                 convert(color[2]), startpos, endpos)
         self.attributes.append(attr)
     self.text_set = False
Example #26
0
    def draw_text(self, text='Hello'):
        self.window.window.move_resize(700, 750, 1280, 80)
        ctx = self.window.window.cairo_create()
        ptx = self.window.get_pango_context()

        ctx.save()
        ctx.set_source_rgba(0.3, 0.0, 0.0, 0.3)
        ctx.set_operator(cairo.OPERATOR_SOURCE)
        ctx.paint()
        ctx.restore()

        font = pango.FontDescription()

        font.set_family("sans")
        font.set_size(32 * pango.SCALE)

        ctx.move_to(400, 0)
        if not self.layout:
            #                layout = pango.Layout(ptx)
            #                layout = ctx.create_layout()
            #                layout = self.object.get_layout()
            layout = self.object.create_pango_layout(text)
            layout.set_font_description(font)
            layout.set_text(text)
            attrs = pango.AttrList()
            attr = pango.AttrForeground(65535, 0, 0, 0, -1)
            attrs.insert(attr)
            layout.set_attributes(attrs)
            self.layout = layout

            ctx.show_layout(layout)

        layout = self.layout
        layout.set_alignment(pango.ALIGN_RIGHT)
        print layout.get_alignment()
        print layout.get_pixel_size()

        layout.set_text(text)

        ctx.set_source_rgba(1, 0, 0, 0.5)
        ctx.fill()
        ctx.show_layout(layout)
Example #27
0
    def set_window_size(self, setting):
        """Set window and label size."""
        window_width = self.screen_width
        window_height = -1

        if setting == SIZE_LARGE:
            window_height = 24 * self.screen_height / 100
        if setting == SIZE_MEDIUM:
            window_height = 12 * self.screen_height / 100
        if setting == SIZE_SMALL:
            window_height = 8 * self.screen_height / 100

        attr = pango.AttrList()
        attr.change(pango.AttrSize((50 * window_height / 100) * 1000, 0, -1))
        attr.change(pango.AttrFamily("Sans", 0, -1))
        attr.change(pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1))
        attr.change(pango.AttrForeground(65535, 65535, 65535, 0, -1))

        self.label.set_attributes(attr)
        self.resize(window_width, window_height)
Example #28
0
    def _generate_thumb_with_text(self):
        """ Generate the text on the pixbuf """
        # This technique is used to compose image with text
        # create a pixmap with the data of the pixbuf then insert text
        # cf. pygtk FAQ  How do I draw a text [or something else] on a gtk.gdk.pixbuf? for mor explication
        # (http://faq.pygtk.org/index.py?req=show&file=faq08.020.htp )

        pixmap, mask = self._pixbuf_thumb.render_pixmap_and_mask()

        # graphic context and Drawarea any created to allow generation of pixbuf composition
        gc = pixmap.new_gc()
        area = gtk.DrawingArea()
        # create pango layout
        self.pangolayout = area.create_pango_layout("")

        # extract only the image name without extenstion
        text_buffer, ext = os.path.splitext(self._name)
        text_buffer = " " + text_buffer + " "
        self.pangolayout.set_text(text_buffer)
        # set text attributes
        attrs = pango.AttrList()
        attrs.insert(pango.AttrFamily(LCONST.THUMB_TEXT_FAMILY, 0, -1))
        attrs.insert(pango.AttrStyle(pango.STYLE_ITALIC, 0, -1))
        attrs.insert(
            pango.AttrForeground(LCONST.THUMB_TEXT_COLOR[0],
                                 LCONST.THUMB_TEXT_COLOR[1],
                                 LCONST.THUMB_TEXT_COLOR[2], 0, -1))
        attrs.insert(pango.AttrBackground(0, 0, 0, 0, -1))
        attrs.insert(pango.AttrSize(LCONST.THUMB_TEXT_SIZE, 0, -1))
        self.pangolayout.set_attributes(attrs)

        # compute text layout position and set it on pixmap
        (w, h) = (self._pixbuf_thumb.get_width(),
                  self._pixbuf_thumb.get_height())
        (lw, lh) = self.pangolayout.get_pixel_size()
        pixmap.draw_layout(gc, (w - lw) // 2, (h - lh - 2), self.pangolayout)

        # function get_from_drawable gets the the pixbuf from the pixmap
        # no need to affect resuly to a new pisbuf: self._pixbuf_thumb is changed whe get_from_drawable is used
        self._pixbuf_thumb.get_from_drawable(pixmap, pixmap.get_colormap(), 0,
                                             0, 0, 0, -1, -1)
Example #29
0
    def on_configure(self, _, event):
        window_height = event.height
        attr = pango.AttrList()
        attr.change(pango.AttrSize(int(self.options['fontsize']) * 1000, 0, -1))
        attr.change(pango.AttrFamily(self.options['font'], 0, -1))
        attr.change(pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1))

        fgcolor = gtk.gdk.color_parse(self.fg)
        attr.change(pango.AttrForeground(
            fgcolor.red, fgcolor.green, fgcolor.blue, 0, -1))

        self.pos_x = event.x
        self.pos_y = event.y

        if self.timer:
            self.timer.cancel()

        self.timer = Timer(self.options['timeout'], self.on_timeout)
        self.timer.start()

        self.label.set_attributes(attr)
Example #30
0
 def gfx_draw_axes(self):
     axes = np.identity(3) * 32
     axes[0] = np.dot(self.rotation, axes[0])
     axes[1] = np.dot(self.rotation, axes[1])
     axes[2] = np.dot(self.rotation, axes[2])
     x0 = 48
     y0 = self.height - 48
     self.gfx_draw_line(x0, y0, x0 + axes[0][0], y0 - axes[0][1])
     self.gfx_draw_line(x0, y0, x0 + axes[1][0], y0 - axes[1][1])
     self.gfx_draw_line(x0, y0, x0 + axes[2][0], y0 - axes[2][1])
     font = pango.FontDescription("courier sans 12")
     X = self.area.create_pango_layout("x")
     Y = self.area.create_pango_layout("y")
     Z = self.area.create_pango_layout("z")
     attr = pango.AttrList()
     fg = pango.AttrForeground(65535, 0, 0, 0, -1)
     attr.insert(fg)
     X.set_alignment(pango.ALIGN_CENTER)
     Y.set_alignment(pango.ALIGN_CENTER)
     Z.set_alignment(pango.ALIGN_CENTER)
     X.set_font_description(font)
     Y.set_font_description(font)
     Z.set_font_description(font)
     X.set_attributes(attr)
     Y.set_attributes(attr)
     Z.set_attributes(attr)
     self.pixmap.draw_layout(
         self.black_gc,
         int(x0 + axes[0][0]) - X.get_pixel_size()[0] / 2,
         int(y0 - axes[0][1]) - X.get_pixel_size()[1], X)
     self.pixmap.draw_layout(
         self.black_gc,
         int(x0 + axes[1][0]) - Y.get_pixel_size()[0] / 2,
         int(y0 - axes[1][1]) - Y.get_pixel_size()[1], Y)
     self.pixmap.draw_layout(
         self.black_gc,
         int(x0 + axes[2][0]) - Z.get_pixel_size()[0] / 2,
         int(y0 - axes[2][1]) - Z.get_pixel_size()[1], Z)