forked from M-Labs/artiq
gui: access to parameter DB from GUI files
This commit is contained in:
parent
1b122dd887
commit
2f4a83b97a
@ -68,13 +68,6 @@ def main():
|
|||||||
atexit.register(
|
atexit.register(
|
||||||
lambda: loop.run_until_complete(parameters_win.sub_close()))
|
lambda: loop.run_until_complete(parameters_win.sub_close()))
|
||||||
|
|
||||||
parameters_sub = Subscriber("parameters",
|
|
||||||
parameters_win.init_parameters_store)
|
|
||||||
loop.run_until_complete(
|
|
||||||
parameters_sub.connect(args.server, args.port_notify))
|
|
||||||
atexit.register(
|
|
||||||
lambda: loop.run_until_complete(parameters_sub.close()))
|
|
||||||
|
|
||||||
def exit(*args):
|
def exit(*args):
|
||||||
lmgr.save()
|
lmgr.save()
|
||||||
Gtk.main_quit(*args)
|
Gtk.main_quit(*args)
|
||||||
@ -87,6 +80,15 @@ def main():
|
|||||||
args.server, args.port_notify))
|
args.server, args.port_notify))
|
||||||
atexit.register(
|
atexit.register(
|
||||||
lambda: loop.run_until_complete(explorer_win.sub_close()))
|
lambda: loop.run_until_complete(explorer_win.sub_close()))
|
||||||
|
|
||||||
|
parameters_sub = Subscriber("parameters",
|
||||||
|
[parameters_win.init_parameters_store,
|
||||||
|
explorer_win.init_parameters_dict])
|
||||||
|
loop.run_until_complete(
|
||||||
|
parameters_sub.connect(args.server, args.port_notify))
|
||||||
|
atexit.register(
|
||||||
|
lambda: loop.run_until_complete(parameters_sub.close()))
|
||||||
|
|
||||||
scheduler_win.show_all()
|
scheduler_win.show_all()
|
||||||
parameters_win.show_all()
|
parameters_win.show_all()
|
||||||
explorer_win.show_all()
|
explorer_win.show_all()
|
||||||
|
32
artiq/gui/explib.py
Normal file
32
artiq/gui/explib.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import asyncio
|
||||||
|
|
||||||
|
from gi.repository import Gtk
|
||||||
|
|
||||||
|
|
||||||
|
class BaseControls:
|
||||||
|
def __init__(self, facilities):
|
||||||
|
self.facilities = facilities
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def build(self):
|
||||||
|
self.finalize()
|
||||||
|
|
||||||
|
def finalize(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class GladeControls(BaseControls):
|
||||||
|
def __init__(self, facilities, glade_file, top_widget_name="top"):
|
||||||
|
BaseControls.__init__(self, facilities)
|
||||||
|
self.glade_file = glade_file
|
||||||
|
self.top_widget_name = top_widget_name
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def build(self):
|
||||||
|
self.builder = Gtk.Builder()
|
||||||
|
data = yield from self.facilities.get_data(self.glade_file)
|
||||||
|
self.builder.add_from_string(data)
|
||||||
|
self.finalize()
|
||||||
|
|
||||||
|
def get_top_widget(self):
|
||||||
|
return self.builder.get_object(self.top_widget_name)
|
@ -1,4 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import types
|
||||||
|
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
|
||||||
@ -96,6 +97,10 @@ class ExplorerWindow(Window):
|
|||||||
def sub_close(self):
|
def sub_close(self):
|
||||||
yield from self.explist_subscriber.close()
|
yield from self.explist_subscriber.close()
|
||||||
|
|
||||||
|
def init_parameters_dict(self, init):
|
||||||
|
self.parameters = init
|
||||||
|
return init
|
||||||
|
|
||||||
def set_pane_contents(self, widget):
|
def set_pane_contents(self, widget):
|
||||||
self.pane_contents.destroy()
|
self.pane_contents.destroy()
|
||||||
self.pane_contents = widget
|
self.pane_contents = widget
|
||||||
@ -123,8 +128,11 @@ class ExplorerWindow(Window):
|
|||||||
gui_mod_data = yield from self.repository.get_data(gui_file)
|
gui_mod_data = yield from self.repository.get_data(gui_file)
|
||||||
gui_mod = dict()
|
gui_mod = dict()
|
||||||
exec(gui_mod_data, gui_mod)
|
exec(gui_mod_data, gui_mod)
|
||||||
self.controls = gui_mod["Controls"]()
|
facilities = types.SimpleNamespace(
|
||||||
yield from self.controls.build(self.repository.get_data)
|
get_data=self.repository.get_data,
|
||||||
|
get_parameter=lambda p: self.parameters[p])
|
||||||
|
self.controls = gui_mod["Controls"](facilities)
|
||||||
|
yield from self.controls.build()
|
||||||
self.set_pane_contents(self.controls.get_top_widget())
|
self.set_pane_contents(self.controls.get_top_widget())
|
||||||
|
|
||||||
def run(self, widget):
|
def run(self, widget):
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Generated with glade 3.16.1 -->
|
<!-- Generated with glade 3.18.3 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.10"/>
|
<requires lib="gtk+" version="3.10"/>
|
||||||
<object class="GtkAdjustment" id="F0">
|
<object class="GtkAdjustment" id="F0">
|
||||||
@ -9,21 +9,14 @@
|
|||||||
<property name="step_increment">1</property>
|
<property name="step_increment">1</property>
|
||||||
<property name="page_increment">10</property>
|
<property name="page_increment">10</property>
|
||||||
</object>
|
</object>
|
||||||
<object class="GtkBox" id="top">
|
<object class="GtkGrid" id="top">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<child>
|
<property name="halign">center</property>
|
||||||
<object class="GtkLabel" id="label1">
|
<property name="valign">center</property>
|
||||||
<property name="visible">True</property>
|
<property name="orientation">vertical</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="row_spacing">6</property>
|
||||||
<property name="label" translatable="yes">Simulated flopping frequency</property>
|
<property name="column_spacing">6</property>
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="expand">False</property>
|
|
||||||
<property name="fill">True</property>
|
|
||||||
<property name="position">0</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkSpinButton" id="spinbutton1">
|
<object class="GtkSpinButton" id="spinbutton1">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
@ -33,9 +26,32 @@
|
|||||||
<property name="value">1500</property>
|
<property name="value">1500</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="left_attach">1</property>
|
||||||
<property name="fill">True</property>
|
<property name="top_attach">0</property>
|
||||||
<property name="position">1</property>
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="getparam">
|
||||||
|
<property name="label" translatable="yes">Get from parameter DB</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
<property name="width">2</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="label2">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">Simulated flopping frequency:</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
import asyncio
|
from artiq.gui.explib import GladeControls
|
||||||
|
|
||||||
from gi.repository import Gtk
|
|
||||||
|
|
||||||
|
|
||||||
class Controls:
|
class Controls(GladeControls):
|
||||||
@asyncio.coroutine
|
def __init__(self, facilities):
|
||||||
def build(self, get_data):
|
GladeControls.__init__(self, facilities,
|
||||||
self.builder = Gtk.Builder()
|
"flopping_f_simulation_gui.glade")
|
||||||
data = yield from get_data("flopping_f_simulation_gui.glade")
|
|
||||||
self.builder.add_from_string(data)
|
|
||||||
|
|
||||||
def get_top_widget(self):
|
def finalize(self):
|
||||||
return self.builder.get_object("top")
|
getparam = self.builder.get_object("getparam")
|
||||||
|
getparam.connect("clicked", self.getparam)
|
||||||
|
|
||||||
|
def getparam(self, widget):
|
||||||
|
F0 = self.facilities.get_parameter("flopping_freq")
|
||||||
|
self.builder.get_object("F0").set_value(F0)
|
||||||
|
|
||||||
def get_arguments(self):
|
def get_arguments(self):
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user