Hi, I'm not able to figure out why gtk.TextTags wrap-mode is only respected if it is set at the beginning of a paragraph. What I'm trying to achieve is to have some parts of a paragraph text have other wrapping then the rest.
See attached screen dump and test script that shows my problem. I've tested on Windows XP and Ubuntu 6.10 with the same result. Is this how it is supposed to work? And in that case is there another way to achieve what I want? Regards, Fredrik
gtk_wrap_setting_problem.PNG
Description: PNG image
#!/usr/bin/env python
# pygtk version: Maik Hertha <[EMAIL PROTECTED]>
import os
import sys
import gobject
import gtk
class TextViewDemo(gtk.Window):
def __init__(self, parent=None):
# Create the toplevel window
gtk.Window.__init__(self)
try:
self.set_screen(parent.get_screen())
except AttributeError:
self.connect('destroy', lambda *w: gtk.main_quit())
self.set_title(self.__class__.__name__)
self.set_default_size(450, 450)
self.set_border_width(0)
view1 = gtk.TextView()
buffer_1 = view1.get_buffer()
sw = gtk.ScrolledWindow()
sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
sw.add(view1)
view1.set_wrap_mode(gtk.WRAP_WORD)
self.add(sw)
self.create_tags(buffer_1)
self.insert_text(buffer_1)
self.win = None
self.show_all()
def create_tags(self, text_buffer):
text_buffer.create_tag("info",foreground='black',scale=1,weight=700,pixels_below_lines=10)
text_buffer.create_tag("nowrap",foreground='blue',background='yellow',wrap_mode=gtk.WRAP_NONE)
text_buffer.create_tag("wordwrap",foreground='red',background='yellow',wrap_mode=gtk.WRAP_WORD)
def insert_text(self, text_buffer):
iter = text_buffer.get_iter_at_offset(0)
text_buffer.insert_with_tags_by_name(iter, 'Do not wrap overides wrap for the whole paragraph:\n', "info")
text_buffer.insert_with_tags_by_name(iter, 'Do-not-wrap! '*5, "nowrap")
text_buffer.insert_with_tags_by_name(iter, 'Wrap-this! '*5, 'wordwrap')
text_buffer.insert_with_tags_by_name(iter, '\n'*2, "wordwrap")
text_buffer.insert_with_tags_by_name(iter, 'Do word wrap overides nowrap for the whole paragraph:\n', "info")
text_buffer.insert_with_tags_by_name(iter, 'Wrap-this! '*5, 'wordwrap')
text_buffer.insert_with_tags_by_name(iter, 'Do-not-wrap! '*5, "nowrap")
text_buffer.insert_with_tags_by_name(iter, '\n'*2, "nowrap")
text_buffer.insert_with_tags_by_name(iter, 'Conclusion: The first word wrap setting defined for a paragraph overrides all other TextTag wrapping settings:\n', "info")
text_buffer.insert_with_tags_by_name(iter, 'Do-not-wrap! '*15, "nowrap")
text_buffer.insert_with_tags_by_name(iter, '\n'*2, "nowrap")
text_buffer.insert_with_tags_by_name(iter, 'Wrap-this! '*15, 'wordwrap')
def main():
TextViewDemo()
gtk.main()
if __name__ == '__main__':
main()
_______________________________________________ pygtk mailing list [email protected] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
