Exemple #1
0
    def __init__(self):
        gtk.VBox.__init__(self)
        self.set_spacing(6)
        # Setup some child widgets
        self._expander = gtk.Expander(_("Details"))
        self._terminal = vte.Terminal()
        #self._terminal.set_font_from_string("monospace 10")
        self._expander.add(self._terminal)
        self._progressbar = gtk.ProgressBar()
        # Setup the always italic status label
        self._label = gtk.Label()
        attr_list = pango.AttrList()
        attr_list.insert(pango.AttrStyle(pango.STYLE_ITALIC, 0, -1))
        self._label.set_attributes(attr_list)
        self._label.set_ellipsize(pango.ELLIPSIZE_END)
        self._label.set_alignment(0, 0)
        # add child widgets
        self.pack_start(self._progressbar, False)
        self.pack_start(self._label, False)
        self.pack_start(self._expander, False)
        # Setup the internal progress handlers
        self._progress_open = GOpProgress()
        self._progress_open.connect("status-changed", self._on_status_changed)
        self._progress_open.connect("status-started", self._on_status_started)
        self._progress_open.connect("status-finished",
                                    self._on_status_finished)
        self._progress_acquire = GAcquireProgress()
        self._progress_acquire.connect("status-changed",
                                       self._on_status_changed)
        self._progress_acquire.connect("status-started",
                                       self._on_status_started)
        self._progress_acquire.connect("status-finished",
                                     self._on_status_finished)

        self._progress_fetch = None
        self._progress_install = GInstallProgress(self._terminal)
        self._progress_install.connect("status-changed",
                                       self._on_status_changed)
        self._progress_install.connect("status-started",
                                       self._on_status_started)
        self._progress_install.connect("status-finished",
                                     self._on_status_finished)
        self._progress_install.connect("status-timeout",
                                     self._on_status_timeout)
        self._progress_install.connect("status-error",
                                     self._on_status_timeout)
        self._progress_install.connect("status-conffile",
                                     self._on_status_timeout)
Exemple #2
0
def get_label_attributes(readonly, required):
    "Return the pango attributes applied to a label according to its state"
    if readonly:
        style = pango.STYLE_NORMAL
        weight = pango.WEIGHT_NORMAL
    else:
        style = pango.STYLE_ITALIC
        if required:
            weight = pango.WEIGHT_BOLD
        else:
            weight = pango.WEIGHT_NORMAL
    attrlist = pango.AttrList()
    if hasattr(pango, 'AttrWeight'):
        attrlist.change(pango.AttrWeight(weight, 0, -1))
    if hasattr(pango, 'AttrStyle'):
        attrlist.change(pango.AttrStyle(style, 0, -1))
    return attrlist
Exemple #3
0
    def __begin(self, ctx):
        """ callback dor drag-begin signal 
        Enable the display of moved rows.

        At MAX 3 rows ares shown during motion.
        """
        model, paths = self.get_selection().get_selected_rows()
        MAX = 3
        if paths:
            icons = map(self.create_row_drag_icon, paths[:MAX])
            height = (
                sum(map(lambda s: s.get_size()[1], icons))-2*len(icons))+2
            width = max(map(lambda s: s.get_size()[0], icons))
            final = gtk.gdk.Pixmap(icons[0], width, height)
            gc = gtk.gdk.GC(final)
            gc.copy(self.style.fg_gc[gtk.STATE_NORMAL])
            gc.set_colormap(self.window.get_colormap())
            count_y = 1
            for icon in icons:
                w, h = icon.get_size()
                final.draw_drawable(gc, icon, 1, 1, 1, count_y, w-2, h-2)
                count_y += h - 2
            if len(paths) > MAX:
                count_y -= h - 2
                bgc = gtk.gdk.GC(final)
                bgc.copy(self.style.base_gc[gtk.STATE_NORMAL])
                final.draw_rectangle(bgc, True, 1, count_y, w-2, h-2)
                more = ("and %d more...") % (len(paths) - MAX + 1)
                layout = self.create_pango_layout(more)
                attrs = pango.AttrList()
                attrs.insert(pango.AttrStyle(pango.STYLE_ITALIC, 0, len(more)))
                layout.set_attributes(attrs)
                layout.set_width(pango.SCALE * (w - 2))
                lw, lh = layout.get_pixel_size()
                final.draw_layout(gc, (w-lw)//2, count_y + (h-lh)//2, layout)

            final.draw_rectangle(gc, False, 0, 0, width-1, height-1)
            self.drag_source_set_icon(final.get_colormap(), final)
        else:
            gobject.idle_add(ctx.drag_abort, gtk.get_current_event_time())
            self.drag_source_set_icon_stock(gtk.STOCK_MISSING_IMAGE)
    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)
