def __init__(self): self.app = comet.Application("comet-pqc") self.app.version = __version__ self.app.title = f"PQC {__version__}" self.app.about = f"COMET application for PQC measurements, version {__version__}." self._setup_resources() self._setup_processes() # Dashboard self.dashboard = Dashboard(message_changed=self.on_message, progress_changed=self.on_progress) self.app.layout = self.dashboard # Fix progress bar width self.app.window.progress_bar.width = 600 # Set URLs self.app.window.contents_url = CONTENTS_URL self.app.window.github_url = GITHUB_URL self._setup_actions() self._setup_menus() self._setup_preferences() logger.info("PQC version %s", __version__) logger.info("Analysis-PQC version %s", analysis_pqc.__version__)
def main(): app = comet.Application() app.title = "Measurement" def on_finish(): start_button.enabled = True stop_button.enabled = False current_number.value = 0 def on_reading(value): print(value) current_number.value = value def on_start(): start_button.enabled = False stop_button.enabled = True process = app.processes.get("measure") process.start() def on_stop(): start_button.enabled = False stop_button.enabled = False process = app.processes.get("measure") process.stop() def on_voltage(value): process = app.processes.get("measure") process.set('voltage', value) process = comet.Process(target=measure) process.finished = on_finish process.failed = ui.show_exception process.reading = on_reading app.processes.add("measure", process) voltage_number = ui.Number(value=0, minimum=0, maximum=1000, decimals=1, suffix="V", changed=on_voltage) current_number = ui.Number(readonly=True, value=0, decimals=3, suffix="mA", stylesheet="color: red") start_button = ui.Button(text="Start", clicked=on_start) stop_button = ui.Button(text="Stop", enabled=False, clicked=on_stop) l = ui.Column( ui.Label("Voltage"), voltage_number, ui.Label("Current"), current_number, start_button, stop_button, ui.Spacer() ) app.layout = l return app.run()
def main(): app = comet.Application() app.title = "Plot" app.about = "An example plot application." def on_reset(): for series in plot.series.values(): series.clear() plot.fit() def on_reading(value): time, temp, humid = value plot.series.get("temp").append(time, temp) plot.series.get("humid").append(time, humid) if plot.zoomed: plot.update("x") else: plot.fit() plot = ui.Plot(legend="bottom") plot.add_axis("x", align="bottom", type="datetime") plot.add_axis("y1", align="left", text="Temperature [°C]", color="red") plot.add_axis("y2", align="right", text="Humidity [%rH]", color="blue") plot.add_series("temp", "x", "y1", text="Temperature", color="red") plot.add_series("humid", "x", "y2", text="Humidity", color="blue") reset_button = ui.Button(text="Reset", clicked=on_reset) app.layout = ui.Column(plot, reset_button) process = comet.Process(target=fake_data) process.reading = on_reading process.failed = ui.show_exception process.start() app.processes.add("process", process) return app.run()
"""Example registering and listing resources. Use Edit -> Preferences... to edit the resources and see changes after application restart. """ import comet from comet import ui app = comet.Application("comet-example") # Register resources app.resources.add("SMU", comet.Resource("ASRL1::INSTR", visa_library="@sim")) app.resources.add("ELM", comet.Resource("ASRL2::INSTR", visa_library="@sim")) app.resources.add("LCR", comet.Resource("ASRL3::INSTR", visa_library="@sim")) # Load stored settings (optional) app.resources.load_settings() table = ui.Table(header=["Name", "Resource", "VISA Library"]) # List resources for name, resource in app.resources.items(): table.append([name, resource.resource_name, resource.visa_library]) table.fit() app.layout = table app.run()
def main(): app = comet.Application() def on_activated(item): ui.show_info(text=format(item.value)) def on_selected(item): print("Item", format(item.value)) table = ui.Table() table.header = "Name", "Status", "HV", "Current", "Temp.", "Calib." table.stretch = True table.activated = on_activated table.selected = on_selected for i in range(10): table.append([ f"Unnamed{i}", "OK", "", "n/a", "n/a", f"{random.random()*1000:.0f} ohm" ]) # First column user checkable table[i][0].checkable = True table[i][0].checked = random.choice([True, False]) # First column editabled table[i][0].readonly = False table.qt.setCurrentItem(table[0][0].qt) table.fit() def on_activated(index, item): ui.show_info(text=format(item[index].value)) def on_selected(item): print("Item", format(item[0].value)) tree = ui.Tree() tree.header = "Measurement", "Status" tree.activated = on_activated tree.selected = on_selected tree.append(["Flute 1", "OK"]) tree.clear() tree.append(["Flute 2", "OK"]) tree.insert(0, ["Flute 3", "Meas..."]) tree[0][0].checked = True tree[0][1].color = "red" tree[0][1].background = "blue" #tree[0][1].color = None tree[0][1].background = None tree.append(["Flute 4", "OK"]) tree.append(["Flute 5", "OK"]) tree.append(["Flute 6"]) tree.qt.setCurrentItem(tree[2].qt) tree.remove(tree[3]) for i, item in enumerate(tree): if i == 1: item.expanded = True item[0].checked = True item.append(["Test 1", "OK"]) item.append(["Test 2", "OK"]) item.insert(0, ["Test 3", "OK"]) item.children[0][0].checked = True item.children[1][0].checked = False item.children[2][0].checked = True for item in tree: print(item[0].checked) for item in item.children: print(item[0].checked) def measure(process): while process.running: for i in range(10): value = random.choice([True, False]) process.emit('hv', i, value) value = random.uniform(22., 24.) process.emit('temp', i, value) for i in range(2): value = random.choice(["OK", "FAIL"]) process.emit('status', i, value) time.sleep(1) def on_hv(i, value): item = table[i][2] if table[i][0].checked: item.value = {True: "ON", False: "OFF"}[value] item.color = {True: "green", False: "red"}[value] item.bold = not value else: item.value = None def on_temp(i, value): item = table[i][4] if table[i][0].checked: item.value = value item.color = "green" if item.value < 22.5: item.color = "red" else: item.value = None def on_status(i, value): color = {"OK": "green", "FAIL": "red"}[value] tree[i][1].value = value tree[i][1].color = color tree[i][1].bold = value == "FAIL" for item in tree[i].children: if item[0].checked: item[1].value = value item[1].color = color item[1].bold = value == "FAIL" else: item[1].value = None app.layout = ui.Column(table, tree) process = comet.Process(target=measure) process.hv = on_hv process.temp = on_temp process.status = on_status app.processes.add("process", process) process.start() return app.run()
def main(): app = comet.Application() app.title = "UI Demo" values = ["Chapman", "Cleese", "Gilliam", "Idle", "Jones", "Palin"] tab1 = ui.Tab(title="Tab 1", layout=ui.Column( ui.Row(ui.Column( ui.GroupBox(title="Numbers", layout=ui.Column( ui.Label(text="Number 1"), ui.Number(value=1, minimum=0, maximum=10, step=1, prefix="#"), ui.Label(text="Number 2"), ui.Number(value=2.345, minimum=0, maximum=10, step=.1, decimals=3, suffix="mV"), ui.Label(text="Number 3"), ui.Number(value=1.23, minimum=0, maximum=10, decimals=2, suffix="mA", readonly=True), ui.Label(text="Number 4"), ui.Number(value=4.2, minimum=0, maximum=10, decimals=1, suffix="dB", enabled=False)))), ui.Column( ui.GroupBox(title="Text", layout=ui.Column( ui.Label(text="Text 1"), ui.Text(value="Chapman"), ui.Label(text="Text 2"), ui.Text(value="Cleese", clearable=True), ui.Label(text="Text 3"), ui.Text(value="Idle", readonly=True), ui.Label(text="Text 4"), ui.Text(value="Palin", enabled=False)))), ui.Spacer(), stretch=(2, 2, 3)), ui.Spacer(), stretch=(0, 1))) def on_append(): list1.append(f"Spam {len(list1)}") list1.current = list1[0] def on_remove(): if list1.current is not None: list1.remove(list1.current) list1 = ui.List() tab2 = ui.Tab(title="Tab 2", layout=ui.Column(ui.Row( ui.GroupBox(title="List 1", layout=ui.Column( list1, ui.Button(text="&Add", clicked=on_append), ui.Button(text="&Remove", clicked=on_remove))), ui.GroupBox(title="List 2", layout=ui.List(values)), ui.GroupBox(title="List 3", layout=ui.List(values, enabled=False))), ui.Spacer(), stretch=(0, 1))) table1 = ui.Table(header=["Key", "Value"]) tab3 = ui.Tab(title="Tab 3", layout=ui.Column(table1)) tree1 = ui.Tree(header=["Key", "Value"]) tab4 = ui.Tab(title="Tab 4", layout=ui.Column(tree1)) first = ui.Button(text="Click") scroll = ui.ScrollArea(layout=ui.Column(*[ ui.CheckBox(text=f"Option {i+1}", checked=random.choice([True, False])) for i in range(64) ])) second = ui.Column(scroll) tab5 = ui.Tab(title="Tab 5", layout=first) tab5.layout = second del first tab6 = ui.Tab(title="Tab 6", layout=ui.Row(ui.Column( ui.Label("Metric 1"), ui.Metric('V', decimals=3, changed=lambda value: print(value)), ui.Label("Metric 2"), ui.Metric('A', prefixes='munp', changed=lambda value: print(value)), ui.Spacer()), ui.Spacer(), stretch=(1, 2))) def on_changed(value): app.message = value def on_click(): app.message = combobox1.current tabs = ui.Tabs(tab1, tab2, tab3, tab4, tab5, tab6) combobox1 = ui.ComboBox(values) app.layout = ui.Row(ui.Column( ui.GroupBox(title="GroupBox 1", layout=ui.Column( ui.Button(text="Button 1", clicked=on_click), ui.Button(text="Button 2", enabled=False), ui.Button(text="Button 3", checkable=True), ui.Button(text="Button 4", checkable=True, enabled=False), ui.Button(text="Button 5", checkable=True, checked=True))), ui.GroupBox(title="GroupBox 2", layout=ui.Column( ui.CheckBox(text="CheckBox 1"), ui.CheckBox(text="CheckBox 2", enabled=False), ui.CheckBox(text="CheckBox 3", checked=True, enabled=False), ui.CheckBox(text="CheckBox 4", checked=True))), ui.GroupBox(title="GroupBox 3", layout=ui.Column( ui.ComboBox(), combobox1, ui.ComboBox(values, current="Cleese", changed=on_changed), ui.ComboBox(values, current="Idle", enabled=False))), ui.Spacer()), tabs, stretch=(2, 7)) # Populate table spam = table1.append(["Spam", 42]) spam[0].checked = True #spam[0].enabled = False ham = table1.append(["Ham", 41]) ham[0].checked = True #ham[0].enabled = False # Populate tree spam = tree1.append(["Spam", 42]) spam[0].checked = True spam.append(["Ham", 41]) spam.append(["Eggs", 40]) # Add an remove tab tab = ui.Tab() tabs.insert(0, tab) tab.title = "Spam" tabs.remove(tab) app.message = "Notification message..." app.progress = 3, 4 return app.run()
def main(): args = parse_args() # Logging logging.getLogger().setLevel(logging.INFO) logging.info("PQC version %s", __version__) app = comet.Application("comet-pqc") app.version = __version__ app.title = f"PQC {__version__}" app.about = f"COMET application for PQC measurements, version {__version__}." # Register devices app.resources.add("matrix", comet.Resource( resource_name="TCPIP::10.0.0.2::5025::SOCKET", encoding='latin1', read_termination="\n", write_termination="\n" )) app.resources.add("hvsrc", comet.Resource( resource_name="TCPIP::10.0.0.5::10002::SOCKET", read_termination="\r\n", write_termination="\r\n", timeout=4000 )) app.resources.add("vsrc", comet.Resource( resource_name="TCPIP::10.0.0.3::5025::SOCKET", encoding='latin1', read_termination="\n", write_termination="\n" )) app.resources.add("lcr", comet.Resource( resource_name="TCPIP::10.0.0.4::5025::SOCKET", read_termination="\n", write_termination="\n", timeout=8000 )) app.resources.add("elm", comet.Resource( resource_name="TCPIP::10.0.0.5::10001::SOCKET", read_termination="\r\n", write_termination="\r\n", timeout=8000 )) app.resources.add("table", comet.Resource( resource_name="TCPIP::10.0.0.6::23::SOCKET", read_termination="\r\n", write_termination="\r\n", timeout=8000 )) app.resources.add("environ", comet.Resource( resource_name="TCPIP::10.0.0.8::10001::SOCKET", read_termination="\r\n", write_termination="\r\n" )) app.resources.load_settings() # Callbacks def on_show_error(exc, tb): app.message = "Exception occured!" app.progress = None logging.error(tb) ui.show_exception(exc, tb) def on_message(message): ## logging.info(message) app.message = message def on_progress(value, maximum): if value == maximum: app.progress = None else: app.progress = value, maximum # Register processes app.processes.add("environ", EnvironmentProcess( name="environ", failed=on_show_error )) app.processes.add("status", StatusProcess( failed=on_show_error, message=on_message, progress=on_progress )) app.processes.add("table", AlternateTableProcess( failed=on_show_error )) app.processes.add("measure", MeasureProcess( failed=on_show_error, message=on_message, progress=on_progress, )) # Dashboard dashboard = Dashboard( message_changed=on_message, progress_changed=on_progress ) # Layout app.layout = dashboard # Restore window size app.width, app.height = app.settings.get('window_size', (1420, 920)) # Extend actions app.window.github_action = ui.Action( text="&GitHub", triggered=dashboard.on_github ) # Extend menus app.window.file_menu.insert(-1, ui.Action(separator=True)) app.window.help_menu.insert(1, app.window.github_action) # Extend preferences table_tab = TableTab() app.window.preferences_dialog.tab_widget.append(table_tab) app.window.preferences_dialog.table_tab = table_tab options_tab = OptionsTab() app.window.preferences_dialog.tab_widget.append(options_tab) app.window.preferences_dialog.options_tab = options_tab # Set URLs app.window.contents_url = CONTENTS_URL app.window.github_url = GITHUB_URL # Fix progress bar width app.window.progress_bar.width = 600 # Load configurations dashboard.load_settings() # Sync environment controls if dashboard.use_environment(): dashboard.environ_process.start() dashboard.sync_environment_controls() if dashboard.use_table(): dashboard.table_process.start() dashboard.sync_table_controls() # HACK: resize preferences dialog for HiDPI dialog_size = app.settings.get('preferences_dialog_size', (640, 480)) app.window.preferences_dialog.resize(*dialog_size) result = app.run() dashboard.store_settings() # Store window size app.settings['window_size'] = app.width, app.height dialog_size = app.window.preferences_dialog.size app.settings['preferences_dialog_size'] = dialog_size return result
def main(): app = comet.Application(title="Sandbox", version="1.0") app.layout = comet.Label(text="Sandbox") app.run()
def main(): app = comet.Application(name="comet-pt100") app.title = "Pt100" # Resources resources = QtCore.QSettings().value('resources', {}) app.resources.update({ "cts": resources.get("cts", "TCPIP::127.0.0.1::1080::SOCKET"), "multi": resources.get("multi", "TCPIP::127.0.0.1::10001::SOCKET") }) # Processes measure = MeasureProcess() measure.started.connect(on_started) measure.finished.connect(on_finished) measure.reading.connect(on_update) app.processes().add("measure", measure) # Connect process with main window (tweak) app.get('root').qt.connectProcess(measure) # Layout app.layout = comet.Row( comet.Column( comet.FieldSet( title="Control", layout=comet.Column( comet.Button(id="start", title="Start", click=lambda e: measure.start()), comet.Button(id="stop", title="Stop", enabled=False, click=lambda e: measure.stop()) ) ), comet.FieldSet( id="add_ramp_fs", title="Add Temperature", layout=comet.Column( comet.Label(text="Target Temp."), comet.Number(id="ramp_end", value=25, minimum=-40, maximum=120, unit="°C"), comet.Label(text="Duration"), comet.Number(id="ramp_interval", value=1, maximum=3600, precision=1, unit="min"), comet.Button(title="Add", click=on_add_ramp) ) ), comet.FieldSet( id="ramps_fs", title="Temp. Ramps", layout=comet.Column( comet.Table( id="table", columns=["end", "interval"], titles=dict(end="Target °C", interval="Dur. min") ), comet.Button(title="Clear", click=on_clear_ramps) ) ), comet.Stretch() ), comet.Plot( id="plot", axes=dict( x=dict(align="bottom", type="datetime", title="Time"), y=dict(align="left", type="value", title="Temp/Humid"), ), series=[ dict(name="temp", x="x", y="y", title="CTS Temp."), dict(name="humid", x="x", y="y", title="CTS Humid"), dict(name="pt100", x="x", y="y", title="PT100") ] ) ) return app.run()