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 Answer 1

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).

5
  • Good idea. I'll try to move to Gtk3 and see, whether these functions help.
    – alephreish
    Nov 24, 2013 at 17:59
  • @har-wradim: I'm sorry. I didn't noticed that your example was in GTK2. My edit above shows a ported example, but no luck either.
    – Timo
    Nov 24, 2013 at 19:34
  • No, that actually nearly solves the problem. See updates in my question.
    – alephreish
    Nov 24, 2013 at 20:16
  • I don't think this is a good or standard way to make the menu RTL. For example it screws up the menu in MATE desktop which was RTL without that set_hexpand and set_halign. And has no effect in KDE. And remember: text alignment is completely different from text direction.
    – saeedgnu
    Jan 1, 2017 at 6:36
  • I assume AppIndicator does not support direction / RTL. We should probably leave it with that!
    – saeedgnu
    Jan 1, 2017 at 6:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .