2

I'm writing an appindicator python script for my Gnome panel (under Ubuntu 12.10, English as the system-wide language) with a gtk.Menu, containing MenuItem's with Hebrew labels.

The text is correctly justified to the right [Hebrew is RTL], but the problem is that each menu bar (the box bounding the labels) is itself aligned to the left, such that the right indentation becomes different for different items:

(for the sake of clarity, in this example there are two menu items, each with two rows of text) Screenshot

My test code is as follows:

#!/usr/bin/python
#coding=utf-8

import appindicator
import gtk

a = appindicator.Indicator('test_indicator', '/some/ico', appindicator.CATEGORY_APPLICATION_STATUS)
a.set_status(appindicator.STATUS_ACTIVE)
m = gtk.Menu()

item0 = gtk.MenuItem("דוגמה: שורה ראשונה\nשורה שניה")
item1 = gtk.MenuItem("שורה שלישית\nשורה רביעית")
m.append(item0)
m.append(item1)

a.set_menu(m)
item0.show()
item1.show()
gtk.main()

Is there a way to align both the text and the bar to the right without changing the language globally? I see neither relevant keys in gconf, nor relevant members in MenuItem class (set_right_justified doesn't do the job).

Update

Code update inspired by the suggestion of Timo (note the shift to Gtk3):

from gi.repository import Gtk
from gi.repository import AppIndicator3 as appindicator

a = appindicator.Indicator.new('test_indicator', '/some/ico', appindicator.IndicatorCategory.APPLICATION_STATUS)
a.set_status(appindicator.IndicatorStatus.ACTIVE)
m = Gtk.Menu()

item0 = Gtk.MenuItem("\tדוגמה: שורה ראשונה\n\tשורה שניה")
item1 = Gtk.MenuItem("\tשורה שלישית\n\tשורה רביעית")
item0.set_halign(Gtk.Align.END)
item1.set_halign(Gtk.Align.END)

#the rest is the same

The important adjustment in this version is: addition of leading \t's for each row - otherwise the text starts out of the menu boundaries. This is more like a workaround, but the current state is nearly satisfactory:

Scrennshot2

1 Answers1

1

set_right_justified() is deprecated since GTK3.2 anyway and should be replaced by gtk_widget_set_hexpand or gtk_widget_set_halign

Edit: Save yourself the time with porting to GTK3, these methods don't work either. Here's your ported example:

#!/usr/bin/python
#coding=utf-8

from gi.repository import Gtk
from gi.repository import AppIndicator3 as appindicator

a = appindicator.Indicator.new('test_indicator', '/some/ico',
                               appindicator.IndicatorCategory.APPLICATION_STATUS)
a.set_status(appindicator.IndicatorStatus.ACTIVE)
m = Gtk.Menu()

item0 = Gtk.MenuItem("דוגמה: שורה ראשונה\nשורה שניה")
item1 = Gtk.MenuItem("שורה שלישית\nשורה רביעית")
item1.set_hexpand(True)
item1.set_halign(Gtk.Align.END)
m.append(item0)
m.append(item1)

a.set_menu(m)
item0.show()
item1.show()
Gtk.main()

It seems like this is an appindicator restriction (like many).

Timo
  • 4,700