Пример #1
0
 def baseline(self):
     # FIXME
     layout_height = pango.PIXELS(self._widget.get_layout().get_size()[1])
     ypad = (self._widget.size_request()[1] - layout_height) / 2
     pango_context = self._widget.get_pango_context()
     metrics = pango_context.get_metrics(self._widget.style.font_desc)
     return pango.PIXELS(metrics.get_descent()) + ypad
Пример #2
0
    def use_pango_font(font, start, count, will_call_prepost=False):
        import pango, cairo, pangocairo
        fontDesc = pango.FontDescription(font)
        a = array.array('b', itertools.repeat(0, 256 * 256))
        surface = cairo.ImageSurface.create_for_data(a, cairo.FORMAT_A8, 256,
                                                     256)
        context = pangocairo.CairoContext(cairo.Context(surface))
        layout = context.create_layout()
        fontmap = pangocairo.cairo_font_map_get_default()
        font = fontmap.load_font(fontmap.create_context(), fontDesc)
        layout.set_font_description(fontDesc)
        metrics = font.get_metrics()
        descent = metrics.get_descent()
        d = pango.PIXELS(descent)
        linespace = metrics.get_ascent() + metrics.get_descent()
        width = metrics.get_approximate_char_width()

        glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT)
        glPixelStorei(GL_UNPACK_SWAP_BYTES, 0)
        glPixelStorei(GL_UNPACK_LSB_FIRST, 1)
        glPixelStorei(GL_UNPACK_ROW_LENGTH, 256)
        glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 256)
        glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0)
        glPixelStorei(GL_UNPACK_SKIP_ROWS, 0)
        glPixelStorei(GL_UNPACK_SKIP_IMAGES, 0)
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
        glPixelZoom(1, -1)

        base = glGenLists(count)
        for i in range(count):
            ch = unichr(start + i)
            layout.set_text(ch)
            w, h = layout.get_size()
            context.save()
            context.new_path()
            context.rectangle(0, 0, 256, 256)
            context.set_source_rgba(0., 0., 0., 0.)
            context.set_operator(cairo.OPERATOR_SOURCE)
            context.paint()
            context.restore()

            context.save()
            context.set_source_rgba(1., 1., 1., 1.)
            context.set_operator(cairo.OPERATOR_SOURCE)
            context.move_to(0, 0)
            context.update_layout(layout)
            context.show_layout(layout)
            context.restore()

            w, h = pango.PIXELS(w), pango.PIXELS(h)
            glNewList(base + i, GL_COMPILE)
            glBitmap(0, 0, 0, 0, 0, h - d, '')
            if not will_call_prepost: pango_font_pre()
            if w and h: glDrawPixels(w, h, GL_LUMINANCE, GL_UNSIGNED_BYTE, a)
            glBitmap(0, 0, 0, 0, w, -h + d, '')
            if not will_call_prepost: pango_font_post()
            glEndList()

        glPopClientAttrib()
        return base, pango.PIXELS(width), pango.PIXELS(linespace)
Пример #3
0
def tab_label_style_set_cb (tab_label, style):
    context = tab_label.get_pango_context()
    metrics = context.get_metrics(tab_label.style.font_desc, context.get_language())
    char_width = metrics.get_approximate_digit_width()
    (width, height) = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)
    tab_label.set_size_request(16 * pango.PIXELS(char_width) + 2 * width,
                               pango.PIXELS(metrics.get_ascent() +
    metrics.get_descent()) +2)