Exemple #5
0
    def __init__(self, display_tracklist=False):
        """
            :param display_tracklist: Whether to display
                a short list of tracks
        """
        gtk.Alignment.__init__(self)

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

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

        self._display_tracklist = display_tracklist

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

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

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

            self.rownumber = 1
            self.pango_attributes = pango.AttrList()
            self.pango_attributes.insert(
                pango.AttrScale(pango.SCALE_SMALL, end_index=-1))
            self.pango_attributes.insert(
                pango.AttrStyle(pango.STYLE_ITALIC, end_index=-1))
            self.ellipse_pango_attributes = pango.AttrList()
            self.ellipse_pango_attributes.insert(
                pango.AttrWeight(pango.WEIGHT_BOLD, end_index=-1))
 def setup_default_tags (self):
     self.italics = self.get_tags_from_attrs(None,None,[pango.AttrStyle('italic')])[0]
     self.bold = self.get_tags_from_attrs(None,None,[pango.AttrWeight('bold')])[0]
     self.underline = self.get_tags_from_attrs(None,None,[pango.AttrUnderline('single')])[0]
Exemple #7
0
 def get_calculated_rect(self, context, rect):
     angle = 2 * math.pi * self._rotation / 360.0
     
     if self._context == None:
         label = gtk.Label()
         self._context = label.create_pango_context()          
     pango_context = self._context
     
     attrs = pango.AttrList()
     attrs.insert(pango.AttrWeight(self._weight, 0, len(self._text)))
     attrs.insert(pango.AttrStyle(self._slant, 0, len(self._text)))
     attrs.insert(pango.AttrUnderline(self._underline, 0,
                     len(self._text)))
     if self._size != None:
         attrs.insert(pango.AttrSize(1000 * self._size, 0,
                         len(self._text)))
     
     if self._layout == None:
         self._layout = pango.Layout(pango_context)
     layout = self._layout
     if self._markup:
         layout.set_markup(self._text)
     else:
         layout.set_text(self._text)
         layout.set_attributes(attrs)
     
     #find out where to draw the layout and calculate the maximum width
     width = rect.width * math.cos(angle) + rect.height * math.sin(angle)
     if self._anchor in [ANCHOR_BOTTOM_LEFT, ANCHOR_TOP_LEFT,
                         ANCHOR_LEFT_CENTER]:
         width = rect.width - self._position[0]
     elif self._anchor in [ANCHOR_BOTTOM_RIGHT, ANCHOR_TOP_RIGHT,
                             ANCHOR_RIGHT_CENTER]:
         width = self._position[0]
     
     text_width, text_height = layout.get_pixel_size()
     width = min(width, self._max_width)
     
     if self._wrap:
         layout.set_wrap(pango.WRAP_WORD_CHAR)
     layout.set_width(int(1000 * width))
     
     #======================================================================
     text_width, text_height = layout.get_pixel_size()
     anchor = self._anchor
     x, y = self._position
 
     #anchor translation
     tx, ty = 0, 0
     ttx, tty = 0, 0
     if anchor == ANCHOR_BOTTOM_LEFT:
         tx = text_height * math.sin(angle)
         ty = text_height * math.cos(angle)
         ttx = 0
         tty = text_height
     elif anchor == ANCHOR_TOP_LEFT:
         tx = 0
         ty = 0
     elif anchor ==  ANCHOR_TOP_RIGHT:
         tx = text_width * math.cos(angle)
         ty = -text_width * math.sin(angle)
         ttx = text_width
         tty = 0
     elif anchor == ANCHOR_BOTTOM_RIGHT:
         tx = text_width * math.cos(angle) + text_height * math.sin(angle)
         ty = -text_width * math.sin(angle) + text_height * math.cos(angle)
         ttx = text_width
         tty = text_height
     elif anchor == ANCHOR_CENTER:
         tx = (text_width * math.cos(angle) + text_height * math.sin(angle)) / 2
         ty = (-text_width * math.sin(angle) + text_height * math.cos(angle)) / 2
         ttx = text_width / 2
         tty = text_height / 2
     elif anchor == ANCHOR_TOP_CENTER:
         tx = text_width * math.cos(angle) / 2
         ty = -text_width * math.sin(angle) / 2
         ttx = text_width / 2
         tty = 0
     elif anchor == ANCHOR_BOTTOM_CENTER:
         tx = text_width * math.cos(angle) / 2 + text_height * math.sin(angle)
         ty = -text_width * math.sin(angle) / 2 + text_height * math.cos(angle)
         ttx = text_width / 2
         tty = text_height
     elif anchor == ANCHOR_LEFT_CENTER:
         tx = text_height * math.sin(angle) / 2
         ty = text_height * math.cos(angle) / 2
         ttx = 0
         tty = text_height / 2
     elif anchor == ANCHOR_RIGHT_CENTER:
         tx = text_width * math.cos(angle) + text_height * math.sin(angle) / 2
         ty = -text_width * math.sin(angle) + text_height * math.cos(angle) / 2
         ttx = text_width
         tty = text_height / 2
     
     #calculate the bounding rect
     real_x = x - ttx
     real_y = y - tty
     top_left = real_x, real_y
     bottom_left = real_x , real_y + text_height
     bottom_right = real_x + text_width, real_y + text_height
     top_right = real_x + text_width, real_y
     
     offset = x, y
     
     n_top_left = rotate_vector(offset, top_left, angle)
     n_bottom_left = rotate_vector(offset, bottom_left, angle)
     n_bottom_right = rotate_vector(offset, bottom_right, angle)
     n_top_right = rotate_vector(offset, top_right, angle)
     
     alloc_x_min = int(min(n_top_left[0], n_bottom_left[0], n_bottom_right[0],
                         n_top_right[0]))
     alloc_x_max = int(max(n_top_left[0], n_bottom_left[0], n_bottom_right[0],
                         n_top_right[0]))
     alloc_y_min = int(min(n_top_left[1], n_bottom_left[1], n_bottom_right[1],
                         n_top_right[1]))
     alloc_y_max = int(max(n_top_left[1], n_bottom_left[1], n_bottom_right[1],
                         n_top_right[1]))
                         
     rect = gtk.gdk.Rectangle(alloc_x_min, alloc_y_min,
                                 alloc_x_max - alloc_x_min,
                                 alloc_y_max - alloc_y_min)
     return rect
