Пример #1
0
 def configure(self, widget, _event):
     """Handles window configuration event."""
     self.pixmap = gtk.gdk.Pixmap(
         self.window, self.window_width, self.window_height)
     graphics_context = widget.get_style().black_gc
     self.pixmap.draw_rectangle(graphics_context, True,
         0, 0, self.window_width, self.window_height)
     center_x, center_y = ((self.window_width - self.new_w)/2,
                           (self.window_height-self.new_h)/2)
     self.pixmap.draw_pixbuf(graphics_context, self.pixbuf, 0, 0,
         center_x, center_y,
         self.new_w, self.new_h)
     context = self.create_pango_context()
     fsize = context.get_font_description().get_size()*3/2
     font = context.get_font_description()
     font.set_size(fsize)
     context.set_font_description(font)
     layout = pango.Layout(context)
     layout.set_alignment(pango.ALIGN_CENTER)
     layout.set_markup(self.p_title+'\n'+self.p_credit)
     psize_x, _unused_psize_y = layout.get_pixel_size()
     self.pixmap.draw_layout(graphics_context,
         (self.window_width-psize_x)/2, center_y+23, layout)
     self.pixmap.draw_layout(widget.get_style().white_gc,
             (self.window_width-psize_x)/2-3, center_y+20,
             layout)
Пример #2
0
    def redraw_rect(self, widget, r):
        style = widget.get_style()
        (w, h) = (widget.allocation.width, widget.allocation.height)

        xc = w // 2
        yc = h // 2
        radius = min(w, h) // 2 - 1

        # text
        context = widget.get_pango_context()
        layout = pango.Layout(context)

        # some pygtk versions want 2 args, some want 1. sigh
        try:
            layout.set_text(self.text)
        except TypeError:
            layout.set_text(self.text, len(self.text))

        (text_width, text_height) = layout.get_pixel_size()
        style.paint_layout(widget.window, widget.state, True, r, widget, "",
                           xc - text_width // 2, yc - text_height // 2, layout)

        # outer circle
        gc = style.fg_gc[widget.state]
        widget.window.draw_arc(gc, False, xc - radius, yc - radius,
                               radius * 2 - 1, radius * 2 - 1, 0, 360 * 64)

        # inner circle indicating current angle
        angle = self.get_current_angle()
        (ptr_xc, ptr_yc) = self.pointer_coords(radius, angle)

        widget.window.draw_arc(gc, True, int(xc + ptr_xc - T.ptr_radius),
                               int(yc + ptr_yc - T.ptr_radius),
                               T.ptr_radius * 2 - 1, T.ptr_radius * 2 - 1, 0,
                               360 * 64)
Пример #3
0
    def drawLegend(self):
        widget = self.wTree.get_widget("drawingarea2")

        lyt = pango.Layout(gtk.Widget.create_pango_context(widget))

        background = Color(red=35535, green=35535, blue=35535)
        maxI = 0

        for i in xrange(len(self.wls)):
            maxI = i
            #self.drawHorizontalWall( 10, i*30, i, widget )
            x = 0
            y = i * 30 + 10

            for a in xrange(self.borderSize):
                widget.window.draw_line(self.wall_colors[i], x, y + a,
                                        x + self.rectSize, y + a)

            lyt.set_text(self.wls[i])
            widget.window.draw_layout(self.wall_colors[0], 0, i * 30 + 20, lyt,
                                      None, background)

        maxI += 1
        widget.window.draw_rectangle(self.gcRed, 0, 1, maxI * 30 + 20,
                                     self.rectSize - 1, self.rectSize - 1)
        lyt.set_text("Red deploy")
        widget.window.draw_layout(self.wall_colors[0], 0, maxI * 30 + 41, lyt,
                                  None, background)

        widget.window.draw_rectangle(self.gcBlue, 0, 1, maxI * 30 + 60,
                                     self.rectSize - 1, self.rectSize - 1)
        lyt.set_text("Blue deploy")
        widget.window.draw_layout(self.wall_colors[0], 0, maxI * 30 + 81, lyt,
                                  None, background)
Пример #4
0
    def display_license_window(self, licenses):
        dialog = gtk.MessageDialog(self.parent(), 0,
                                   gtk.MESSAGE_INFO,
                                   gtk.BUTTONS_NONE,
                                   _("You must agree to the licenses "
                                     "covering this software before "
                                     "installing it."))

        license_texts = string.join(licenses, "\n" + "#"*79 + "\n")

        text = gtk.TextView()
        text.set_editable(0)
        text.set_cursor_visible(0)
        text.set_wrap_mode(gtk.WRAP_WORD)

        buf = text.get_buffer()
        buf.set_text(license_texts)

        context = text.get_pango_context()
        font_desc = context.get_font_description()
        font_desc.set_family("monospace")

        # Try to estimate the size of the window we want.
        # "W" being the widest glyph.
        s = ("W"*82 + "\n")*20
        layout = pango.Layout(context)
        layout.set_font_description(font_desc)
        layout.set_text(s)
        width, height = layout.get_pixel_size()
        text.set_size_request(width, height)

        # Create a tag with our monospace font
        tag = buf.create_tag()
        tag.set_property("font-desc", font_desc)
        buf.apply_tag(tag, buf.get_start_iter(), buf.get_end_iter())

        # Get a mark to the start of the buffer and then scroll there
        iter = buf.get_start_iter()
        mark = buf.create_mark("start", iter, left_gravity=1)
        text.scroll_to_mark(mark, 0.0)

        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        sw.set_shadow_type(gtk.SHADOW_IN)
        sw.add(text)
        sw.show_all()
        dialog.vbox.pack_start(sw, expand=1, fill=1)

        dialog.add_button(_("I Agree"), gtk.RESPONSE_OK)
        dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)

        gtk.threads_enter()
        response = dialog.run()
        dialog.destroy()
        gtk.threads_leave()
        if response != gtk.RESPONSE_OK:
            self.pop()
            return 0

        return 1