Пример #4
0
    def show(self, text, x, y):
        """
        Show the window with the given text, its top-left corner at x-y.
        Decide on initial size.
        """
        # The initial size is the minimum of:
        # * N_COLS*N_ROWS
        # * Whatever fits into the screen
        # * The actual content

        tv = self.textview
        vs = self.vscrollbar
        win = self.window

        text = text.replace('\0', '')  # Fixes bug #611513

        win.hide()
        tv.get_buffer().set_text(text)

        f_width = self.char_width * N_COLS
        f_height = self.char_height * N_ROWS

        s_width = gdk.screen_width() - x
        s_height = gdk.screen_height() - y

        # Get the size of the contents
        layout = tv.create_pango_layout(text)
        p_width, p_height = layout.get_size()
        c_width = pango.PIXELS(p_width)
        c_height = pango.PIXELS(p_height)
        del layout

        add_width = vs.size_request()[0] + 5
        width = int(min(f_width, s_width, c_width) + add_width)
        height = int(min(f_height, s_height, c_height))

        # Don't show the vertical scrollbar if the height is short enough.
        vs.props.visible = (height > vs.size_request()[1])

        win.resize(width, height)

        win.move(x, y)

        self.hscrollbar.props.adjustment.props.value = 0
        self.vscrollbar.props.adjustment.props.value = 0

        self.sourceview.handler_unblock(self.keypress_handler)
        self.keypress_handler_blocked = False

        win.show()

        # This has to be done after the textview was displayed
        if not self.was_displayed:
            self.was_displayed = True
            hand = gdk.Cursor(gdk.HAND1)
            tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(hand)
            br_corner = gdk.Cursor(gdk.BOTTOM_RIGHT_CORNER)
            self.resizegrip.window.set_cursor(br_corner)
Пример #5
0
 def measure_font(self):
     # dummy fixed width character we be working with.
     self.layout.set_text("X")
     # get the logical extents
     extents = self.layout.get_extents()[1]
     # logical extent width
     self.width = pango.PIXELS(extents[2])
     # logical extent height
     self.height = pango.PIXELS(extents[3])
     self.ascent = pango.PIXELS(self.layout.get_iter().get_baseline())
Пример #6
0
 def get_char_size(textview):
     """
     Get width, height of a character in pixels.
     """
     tv = textview
     context = tv.get_pango_context()
     metrics = context.get_metrics(tv.style.font_desc,
                                   context.get_language())
     width = pango.PIXELS(metrics.get_approximate_digit_width())
     height = pango.PIXELS(metrics.get_ascent() + metrics.get_descent())
     return width, height
Пример #7
0
        def get_default_size(self):
            context = self.get_pango_context()
            metrics = context.get_metrics(context.get_font_description(),
                                          context.get_language())
            width = metrics.get_approximate_char_width()
            height = metrics.get_ascent() + metrics.get_descent()

            # Default to a 80x40 console
            width = pango.PIXELS(int(width * 80 * 1.05))
            height = pango.PIXELS(height * 40)

            return width, height
Пример #8
0
 def draw(self, context, x, baseline, line):
     baseline = round(baseline) + 0.5
     context.set_line_width(1)
     while not self.finished and line.start_index <= self.startpos:
         startpos = max(line.start_index, self.startpos)
         endpos = min(self.endpos, line.start_index + line.length)
         x1 = x + pango.PIXELS(line.index_to_x(startpos, 0))
         x2 = x + pango.PIXELS(line.index_to_x(endpos, 1))
         context.move_to(x1, baseline + 1)
         context.line_to(x2, baseline + 1)
         context.stroke()
         if endpos < self.endpos:
             break
         else:
             self.next_underline()
Пример #9
0
    def update_layout(self, rectangle=None):
        if rectangle is None:
            rectangle = self.allocation
        # print 'updating layout'
        self.available_width = rectangle[2] - 2 * BORDER_SIZE
        self.cell_width = self.thumbnail_width + 2 * CELL_BORDER_WIDTH
        self.cell_height = self.thumbnail_height + 2 * CELL_BORDER_WIDTH
        self.cells_per_row = max(int(self.available_width / self.cell_width),
                                 1)
        self.cell_width += \
            (self.available_width - self.cells_per_row * self.cell_width) \
            / self.cells_per_row

        if True:  # display date
            metrics = self.get_pango_context().\
                get_metrics(self.style.font_desc, pango.Language('en_US'))
            self.cell_height += pango.PIXELS(metrics.get_ascent() +
                                             metrics.get_descent())

        self.num_thumbnails = len(self.items)
        self.num_rows = int(self.num_thumbnails / self.cells_per_row)
        if self.num_thumbnails % self.cells_per_row:
            self.num_rows += 1

        self.height = int(self.num_rows * self.cell_height + 2 * BORDER_SIZE)

        vadjustment = self.get_vadjustment()
        hadjustment = self.get_hadjustment()
        vadjustment.step_increment = self.cell_height
        x = hadjustment.value
        y = self.height * self.scroll_value
        self.set_size(x, y, self.allocation.width, self.height)
