#!/usr/bin/env python
# -*- coding: utf-8 -*-
import gtk
import pango

win = gtk.Window()
win.connect('destroy', gtk.main_quit)

vbox = gtk.VBox(False, 0)

def add_label(ellipsize, xalign, text="Ellipsizing label", dir=None, set_justify=None, vbox=vbox):
    if set_justify is None:
	# "gtk_label_set_justify() has no effect on labels containing only a
	# single line."
	# ...so both labels between the separators should behave the same,
	# right?
	add_label(ellipsize, xalign, text, dir, set_justify=False)
	add_label(ellipsize, xalign, text, dir, set_justify=True)
	vbox.pack_start(gtk.HSeparator(), False, True)
	return

    label = gtk.Label(text)
    if dir is not None:
	label.set_direction(dir)
    label.set_ellipsize(ellipsize)
    label.set_alignment(xalign, 0.5)

    if set_justify:
	if xalign < 0.1:
	    label.set_justify(gtk.JUSTIFY_LEFT)
	elif 0.4 < xalign < 0.6:
	    label.set_justify(gtk.JUSTIFY_CENTER)
	elif xalign > 0.9:
	    label.set_justify(gtk.JUSTIFY_RIGHT)

    vbox.pack_start(label, True, True)

add_label(pango.ELLIPSIZE_START,  0.0)
add_label(pango.ELLIPSIZE_MIDDLE, 0.0)
add_label(pango.ELLIPSIZE_END,    0.0)
add_label(pango.ELLIPSIZE_START,  0.5)
add_label(pango.ELLIPSIZE_MIDDLE, 0.5)
add_label(pango.ELLIPSIZE_END,    0.5)
add_label(pango.ELLIPSIZE_START,  1.0)
add_label(pango.ELLIPSIZE_MIDDLE, 1.0)
add_label(pango.ELLIPSIZE_END,    1.0)
add_label(pango.ELLIPSIZE_END,    0.0, text="در حال باز کردن...")
add_label(pango.ELLIPSIZE_END,    0.5, text="در حال باز کردن...")
add_label(pango.ELLIPSIZE_END,    1.0, text="در حال باز کردن...")
add_label(pango.ELLIPSIZE_END,    0.0, text="در حال باز کردن...", dir=gtk.TEXT_DIR_RTL)
add_label(pango.ELLIPSIZE_END,    0.5, text="در حال باز کردن...", dir=gtk.TEXT_DIR_RTL)
add_label(pango.ELLIPSIZE_END,    1.0, text="در حال باز کردن...", dir=gtk.TEXT_DIR_RTL)

win.add(vbox)

win.set_default_size(400, -1)
win.show_all()

gtk.main()