Exemple #8
0
    def get_calculated_dimensions(self, context, rect):
        angle = 2 * math.pi * self._rotation / 360.0

        if self._context == None:
            label = gtk.Label()
            self._context = label.create_pango_context()
        pango_context = self._context

        attrs = pango.AttrList()
        attrs.insert(pango.AttrWeight(self._weight, 0, len(self._text)))
        attrs.insert(pango.AttrStyle(self._slant, 0, len(self._text)))
        attrs.insert(pango.AttrUnderline(self._underline, 0, len(self._text)))
        if self._size != None:
            attrs.insert(pango.AttrSize(1000 * self._size, 0, len(self._text)))

        if self._layout == None:
            self._layout = pango.Layout(pango_context)
        layout = self._layout

        layout.set_text(self._text)
        layout.set_attributes(attrs)

        #find out where to draw the layout and calculate the maximum width
        width = rect.width
        if self._anchor in [
                ANCHOR_BOTTOM_LEFT, ANCHOR_TOP_LEFT, ANCHOR_LEFT_CENTER
        ]:
            width = rect.width - self._position[0]
        elif self._anchor in [
                ANCHOR_BOTTOM_RIGHT, ANCHOR_TOP_RIGHT, ANCHOR_RIGHT_CENTER
        ]:
            width = self._position[0]

        text_width, text_height = layout.get_pixel_size()
        width = width * math.cos(angle)
        width = min(width, self._max_width)

        if self._wrap:
            layout.set_wrap(pango.WRAP_WORD_CHAR)
        layout.set_width(int(1000 * width))

        x, y = get_text_pos(layout, self._position, self._anchor, angle)

        if not self._fixed:
            #Find already drawn labels that would intersect with the current one
            #and adjust position to avoid intersection.
            text_width, text_height = layout.get_pixel_size()
            real_width = abs(text_width * math.cos(angle)) + abs(
                text_height * math.sin(angle))
            real_height = abs(text_height * math.cos(angle)) + abs(
                text_width * math.sin(angle))

            other_labels = get_registered_labels()
            this_rect = gtk.gdk.Rectangle(int(x), int(y), int(real_width),
                                          int(real_height))
            for label in other_labels:
                label_rect = label.get_allocation()
                intersection = this_rect.intersect(label_rect)
                if intersection.width == 0 and intersection.height == 0:
                    continue

                y_diff = 0
                if label_rect.y <= y and label_rect.y + label_rect.height >= y:
                    y_diff = y - label_rect.y + label_rect.height
                elif label_rect.y > y and label_rect.y < y + real_height:
                    y_diff = label_rect.y - real_height - y
                y += y_diff

        #calculate the dimensions
        text_width, text_height = layout.get_pixel_size()
        real_width = abs(text_width * math.cos(angle)) + abs(
            text_height * math.sin(angle))
        real_height = abs(text_height * math.cos(angle)) + abs(
            text_width * math.sin(angle))
        return real_width, real_height