Пример #10
0
 def _adjust_size_request(self):
     context = self.get_pango_context()
     metrics = context.get_metrics(self._fdesc)
     width = pango.PIXELS(metrics.get_approximate_char_width() * self._width_in_chars)
     height = int(width * self._aspect_ratio)
     x, y = self.buffer_to_window_coords(gtk.TEXT_WINDOW_TEXT, width, height)
     self.set_size_request(x, y)
Пример #11
0
    def use_two_line_format(self):
        if not self.get_parent():
            return False

        popup_dir = self.get_parent().get_orient()

        orient_vertical = popup_dir in [gnomeapplet.ORIENT_LEFT] or \
                          popup_dir in [gnomeapplet.ORIENT_RIGHT]

        context = self.label.get_pango_context()
        metrics = context.get_metrics(self.label.style.font_desc,
                                      pango.Context.get_language(context))
        ascent = pango.FontMetrics.get_ascent(metrics)
        descent = pango.FontMetrics.get_descent(metrics)

        if orient_vertical == False:
            thickness = self.style.ythickness
        else:
            thickness = self.style.xthickness

        focus_width = self.style_get_property("focus-line-width")
        focus_pad = self.style_get_property("focus-padding")

        required_size = 2 * ((pango.PIXELS(ascent + descent)) + 2 *
                             (focus_width + focus_pad + thickness))

        if orient_vertical:
            available_size = self.get_allocation().width
        else:
            available_size = self.get_allocation().height

        return required_size <= available_size
Пример #12
0
    def __init__(self, field_type):
        gtk.Label.__init__(self)
        self.set_selectable(True)

        self.field_type = field_type

        if field_type.right_justify:
            set_props(self, xalign=1.0)
        else:
            set_props(self, xalign=0.0)

        self.modify_font(INFO_LABEL_FONT)

        if hasattr(field_type, 'width_chars'):
            context = self.get_pango_context()

            desc = INFO_LABEL_FONT.copy()
            desc.set_size(context.get_font_description().get_size())

            metrics = context.get_metrics(desc, context.get_language())

            char_width = metrics.get_approximate_char_width()
            digit_width = metrics.get_approximate_digit_width()
            char_pixels = pango.PIXELS(max(char_width, digit_width))

            self.set_size_request(char_pixels * field_type.width_chars, -1)
Пример #13
0
    def get_pixel_size(self):
        natural_width, natural_height = pango.Layout.get_pixel_size(self)

        if self._width >= 0 and self._ellipsize:  # if ellipsize
            return pango.PIXELS(self._width), natural_height
        else:
            return natural_width, natural_height
Пример #14
0
def cairo_add_text_in_widget_style(context,
                                   text,
                                   widget=None,
                                   size_factor=1.2,
                                   weight='normal',
                                   alignment='left'):
    weight = {
        'normal': cairo.FONT_WEIGHT_NORMAL,
        'bold': cairo.FONT_WEIGHT_BOLD
    }[weight.lower()]

    if widget != None:
        context.set_source_rgb(
            *gdk_color_to_float(widget.get_style().text[gtk.STATE_NORMAL]))
        context.select_font_face(widget.get_style().font_desc.get_family(),
                                 cairo.FONT_SLANT_NORMAL, weight)
        context.set_font_size(
            pango.PIXELS(widget.get_style().font_desc.get_size()) *
            size_factor)

    x_bearing, y_bearing, width, height = context.text_extents(text)[:4]

    if alignment.lower() == 'left':
        context.move_to(x_bearing,
                        widget.allocation.height / 2 - height / 2 - y_bearing)
    elif alignment.lower() == 'right':
        context.move_to(widget.allocation.width - width - x_bearing,
                        widget.allocation.height / 2 - height / 2 - y_bearing)
    elif alignment.lower() == 'center':
        context.move_to(widget.allocation.width / 2 - width / 2 - x_bearing,
                        widget.allocation.height / 2 - height / 2 - y_bearing)

    context.show_text(text)
