Here's a weird one Guys. I'm trying to format a string with fixed
length fields and display in a textview. The format is absolutely
perfect when I print it out to a terminal with all the fields neatly
aligned. When I write the same thing to a textview, they look really
out of place with fields not aligned at all. What am I missing?
Interestingly when I copy everything (ctrl + c) from textview and
paste it to gedit. They are neatly aligned ???

Any ideas?

Here's my code.

 writeTextView(textview, "a", "debug", fmtrecord("field1,field2,field3") + "\n")


def fmtrecord(rowstr):
     srstr = rowstr.split(",")
     fmtstr = string.rjust(srstr[0].strip(), 15) +
string.rjust(srstr[1].strip(), 15) + string.rjust(srstr[2].strip(),
15)
     return fmtstr

 def writeTextView(tview, mode, type, wstr):
     tbuf = tview.get_buffer()
     ttable = tbuf.get_tag_table()
     if mode == 'w':
        tbuf.set_text("")
     sob, eob = tbuf.get_bounds()
     tagexists = ttable.lookup(type)
     if (tagexists == None):
        tag = gtk.TextTag(type)
        if type == 'error':
           tag.set_property("font", "Arial")
           tag.set_property("foreground", "red")
           tag.set_property("size-points", 12)
           tag.set_property("weight", 400)
        elif type == 'warn':
           tag.set_property("font", "Arial")
           tag.set_property("foreground", "orange")
           tag.set_property("size-points", 12)
           tag.set_property("weight", 400)
        else:
           tag.set_property("font", "Arial")
           tag.set_property("foreground", "blue")
           tag.set_property("size-points", 10)
           tag.set_property("weight", 400)
        ttable.add(tag)
     else:
        tag = tagexists

     tbuf.insert_with_tags_by_name(eob, wstr, type)
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to