forked from M-Labs/artiq
1
0
Fork 0

gui: save layout

This commit is contained in:
Sebastien Bourdeauducq 2015-01-23 19:00:09 +08:00
parent f983fdc985
commit 82330b3c2a
5 changed files with 69 additions and 13 deletions

View File

@ -7,7 +7,9 @@ import atexit
import gbulb import gbulb
from gi.repository import Gtk from gi.repository import Gtk
from artiq.protocols.file_db import FlatFileDB
from artiq.protocols.pc_rpc import AsyncioClient from artiq.protocols.pc_rpc import AsyncioClient
from artiq.gui.tools import LayoutManager
from artiq.gui.scheduler import SchedulerWindow from artiq.gui.scheduler import SchedulerWindow
from artiq.gui.parameters import ParametersWindow from artiq.gui.parameters import ParametersWindow
from artiq.gui.rt_results import RTResults from artiq.gui.rt_results import RTResults
@ -24,12 +26,18 @@ def get_argparser():
parser.add_argument( parser.add_argument(
"--port-control", default=3251, type=int, "--port-control", default=3251, type=int,
help="TCP port to connect to for control") help="TCP port to connect to for control")
parser.add_argument(
"--db-file", default="artiq_gui.pyon",
help="database file for local GUI settings")
return parser return parser
def main(): def main():
args = get_argparser().parse_args() args = get_argparser().parse_args()
db = FlatFileDB(args.db_file, default_data=dict())
lmgr = LayoutManager(db)
asyncio.set_event_loop_policy(gbulb.GtkEventLoopPolicy()) asyncio.set_event_loop_policy(gbulb.GtkEventLoopPolicy())
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
atexit.register(lambda: loop.close()) atexit.register(lambda: loop.close())
@ -40,7 +48,9 @@ def main():
args.server, args.port_control, "master_schedule")) args.server, args.port_control, "master_schedule"))
atexit.register(lambda: schedule_ctl.close_rpc()) atexit.register(lambda: schedule_ctl.close_rpc())
scheduler_win = SchedulerWindow(schedule_ctl) scheduler_win = lmgr.create_window(SchedulerWindow,
"scheduler",
schedule_ctl)
scheduler_win.connect("delete-event", Gtk.main_quit) scheduler_win.connect("delete-event", Gtk.main_quit)
scheduler_win.show_all() scheduler_win.show_all()
loop.run_until_complete(scheduler_win.sub_connect( loop.run_until_complete(scheduler_win.sub_connect(
@ -48,7 +58,8 @@ def main():
atexit.register( atexit.register(
lambda: loop.run_until_complete(scheduler_win.sub_close())) lambda: loop.run_until_complete(scheduler_win.sub_close()))
parameters_win = ParametersWindow() parameters_win = lmgr.create_window(ParametersWindow,
"parameters")
parameters_win.connect("delete-event", Gtk.main_quit) parameters_win.connect("delete-event", Gtk.main_quit)
parameters_win.show_all() parameters_win.show_all()
loop.run_until_complete(parameters_win.sub_connect( loop.run_until_complete(parameters_win.sub_connect(
@ -62,8 +73,9 @@ def main():
atexit.register( atexit.register(
lambda: loop.run_until_complete(rtr.sub_close())) lambda: loop.run_until_complete(rtr.sub_close()))
loop.run_forever() loop.run_forever()
lmgr.save()
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -28,9 +28,11 @@ class _LastChangesStoreSyncer(ListSyncer):
class ParametersWindow(Window): class ParametersWindow(Window):
def __init__(self): def __init__(self, **kwargs):
Window.__init__(self, title="Parameters") Window.__init__(self,
self.set_default_size(500, 500) title="Parameters",
default_size=(500, 500),
**kwargs)
notebook = Gtk.Notebook() notebook = Gtk.Notebook()
self.add(notebook) self.add(notebook)

View File

@ -13,8 +13,8 @@ class _PlotWindow(Window):
self.set_names = set_names self.set_names = set_names
self.data = None self.data = None
Window.__init__(self, title="/".join(set_names)) Window.__init__(self, title="/".join(set_names),
self.set_default_size(700, 500) default_size=(700, 500))
self.darea = Gtk.DrawingArea() self.darea = Gtk.DrawingArea()
self.darea.set_size_request(100, 100) self.darea.set_size_request(100, 100)

View File

@ -34,11 +34,13 @@ class _TimedStoreSyncer(DictSyncer):
class SchedulerWindow(Window): class SchedulerWindow(Window):
def __init__(self, schedule_ctl): def __init__(self, schedule_ctl, **kwargs):
self.schedule_ctl = schedule_ctl self.schedule_ctl = schedule_ctl
Window.__init__(self, title="Scheduler") Window.__init__(self,
self.set_default_size(720, 570) title="Scheduler",
default_size=(720, 570),
**kwargs)
topvbox = Gtk.VBox(spacing=6) topvbox = Gtk.VBox(spacing=6)
self.add(topvbox) self.add(topvbox)

View File

@ -7,12 +7,52 @@ data_dir = os.path.abspath(os.path.dirname(__file__))
class Window(Gtk.Window): class Window(Gtk.Window):
def __init__(self, *args, **kwargs): def __init__(self, title, default_size, layout_dict=dict()):
Gtk.Window.__init__(self, *args, **kwargs) Gtk.Window.__init__(self, title=title)
self.set_wmclass("ARTIQ", "ARTIQ") self.set_wmclass("ARTIQ", "ARTIQ")
self.set_icon_from_file(os.path.join(data_dir, "icon.png")) self.set_icon_from_file(os.path.join(data_dir, "icon.png"))
self.set_border_width(6) self.set_border_width(6)
try:
size = layout_dict["size"]
except KeyError:
size = default_size
self.set_default_size(size[0], size[1])
try:
position = layout_dict["position"]
except KeyError:
pass
else:
self.move(position[0], position[1])
def get_layout_dict(self):
return {
"size": self.get_size(),
"position": self.get_position()
}
class LayoutManager:
def __init__(self, db):
self.db = db
self.windows = dict()
def create_window(self, cls, name, *args, **kwargs):
try:
win_layouts = self.db.request("win_layouts")
layout_dict = win_layouts[name]
except KeyError:
layout_dict = dict()
win = cls(*args, layout_dict=layout_dict, **kwargs)
self.windows[name] = win
return win
def save(self):
win_layouts = {name: window.get_layout_dict()
for name, window in self.windows.items()}
self.db.set("win_layouts", win_layouts)
class ListSyncer: class ListSyncer:
def __init__(self, store, init): def __init__(self, store, init):