Пример #15
0
    def baseline(self):
        my_size = self._widget.size_request()
        child_size = self._widget.child.size_request()
        ypad = (my_size[1] - child_size[1]) / 2

        pango_context = self._widget.get_pango_context()
        metrics = pango_context.get_metrics(self._widget.style.font_desc)
        return pango.PIXELS(metrics.get_descent()) + ypad
Пример #16
0
    def box_size(self, widget):
        """Calculate box size based on widget's font.

        Cache this as it's probably expensive to get.  It ensures that we
        draw the graph at least as large as the text.
        """
        try:
            return self._box_size
        except AttributeError:
            pango_ctx = widget.get_pango_context()
            font_desc = widget.get_style().font_desc
            metrics = pango_ctx.get_metrics(font_desc)

            ascent = pango.PIXELS(metrics.get_ascent())
            descent = pango.PIXELS(metrics.get_descent())

            self._box_size = ascent + descent + 1
            return self._box_size
Пример #17
0
    def get_max_char_size(self):
        context = self.get_pango_context()
        metrics = context.get_metrics(self.style.font_desc,
                                      context.get_language())

        # width
        char_width = metrics.get_approximate_char_width()
        digit_width = metrics.get_approximate_digit_width()
        max_char_width = pango.PIXELS(
            int(max(char_width, digit_width) * self.DEFAULT_FONT_SCALE))

        # height
        ascent = metrics.get_ascent()
        descent = metrics.get_descent()
        max_char_height = pango.PIXELS(
            int((ascent + descent) * self.DEFAULT_FONT_SCALE))

        return (max_char_width, max_char_height)
Пример #18
0
    def __on_size_request(self, widget, alloc):
        ctx = self.get_pango_context()
        font = ctx.load_font(pango.FontDescription(self._parent.font))
        metric = font.get_metrics(ctx.get_language())

        w = pango.PIXELS(metric.get_approximate_char_width()) * (self.off_len + 1)
        w += 2

        if alloc.width < w:
            alloc.width = w
Пример #19
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)
Пример #20
0
def get_max_text_length(length_to_check, text, widget):
    if widget == None:
        return 0
    context = widget.get_pango_context()
    metrics = context.get_metrics(context.get_font_description())
    current_length = pango.PIXELS(metrics.get_approximate_char_width() *
                                  len(text))
    if current_length > length_to_check:
        return current_length
    else:
        return length_to_check
Пример #21
0
def tab_label_style_set_cb(tab_label, style):
    context = tab_label.get_pango_context()
    metrics = context.get_metrics(tab_label.style.font_desc,
                                  context.get_language())
    char_width = metrics.get_approximate_digit_width()
    (width,
     height) = gtk.icon_size_lookup_for_settings(tab_label.get_settings(),
                                                 gtk.ICON_SIZE_MENU)
    tab_label.set_size_request(20 * pango.PIXELS(char_width) + 2 * width, -1)
    button = tab_label.get_data("close-button")
    button.set_size_request(width + 4, height + 4)
Пример #22
0
    def do_get_size(self, widget, cell_area):
        context = widget.get_pango_context()
        metrics = context.get_metrics(widget.style.font_desc,
                                      context.get_language())
        row_height = metrics.get_ascent() + metrics.get_descent()
        height = pango.PIXELS(row_height) + self._ypad * 2

        layout = widget.create_pango_layout(self.text)
        (row_width, layout_height) = layout.get_pixel_size()
        width = row_width + self._xpad * 2

        return (0, 0, width, height)
