plugin-viewer-gtk.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/usr/bin/python3
  2. import os
  3. import sys
  4. from gi.repository import Gtk
  5. from dbus.mainloop.glib import DBusGMainLoop
  6. DBusGMainLoop(set_as_default=True)
  7. # we could use this as the base for the MockController as well
  8. # from ubiquity.frontend.base import Controller
  9. # for testing online status
  10. #from ubiquity.misc import add_connection_watch
  11. class MockController(object):
  12. def __init__(self, parent):
  13. self.parent = parent
  14. self.oem_user_config = None
  15. self.oem_config = None
  16. self.dbfilter = None
  17. self._allow_go_foward = True
  18. self._allow_go_backward = True
  19. def go_forward(self):
  20. self.parent.button_next.clicked()
  21. def get_string(self, s, lang):
  22. return "get_string: %s (lang=%s)" % (s, lang)
  23. def add_builder(self, builder):
  24. pass
  25. def allow_go_forward(self, v):
  26. self._allow_go_forward = v
  27. self.parent.button_next.set_sensitive(v)
  28. def allow_go_backward(self, v):
  29. self._allow_go_backward = v
  30. self.parent.button_back.set_sensitive(v)
  31. if __name__ == "__main__":
  32. """ Run with:
  33. ./plugin-viewer-gtk.py ubi-timezone
  34. """
  35. def _on_button_next_clicked(button):
  36. stop = page_gtk.plugin_on_next_clicked()
  37. if not stop:
  38. Gtk.main_quit()
  39. # setup env
  40. for envvar, path in (
  41. ("UBIQUITY_PLUGIN_PATH", "./ubiquity/plugins"),
  42. ("UBIQUITY_GLADE", "./gui/gtk")):
  43. if os.path.exists(path):
  44. os.environ[envvar] = path
  45. # ... and then import the plugin_manager
  46. from ubiquity.plugin_manager import load_plugin
  47. plugin_name = sys.argv[1]
  48. plugin_module = load_plugin(plugin_name)
  49. win = Gtk.Window()
  50. win.button_next = Gtk.Button("next")
  51. win.button_back = Gtk.Button("back")
  52. mock_controller = MockController(win)
  53. page_gtk = plugin_module.PageGtk(mock_controller)
  54. #page_gtk.plugin_translate("en")
  55. win.button_next.connect(
  56. "clicked", _on_button_next_clicked)
  57. win.button_back.connect(
  58. "clicked", lambda b: page_gtk.plugin_on_back_clicked())
  59. #add_connection_watch(page_gtk.plugin_set_online_state)
  60. # fake debconf interface:
  61. page_gtk.db = {'netcfg/get_hostname': 'test hostname'}
  62. button_box = Gtk.ButtonBox(spacing=12)
  63. button_box.set_layout(Gtk.ButtonBoxStyle.END)
  64. button_box.pack_start(win.button_back, True, True, 6)
  65. button_box.pack_start(win.button_next, True, True, 6)
  66. box = Gtk.VBox()
  67. if hasattr(page_gtk, 'page'):
  68. box.pack_start(page_gtk.page, True, True, 6)
  69. else:
  70. box.pack_start(page_gtk.current_page, True, True, 6)
  71. box.pack_start(button_box, True, True, 6)
  72. win.add(box)
  73. win.connect("destroy", Gtk.main_quit)
  74. win.show_all()
  75. Gtk.main()