logo       

pango font need refresh: msg#00057

gnome.gtk+.python

Subject: pango font need refresh

hi,

I'm playing with pango layout, I have now this verySimpleThing that
shows the line number aside of the textview area.

The problem appear when you scroll up or down the window, all the
numbers into the pango layout are unreadable.

I've tried also googling but with no luck.
Maybe someone already have fall into this issue?

Here is the code:

#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk
import pango

class MainWindow(gtk.Window):
def __init__(self):
gtk.Window.__init__(self)
self.connect("delete_event", self.doQuit)
self.set_default_size(300, 200)
self.set_border_width(5)
self.text = gtk.TextView()
self.text.set_border_window_size(gtk.TEXT_WINDOW_LEFT, 30)
buffer = self.text.get_buffer()
self.text.connect('expose-event', self.expose)
scrollWin = gtk.ScrolledWindow()
scrollWin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scrollWin.add(self.text)
self.add(scrollWin)
self.show_all()

def expose(self, widget, event):
text = widget
left_win = text.get_window(gtk.TEXT_WINDOW_LEFT)
type = gtk.TEXT_WINDOW_LEFT
target = left_win
first_y = event.area.y
last_y = first_y + event.area.height
x, first_y = text.window_to_buffer_coords(type, 0, first_y)
x, last_y = text.window_to_buffer_coords(type, 0, last_y)
numbers = []
pixels = []
count = self.get_lines(first_y, last_y, pixels, numbers)
layout = widget.create_pango_layout("")

layout.set_alignment(pango.ALIGN_RIGHT)
layout.set_width(25 * pango.SCALE)
attrList = pango.AttrList()
atrribute = pango.AttrForeground(0, 0, 65535, 0, -1)
attrList.insert(atrribute)
layout.set_attributes(attrList)

for i in range(count):
x, pos = text.buffer_to_window_coords(type, 0, pixels[i])
str = "%d" % numbers[i]
layout.set_text(str)
widget.style.paint_layout(target, widget.state, gtk.FALSE,
None, widget, None, 2, pos + 2, layout)

return gtk.FALSE

def get_lines(self, first_y, last_y, buffer_coords, numbers):
text = self.text
iter, top = text.get_line_at_y(first_y)
count = 0
size = 0
while not iter.is_end():
y, height = self.text.get_line_yrange(iter)
buffer_coords.append(y)
line_num = iter.get_line()
numbers.append(line_num)
count += 1
if (y + height) >= last_y:
break
iter.forward_line()
return count

def doQuit(self, widget, data=None):
gtk.main_quit()

def main(self):
gtk.main()

if __name__ == "__main__":
go = MainWindow()
go.main()


Thanks, regards
*L*

_______________________________________________
pygtk mailing list pygtk@xxxxxxxxxx
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise