- items = {
- 'caps' : Gtk.MenuItem.new_with_label('Caps Lock'),
- 'num' : Gtk.MenuItem.new_with_label('Num Lock'),
- 'scr' : Gtk.MenuItem.new_with_label('Scroll Lock')
- }
- menu.append(items['caps'])
- menu.append(items['num'])
- menu.append(items['scr'])
-
- items['caps'].connect('activate', self.send_keypress, 'Caps_Lock')
- items['num' ].connect('activate', self.send_keypress, 'Num_Lock')
- items['scr' ].connect('activate', self.send_keypress, 'Scroll_Lock')
+ xdotool = xdotool or shutil.which('xdotool')
+ if xdotool and os.access(xdotool, os.X_OK) and os.path.isfile(xdotool):
+ def send_keypress(menuitem, keystroke):
+ subprocess.call([xdotool, 'key', keystroke])
+ def new_menu_item(itemtype):
+ if itemtype == 'N':
+ item = Gtk.MenuItem.new_with_label(_('Num Lock'))
+ item.connect('activate', send_keypress, 'Num_Lock')
+ elif itemtype == 'C':
+ item = Gtk.MenuItem.new_with_label(_('Caps Lock'))
+ item.connect('activate', send_keypress, 'Caps_Lock')
+ elif itemtype == 'S':
+ item = Gtk.MenuItem.new_with_label(_('Scroll Lock'))
+ item.connect('activate', send_keypress, 'Scroll_Lock')
+ else:
+ raise ValueError('Invalid itemtype')
+ return item
+
+ for i in order:
+ menu.append(new_menu_item(i))
+ menu.append(Gtk.SeparatorMenuItem())
+
+ quit_item = Gtk.MenuItem.new_with_label(_('Quit'))
+ menu.append(quit_item)
+ quit_item.connect('activate', Gtk.main_quit)