Exemple #9
0
    def __init__(self, parent, tracks, current_position=0, with_extras=False):
        """
            :param parent: the parent window for modal operation
            :type parent: :class:`gtk.Window`
            :param tracks: the tracks to process
            :type tracks: list of :class:`xl.trax.Track` objects
            :param current_position: the position of the currently
                selected track in the list
            :type current_position: int
            :param with_extras: whether there are extra, non-selected tracks in
                `tracks` (currently happens when only 1 track is selected)
            :type with_extras: bool
        """
        gobject.GObject.__init__(self)

        self.builder = gtk.Builder()
        self.builder.add_from_file(
            xdg.get_data_path('ui', 'trackproperties_dialog.ui'))
        self.builder.connect_signals(self)
        self.dialog = self.builder.get_object('TrackPropertiesDialog')
        self.dialog.set_transient_for(parent)

        self.__default_attributes = pango.AttrList()
        self.__changed_attributes = pango.AttrList()
        self.__changed_attributes.insert(
            pango.AttrStyle(pango.STYLE_ITALIC, 0, -1))

        self.message = dialogs.MessageBar(
            parent=self.builder.get_object('main_container'),
            buttons=gtk.BUTTONS_CLOSE)

        self.remove_tag_button = self.builder.get_object('remove_tag_button')
        self.cur_track_label = self.builder.get_object('current_track_label')
        self.apply_button = self.builder.get_object('apply_button')
        self.prev_button = self.builder.get_object('prev_track_button')
        self.next_button = self.builder.get_object('next_track_button')

        self.tags_table = self.builder.get_object('tags_table')
        self.properties_table = self.builder.get_object('properties_table')
        self.rows = []

        self.new_tag_combo = self.builder.get_object('new_tag_combo')
        self.new_tag_combo_list = gtk.ListStore(str, str)
        for tag, tag_info in tag_data.iteritems():
            if tag_info is not None and tag_info.editable:
                self.new_tag_combo_list.append((tag, tag_info.translated_name))
        self.new_tag_combo_list.set_sort_column_id(1, gtk.SORT_ASCENDING)
        self.new_tag_combo.set_model(self.new_tag_combo_list)
        self.new_tag_combo.set_text_column(1)
        self.add_tag_button = self.builder.get_object('add_tag_button')
        self.add_tag_button.set_sensitive(False)

        # Show these tags for all tracks, no matter what
        def_tags = [
            'tracknumber', 'title', 'artist', 'album', 'discnumber', 'date',
            'genre', 'cover', 'comment', '__startoffset', '__stopoffset'
        ]

        self.def_tags = OrderedDict([(tag, tag_data[tag]) for tag in def_tags])

        # Store the tracks and a working copy
        self.tracks = tracks
        self.trackdata = self._tags_copy(tracks)
        self.trackdata_original = self._tags_copy(tracks)
        self.current_position = current_position

        self._build_from_track(self.current_position)

        self.dialog.resize(600, 350)
        self.dialog.show()

        self.rows[0].field.grab_focus()