Пример #23
0
	def Show(self):
		if utils.RUNNING_HILDON:
			self._all_tags_treeview.set_property('height-request', 150)
			self.resize(650,300)
	
		context = self.create_pango_context()
		style = self.get_style().copy()
		font_desc = style.font_desc
		metrics = context.get_metrics(font_desc, None)
		char_width = metrics.get_approximate_char_width()
		
		widest_left = 15
		widest_right = 0
		
		for row in self._all_tags_model:
			width = len(row[F_DISPLAY])
			if width > widest_right:
				widest_right = width
				
		for row in self._favorites_model:
			width = len(row[F_DISPLAY])
			if width > widest_left:
				widest_left = width
		
		self._pane_position = pango.PIXELS((widest_left+10)*char_width)
		self._window_width  = pango.PIXELS((widest_left+widest_right+10)*char_width)+100
		
		if not utils.RUNNING_HILDON:
			self.resize(self._window_width,1)
		self._pane.set_position(self._pane_position)
		self._favorites_treeview.columns_autosize()
		self._all_tags_treeview.columns_autosize()
		
		self.set_transient_for(self._main_window.get_parent())
		
		self.show_all()
		
		if utils.RUNNING_HILDON:
			self._pane_position = 250
			self._pane.set_position(self._pane_position)
Пример #24
0
    def do_size_request(self, requisition):
        """
        The do_size_request method Gtk+ is called on a widget to ask it the
        widget how large it wishes to be.
        It's not guaranteed that gtk+ will actually give this size to the
        widget.
        """
        self.ensure_style()
        context = self.get_pango_context()
        metrics = context.get_metrics(self.style.font_desc,
                                      context.get_language())

        # width
        char_width = metrics.get_approximate_char_width()
        digit_width = metrics.get_approximate_digit_width()
        char_pixels = pango.PIXELS(
            int(max(char_width, digit_width) * self.DEFAULT_FONT_SCALE))
        requisition.width = char_pixels + self._padding * 2

        # height
        ascent = metrics.get_ascent()
        descent = metrics.get_descent()
        requisition.height = pango.PIXELS(ascent + descent) + self._padding * 2
Пример #25
0
    def __init__(self, iconname, text, onclose):
        gtk.HBox.__init__(self, False, 4)

        label = gtk.Label(text)
        # FIXME: ideally, we would use custom ellipsization that ellipsized the
        # two paths separately, but that requires significant changes to label
        # generation in many different parts of the code
        label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
        label.set_single_line_mode(True)
        label.set_alignment(0.0, 0.5)
        label.set_padding(0, 0)

        context = self.get_pango_context()
        metrics = context.get_metrics(self.style.font_desc,
                                      context.get_language())
        char_width = metrics.get_approximate_digit_width()
        (w, h) = gtk.icon_size_lookup_for_settings(self.get_settings(),
                                                   gtk.ICON_SIZE_MENU)
        self.set_size_request(
            self.tab_width_in_chars * pango.PIXELS(char_width) + 2 * w, -1)

        button = gtk.Button()
        button.set_relief(gtk.RELIEF_NONE)
        button.set_focus_on_click(False)
        image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
        if gtk.pygtk_version >= (2, 12, 0):
            image.set_tooltip_text(_("Close tab"))
        button.add(image)
        button.set_name("meld-tab-close-button")
        button.set_size_request(w + 2, h + 2)
        button.connect("clicked", onclose)

        icon = gtk.image_new_from_icon_name(iconname, gtk.ICON_SIZE_MENU)

        label_box = gtk.EventBox()
        label_box.add_events(gtk.gdk.BUTTON_PRESS_MASK)
        label_box.props.visible_window = False
        label_box.connect("button-press-event", self.on_label_clicked)
        label_box.add(label)

        self.pack_start(icon, expand=False)
        self.pack_start(label_box)
        self.pack_start(button, expand=False)
        if gtk.pygtk_version >= (2, 12, 0):
            self.set_tooltip_text(text)
        self.show_all()

        self.__label = label
        self.__onclose = onclose