Пример #5
0
    def prepare_stringed(self, rows, cols):
        # We use a Pixmap as offscreen drawing canvas
        cm = gtk.gdk.colormap_get_system()
        pm = gtk.gdk.Pixmap(None, self.width, self.height,
                            cm.get_visual().depth)
        #pangolayout = pm.create_pango_layout("")
        font_size = int(self.width / cols / 4)
        l = gtk.Label()
        pangolayout = pango.Layout(l.create_pango_context())
        pangolayout.set_font_description(
            pango.FontDescription("sans bold %i" % font_size))
        gc = pm.new_gc()
        gc.set_colormap(gtk.gdk.colormap_get_system())
        color = cm.alloc_color('white')
        gc.set_foreground(color)
        pm.draw_rectangle(gc, True, 0, 0, self.width, self.height)
        color = cm.alloc_color('black')
        gc.set_foreground(color)

        sw, sh = (self.width / cols), (self.height / rows)
        item = iter(self.tlist)
        for r in range(rows):
            for c in range(cols):
                px = sw * c
                py = sh * r
                #if c > 0 and r > 0:
                #    pm.draw_line(gc, px, 0, px, self.height-1)
                #    pm.draw_line(gc, 0, py, self.width-1, py)
                pangolayout.set_text(str(item.next()))
                pe = pangolayout.get_pixel_extents()
                pe = pe[1][2] / 2, pe[1][3] / 2