Exemple #10
0
    def attrs_changed(self):
        bold = False
        italics = False
        underline = False
        pango_font = None
        del self.attrlist
        self.attrlist = self.attributes.copy()

        if self.preedit:
            ins_text = self.preedit[0]
            ins_style = self.preedit[1]
            if self.index == len(self.text):
                show_text = self.text + ins_text
            elif self.index == 0:
                show_text = ins_text + self.text
            else:
                split1 = self.text[:self.index]
                split2 = self.text[self.index:]
                show_text = split1 + ins_text + split2
            self.attrlist.splice(ins_style, self.index, len(ins_text))
        else:
            show_text = self.text

        it = wrap_attriterator(self.attributes.get_iterator())
        for attrs, (start, end) in it:
            found = False
            if self.index == self.end_index:
                if start <= self.index and end > self.index:
                    found = True
            elif self.index < self.end_index:
                if start > self.end_index:
                    break
                elif start <= self.index and \
                     end   >= self.end_index:
                    # We got a winner!
                    found = True
            else:  # i.e. self.index > self.end_index
                if start > self.index:
                    break
                elif start <= self.end_index and \
                     end   >= self.index:
                    # We got another winner!
                    found = True

            if found:
                for x in attrs:
                    if x.type == pango.ATTR_WEIGHT and \
                       x.value == pango.WEIGHT_BOLD:
                        bold = True
                    elif x.type == pango.ATTR_STYLE and \
                             x.value == pango.STYLE_ITALIC:
                        italics = True
                    elif x.type == pango.ATTR_UNDERLINE and \
                             x.value == pango.UNDERLINE_SINGLE:
                        underline = True
                    elif x.type == pango.ATTR_FONT_DESC:
                        pango_font = x.desc

        to_add = []
        if bold:
            to_add.append(
                pango.AttrWeight(pango.WEIGHT_BOLD, self.index, self.index))
        if italics:
            to_add.append(
                pango.AttrStyle(pango.STYLE_ITALIC, self.index, self.index))
        if underline:
            to_add.append(
                pango.AttrUnderline(pango.UNDERLINE_SINGLE, self.index,
                                    self.index))
        if pango_font:
            to_add.append(
                pango.AttrFontDesc(pango_font, self.index, self.index))
        for x in self.current_attrs:
            if x.type == pango.ATTR_WEIGHT and x.value == pango.WEIGHT_BOLD:
                bold = True
                to_add.append(x)
            if x.type == pango.ATTR_STYLE and x.value == pango.STYLE_ITALIC:
                italics = True
                to_add.append(x)
            if x.type == pango.ATTR_UNDERLINE and x.value == pango.UNDERLINE_SINGLE:
                underline = True
                to_add.append(x)
            if x.type == pango.ATTR_FONT_DESC:
                pango_font = x.desc
                to_add.append(x)
        del self.current_attrs
        self.current_attrs = to_add
        self.emit("update-attrs", bold, italics, underline, pango_font)
        return show_text