Пример #26
0
    def tab_stops_expose(self, widget, event):
        #print self, widget, event
        text_view = widget

        # See if this expose is on the tab stop window
        top_win = text_view.get_window(gtk.TEXT_WINDOW_TOP)
        bottom_win = text_view.get_window(gtk.TEXT_WINDOW_BOTTOM)

        if event.window == top_win:
            type = gtk.TEXT_WINDOW_TOP
            target = top_win
        elif event.window == bottom_win:
            type = gtk.TEXT_WINDOW_BOTTOM
            target = bottom_win
        else:
            return False

        first_x = event.area.x
        last_x = first_x + event.area.width

        first_x, y = text_view.window_to_buffer_coords(type, first_x, 0)
        last_x, y = text_view.window_to_buffer_coords(type, last_x, 0)

        buffer = text_view.get_buffer()
        insert = buffer.get_iter_at_mark(buffer.get_insert())
        attrs = gtk.TextAttributes()
        insert.get_attributes(attrs)

        tabslist = []
        in_pixels = False
        if attrs.tabs:
            tabslist = attrs.tabs.get_tabs()
            in_pixels = attrs.tabs.get_positions_in_pixels()

        for align, position in tabslist:
            if not in_pixels:
                position = pango.PIXELS(position)

            pos, y = text_view.buffer_to_window_coords(type, position, 0)
            target.draw_line(text_view.style.fg_gc[text_view.state], pos, 0,
                             pos, 15)

        return True
Пример #27
0
    def reaffichage_tabs(self, widget, evenement):
        #print self, widget, evenement
        zonetexte = widget

        # On controle si l'evenement vient des fenetres avec tabulations
        fenetre_sup = zonetexte.get_window(gtk.TEXT_WINDOW_TOP)
        fenetre_inf = zonetexte.get_window(gtk.TEXT_WINDOW_BOTTOM)

        if evenement.window == fenetre_sup:
            type = gtk.TEXT_WINDOW_TOP
            cible = fenetre_sup
        elif evenement.window == fenetre_inf:
            type = gtk.TEXT_WINDOW_BOTTOM
            cible = fenetre_inf
        else:
            return False

        premier_x = evenement.area.x
        dernier_x = premier_x + evenement.area.width

        premier_x, y = zonetexte.window_to_buffer_coords(type, premier_x, 0)
        dernier_x, y = zonetexte.window_to_buffer_coords(type, dernier_x, 0)

        buffer = zonetexte.get_buffer()
        curseur = buffer.get_iter_at_mark(buffer.get_insert())
        attrs = gtk.TextAttributes()
        curseur.get_attributes(attrs)

        listetabs = []
        en_pixels = False
        if attrs.tabs:
            listetabs = attrs.tabs.get_tabs()
            en_pixels = attrs.tabs.get_positions_in_pixels()

        for align, position in listetabs:
            if not en_pixels:
                position = pango.PIXELS(position)

            pos, y = zonetexte.buffer_to_window_coords(type, position, 0)
            cible.draw_line(zonetexte.style.fg_gc[zonetexte.state], pos, 0,
                            pos, 15)

        return True
