def __init__(self): dockarea.Dock.__init__(self, "Log", size=(1000, 300)) grid = LayoutWidget() self.addWidget(grid) grid.addWidget(QtGui.QLabel("Minimum level: "), 0, 0) grid.layout.setColumnStretch(0, 0) grid.layout.setColumnStretch(1, 0) grid.layout.setColumnStretch(2, 1) self.filterbox = QtGui.QComboBox() for item in "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL": self.filterbox.addItem(item) self.filterbox.setToolTip("Display entries at or above this level") grid.addWidget(self.filterbox, 0, 1) self.filterbox.currentIndexChanged.connect(self.filter_changed) self.log = QtGui.QTableView() self.log.setSelectionMode(QtGui.QAbstractItemView.NoSelection) self.log.horizontalHeader().setResizeMode( QtGui.QHeaderView.ResizeToContents) self.log.setHorizontalScrollMode( QtGui.QAbstractItemView.ScrollPerPixel) self.log.setShowGrid(False) self.log.setTextElideMode(QtCore.Qt.ElideNone) grid.addWidget(self.log, 1, 0, colspan=3) self.scroll_at_bottom = False
def __init__(self, name): dockarea.Dock.__init__(self, name, size=(1500, 500)) self.grid = QtGui.QGridLayout() gridw = QtGui.QWidget() gridw.setLayout(self.grid) self.addWidget(gridw)
def __init__(self, channel, sysclk, title): self.channel = channel self.sysclk = sysclk QtGui.QFrame.__init__(self) self.setFrameShape(QtGui.QFrame.Panel) self.setFrameShadow(QtGui.QFrame.Raised) grid = QtGui.QGridLayout() self.setLayout(grid) label = QtGui.QLabel(title) label.setAlignment(QtCore.Qt.AlignCenter) label.setWordWrap(True) grid.addWidget(label, 1, 1) self._value = QtGui.QLabel() self._value.setAlignment(QtCore.Qt.AlignCenter) self._value.setWordWrap(True) grid.addWidget(self._value, 2, 1, 6, 1) grid.setRowStretch(1, 1) grid.setRowStretch(2, 0) grid.setRowStretch(3, 1) self.set_value(0)
def __init__(self, dialog_parent, dock_area): dockarea.Dock.__init__(self, "Results", size=(1500, 500)) self.dialog_parent = dialog_parent self.dock_area = dock_area grid = LayoutWidget() self.addWidget(grid) self.table = QtGui.QTableView() self.table.setSelectionMode(QtGui.QAbstractItemView.NoSelection) self.table.horizontalHeader().setResizeMode( QtGui.QHeaderView.ResizeToContents) grid.addWidget(self.table, 0, 0) add_display_box = QtGui.QGroupBox("Add display") grid.addWidget(add_display_box, 0, 1) display_grid = QtGui.QGridLayout() add_display_box.setLayout(display_grid) for n, name in enumerate(display_types.keys()): btn = QtGui.QPushButton(name) display_grid.addWidget(btn, n, 0) btn.clicked.connect(partial(self.create_dialog, name)) self.displays = dict()
def __init__(self, procdesc): LayoutWidget.__init__(self) self.stack = QtGui.QStackedWidget() self.addWidget(self.stack, 1, 0, colspan=4) self.scale = procdesc["scale"] gmin, gmax = procdesc["global_min"], procdesc["global_max"] gstep = procdesc["global_step"] unit = procdesc["unit"] ndecimals = procdesc["ndecimals"] self.v_noscan = QtGui.QDoubleSpinBox() self.v_noscan.setDecimals(ndecimals) if gmin is not None: self.v_noscan.setMinimum(gmin / self.scale) else: self.v_noscan.setMinimum(float("-inf")) if gmax is not None: self.v_noscan.setMaximum(gmax / self.scale) else: self.v_noscan.setMaximum(float("inf")) self.v_noscan.setSingleStep(gstep / self.scale) if unit: self.v_noscan.setSuffix(" " + unit) self.v_noscan_gr = LayoutWidget() self.v_noscan_gr.addWidget(QtGui.QLabel("Value:"), 0, 0) self.v_noscan_gr.addWidget(self.v_noscan, 0, 1) self.stack.addWidget(self.v_noscan_gr) self.v_linear = _Range(gmin, gmax, gstep, unit, self.scale, ndecimals) self.stack.addWidget(self.v_linear) self.v_random = _Range(gmin, gmax, gstep, unit, self.scale, ndecimals) self.stack.addWidget(self.v_random) self.v_explicit = QtGui.QLineEdit() self.v_explicit_gr = LayoutWidget() self.v_explicit_gr.addWidget(QtGui.QLabel("Sequence:"), 0, 0) self.v_explicit_gr.addWidget(self.v_explicit, 0, 1) self.stack.addWidget(self.v_explicit_gr) self.noscan = QtGui.QRadioButton("No scan") self.linear = QtGui.QRadioButton("Linear") self.random = QtGui.QRadioButton("Random") self.explicit = QtGui.QRadioButton("Explicit") radiobuttons = QtGui.QButtonGroup() for n, b in enumerate( [self.noscan, self.linear, self.random, self.explicit]): self.addWidget(b, 0, n) radiobuttons.addButton(b) b.toggled.connect(self.select_page) if "default" in procdesc: self.set_argument_value(procdesc["default"]) else: self.noscan.setChecked(True)
def _get_group(self, name): if name in self._groups: return self._groups[name] group = QtGui.QTreeWidgetItem([name, ""]) for c in 0, 1: group.setBackground(c, QtGui.QBrush(QtGui.QColor(100, 100, 100))) group.setForeground(c, QtGui.QBrush(QtGui.QColor(220, 220, 255))) font = group.font(c) font.setBold(True) group.setFont(c, font) self.addTopLevelItem(group) self._groups[name] = group return group
def __init__(self, parent, window_title, prev_name, create_cb): QtGui.QDialog.__init__(self, parent=parent) self.setWindowTitle(window_title) self.grid = QtGui.QGridLayout() self.setLayout(self.grid) self.grid.addWidget(QtGui.QLabel("Name:"), 0, 0) self.name = QtGui.QLineEdit() self.grid.addWidget(self.name, 0, 1) if prev_name is not None: self.name.setText(prev_name) def on_accept(): create_cb(self.name.text(), self.get_input()) self.accepted.connect(on_accept)
def __init__(self, name, settings): dockarea.Dock.__init__(self, "Display: " + name, size=(250, 250), closable=True) self.settings = settings self.number = QtGui.QLCDNumber() self.number.setDigitCount(10) self.addWidget(self.number)
def __init__(self): dockarea.Dock.__init__(self, "Parameters", size=(400, 300)) grid = LayoutWidget() self.addWidget(grid) self.search = QtGui.QLineEdit() self.search.setPlaceholderText("search...") self.search.editingFinished.connect(self._search_parameters) grid.addWidget(self.search, 0, 0) self.table = QtGui.QTableView() self.table.setSelectionMode(QtGui.QAbstractItemView.NoSelection) self.table.horizontalHeader().setResizeMode( QtGui.QHeaderView.ResizeToContents) grid.addWidget(self.table, 1, 0)
def set_arguments(self, arguments): self.clear() if not arguments: self.addTopLevelItem(QtGui.QTreeWidgetItem(["No arguments", ""])) self._args_to_entries = dict() for n, (name, (procdesc, group)) in enumerate(arguments): entry = _procty_to_entry[procdesc["ty"]](procdesc) self._args_to_entries[name] = entry widget_item = QtGui.QTreeWidgetItem([name, ""]) if group is None: self.addTopLevelItem(widget_item) else: self._get_group(group).addChild(widget_item) self.setItemWidget(widget_item, 1, entry)
def __init__(self, parent, prev_name, prev_settings, result_list, create_cb): _BaseSettings.__init__(self, parent, self._window_title, prev_name, create_cb) self.result_widgets = dict() for row, (has_none, key) in enumerate(self._result_keys): self.grid.addWidget(QtGui.QLabel(key.capitalize() + ":")) w = QtGui.QComboBox() self.grid.addWidget(w, row + 1, 1) if has_none: w.addItem("<None>") w.addItems(result_list) w.setEditable(True) if key in prev_settings: w.setEditText(prev_settings[key]) self.result_widgets[key] = w self.add_buttons()
def __init__(self, status_bar, schedule_ctl): dockarea.Dock.__init__(self, "Schedule", size=(1000, 300)) self.status_bar = status_bar self.schedule_ctl = schedule_ctl self.table = QtGui.QTableView() self.table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) self.table.setSelectionMode(QtGui.QAbstractItemView.SingleSelection) self.table.horizontalHeader().setResizeMode( QtGui.QHeaderView.ResizeToContents) self.table.verticalHeader().setResizeMode( QtGui.QHeaderView.ResizeToContents) self.addWidget(self.table) self.table.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) delete_action = QtGui.QAction("Delete", self.table) delete_action.triggered.connect(self.delete_clicked) self.table.addAction(delete_action)
def __init__(self, global_min, global_max, global_step, unit, ndecimals): LayoutWidget.__init__(self) def apply_properties(spinbox): spinbox.setDecimals(ndecimals) if global_min is not None: spinbox.setMinimum(global_min) else: spinbox.setMinimum(float("-inf")) if global_max is not None: spinbox.setMaximum(global_max) else: spinbox.setMaximum(float("inf")) if global_step is not None: spinbox.setSingleStep(global_step) if unit: spinbox.setSuffix(" " + unit) self.addWidget(QtGui.QLabel("Min:"), 0, 0) self.min = QtGui.QDoubleSpinBox() apply_properties(self.min) self.addWidget(self.min, 0, 1) self.addWidget(QtGui.QLabel("Max:"), 0, 2) self.max = QtGui.QDoubleSpinBox() apply_properties(self.max) self.addWidget(self.max, 0, 3) self.addWidget(QtGui.QLabel("#Points:"), 0, 4) self.npoints = QtGui.QSpinBox() self.npoints.setMinimum(2) self.npoints.setValue(10) self.addWidget(self.npoints, 0, 5)
def __init__(self): dockarea.Dock.__init__(self, "Log", size=(1000, 300)) self.log = QtGui.QTableView() self.log.setSelectionMode(QtGui.QAbstractItemView.NoSelection) self.log.horizontalHeader().setResizeMode( QtGui.QHeaderView.ResizeToContents) self.log.setHorizontalScrollMode( QtGui.QAbstractItemView.ScrollPerPixel) self.log.setShowGrid(False) self.log.setTextElideMode(QtCore.Qt.ElideNone) self.addWidget(self.log) self.scroll_at_bottom = False
def __init__(self, send_to_device, channel, sysclk, name, comment): self.send_to_device = send_to_device self.channel = channel self.comment = comment self.sysclk = sysclk self.name = name QtGui.QFrame.__init__(self) self.setFrameShape(QtGui.QFrame.Panel) self.setFrameShadow(QtGui.QFrame.Raised) grid = QtGui.QGridLayout() self.setLayout(grid) label = QtGui.QLabel("{} {}".format(name, comment)) label.setAlignment(QtCore.Qt.AlignCenter) grid.addWidget(label, 1, 1) self._value = QtGui.QLabel() self._value.setAlignment(QtCore.Qt.AlignCenter) grid.addWidget(self._value, 2, 1, 6, 1) self.set_value(0)
def get_argument_values(self, show_error_message): r = dict() for arg, entry in self._args_to_entries.items(): try: r[arg] = entry.get_argument_value() except Exception as e: if show_error_message: msgbox = QtGui.QMessageBox(self.dialog_parent) msgbox.setWindowTitle("Error") msgbox.setText( "Failed to obtain value for argument '{}':\n{}".format( arg, str(e))) msgbox.setStandardButtons(QtGui.QMessageBox.Ok) msgbox.show() return None return r
def __init__(self, serial, printHz=False, bufsize=2048, baudrate=1e6): super().__init__() self.serial = serial self.baudrate = baudrate self.bufsize = bufsize self.run = True self.fs = 80000 self.c = 34300 # Filter parameters self.alpha = 0.05 self.cutoff = 100 self.order = 5 # Touch detection parameters self.threshold = 180.0 # Creating plot window app = QtGui.QApplication(sys.argv) loop = QEventLoop(app) asyncio.set_event_loop(loop) self.resize(800, 400) # App ranges self.ranges = {'a': (20, 53), 'b': (62, 101), 'c': (110, 150)} # Plotting parameters p = self.addPlot() self.plotline = p.plot(pen='y') self.baseline = p.plot(pen='b') self.l = pg.TextItem() self.l.setText('') self.l.setColor('y') self.l.setTextWidth(500) p.addItem(self.l) self.show() loop.run_until_complete(self.read_data())
def add_buttons(self): buttons = QtGui.QDialogButtonBox( QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel) self.grid.addWidget(buttons, self.grid.rowCount(), 0, 1, 2) buttons.accepted.connect(self.accept) buttons.rejected.connect(self.reject)
def main(): args = get_argparser().parse_args() init_logger(args) app = QtGui.QApplication([]) loop = QEventLoop(app) asyncio.set_event_loop(loop) atexit.register(lambda: loop.close()) smgr = StateManager(args.db_file) schedule_ctl = AsyncioClient() loop.run_until_complete( schedule_ctl.connect_rpc(args.server, args.port_control, "master_schedule")) atexit.register(lambda: schedule_ctl.close_rpc()) win = MainWindow(app, args.server) area = dockarea.DockArea() smgr.register(area) smgr.register(win) win.setCentralWidget(area) status_bar = QtGui.QStatusBar() status_bar.showMessage("Connected to {}".format(args.server)) win.setStatusBar(status_bar) d_explorer = ExplorerDock(win, status_bar, schedule_ctl) smgr.register(d_explorer) loop.run_until_complete( d_explorer.sub_connect(args.server, args.port_notify)) atexit.register(lambda: loop.run_until_complete(d_explorer.sub_close())) d_datasets = DatasetsDock(win, area) smgr.register(d_datasets) loop.run_until_complete( d_datasets.sub_connect(args.server, args.port_notify)) atexit.register(lambda: loop.run_until_complete(d_datasets.sub_close())) 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())) 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) area.addDock(d_datasets, "above", d_ttl_dds.ttl_dock) else: area.addDock(d_datasets, "top") area.addDock(d_explorer, "above", d_datasets) d_schedule = ScheduleDock(status_bar, schedule_ctl) loop.run_until_complete( d_schedule.sub_connect(args.server, args.port_notify)) atexit.register(lambda: loop.run_until_complete(d_schedule.sub_close())) d_log = LogDock() smgr.register(d_log) loop.run_until_complete(d_log.sub_connect(args.server, args.port_notify)) atexit.register(lambda: loop.run_until_complete(d_log.sub_close())) dataset_db = AsyncioClient() loop.run_until_complete( dataset_db.connect_rpc(args.server, args.port_control, "master_dataset_db")) atexit.register(lambda: dataset_db.close_rpc()) def _set_dataset(k, v): asyncio.ensure_future(dataset_db.set(k, v)) def _del_dataset(k): asyncio.ensure_future(dataset_db.delete(k)) d_console = ConsoleDock(d_datasets.get_dataset, _set_dataset, _del_dataset) area.addDock(d_console, "bottom") area.addDock(d_log, "above", d_console) area.addDock(d_schedule, "above", d_log) smgr.load() smgr.start() atexit.register(lambda: loop.run_until_complete(smgr.stop())) win.show() loop.run_until_complete(win.exit_request.wait())
def __init__(self, app, server): QtGui.QMainWindow.__init__(self) self.setWindowIcon(QtGui.QIcon(os.path.join(data_dir, "icon.png"))) self.setWindowTitle("ARTIQ - {}".format(server)) self.exit_request = asyncio.Event()
def __init__(self, send_to_device, channel, force_out, name, comment): self.send_to_device = send_to_device self.channel = channel self.comment = comment self.force_out = force_out QtGui.QFrame.__init__(self) self.setFrameShape(QtGui.QFrame.Panel) self.setFrameShadow(QtGui.QFrame.Raised) grid = QtGui.QGridLayout() self.setLayout(grid) label = QtGui.QLabel("{} {}".format(name, comment)) label.setAlignment(QtCore.Qt.AlignCenter) grid.addWidget(label, 1, 1) self._direction = QtGui.QLabel() self._direction.setAlignment(QtCore.Qt.AlignCenter) grid.addWidget(self._direction, 2, 1) self._override = QtGui.QLabel() self._override.setAlignment(QtCore.Qt.AlignCenter) grid.addWidget(self._override, 3, 1) self._value = QtGui.QLabel() self._value.setAlignment(QtCore.Qt.AlignCenter) grid.addWidget(self._value, 4, 1, 6, 1) self._value.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) menu = QtGui.QActionGroup(self._value) menu.setExclusive(True) self._expctl_action = QtGui.QAction("Experiment controlled", self._value) self._expctl_action.setCheckable(True) menu.addAction(self._expctl_action) self._value.addAction(self._expctl_action) self._expctl_action.triggered.connect(lambda: self.set_mode("exp")) separator = QtGui.QAction(self._value) separator.setSeparator(True) self._value.addAction(separator) self._force1_action = QtGui.QAction("Force 1", self._value) self._force1_action.setCheckable(True) menu.addAction(self._force1_action) self._value.addAction(self._force1_action) self._force1_action.triggered.connect(lambda: self.set_mode("1")) self._force0_action = QtGui.QAction("Force 0", self._value) self._force0_action.setCheckable(True) menu.addAction(self._force0_action) self._value.addAction(self._force0_action) self._force0_action.triggered.connect(lambda: self.set_mode("0")) self._forcein_action = QtGui.QAction("Force input", self._value) self._forcein_action.setCheckable(True) self._forcein_action.setEnabled(not force_out) menu.addAction(self._forcein_action) self._value.addAction(self._forcein_action) self._forcein_action.triggered.connect(lambda: self.set_mode("in")) self.set_value(0, False, False)
def __init__(self, dialog_parent, status_bar, schedule_ctl): dockarea.Dock.__init__(self, "Explorer", size=(1500, 500)) self.dialog_parent = dialog_parent self.status_bar = status_bar self.schedule_ctl = schedule_ctl self.splitter = QtGui.QSplitter(QtCore.Qt.Horizontal) self.addWidget(self.splitter) grid = LayoutWidget() self.splitter.addWidget(grid) self.el = QtGui.QListView() self.el.selectionChanged = self._selection_changed self.selected_key = None grid.addWidget(self.el, 0, 0, colspan=4) self.datetime = QtGui.QDateTimeEdit() self.datetime.setDisplayFormat("MMM d yyyy hh:mm:ss") self.datetime.setDate(QtCore.QDate.currentDate()) self.datetime.dateTimeChanged.connect(self.enable_duedate) self.datetime_en = QtGui.QCheckBox("Due date:") grid.addWidget(self.datetime_en, 1, 0, colspan=2) grid.addWidget(self.datetime, 1, 2, colspan=2) self.pipeline = QtGui.QLineEdit() self.pipeline.setText("main") grid.addWidget(QtGui.QLabel("Pipeline:"), 2, 0, colspan=2) grid.addWidget(self.pipeline, 2, 2, colspan=2) self.priority = QtGui.QSpinBox() self.priority.setRange(-99, 99) grid.addWidget(QtGui.QLabel("Priority:"), 3, 0) grid.addWidget(self.priority, 3, 1) self.flush = QtGui.QCheckBox("Flush") self.flush.setToolTip( "Flush the pipeline before starting the experiment") grid.addWidget(self.flush, 3, 2) self.log_level = QtGui.QComboBox() for item in "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL": self.log_level.addItem(item) self.log_level.setCurrentIndex(1) self.log_level.setToolTip("Minimum level for log entry production") grid.addWidget(self.log_level, 3, 3) submit = QtGui.QPushButton("Submit") submit.setShortcut("CTRL+RETURN") submit.setToolTip("Schedule the selected experiment (CTRL+ENTER)") grid.addWidget(submit, 4, 0, colspan=4) submit.clicked.connect(self.submit_clicked) self.argeditor = _ArgumentEditor(self.dialog_parent) self.splitter.addWidget(self.argeditor) self.splitter.setSizes([grid.minimumSizeHint().width(), 1000]) self.state = dict()
def __init__(self, serialport, *, baudrate=115200, outpath=None, printlines=False, firstline='', printHz=False, bufsize=2048, pMin=0, pMax=25, convert_pressure=False, socket_start=False): super().__init__() self.serialport = serialport self.baudrate = baudrate self.outpath = outpath self.outfile = None self.printlines = printlines self.printHz = printHz self.bufsize = bufsize self.plotbuf = deque(maxlen=self.bufsize) self.rawdata = deque(maxlen=self.bufsize) self.pMin = pMin self.pMax = pMax self.convert_pressure = convert_pressure self.f = OneEuroFilter(100, .25, .1) self.event = 0 self.run = True self.filterflag = True #Touch event detection self.diffsamps = 100 #How far back to look for diff self.event_thresh = 7 #Standard Deviation value to consider an event is happening self.touch = False #Is a touch happening? self.touchcount = 0 #How many touch samples so far? self.touchthresh = 1000 #Number of touch samples to check self.touch_data = [ ] #Data from touch to be sent to machine learning thingy self.touch_buf = [] # self.model = load(model) # Path to compiled model file self.printed = False self.socket = socket_start #Keep values to update baseline self.baselinebuf = deque(maxlen=self.bufsize // 4) app = QtGui.QApplication(sys.argv) loop = QEventLoop(app) asyncio.set_event_loop(loop) self.resize(800, 400) p = self.addPlot() self.plotline = p.plot(pen='y') self.baseline = p.plot(pen='b') self.show() if self.socket: # Create socket and wait for connection ip = '' port = 6969 connected = False s = socket.socket() print('Waiting on connection') s.bind((ip, port)) s.listen(1) self.conn, self.addr = s.accept() loop.run_until_complete(self.read_data()) if self.outpath: with open(self.outpath, 'w') as self.outfile: if firstline: self.log('#{}'.format(firstline)) loop.run_until_complete(self.read_data()) else: if firstline: self.log('#{}'.format(firstline)) loop.run_until_complete(self.read_data())
def __init__(self, parent, init): ListSyncModel.__init__(self, ["RID", "Message"], parent, init) self.fixed_font = QtGui.QFont() self.fixed_font.setFamily("Monospace")
def __init__(self, parent, init): ListSyncModel.__init__(self, ["Level", "Source", "Time", "Message"], parent, init) self.fixed_font = QtGui.QFont() self.fixed_font.setFamily("Monospace") self.white = QtGui.QBrush(QtGui.QColor(255, 255, 255)) self.black = QtGui.QBrush(QtGui.QColor(0, 0, 0)) self.debug_fg = QtGui.QBrush(QtGui.QColor(55, 55, 55)) self.warning_bg = QtGui.QBrush(QtGui.QColor(255, 255, 180)) self.error_bg = QtGui.QBrush(QtGui.QColor(255, 150, 150))