2014-12-29 12:48:14 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import asyncio
|
2015-01-02 14:47:09 +08:00
|
|
|
import atexit
|
2015-07-17 02:52:53 +08:00
|
|
|
import os
|
2014-12-29 12:48:14 +08:00
|
|
|
|
2015-05-22 17:05:15 +08:00
|
|
|
# Quamash must be imported first so that pyqtgraph picks up the Qt binding
|
|
|
|
# it has chosen.
|
2015-08-06 22:27:46 +08:00
|
|
|
from quamash import QEventLoop, QtGui, QtCore
|
2015-05-22 23:30:46 +08:00
|
|
|
from pyqtgraph import dockarea
|
2014-12-29 12:48:14 +08:00
|
|
|
|
2015-11-04 00:35:03 +08:00
|
|
|
from artiq.tools import verbosity_args, init_logger, artiq_dir
|
2015-05-24 20:24:07 +08:00
|
|
|
from artiq.protocols.pc_rpc import AsyncioClient
|
2015-08-01 16:48:44 +08:00
|
|
|
from artiq.gui.state import StateManager
|
2015-05-22 23:30:46 +08:00
|
|
|
from artiq.gui.explorer import ExplorerDock
|
2015-06-12 17:41:04 +08:00
|
|
|
from artiq.gui.moninj import MonInj
|
2015-10-12 17:18:23 +08:00
|
|
|
from artiq.gui.datasets import DatasetsDock
|
2015-05-22 23:30:46 +08:00
|
|
|
from artiq.gui.schedule import ScheduleDock
|
2015-06-05 14:52:41 +08:00
|
|
|
from artiq.gui.log import LogDock
|
2015-07-25 00:36:16 +08:00
|
|
|
from artiq.gui.console import ConsoleDock
|
2014-12-29 18:44:50 +08:00
|
|
|
|
2015-07-14 04:08:20 +08:00
|
|
|
|
2015-01-23 00:52:13 +08:00
|
|
|
def get_argparser():
|
2014-12-29 12:48:14 +08:00
|
|
|
parser = argparse.ArgumentParser(description="ARTIQ GUI client")
|
|
|
|
parser.add_argument(
|
|
|
|
"-s", "--server", default="::1",
|
|
|
|
help="hostname or IP of the master to connect to")
|
|
|
|
parser.add_argument(
|
2015-01-13 03:55:50 +08:00
|
|
|
"--port-notify", default=3250, type=int,
|
2014-12-31 20:13:10 +08:00
|
|
|
help="TCP port to connect to for notifications")
|
2014-12-29 12:48:14 +08:00
|
|
|
parser.add_argument(
|
2015-01-13 03:55:50 +08:00
|
|
|
"--port-control", default=3251, type=int,
|
2014-12-31 20:13:10 +08:00
|
|
|
help="TCP port to connect to for control")
|
2015-01-23 19:00:09 +08:00
|
|
|
parser.add_argument(
|
|
|
|
"--db-file", default="artiq_gui.pyon",
|
|
|
|
help="database file for local GUI settings")
|
2015-08-05 11:41:43 +08:00
|
|
|
verbosity_args(parser)
|
2015-01-23 00:52:13 +08:00
|
|
|
return parser
|
2014-12-29 12:48:14 +08:00
|
|
|
|
|
|
|
|
2015-08-06 22:27:46 +08:00
|
|
|
class MainWindow(QtGui.QMainWindow):
|
2015-08-25 00:37:49 +08:00
|
|
|
def __init__(self, app, server):
|
2015-07-20 00:27:41 +08:00
|
|
|
QtGui.QMainWindow.__init__(self)
|
2015-11-04 00:35:03 +08:00
|
|
|
icon = QtGui.QIcon(os.path.join(artiq_dir, "gui", "icon.png"))
|
|
|
|
self.setWindowIcon(icon)
|
2015-08-25 00:37:49 +08:00
|
|
|
self.setWindowTitle("ARTIQ - {}".format(server))
|
2015-07-20 00:27:41 +08:00
|
|
|
self.exit_request = asyncio.Event()
|
|
|
|
|
|
|
|
def closeEvent(self, *args):
|
|
|
|
self.exit_request.set()
|
|
|
|
|
2015-08-06 22:27:46 +08:00
|
|
|
def save_state(self):
|
|
|
|
return bytes(self.saveGeometry())
|
|
|
|
|
|
|
|
def restore_state(self, state):
|
|
|
|
self.restoreGeometry(QtCore.QByteArray(state))
|
|
|
|
|
2015-01-23 19:00:09 +08:00
|
|
|
|
2015-08-01 16:48:44 +08:00
|
|
|
def main():
|
2015-08-05 11:41:43 +08:00
|
|
|
args = get_argparser().parse_args()
|
|
|
|
init_logger(args)
|
|
|
|
|
2015-05-22 17:05:15 +08:00
|
|
|
app = QtGui.QApplication([])
|
|
|
|
loop = QEventLoop(app)
|
|
|
|
asyncio.set_event_loop(loop)
|
2015-11-01 00:03:46 +08:00
|
|
|
atexit.register(loop.close)
|
2015-01-02 14:47:09 +08:00
|
|
|
|
2015-10-31 23:58:39 +08:00
|
|
|
rpc_clients = dict()
|
|
|
|
for target in "schedule", "repository", "dataset_db":
|
|
|
|
client = AsyncioClient()
|
|
|
|
loop.run_until_complete(client.connect_rpc(
|
|
|
|
args.server, args.port_control, "master_" + target))
|
2015-11-01 00:03:46 +08:00
|
|
|
atexit.register(client.close_rpc)
|
2015-10-31 23:58:39 +08:00
|
|
|
rpc_clients[target] = client
|
2015-08-01 16:48:44 +08:00
|
|
|
|
2015-10-31 23:58:39 +08:00
|
|
|
smgr = StateManager(args.db_file)
|
2015-05-24 20:24:07 +08:00
|
|
|
|
2015-08-25 00:37:49 +08:00
|
|
|
win = MainWindow(app, args.server)
|
2015-05-22 23:30:46 +08:00
|
|
|
area = dockarea.DockArea()
|
2015-08-01 16:48:44 +08:00
|
|
|
smgr.register(area)
|
2015-08-06 22:27:46 +08:00
|
|
|
smgr.register(win)
|
2015-05-22 17:05:15 +08:00
|
|
|
win.setCentralWidget(area)
|
2015-05-23 01:25:33 +08:00
|
|
|
status_bar = QtGui.QStatusBar()
|
|
|
|
status_bar.showMessage("Connected to {}".format(args.server))
|
|
|
|
win.setStatusBar(status_bar)
|
2015-01-05 19:52:58 +08:00
|
|
|
|
2015-10-31 23:58:39 +08:00
|
|
|
d_explorer = ExplorerDock(win, status_bar,
|
|
|
|
rpc_clients["schedule"],
|
|
|
|
rpc_clients["repository"])
|
2015-08-05 13:35:28 +08:00
|
|
|
smgr.register(d_explorer)
|
2015-05-24 20:24:07 +08:00
|
|
|
loop.run_until_complete(d_explorer.sub_connect(
|
|
|
|
args.server, args.port_notify))
|
|
|
|
atexit.register(lambda: loop.run_until_complete(d_explorer.sub_close()))
|
2015-05-22 23:30:46 +08:00
|
|
|
|
2015-10-12 17:18:23 +08:00
|
|
|
d_datasets = DatasetsDock(win, area)
|
|
|
|
smgr.register(d_datasets)
|
|
|
|
loop.run_until_complete(d_datasets.sub_connect(
|
2015-07-14 23:31:18 +08:00
|
|
|
args.server, args.port_notify))
|
2015-10-12 17:18:23 +08:00
|
|
|
atexit.register(lambda: loop.run_until_complete(d_datasets.sub_close()))
|
2015-07-14 23:31:18 +08:00
|
|
|
|
2015-08-24 20:20:33 +08:00
|
|
|
if os.name != "nt":
|
|
|
|
d_ttl_dds = MonInj()
|
|
|
|
loop.run_until_complete(d_ttl_dds.start(args.server, args.port_notify))
|
|
|
|
atexit.register(lambda: loop.run_until_complete(d_ttl_dds.stop()))
|
2015-06-05 14:52:41 +08:00
|
|
|
|
2015-08-24 20:20:33 +08:00
|
|
|
if os.name != "nt":
|
|
|
|
area.addDock(d_ttl_dds.dds_dock, "top")
|
|
|
|
area.addDock(d_ttl_dds.ttl_dock, "above", d_ttl_dds.dds_dock)
|
2015-10-12 17:18:23 +08:00
|
|
|
area.addDock(d_datasets, "above", d_ttl_dds.ttl_dock)
|
2015-08-24 20:20:33 +08:00
|
|
|
else:
|
2015-10-12 17:18:23 +08:00
|
|
|
area.addDock(d_datasets, "top")
|
|
|
|
area.addDock(d_explorer, "above", d_datasets)
|
2015-07-21 23:23:32 +08:00
|
|
|
|
2015-10-31 23:58:39 +08:00
|
|
|
d_schedule = ScheduleDock(status_bar, rpc_clients["schedule"])
|
2015-05-22 17:05:15 +08:00
|
|
|
loop.run_until_complete(d_schedule.sub_connect(
|
2015-01-02 14:47:09 +08:00
|
|
|
args.server, args.port_notify))
|
2015-05-22 17:05:15 +08:00
|
|
|
atexit.register(lambda: loop.run_until_complete(d_schedule.sub_close()))
|
2015-11-05 19:04:10 +08:00
|
|
|
d_explorer.get_current_schedule = d_schedule.get_current_schedule
|
2015-01-14 22:22:33 +08:00
|
|
|
|
2015-06-05 14:52:41 +08:00
|
|
|
d_log = LogDock()
|
2015-10-14 21:21:19 +08:00
|
|
|
smgr.register(d_log)
|
2015-07-22 05:13:50 +08:00
|
|
|
loop.run_until_complete(d_log.sub_connect(
|
|
|
|
args.server, args.port_notify))
|
|
|
|
atexit.register(lambda: loop.run_until_complete(d_log.sub_close()))
|
2015-06-05 14:52:41 +08:00
|
|
|
|
2015-10-12 17:18:23 +08:00
|
|
|
def _set_dataset(k, v):
|
2015-10-31 23:58:39 +08:00
|
|
|
asyncio.ensure_future(rpc_clients["dataset_db"].set(k, v))
|
2015-10-12 17:18:23 +08:00
|
|
|
def _del_dataset(k):
|
2015-10-31 23:58:39 +08:00
|
|
|
asyncio.ensure_future(rpc_clients["dataset_db"].delete(k))
|
2015-07-25 00:36:16 +08:00
|
|
|
d_console = ConsoleDock(
|
2015-10-12 17:18:23 +08:00
|
|
|
d_datasets.get_dataset,
|
|
|
|
_set_dataset,
|
|
|
|
_del_dataset)
|
2015-07-25 00:36:16 +08:00
|
|
|
|
|
|
|
area.addDock(d_console, "bottom")
|
|
|
|
area.addDock(d_log, "above", d_console)
|
2015-06-05 14:52:41 +08:00
|
|
|
area.addDock(d_schedule, "above", d_log)
|
|
|
|
|
2015-08-01 16:48:44 +08:00
|
|
|
smgr.load()
|
|
|
|
smgr.start()
|
|
|
|
atexit.register(lambda: loop.run_until_complete(smgr.stop()))
|
2015-05-22 17:05:15 +08:00
|
|
|
win.show()
|
2015-07-20 00:27:41 +08:00
|
|
|
loop.run_until_complete(win.exit_request.wait())
|
2014-12-29 12:48:14 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|