Пример #28
0
    def __init__(self):
        """
            Retorna: un EditorSatusbar.

            Crea un nuevo EditorSatusbar.
        """

        gtk.Statusbar.__init__(self)

        # Creacion de la barra de estado con el modo de insercion.
        self.__overwrite_sb = gtk.Statusbar()

        # Creacion de la barra de estado con la posicion del cursor.
        self.__cursor_sb = gtk.Statusbar()

        # Obtenemos el ancho en pixeles del caracter mas ancho.
        context = self.__overwrite_sb.get_pango_context()
        font = self.__overwrite_sb.style.font_desc
        metrics = context.get_metrics(font, context.get_language())
        digit_width = metrics.get_approximate_digit_width()
        char_width = metrics.get_approximate_char_width()
        width = pango.PIXELS(max(char_width, digit_width))

        # Reservamos espacio para evitar el crecimiento de las barras.
        self.__overwrite_sb.set_size_request(width * 3 + 38, -1)
        self.__cursor_sb.set_size_request(width * 17 + 8, -1)

        self.pack_end(self.__overwrite_sb, False, True, 0)
        self.pack_end(self.__cursor_sb, False, True, 0)

        gtk.Statusbar.set_has_resize_grip(self, False)
        self.__overwrite_sb.set_has_resize_grip(True)
        self.__cursor_sb.set_has_resize_grip(False)

        # tmp flash timeout data
        self.__flash_timeout_id = None
        self.__flash_context_id = None
        self.__flash_message_id = None

        self.connect("destroy", self.on_destroy)
Пример #29
0
    def __init__(self, controlState, xml):
        controlState.displayHeaderBar = True
        controlState.windowIcon = 'abouttoinstall.png'
        controlState.windowTitle = "Summary of installation settings"
        controlState.windowText = \
            "Review the summary of the installation settings"

        htmlTextView = HtmlTextView()
        htmlTextView.set_wrap_mode(gtk.WRAP_NONE)
        context = htmlTextView.get_pango_context()
        initialFont = context.get_font_description()
        # The review uses monospace, so get the font description for that at the
        # same size as the default font used by the text view.
        metrics = context.get_metrics(
            pango.FontDescription('monospace, %d' %
                                  (initialFont.get_size() / pango.SCALE)))

        # Generate the list of tab stops from the column widths specified in
        # the review module.
        tabPosition = 0
        ta = pango.TabArray(len(review.COLUMN_WIDTHS), True)
        for index, charWidth in enumerate(review.COLUMN_WIDTHS):
            tabPosition += pango.PIXELS(metrics.get_approximate_char_width() *
                                        charWidth)
            ta.set_tab(index, pango.TAB_LEFT, tabPosition)

        htmlTextView.set_tabs(ta)

        buf = review.produceText()
        htmlTextView.display_html(buf)

        viewPort = xml.get_widget('ReviewViewPort')
        assert (viewPort)
        for child in viewPort.get_children():
            viewPort.remove(child)
        viewPort.add(htmlTextView)

        htmlTextView.show()
Пример #30
0
    def __init__(self, parent):
        gnomeglade.Component.__init__(self, paths.ui_dir("vcview.ui"),
                                      "commitdialog")
        self.parent = parent
        self.widget.set_transient_for(parent.widget.get_toplevel())
        selected = parent._get_selected_files()

        try:
            to_commit = parent.vc.get_files_to_commit(selected)
            topdir = parent.vc.root
            if to_commit:
                to_commit = ["\t" + s for s in to_commit]
            else:
                to_commit = ["\t" + _("No files will be committed")]
        except NotImplementedError:
            topdir = _commonprefix(selected)
            to_commit = ["\t" + s[len(topdir) + 1:] for s in selected]
        self.changedfiles.set_text("(in %s)\n%s" %
                                   (topdir, "\n".join(to_commit)))

        fontdesc = pango.FontDescription(self.parent.prefs.get_current_font())
        self.textview.modify_font(fontdesc)
        commit_prefill = self.parent.vc.get_commit_message_prefill()
        if commit_prefill:
            buf = self.textview.get_buffer()
            buf.set_text(commit_prefill)
            buf.place_cursor(buf.get_start_iter())

        # Try and make the textview wide enough for a standard 80-character
        # commit message.
        context = self.textview.get_pango_context()
        metrics = context.get_metrics(fontdesc, context.get_language())
        char_width = metrics.get_approximate_char_width()
        self.textview.set_size_request(80 * pango.PIXELS(char_width), -1)

        self.widget.show_all()