Hi, I have a BIDI question regarding the Text Tag property "direction". It says in the documentation it can be set to TEXT_DIR_LTR, TEXT_DIR_RTL or TEXT_DIR_NONE. However I cant detect that it makes any difference. The only way I can get the desired behaviour is using Unicode directional markers but that is sub optimal in my case I've tried both on both Ubuntu and win32 and they behave the same.
I've attached a screen shot of the issue and a pygtk example (the embedded LTR text "1-left-to-right-2" should be displayed exactly like that). Regards, Fredrik
text_tag_dir_problem.PNG
Description: PNG image
#!/usr/bin/env python
# pygtk version: Maik Hertha <[EMAIL PROTECTED]>
import os
import sys
import gobject
import gtk
rtl_text = ''.join(("\331\210\331\202\330\257 \330\250\330\257\330\243 "
"\330\253\331\204\330\247\330\253 \331\205\331\206 ",
"\330\243\331\203\330\253\330\261 \330\247\331\204\331",
"\205\330\244\330\263\330\263\330\247\330\252 \330\252",
"\331\202\330\257\331\205\330\247 \331\201\331\212 \330",
"\264\330\250\331\203\330\251 \330\247\331\203\330\263",
"\331\212\331\210\331\206 \330\250\330\261\330\247\331",
"\205\330\254\331\207\330\247 \331\203\331\205\331\206",
"\330\270\331\205\330\247\330\252 \331\204\330\247 \330",
"\252\330\263\330\271\331\211 \331\204\331\204\330\261",
"\330\250\330\255\330\214 \330\253\331\205 \330\252\330",
"\255\331\210\331\204\330\252 \331\201\331\212 \330\247",
"\331\204\330\263\331\206\331\210\330\247\330\252 \330",
"\247\331\204\330\256\331\205\330\263 \330\247\331\204",
"\331\205\330\247\330\266\331\212\330\251 \330\245\331",
"\204\331\211 \331\205\330\244\330\263\330\263\330\247",
"\330\252 \331\205\330\247\331\204\331\212\330\251 \331",
"\205\331\206\330\270\331\205\330\251\330\214 \331\210",
"\330\250\330\247\330\252\330\252 \330\254\330\262\330\241",
"\330\247 \331\205\331\206 \330\247\331\204\331\206\330\270",
"\330\247\331\205 \330\247\331\204\331\205\330\247\331\204",
"\331\212 \331\201\331\212 \330\250\331\204\330\257\330\247",
"\331\206\331\207\330\247\330\214 \331\210\331\204\331\203",
"\331\206\331\207\330\247 \330\252\330\252\330\256\330\265",
"\330\265 \331\201\331\212 \330\256\330\257\331\205\330\251 ",
"\331\202\330\267\330\247\330\271 \330\247\331\204\331\205\330",
"\264\330\261\331\210\330\271\330\247\330\252 \330\247\331\204",
"\330\265\330\272\331\212\330\261\330\251. \331\210\330\243",
"\330\255\330\257 \330\243\331\203\330\253\330\261 \331\207",
"\330\260\331\207 \330\247\331\204\331\205\330\244\330\263",
"\330\263\330\247\330\252 \331\206\330\254\330\247\330\255",
"\330\247 \331\207\331\210 \302\273\330\250\330\247\331\206",
"\331\203\331\210\330\263\331\210\331\204\302\253 \331\201",
"\331\212 \330\250\331\210\331\204\331\212\331\201\331\212",
"\330\247."))
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)
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):
import pango
text_buffer.create_tag("right_justify", justification=gtk.JUSTIFY_RIGHT)
text_buffer.create_tag("rtl_quote",
wrap_mode=gtk.WRAP_WORD, direction=gtk.TEXT_DIR_RTL,
indent=30, left_margin=20, right_margin=20)
text_buffer.create_tag("ltr_quote",
wrap_mode=gtk.WRAP_WORD, direction=gtk.TEXT_DIR_LTR,
indent=30, left_margin=20, right_margin=20,foreground="red")
def insert_text(self, text_buffer):
# get start of buffer; each insertion will revalidate the
# iterator to point to just after the inserted text.
iter = text_buffer.get_iter_at_offset(0)
# Test with embeded ltr ("1-left-to-right-2") using just a text marker using unicode direction markers
text_buffer.insert(iter, 'Test of bidi using text tag with "direction=gtk.TEXT_DIR_LTR":\n', -1)
text_buffer.insert_with_tags_by_name(iter,rtl_text, "rtl_quote")
text_buffer.insert_with_tags_by_name(iter, "1-left-to-right-2", "ltr_quote")
text_buffer.insert_with_tags_by_name(iter,rtl_text + '\n\n', "rtl_quote")
# Test with embeded ltr using unicode direction markers
LTE = unichr(0x202a)
PDF = unichr(0x202c)
text_buffer.insert(iter, "Test of bidi using unicode direction markers:\n", -1)
text_buffer.insert_with_tags_by_name(iter,rtl_text, "rtl_quote")
text_buffer.insert_with_tags_by_name(iter, LTE + "1-left-to-right-2" + PDF, "ltr_quote")
text_buffer.insert_with_tags_by_name(iter,rtl_text + '\n\n', "rtl_quote")
# Apply word_wrap tag to whole buffer */
start, end = text_buffer.get_bounds()
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/