Exemple #11
0
def generate_images(opts,args):
    # Set up variables for drawing space
    width = 2550 # Will resize to match text; default 8.5"x11" @ 300dpi
    height = 3300
    MARGIN_X = 300
    MARGIN_Y = 300
    LINE_SPACE = 35 #TODO: Command-line opts
    LANG = "ka"
    TESS_LANG = "kat"
    # Set up decent spacing for box files
    attrs = pango.AttrList() #TODO: Command line opts or config
    attrs.insert(pango.AttrLanguage(LANG,0,-1))
    attrs.insert(pango.AttrLetterSpacing(10000,0,-1))
    attrs.insert(pango.AttrSize(48000,0,-1))
    attrs.insert(pango.AttrFallback(False,0,-1))
    attrs.insert(pango.AttrStyle(pango.STYLE_NORMAL,0,-1))
    attrs.insert(pango.AttrWeight(pango.WEIGHT_NORMAL,0,-1))
    attrs.insert(pango.AttrUnderline(pango.UNDERLINE_NONE,0,-1))

    # Instantiate Cairo surface and context
    surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    context = pangocairo.CairoContext(cairo.Context(surf))

    # Instantiate PangoCairo context
    context.set_antialias(cairo.ANTIALIAS_SUBPIXEL)

    #get font families:
    font_map = pangocairo.cairo_font_map_get_default()

    # to see family names:
    if opts.list_fonts:
        print [f.get_name() for f in font_map.list_families()]
        return

    # Set up pango layout
    layout = context.create_layout()
    layout.set_attributes(attrs)
    layout.set_width((width+MARGIN_X)*pango.SCALE)
    layout.set_spacing(LINE_SPACE*pango.SCALE)

    #print layout.get_width()

    # Read text from file TODO: Command line argument
    # TODO: Multiple files print to multiple image documents
    text = ''
    with codecs.open(opts.input_file) as text_file:
        for line in text_file:
            text += line + '\n'

    font_names = args

    # (variant, reset,"desc")
    #Font variants is an array of tuples consisting of: (AttrStyle, InverseAttrStyle, Name)
    font_variants = [
        (pango.AttrStyle(pango.STYLE_NORMAL,0,-1),pango.AttrStyle(pango.STYLE_NORMAL,0,-1),"")]

    #Add other stylings based on command-line options
    if opts.italic:
        font_variants.append((pango.AttrStyle(pango.STYLE_ITALIC,0,-1),pango.AttrStyle(pango.STYLE_NORMAL,0,-1),"italic"))
    if opts.bold:
        font_variants.append((pango.AttrWeight(pango.WEIGHT_HEAVY,0,-1),pango.AttrWeight(pango.WEIGHT_NORMAL,0,-1),"bold"))
    if opts.underline:
        font_variants.append((pango.AttrUnderline(pango.UNDERLINE_SINGLE,0,-1),pango.AttrUnderline(pango.UNDERLINE_NONE,0,-1),"underline"))

    #Generate pages for each font name and variation.
    for fn in font_names:
        for fvar in font_variants:
            # Change to a new variant
            attrs.change(fvar[0])
            layout.set_attributes(attrs)

            # Change to a new font
            fontname = fn
            font = pango.FontDescription(fontname + " 25")
            
            layout.set_font_description(font)
            layout.set_text(text)

            (ink, logical) = layout.get_pixel_extents()

            # If layout exceeds size of surface, change surface size
            if logical[2] > (width-MARGIN_X) or logical[3] > (height-MARGIN_Y):
                width = logical[2]+MARGIN_X
                height = logical[3]+MARGIN_Y
                surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
                context = pangocairo.CairoContext(cairo.Context(surf))
                context.update_layout(layout)

            #draw a background rectangle:
            context.rectangle(0,0,width,height)
            context.set_source_rgb(1, 1, 1)
            context.fill()

            # Translate context so that desired text upperleft corner is at 0,0
            context.translate(50,25)
            context.set_source_rgb(0, 0, 0)

            context.update_layout(layout)
            context.show_layout(layout)

            # Write to image 
            # TODO: Specify outfile on command line
            #print fontname
            #print fvar[2]
            with open(TESS_LANG+"."+fontname+fvar[2]+".exp0.png", "wb") as image_file:
                    surf.write_to_png(image_file)

            attrs.change(fvar[1])
            layout.set_attributes(attrs)
    def set_attribute(self, active, attribute):
        if not self.editing:
            return

        if attribute == 'bold':
            pstyle, ptype, pvalue = (pango.WEIGHT_NORMAL, pango.ATTR_WEIGHT,
                                     pango.WEIGHT_BOLD)
        elif attribute == 'italic':
            pstyle, ptype, pvalue = (pango.STYLE_NORMAL, pango.ATTR_STYLE,
                                     pango.STYLE_ITALIC)
        elif attribute == 'underline':
            pstyle, ptype, pvalue = (pango.UNDERLINE_NONE,
                                     pango.ATTR_UNDERLINE,
                                     pango.UNDERLINE_SINGLE)

        index, end_index = (self.index, self.end_index)
        init = min(index, end_index)
        end = max(index, end_index)

        if not active:
            attr = pango.AttrStyle(pstyle, init, end)
            if index == end_index:
                self.current_attrs.change(attr)
            else:
                self.attributes.change(attr)

            tmp = []
            attr = None
            if index == end_index:
                for x in self.current_attrs:
                    if x.type == ptype and x.value == pvalue:
                        attr = x
                    else:
                        tmp.append(x)
                    self.current_attrs = tmp
                    self.recalc_edges()
                    self.undo.add_undo(UndoManager.UndoAction(self, UNDO_REMOVE_ATTR, \
                               self.undo_attr_cb,\
                               attr))
                    return

            it = self.attributes.get_iterator()
            old_attrs = self.attributes.copy()
            changed = []

            while True:
                r = it.range()
                if r[0] <= init and r[1] >= end:
                    for x in it.get_attrs():
                        if x.type == ptype and x.value == pvalue:
                            changed.append(
                                self.create_attribute(attribute, r[0], init))
                            changed.append(
                                self.create_attribute(attribute, end, r[1]))
                        else:
                            changed.append(x)
                else:
                    map(lambda x: changed.append(x), it.get_attrs())

                if not it.next():
                    break

            del self.attributes
            self.attributes = pango.AttrList()
            map(lambda x: self.attributes.change(x), changed)
            tmp = []
            for x in self.current_attrs:
                if not (x.type == ptype and x.value == pvalue):
                    tmp.append(x)
            self.current_attrs = tmp
            self.undo.add_undo(
                UndoManager.UndoAction(self, UNDO_REMOVE_ATTR_SELECTION,
                                       self.undo_attr_cb, old_attrs,
                                       self.attributes.copy()))
        else:
            if index == end_index:
                attr = self.create_attribute(attribute, index, end_index)
                self.undo.add_undo(
                    UndoManager.UndoAction(self, UNDO_ADD_ATTR,
                                           self.undo_attr_cb, attr))
                self.current_attrs.change(attr)
            else:
                attr = self.create_attribute(attribute, init, end)
                old_attrs = self.attributes.copy()
                self.attributes.change(attr)
                self.undo.add_undo(
                    UndoManager.UndoAction(self, UNDO_ADD_ATTR_SELECTION,
                                           self.undo_attr_cb, old_attrs,
                                           self.attributes.copy()))
        self.recalc_edges()
    def attrs_changed(self):
        bold = False
        italics = False
        underline = False
        pango_font = None
        del self.attrlist
        self.attrlist = pango.AttrList()
        # TODO: splice instead of own method
        it = self.attributes.get_iterator()

        while 1:
            at = it.get_attrs()
            for x in at:
                self.attrlist.insert(x)
            if it.next() == False:
                break
        if self.preedit:
            ins_text = self.preedit[0]
            ins_style = self.preedit[1]
            if self.index == len(self.text):
                show_text = self.text + ins_text
            elif self.index == 0:
                show_text = ins_text + self.text
            else:
                split1 = self.text[:self.index]
                split2 = self.text[self.index:]
                show_text = split1 + ins_text + split2
            self.attrlist.splice(ins_style, self.index, len(ins_text))
        else:
            show_text = self.text

        it = self.attributes.get_iterator()
        while (1):
            found = False
            r = it.range()
            if self.index == self.end_index:
                if r[0] <= self.index and r[1] > self.index:
                    found = True
            elif self.index < self.end_index:
                if r[0] > self.end_index:
                    break
                if self.index == self.end_index and \
                 r[0] < self.index and \
                 r[1] > self.index:
                    found = True
                elif self.index != self.end_index and r[0] <= self.index and \
                   r[1] >= self.end_index:
                    # We got a winner!
                    found = True
            else:
                if r[0] > self.index:
                    break
                if self.index == self.end_index and \
                 r[0] < self.index and \
                 r[1] > self.index:
                    found = True
                elif self.index != self.end_index and r[0] <= self.end_index and \
                   r[1] >= self.index:
                    # We got another winner!
                    found = True

            if found:
                # FIXME: the it.get() seems to crash python
                # through pango.
                attr = it.get_attrs()
                for x in attr:
                    if x.type == pango.ATTR_WEIGHT and \
                       x.value == pango.WEIGHT_BOLD:
                        bold = True
                    elif x.type == pango.ATTR_STYLE and \
                      x.value == pango.STYLE_ITALIC:
                        italics = True
                    elif x.type == pango.ATTR_UNDERLINE and \
                      x.value == pango.UNDERLINE_SINGLE:
                        underline = True
                    elif x.type == pango.ATTR_FONT_DESC:
                        pango_font = x.desc
            if it.next() == False:
                break
        to_add = []
        if bold:
            to_add.append(
                pango.AttrWeight(pango.WEIGHT_BOLD, self.index, self.index))
        if italics:
            to_add.append(
                pango.AttrStyle(pango.STYLE_ITALIC, self.index, self.index))
        if underline:
            to_add.append(
                pango.AttrUnderline(pango.UNDERLINE_SINGLE, self.index,
                                    self.index))
        if pango_font:
            to_add.append(
                pango.AttrFontDesc(pango_font, self.index, self.index))
        for x in self.current_attrs:
            if x.type == pango.ATTR_WEIGHT and x.value == pango.WEIGHT_BOLD:
                bold = True
                to_add.append(x)
            if x.type == pango.ATTR_STYLE and x.value == pango.STYLE_ITALIC:
                italics = True
                to_add.append(x)
            if x.type == pango.ATTR_UNDERLINE and x.value == pango.UNDERLINE_SINGLE:
                underline = True
                to_add.append(x)
            if x.type == pango.ATTR_FONT_DESC:
                pango_font = x.desc
                to_add.append(x)
        del self.current_attrs
        self.current_attrs = to_add
        self.emit("update-attrs", bold, italics, underline, pango_font)
        return show_text
