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
On Wed, 10 Dec 2003 16:10:00 +0000
"Gustavo J. A. M. Carneiro" <[EMAIL PROTECTED]> wrote:
> Well, you are doing things in an expose event that are better handled
> somewhere else. Here's how I fixed your example (moved some code to a
> "realize" event handler):
>
> --- test-orig.py 2003-12-10 16:06:28.000000000 +0000
> +++ test.py 2003-12-10 16:06:12.000000000 +0000
> @@ -21,6 +21,7 @@ class DrawingArea:
>
> self.box1 = gtk.HBox(gtk.FALSE, 10)
> self.area = gtk.DrawingArea()
> + self.area.connect("realize", self.area_realize_cb)
>
> self.Xoffset=150
> self.Yoffset=150
> @@ -44,9 +45,16 @@ class DrawingArea:
> self.boxV.show()
> window.show()
>
> + def area_realize_cb(self, area):
> + self.style = self.area.get_style()
> + self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
> + font_desc=pango.FontDescription(self.lab_font)
> + self.area.modify_font(font_desc)
> + self.gc.foreground =self.area.get_colormap().alloc_color("black")
> + gc.collect()
> +
> def area_expose_cb(self, area, event):
> """ Call update of the ld area on the screen """
> -
> if self.__area_expose_cb_lock: return gtk.TRUE
> else:
> self.__area_expose_cb_lock = gtk.TRUE
> @@ -62,12 +70,6 @@ class DrawingArea:
> Xlegend_size=self.Xleg
> Ylegend_size=Yarea_size
>
> - self.style = self.area.get_style()
> - self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
> - font_desc=pango.FontDescription(self.lab_font)
> - self.area.modify_font(font_desc)
> - self.gc.foreground =self.area.get_colormap().alloc_color("black")
> - gc.collect()
> self.__area_expose_cb_lock = gtk.FALSE
> gc.collect()
> return gtk.TRUE
>
>
>
> A Qua, 2003-12-10 �s 15:34, Jean-Baptiste Cazier escreveu:
> > Hi again !
> >
> > Despite the many e-mails and suggestions I received, nothing has solved my problem
> > so far.
> > So, I stripped down my program to some essentials to show you the problem I am
> > running into:
> >
> > The script below does nothing, but consumes 95% of my CPU !
> > If I comment out the line
> >
> > self.area.modify_font(font_desc)
> >
> > Then the CPU usage drops to the expected 0.1%
> >
> > Can anybody find the reason ?
> > Once again the pygtk and python version I am using on my redhat 9.0 box are the
> > following
>
> --
> Gustavo Jo�o Alves Marques Carneiro
> <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
>
>
--
-----------------------------
[EMAIL PROTECTED]
Department of Statistics
deCODE genetics Sturlugata,8
570 2993 101 Reykjav�k
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/