Пример #6
0
 def engrave(self, widget, gc, staff_yoffset):
     self.do_layout()
     dim = dimentions[self.m_fontsize]
     m = (self.m_xpos1 + self.m_xpos2) / 2
     if self.m_direction == const.UP or self.m_direction == const.BOTH:
         y = min(staff_yoffset - dim.linespacing * 3,
                 staff_yoffset + self.m_t * dim.linespacing / 2)
         d = 1
     else:  # == const.DOWN
         y = max(staff_yoffset + dim.linespacing * 5,
                 staff_yoffset + self.m_b * dim.linespacing / 2)
         d = -1
     if len(self.m_stems) > 1:
         # left horiz
         widget.window.draw_line(gc, self.m_xpos1, y, m - 6, y)
         # right horiz
         widget.window.draw_line(gc, m + 6, y, self.m_xpos2, y)
         # left vertic
         widget.window.draw_line(gc, self.m_xpos1, y, self.m_xpos1,
                                 y + 5 * d)
         # right vertic
         widget.window.draw_line(gc, self.m_xpos2, y, self.m_xpos2,
                                 y + 5 * d)
     cc = widget.create_pango_context()
     ll = pango.Layout(cc)
     ll.set_text(str(self.m_ratio.m_den))
     ll.set_font_description(pango.FontDescription("Sans 10"))
     sx, sy = [i / pango.SCALE for i in ll.get_size()]
     widget.window.draw_layout(gc, m - sx / 2, y - sy / 2, ll)
