From 8904d963d27d419f033f1e5f230812442a8faa8d Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 26 Jan 2015 19:56:15 +0800 Subject: [PATCH] gui: add explorer window + rough prototype of control widgets defined with glade --- artiq/frontend/artiq_gui.py | 22 ++++--- artiq/gui/explorer.py | 123 ++++++++++++++++++++++++++++++++++++ artiq/gui/tools.py | 14 ++-- 3 files changed, 146 insertions(+), 13 deletions(-) create mode 100644 artiq/gui/explorer.py diff --git a/artiq/frontend/artiq_gui.py b/artiq/frontend/artiq_gui.py index 808bff328..64beba3bb 100755 --- a/artiq/frontend/artiq_gui.py +++ b/artiq/frontend/artiq_gui.py @@ -13,6 +13,7 @@ from artiq.gui.tools import LayoutManager from artiq.gui.scheduler import SchedulerWindow from artiq.gui.parameters import ParametersWindow from artiq.gui.rt_results import RTResults +from artiq.gui.explorer import ExplorerWindow def get_argparser(): @@ -51,22 +52,29 @@ def main(): scheduler_win = lmgr.create_window(SchedulerWindow, "scheduler", schedule_ctl) - scheduler_win.connect("delete-event", Gtk.main_quit) - scheduler_win.show_all() loop.run_until_complete(scheduler_win.sub_connect( args.server, args.port_notify)) atexit.register( lambda: loop.run_until_complete(scheduler_win.sub_close())) - parameters_win = lmgr.create_window(ParametersWindow, - "parameters") - parameters_win.connect("delete-event", Gtk.main_quit) - parameters_win.show_all() + parameters_win = lmgr.create_window(ParametersWindow, "parameters") loop.run_until_complete(parameters_win.sub_connect( args.server, args.port_notify)) atexit.register( lambda: loop.run_until_complete(parameters_win.sub_close())) + explorer_win = lmgr.create_window(ExplorerWindow, + "explorer", + schedule_ctl) + scheduler_win.show_all() + parameters_win.show_all() + explorer_win.show_all() + + def exit(*args): + lmgr.save() + Gtk.main_quit(*args) + explorer_win.connect("delete-event", exit) + rtr = RTResults() loop.run_until_complete(rtr.sub_connect( args.server, args.port_notify)) @@ -75,7 +83,5 @@ def main(): loop.run_forever() - lmgr.save() - if __name__ == "__main__": main() diff --git a/artiq/gui/explorer.py b/artiq/gui/explorer.py new file mode 100644 index 000000000..943b61cf1 --- /dev/null +++ b/artiq/gui/explorer.py @@ -0,0 +1,123 @@ +import asyncio + +from gi.repository import Gtk + +from artiq.gui.tools import Window, getitem + + +_test_description = """ + + + + + + 1000 + 2000 + 1500 + 1 + 10 + + + True + False + + + True + False + Simulated flopping frequency + + + False + True + 0 + + + + + True + True + number + adjustment1 + + + False + True + 1 + + + + +""" + + +class _ExperimentControls: + def __init__(self): + self.builder = Gtk.Builder() + self.builder.add_from_string(_test_description) + + def get_top_widget(self): + return self.builder.get_object("top") + + def get_arguments(self): + return { + "F0": self.builder.get_object("adjustment1").get_value() + } + + +class ExplorerWindow(Window): + def __init__(self, schedule_ctl, layout_dict=dict()): + self.schedule_ctl = schedule_ctl + + Window.__init__(self, + title="Explorer", + default_size=(800, 570), + layout_dict=layout_dict) + + topvbox = Gtk.VBox(spacing=6) + self.add(topvbox) + + menubar = Gtk.MenuBar() + topvbox.pack_start(menubar, False, False, 0) + + windows = Gtk.MenuItem("Windows") + windows_menu = Gtk.Menu() + scheduler = Gtk.MenuItem("Scheduler") + parameters = Gtk.MenuItem("Parameters") + quit = Gtk.MenuItem("Quit") + windows_menu.append(scheduler) + windows_menu.append(parameters) + windows_menu.append(Gtk.SeparatorMenuItem()) + windows_menu.append(quit) + windows.set_submenu(windows_menu) + menubar.append(windows) + + self.pane = Gtk.HPaned( + position=getitem(layout_dict, "pane_position", 180)) + topvbox.pack_start(self.pane, True, True, 0) + + listvbox = Gtk.VBox(spacing=6) + self.pane.pack1(listvbox) + self.list_store = Gtk.ListStore(str) + self.list_tree = Gtk.TreeView(self.list_store) + scroll = Gtk.ScrolledWindow() + scroll.add(self.list_tree) + listvbox.pack_start(scroll, True, True, 0) + button = Gtk.Button("Run") + button.connect("clicked", self.run) + listvbox.pack_start(button, False, False, 0) + + self.controls = _ExperimentControls() + self.pane.pack2(self.controls.get_top_widget()) + + def get_layout_dict(self): + r = Window.get_layout_dict(self) + r["pane_position"] = self.pane.get_position() + return r + + def run(self, widget): + run_params = { + "file": "flopping_f_simulation.py", + "unit": None, + "arguments": self.controls.get_arguments() + } + asyncio.Task(self.schedule_ctl.run_queued(run_params, None)) diff --git a/artiq/gui/tools.py b/artiq/gui/tools.py index 2499a229b..4adc1be39 100644 --- a/artiq/gui/tools.py +++ b/artiq/gui/tools.py @@ -6,18 +6,22 @@ from gi.repository import Gtk data_dir = os.path.abspath(os.path.dirname(__file__)) +def getitem(d, item, default): + try: + return d[item] + except KeyError: + return default + + class Window(Gtk.Window): def __init__(self, title, default_size, layout_dict=dict()): - Gtk.Window.__init__(self, title=title) + Gtk.Window.__init__(self, title=title + " - ARTIQ") self.set_wmclass("ARTIQ", "ARTIQ") self.set_icon_from_file(os.path.join(data_dir, "icon.png")) self.set_border_width(6) - try: - size = layout_dict["size"] - except KeyError: - size = default_size + size = getitem(layout_dict, "size", default_size) self.set_default_size(size[0], size[1]) try: position = layout_dict["position"]