Exemple #14
0
    def __init__(self, ancho, alto, titulo, banner):
        self.pasos = {}
        self.actual = ''

        # Creo la ventana
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
        gtk.Window.set_position(self, gtk.WIN_POS_CENTER_ALWAYS)
        self.set_icon_from_file(BAR_ICON)
        self.titulo = titulo
        self.set_title(titulo)
        self.set_size_request(ancho, alto)
        self.set_resizable(0)
        self.set_border_width(0)

        # Creo el contenedor principal
        self.c_principal = gtk.Fixed()
        self.add(self.c_principal)

        # Calculo tamaño del banner
        self.banner_img = Image.open(banner)
        self.banner_w = self.banner_img.size[0]
        self.banner_h = self.banner_img.size[1]

        # Creo el banner
        self.banner = gtk.Image()
        self.banner.set_from_file(banner)
        self.banner.set_size_request(ancho, self.banner_h)

        # Creo el contenedor del banner y el texto del banner
        banner_container = gtk.Fixed()
        banner_container.set_size_request(self.banner_w, self.banner_h)

        attr = pango.AttrList()
        attr.insert(pango.AttrSize(25000, 0, -1))
        attr.insert(pango.AttrStyle(pango.STYLE_ITALIC, 0, -1))
        attr.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1))

        lbl1 = gtk.Label(_("Canaima Installation"))
        lbl1.set_attributes(attr)

        banner_container.put(self.banner, 0, 0)
        banner_container.put(lbl1, 100, 10)

        self.c_principal.put(banner_container, 0, 0)

        # Creo el contenedor de los pasos
        self.c_pasos = gtk.VBox()
        self.c_pasos.set_size_request((ancho - 10),
                                      (alto - 50 - self.banner_h))
        self.c_principal.put(self.c_pasos, 5, (self.banner_h + 5))

        # Creo la botonera
        self.botonera = gtk.Fixed()
        self.botonera.set_size_request(ancho, 40)
        self.c_principal.put(self.botonera, 0, (alto - 40))

        # Creo la linea divisoria
        self.linea = gtk.HSeparator()
        self.linea.set_size_request(ancho, 5)
        self.botonera.put(self.linea, 0, 0)

        # Anterior
        self.anterior = gtk.Button(stock=gtk.STOCK_GO_BACK)
        self.anterior.set_size_request(100, 30)
        self.botonera.put(self.anterior, (ancho - 210), 10)

        # Siguiente
        self.siguiente = gtk.Button(stock=gtk.STOCK_GO_FORWARD)
        self.siguiente.set_size_request(100, 30)
        self.botonera.put(self.siguiente, (ancho - 110), 10)

        # Cancelar
        self.cancelar = gtk.Button(stock=gtk.STOCK_QUIT)
        self.cancelar.set_size_request(100, 30)
        self.cancelar.connect('clicked', self.close)
        self.botonera.put(self.cancelar, 10, 10)

        # Acerca
        self.acerca = gtk.Button(stock=gtk.STOCK_ABOUT)
        self.acerca.set_size_request(100, 30)
        self.acerca.connect('clicked', AboutWindow)
        self.botonera.put(self.acerca, 110, 10)

        self.connect("destroy", self.close)
        self.connect("delete-event", self.close)

        self.show_all()