Пример #7
0
    def recalc_text_edges(self):
        if (not hasattr(self, "layout")):
            return
        del self.layout
        show_text = self.attrs_changed()

        r, g, b = utils.selected_colors["fill"]
        r *= 65536
        g *= 65536
        b *= 65536
        if self.index > self.end_index:
            bgsel = pango.AttrBackground(int(r), int(g), int(b),
                                         self.end_index, self.index)
        else:
            bgsel = pango.AttrBackground(int(r), int(g), int(b), self.index,
                                         self.end_index)
        self.attrlist.insert(bgsel)

        self.layout = pango.Layout(self.pango_context)
        self.layout.set_text(show_text)
        self.layout.set_attributes(self.attrlist)

        margin = utils.margin_required(utils.STYLE_NORMAL)
        text_w, text_h = self.layout.get_pixel_size()
        text_w += margin[0] + margin[2]
        text_h += margin[1] + margin[3]

        self.width = max(self.width, text_w)
        self.height = max(self.height, text_h)

        self.min_x = self.ul[0] + (self.width - text_w) / 2 + margin[0]
        self.min_y = self.ul[1] + (self.height - text_h) / 2 + margin[1]
        self.max_x = self.min_x + text_w
        self.max_y = self.min_y + text_h
        """
Пример #8
0
        def configure_event(widget, event):
            x, y, w, h = widget.get_allocation()
            self.pix_map = gtk.gdk.Pixmap(widget.window, w, h)

            # make colors
            self.gc = dict()
            for name, color in (('black', (0, 0, 0)), ('red', (32000, 0, 0)),
                                ('blue', (0, 0, 32000)), ('green', (0, 32000,
                                                                    0))):
                self.gc[name] = self.pix_map.new_gc()
                self.gc[name].set_rgb_fg_color(
                    gtk.gdk.Color(red=color[0], green=color[1], blue=color[2]))
            self.layout = pango.Layout(widget.create_pango_context())
            self.canvas_width = w
            self.canvas_height = h
            self.x_max = eval(x_max, {"__builtins__": {}}, safe_dict)
            self.x_min = eval(x_min, {"__builtins__": {}}, safe_dict)
            self.x_scale = eval(x_scale, {"__builtins__": {}}, safe_dict)
            self.y_max = eval(y_max, {"__builtins__": {}}, safe_dict)
            self.y_min = eval(y_min, {"__builtins__": {}}, safe_dict)
            self.y_scale = eval(y_scale, {"__builtins__": {}}, safe_dict)
            self.previousMouseX = 0
            self.previousMouseY = 0
            self.plot()
            return True
Пример #9
0
def draw_text_box_centered(ctx, widget, w_width, w_height, text, font_desc=None, add_progress=None):
    style = widget.rc_get_style()
    text_color = style.text[gtk.STATE_PRELIGHT]
    red, green, blue = text_color.red, text_color.green, text_color.blue
    text_color = [float(x)/65535. for x in (red, green, blue)]
    text_color.append(.5)

    if font_desc is None:
        font_desc = style.font_desc
        font_desc.set_size(14*pango.SCALE)

    pango_context = widget.create_pango_context()
    layout = pango.Layout(pango_context)
    layout.set_font_description(font_desc)
    layout.set_text(text)
    width, height = layout.get_pixel_size()

    ctx.move_to(w_width/2-width/2, w_height/2-height/2)
    ctx.set_source_rgba(*text_color)
    ctx.show_layout(layout)

    # Draw an optional progress bar below the text (same width)
    if add_progress is not None:
        bar_height = 10
        ctx.set_source_rgba(*text_color)
        ctx.set_line_width(1.)
        rounded_rectangle(ctx, w_width/2-width/2-.5, w_height/2+height-.5, width+1, bar_height+1)
        ctx.stroke()
        rounded_rectangle(ctx, w_width/2-width/2, w_height/2+height, int(width*add_progress)+.5, bar_height)
        ctx.fill()
Пример #10
0
    def __init__(self,
                 context,
                 parsed_elements_list=None,
                 color=None,
                 override_color=None,
                 scaling=1.0):
        pango.Layout.__init__(self, context)

        self._width = -1
        self._ellipsize = True
        self._elayout = pango.Layout(context)
        self._elayout.set_text('___')  #…
        self._elayout.set_ellipsize(pango.ELLIPSIZE_END)
        self._elayout.set_width(0)
        self._in_override = False  # color override mode, used for selected text
        self._base_to_center = 0
        self._text_height = 0
        self._smilies = {}  # key: (index_pos), value(pixbuf)
        self._base_attrlist = None  # no color
        self._attrlist = None  # with color
        self._override_attrlist = None  # with override color
        self.angle = 0

        self._color = color
        self._override_color = override_color

        self._smilies_scaled = {}  # key: (index_pos), value(pixbuf)
        self._scaling = scaling  # relative to ascent + desent, -1 for natural
        self._is_rtl = False

        self.set_element_list(parsed_elements_list)
        self._update_layout()
Пример #11
0
def render_to_job(job):
    pc = job.get_context()
    width, height = gnomeprint.job_get_page_size_from_config(job.get_config())

    ## <<<begin drawing>>>
    pc.beginpage("1")
    pc.setlinewidth(3.0)
    x1 = width*.1
    x2 = width*.9
    y1 = height*.1
    y2 = height*.9
    pc.rect_stroked(x1, y1, x2 - x1, y2 - y1)

    for l in l1, l2:
        pc.moveto(l[0], 600 - l[1])
        for i in xrange(len(l)/2):
            x = l[i*2]
            y = 600 - l[i*2 + 1]
            pc.lineto(x, y)
        pc.stroke()

    ## Draw a text paragraph using pango
    paraContext = gnomeprint.pango_create_context(gnomeprint.pango_get_default_font_map())
    para = pango.Layout(paraContext)
    para.set_font_description(pango.FontDescription("Sans 36"))
    para.set_markup("♪ Hello <b>World</b> ♪")
    w, h = para.get_size()
    w /= pango.SCALE
    h /= pango.SCALE
    pc.moveto(width - w, height - h)
    pc.pango_layout(para)

    pc.showpage()
    ## <<<end drawing>>>
    job.close()
Пример #12
0
    def render(self, text, antialias, color, background=None):
        """Render the font onto a new Surface and return it.
        We ignore 'antialias' and use system settings.
        NOTE: Due to a retarded implementation problem you cannot use 
        transparent colors. Alpha is ignored (set to 255)."""

        # create layout
        layout = pango.Layout(gtk.gdk.pango_context_get())
        layout.set_font_description(self.fd)
        layout.set_text(text)

        # determine pixel size
        (logical, ink) = layout.get_pixel_extents()
        ink = pygame.rect.Rect(ink)

        # Create a new Cairo ImageSurface
        csrf = cairo.ImageSurface(cairo.FORMAT_ARGB32, ink.w, ink.h)
        cctx = pangocairo.CairoContext(cairo.Context(csrf))

        # Mangle the colors on little-endian machines. The reason for this
        # is that Cairo writes native-endian 32-bit ARGB values whereas
        # Pygame expects endian-independent values in whatever format. So we
        # tell our users not to expect transparency here (avoiding the A issue)
        # and we swizzle all the colors around.
        big_endian = ((1, ) == struct.unpack("=i", "\0\0\0\001"))

        def mangle_color(color):
            if len(color) not in [3, 4]:
                raise ArgumentError(
                    "expected a 3- or 4-integer-tuple for color")
            if big_endian:
                # Big-endian; leave
                return (color[0] / 255.0, color[1] / 255.0, color[2] / 255.0,
                        1.0)
            else:
                # Little-endian; swizzle
                return (color[2] / 255.0, color[1] / 255.0, color[0] / 255.0,
                        1.0)

        # render onto it
        if background is not None:
            cctx.set_source_rgba(*mangle_color(background))
            cctx.paint()

        cctx.new_path()
        cctx.layout_path(layout)
        cctx.set_source_rgba(*mangle_color(color))
        cctx.fill()

        # Create and return a new Pygame Image derived from the Cairo Surface
        if big_endian:
            # You see, in big-endian-world, we can just use the RGB values
            format = "ARGB"
        else:
            # But with little endian, we've already swapped R and B in
            # mangle_color, so now just move the A
            format = "RGBA"
        return pygame.image.fromstring(str(csrf.get_data()), (ink.w, ink.h),
                                       format)
Пример #13
0
def print_pango_markup(self, context, markup):
    "Print some markup to the supplied context"
    ## need to use pango.Layout to format paragraphs
    ## for each block of text
    paraContext = gnomeprint.pango_create_context(gnomeprint.pango_get_default_font_map())
    para = pango.Layout(paraContext)
    para.set_markup(markup)
    context.pango_layout(para)
Пример #14
0
 def __init__(self, context, font, color, shadow):
     self.layout = pango.Layout(context)
     self.layout.set_wrap(pango.WRAP_WORD_CHAR)
     self.font = font
     self.color = color
     self.layout.set_font_description(font.description.copy())
     self.width = self.height = None
     self.shadow = shadow
Пример #15
0
 def __init__(self, antialias):
     G15Text.__init__(self, antialias)
     pangocairo.context_set_font_options(pango_context,
                                         self._create_font_options())
     self.__pango_cairo_context = None
     self.__layout = None
     self.valign = pango.ALIGN_CENTER
     self.__layout = pango.Layout(pango_context)
Пример #16
0
    def calculate_required_text_size(self, max_len):
        # "W" being the widest glyph.
        s = "W" * max_len
        layout = pango.Layout(gtk.Label("").get_pango_context())
        layout.set_text(s)
        (width, height) = layout.get_pixel_size()

        return (width, height)
Пример #17
0
 def stringSize(self, s, font=None):
     if font is None:
         font = self.defaultFont
     if self.pango_context is None:
         self.pango_context = self.area.get_pango_context()
     layout = pango.Layout(self.pango_context)
     layout.set_markup(self.createPangoMarkup(s, font))
     return layout.get_pixel_size()
Пример #18
0
 def __get_width(self):
     if not (self.flags() & gtk.REALIZED):
         return 80
     layout = pango.Layout(self.get_pango_context())
     letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
     layout.set_text(letters)
     pix_width = layout.get_pixel_size()[0]
     return self.allocation.width * len(letters) / pix_width
Пример #19
0
 def getTopExents(self, attr_list, text):
     c = pango.FontMap.create_context(
         pangocairo.cairo_font_map_get_default())
     l = pango.Layout(c)
     l.set_attributes(attr_list)
     l.set_text(text)
     line = l.get_line(0)
     return (line.get_pixel_extents()[1][3] - line.get_pixel_extents()[0][3]
             ) * (self.input_resolution / self.output_resolution)
Пример #20
0
def widget_get_char_height(widget):
    """
    Return maximum height in pixels of a single character.
    We create a Pango Layout, put in a line of lowercase+uppercase letters
    and read the height of the line."""
    pango_layout = pango.Layout(widget.get_pango_context())
    pango_layout.set_text(sys.modules['string'].ascii_letters)
    extents = pango_layout.get_line(0).get_pixel_extents()
    return int(extents[0][3] - extents[0][1])
Пример #21
0
    def __init__(self, suggested_items, *args, **kwargs):
        self._minimum_width_chars = kwargs.pop("minimum_width_chars", -1)
        self._maximum_width_chars = kwargs.pop("maximum_width_chars", -1)
        self._default_item_value = kwargs.pop("default_item", None)

        self._suggested_fields = _get_suggested_fields(suggested_items)

        suggested_item_values = [item[1] for item in suggested_items]
        if (self._default_item_value is not None
                and self._default_item_value not in suggested_item_values):
            raise ValueError(
                'default item "{0}" not in the list of suggested items: {1}'.
                format(self._default_item_value, suggested_item_values))

        kwargs["placeholder_text"] = (
            suggested_items[suggested_item_values.index(
                self._default_item_value)][0]
            if self._default_item_value is not None else None)

        super().__init__(*args, **kwargs)

        self._cursor_position = 0
        self._cursor_position_before_assigning_from_row = None
        self._reset_cursor_position_before_assigning_from_row = True

        self._last_field_name_with_tooltip = ""

        self._pango_layout = pango.Layout(self.get_pango_context())

        self._minimum_width = -1
        self._maximum_width = -1
        self.set_width_chars(self._minimum_width_chars)

        self._popup = pggui_entrypopup.EntryPopup(self, self._COLUMN_TYPES,
                                                  suggested_items)
        self._popup.filter_rows_func = self._filter_suggested_items
        self._popup.on_assign_from_selected_row = self._on_assign_from_selected_row
        self._popup.on_assign_last_value = self._assign_last_value
        self._popup.on_row_left_mouse_button_press = self._on_row_left_mouse_button_press
        self._popup.on_entry_changed_show_popup_condition = self._on_entry_changed_condition
        self._popup.on_entry_key_press = self._on_entry_key_press
        self._popup.on_entry_after_assign_by_key_press = (
            self._on_entry_after_assign_by_key_press)

        self._create_field_tooltip()

        self._add_columns()

        self.connect("insert-text", self._on_entry_insert_text)
        self.connect("delete-text", self._on_entry_delete_text)
        self.connect("notify::cursor-position",
                     self._on_entry_cursor_position_changed)
        self.connect("changed", self._on_entry_changed)

        self.connect("focus-out-event", self._on_entry_focus_out_event)

        self.connect("size-allocate", self._on_entry_size_allocate)
Пример #22
0
 def __init__(self, text, context, font, pressed, disabled=False):
     self.layout = pango.Layout(context)
     self.font = font
     self.layout.set_font_description(font.description.copy())
     self.layout.set_text(text)
     self.min_width = 0
     self.pressed = pressed
     self.disabled = disabled
     self.icon = None
Пример #23
0
 def __init__(self):
     ''' Init. '''
     self.font = self.get_font()
     self.linear_pos = LINEAR_POS
     self.pango_context = gtk.gdk.pango_context_get()
     self.pango_layout = pango.Layout(self.pango_context)
     self.text = ""
     self.linear_colors = LINEAR_COLORS
     self.update_font()
Пример #24
0
 def _get_pango_layout(self, text, single_paragraph_mode):
     layout = self._pango_layout
     if not layout:
         layout = pango.Layout(_pango_context)
         layout.set_font_description(self._pango_description)
         self._pango_layout = layout
     layout.set_single_paragraph_mode(single_paragraph_mode)
     layout.set_text(text)
     return layout
Пример #25
0
    def __init__(self, adjustment=None):
        gtk.Widget.__init__(self)
        self.set_flags(gtk.CAN_FOCUS)

        self.offscreen_pixmap = None
        self.palette = {}
        self.gc = {}

        self.cursor = gtk.gdk.Cursor(gtk.gdk.CROSS)

        context = self.create_pango_context()
        desc = context.get_font_description()
        desc.set_family("monospace")
        desc.set_absolute_size(12 * pango.SCALE)
        self.layout12 = pango.Layout(context)
        desc.set_absolute_size(10 * pango.SCALE)
        self.layout10 = pango.Layout(context)
        desc.set_absolute_size(9 * pango.SCALE)
        self.layout9 = pango.Layout(context)

        self.metrics = Metrics(self.layout10)

        self.adjustment = None
        self.handler_id_changed = -1
        self.handler_id_value_changed = -1

        self.player = Player(self)

        self.audiofile = ""
        self.caps = None
        self.data = array.array("b")
        self.loader_thread_id = -1
        self.fr_cut_in = 0
        self.fr_cut_out = 8000 * 60
        self.x_cue_pos = -1

        self.draw_solid = True
        self.draw_buf = {0: []}

        self.playback_status = (False, 0)

        if not adjustment:
            adjustment = gtk.Adjustment(0, 0, 8000 * 60, page_size=8000 * 60)
        self.set_adjustment(adjustment)
Пример #26
0
	def on_render(self, window, widget, background_area, cell_area, expose_area, flags):
		cairo_context = window.cairo_create()
		x = cell_area.x 
		y = cell_area.y 
		w = cell_area.width
		h = cell_area.height 
		if x == 0:
			curve_to = 'start'
		elif (x + w ) == widget.allocation.width:
			curve_to = 'end'
		else:
			curve_to = None
		self.render_rect(cairo_context, x, y, w, h, 1, curve_to)
		pat = cairo.LinearGradient(x, y, x, y + h)
		color = gtk.gdk.color_parse("#87D8F5")
		pat.add_color_stop_rgba(
							0.0,
							self.get_cairo_color(color.red),
							self.get_cairo_color(color.green),
							self.get_cairo_color(color.blue),
							1
							)
		color = gtk.gdk.color_parse(self.get_property('background'))
		pat.add_color_stop_rgb(
							1.0,
							self.get_cairo_color(color.red),
							self.get_cairo_color(color.green),
							self.get_cairo_color(color.blue)
							)
####	pat.add_color_stop_rgb(
####						0.8,
####						self.get_cairo_color(color.red),
####						self.get_cairo_color(color.green),
####						self.get_cairo_color(color.blue)
####						)

####	color = gtk.gdk.color_parse("#ffffff")
####	pat.add_color_stop_rgba(
####						1.0,
####						self.get_cairo_color(color.red),
####						self.get_cairo_color(color.green),
####						self.get_cairo_color(color.blue),
####						1
####						)

		cairo_context.set_source(pat)
		cairo_context.fill()

		context = widget.get_pango_context()
		layout = pango.Layout(context)
		layout.set_text(self.get_property('text'))
		layout.set_width(cell_area.width)
		widget.style.paint_layout(window, gtk.STATE_NORMAL, True,
					cell_area, widget, 'footext',
					cell_area.x, cell_area.y,
					layout)
Пример #27
0
    def _get_width_for_string(self, text):
        # Add some extra margin
        text = text + 'aaaaa'

        widget = gtk.Label('')
        context = widget.get_pango_context()
        layout = pango.Layout(context)
        layout.set_text(text)
        width, height_ = layout.get_size()
        return pango.PIXELS(width)
Пример #28
0
    def get_layout(self, pangocontext):
        font = pango.FontDescription()
        font.set_family("sans")
        font.set_size(self.font_size * pango.SCALE)

        layout = pango.Layout(pangocontext)
        layout.set_font_description(font)
        layout.set_text(self.text)

        return layout
Пример #29
0
def _get_pango_layout():

    if (not _DEPTH in _pango_layouts):
        w = gtk.HBox()
        w.set_colormap(_CMAP)
        ctx = gtk.HBox().get_pango_context()
        layout = pango.Layout(ctx)
        _pango_layouts[_DEPTH] = layout

    return _pango_layouts[_DEPTH]
Пример #30
0
 def update_line_height(self):
     pango_context = gtk.gdk.pango_context_get()
     pango_layout = pango.Layout(pango_context)
     font_desc = pango.FontDescription(self.get_font())
     pango_layout.set_font_description(font_desc)
     
     metrics = pango_context.get_metrics(pango_layout.get_font_description())
     ascent = metrics.get_ascent()
     descent = metrics.get_descent()
     line_height = (ascent + descent) / pango.SCALE + self.line_margin
     self.__line_height = line_height