You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

116 lines
3.4 KiB

  1. #! /usr/bin/python3
  2. """
  3. A demo/test script for the XAppKbdLayoutController class
  4. """
  5. import sys, os
  6. import signal
  7. import gettext
  8. import gi
  9. gi.require_version('Gtk', '3.0')
  10. gi.require_version('XApp', '1.0')
  11. from gi.repository import Gtk, XApp, GObject, Gkbd, GdkPixbuf
  12. signal.signal(signal.SIGINT, signal.SIG_DFL)
  13. class Main:
  14. def __init__(self):
  15. win = Gtk.Window()
  16. frame = Gtk.Frame()
  17. frame.set_margin_start(2)
  18. frame.set_margin_end(2)
  19. frame.set_margin_top(2)
  20. frame.set_margin_bottom(2)
  21. win.add(frame)
  22. box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
  23. box.set_margin_start(2)
  24. box.set_margin_end(2)
  25. box.set_margin_top(2)
  26. box.set_margin_bottom(2)
  27. frame.add(box)
  28. self.use_caps = False
  29. self.controller = XApp.KbdLayoutController()
  30. self.controller.connect("layout-changed", self.on_layout_changed)
  31. self.controller.connect("config-changed", self.on_config_changed)
  32. self.label = Gtk.Label()
  33. self.label.set_text(self.controller.get_current_name())
  34. box.pack_start(self.label, True, True, 4)
  35. self.flag_button = Gtk.Button()
  36. box.pack_start(self.flag_button, True, True, 4)
  37. self.flag_button.connect("clicked", self.on_button_clicked)
  38. self.group_button = Gtk.Button()
  39. box.pack_start(self.group_button, True, True, 4)
  40. self.group_button.connect("clicked", self.on_button_clicked)
  41. self.variant_button = Gtk.Button()
  42. box.pack_start(self.variant_button, True, True, 4)
  43. self.variant_button.connect("clicked", self.on_button_clicked)
  44. check = Gtk.CheckButton.new_with_label("Use caps")
  45. check.connect("toggled", self.on_caps_toggled)
  46. box.pack_start(check, True, True, 4)
  47. frame.show_all()
  48. win.connect("delete-event", lambda w, e: Gtk.main_quit())
  49. self.on_layout_changed(self.controller)
  50. win.present()
  51. Gtk.main()
  52. def on_caps_toggled(self, widget):
  53. self.use_caps = widget.get_active()
  54. self.on_layout_changed(self.controller)
  55. def on_button_clicked(self, widget, data=None):
  56. self.controller.next_group()
  57. def on_layout_changed(self, controller, group=None):
  58. handled = False
  59. name = self.controller.get_current_icon_name()
  60. if name != None:
  61. filename = "/usr/share/flags/iso-4x3-svg/%s.svgz" % name
  62. valid, width, height = Gtk.IconSize.lookup(Gtk.IconSize.BUTTON)
  63. pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(filename, -1, height)
  64. image = Gtk.Image.new_from_pixbuf(pixbuf)
  65. self.flag_button.set_image(image)
  66. handled = True
  67. if not handled:
  68. name = self.controller.get_current_short_group_label()
  69. self.flag_button.set_label(name.upper())
  70. self.flag_button.set_image(None)
  71. self.label.set_text(self.controller.get_current_name())
  72. group_label = self.controller.get_current_short_group_label()
  73. variant_label = self.controller.get_current_variant_label()
  74. if self.use_caps:
  75. group_label = group_label.upper()
  76. variant_label = variant_label.upper()
  77. self.group_button.set_label(group_label)
  78. self.variant_button.set_label(variant_label)
  79. def on_config_changed(self, controller):
  80. GObject.idle_add(self.on_layout_changed, controller)
  81. if __name__ == "__main__":
  82. main = Main()