Warning: This message has had one or more attachments removed.
The name of the attachment(s) is plot.1.ext.jpg
Please contact [EMAIL PROTECTED] (+354 570-1890) if you need assistance.
S�l Alejandro
Thanks for your indications. It seems like a nice work around the problem.
But it is quite heavy when I consider to draw potentially hundreds of this labels.
You deserve more explanation to understand my problem:
I want to have at least 2 fonts on the same drawing area because I am drawing a graph
with many labels on X-Y axis.
In order to make them visible I allow the user to chose their font (especially the
size).
At the same time The user can choose the font for the legend, titles,etc...
(see picture)
Now that I figured out where the problem is coming from, one solution for me would be
to have more than 1 drawing area.
But in general it would be useful to have more than 1 font available in a DrawingArea
without needing to save all the pixmaps explicitly
Any easy way to do so ?
Thanks
Jean-Baptiste
On Fri, 12 Dec 2003 20:51:40 +0300
"Alejandro David Weil" <[EMAIL PROTECTED]> wrote:
> Hi!
>
> I'm not sure what's your problem but I had have one of your problems:
>
> The create_pango_layout is not supposed to be called all the time..
> For that, my class caches the layout:
>
> class Message:
> def __init__(self, msg):
> """ We are expecting unicode message strings """
> self.msg = msg.encode('utf-8')
> # create a font description
> self.font_desc = pango.FontDescription('Serif 8')
>
> def _make_layout (self, widget):
> global wrapmode, wrapwidth
> # create a layout for your drawing area
> self.layout = widget.create_pango_layout(self.msg)
> self.layout.set_wrap(wrapmode)
> self.layout.set_width(wrapwidth)
> # tell the layout which font description to use
> self.layout.set_font_description(self.font_desc)
>
> def _make_cache(self, gc):
> """ This method doesn't seems to be fundamental, but.. """
> global depth
> #self.image = string.join(self.mx*3*self.my*['\0'],"")
> #self.image = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8,
> self.mx, self.my)
> self.image = gtk.gdk.Pixmap(None, self.mx, self.my, depth)
>
> self.gc = gc
> colormap = gc.get_colormap()
> white = colormap.alloc_color('white')
> yellow = colormap.alloc_color('yellow')
> black = colormap.alloc_color('black')
>
> gc.set_rgb_fg_color (yellow)
> self.image.draw_rectangle(gc, gtk.TRUE, 0,0, self.mx-1, self.my-1)
> gc.set_rgb_fg_color (black)
> self.image.draw_rectangle(gc, gtk.FALSE,0,0, self.mx-1, self.my-1)
> gc.set_rgb_fg_color (black)
>
> # draw the text with the draw_layout method
> self.image.draw_layout(self.gc, Message.BORDER_SIZE,
> Message.BORDER_SIZE, self.layout)
>
> def drawon(self, atx, aty, widget=None, gc=None):
> if not self.widget:
> if not widget or not gc:
> return
> else:
> self._make_layout(widget)
> self.widget = widget
> self._make_cache(gc)
>
> # draw the text with the draw_layout method
> #widget.window.draw_layout(gc, atx, aty, self.layout)
> #self.image.render_to_drawable (widget.window, gc, 0, 0, atx,aty,
> self.mx, self.my, gtk.gdk.RGB_DITHER_MAX, 0, 0)
> widget.window.draw_drawable(self.gc, self.image, 0, 0, atx, aty,
> self.mx, self.my)
>
>
> This creates the layout and dumps it, with a frame into a pixmap that's
> later used to be draw anytime.
>
> I removed some code, but that should be enough.
> It's from the class Message of IMFish(.sourceforge.net) :-)
>
> Also, i think that you should setup what font do you want
> to use, in other place, than the expose-cb!
>
> Seeya!
>
> -----Original Message-----
> From: Jean-Baptiste Cazier <[EMAIL PROTECTED]>
> To: "Gustavo J. A. M. Carneiro" <[EMAIL PROTECTED]>
> Date: Fri, 12 Dec 2003 17:38:46 +0000
> Subject: Re: [pygtk] High CPU problem example
>
> >Hello Gustavo !
> >
> >Thanks for your answer.
> >Your solution works fine for my simplified problem. It also pin-point the source of
> >my troubles.
> >But in order to solve my original problem I need a further tip:
> >Indeed If I actually draw something based on the modified font by adding the line
> > area.window.draw_layout(self.gc, 10, 10,
> > self.area.create_pango_layout("TEXT"))
> >Nothing is drawn at all if moved to the area_realize_cb routine.
> >
> >In my real area_expose_cb routine I draw many things with various fonts that are
> >set-up in other windows
> >For example I call draw_axes_s which uses 2 types of fonts.
> >
> > def draw_axes_s(self, xo, yo, xs, ys ):
> > """ Draw axis and write down the labels on the screen"""
> >
> > win=self.area.window
> > mini=self.Cld.mini
> > maxi=self.Cld.maxi
> > mindist=self.Cld.mindist
> > markers=self.Cld.markers
> > location=self.Cld.location
> > f_mrkX=markers[0][0]
> > l_mrkX=markers[0][len(markers[0])-1]
> > f_mrkY=markers[1][0]
> > l_mrkY=markers[1][len(markers[1])-1]
> >
> > xsize=min(max(float(xs)/(maxi[0]-mini[0])*mindist[0]*.9,self.min_size),self.max_size)
> >
> > ysize=min(max(float(ys)/(maxi[1]-mini[1])*mindist[1]*.9,self.min_size),self.max_size)
> ># Draw the lines
> > self.gc.foreground =self.area.get_colormap().alloc_color("black")
> > win.draw_line(self.gc, xo, yo, xo+xs, yo)
> > win.draw_line(self.gc, xo, yo, xo, yo-ys)
> > #Draw ticks
> > for m in markers[0]:
> > col=(location[0][m]-mini[0])/(maxi[0]-mini[0])
> > win.draw_line(self.gc, xsize/2+xo+col*(xs-xsize),
> > yo,xsize/2+xo+col*(xs-xsize),yo+3 )
> > for m in markers[1]:
> > col=(location[1][m]-mini[1])/(maxi[1]-mini[1])
> > win.draw_line(self.gc, xo,-ysize/2+yo-col*(ys-ysize), xo-3,
> > -ysize/2+yo-col*(ys-ysize) )
> > font_desc=pango.FontDescription(self.lab_font)
> > <------
> > self.area.modify_font(font_desc)
> > <------
> >
> ># write the labels
> > win.draw_layout(self.gc, xo+xs/2, yo+self.Yoffset*3/4, self.lay(self.Xlabel))
> > win.draw_layout(self.gc, xo-60, yo-ys-30,self.lay(self.Ylabel))
> > font_desc=pango.FontDescription(self.mrk_font)
> > <-------
> > self.area.modify_font(font_desc)
> > <-------
> >
> > ....
> >
> >
> >Moving this call to a realize emission that does not draw any axis at all
> >
> >So am I using pango or realize/expose_event the wrong way ?
> >Any help will be appreciated
> >
> >
> >regards.
> >
> >Jean-Baptiste
>
--
-----------------------------
[EMAIL PROTECTED]
Department of Statistics
deCODE genetics Sturlugata,8
570 2993 101 Reykjav�k
__________________________________________________
deCode quarantine message ID: hBF9NlLQ000512
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/