forked from awendt/pyrelacs
[ui] removing duplicate toolbar, adding textfield
This commit is contained in:
parent
6a3a610cd3
commit
ab51fa7475
@ -32,7 +32,9 @@ from IPython import embed
|
|||||||
class PyRelacs(QMainWindow):
|
class PyRelacs(QMainWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
# self.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) # Ensure icons are displayed with text
|
self.setToolButtonStyle(
|
||||||
|
Qt.ToolButtonStyle.ToolButtonTextBesideIcon
|
||||||
|
) # Ensure icons are displayed with text
|
||||||
self.setWindowTitle("PyRelacs")
|
self.setWindowTitle("PyRelacs")
|
||||||
self.beat_plot = pg.PlotWidget()
|
self.beat_plot = pg.PlotWidget()
|
||||||
self.power_plot = pg.PlotWidget()
|
self.power_plot = pg.PlotWidget()
|
||||||
@ -50,47 +52,51 @@ class PyRelacs(QMainWindow):
|
|||||||
self.create_toolbars()
|
self.create_toolbars()
|
||||||
|
|
||||||
layout = QGridLayout()
|
layout = QGridLayout()
|
||||||
layout.addWidget(self.plot_calibration_button, 0, 0)
|
layout.addWidget(self.beat_plot, 0, 0, 1, 2)
|
||||||
layout.addWidget(self.daq_disconnect_button, 0, 1)
|
layout.addWidget(self.power_plot, 1, 0, 1, 2)
|
||||||
layout.addWidget(self.beat_plot, 2, 0, 1, 2)
|
layout.addWidget(self.text, 2, 0, 1, 2)
|
||||||
layout.addWidget(self.power_plot, 3, 0, 1, 2)
|
|
||||||
|
|
||||||
self.toolbar = QToolBar("Repros")
|
|
||||||
self.addToolBar(self.toolbar)
|
|
||||||
self.repros_to_toolbar()
|
|
||||||
|
|
||||||
# self.setFixedSize(QSize(400, 300))
|
|
||||||
widget = QWidget()
|
widget = QWidget()
|
||||||
widget.setLayout(layout)
|
widget.setLayout(layout)
|
||||||
self.setCentralWidget(widget)
|
self.setCentralWidget(widget)
|
||||||
|
|
||||||
filename = path.joinpath(path.cwd(), "data.nix")
|
filename = path.joinpath(path.cwd(), "data")
|
||||||
self.nix_file = nix.File.open(
|
self.nix_file = nix.File.open(str(filename), nix.FileMode.Overwrite)
|
||||||
str(filename), nix.FileMode.Overwrite
|
|
||||||
)
|
|
||||||
|
|
||||||
def create_actions(self):
|
def create_actions(self):
|
||||||
self._rlx_exitaction = QAction(QIcon(str(path.joinpath(_root, "icons/exit.png"))), "Exit", self)
|
self._rlx_exitaction = QAction(
|
||||||
|
QIcon(str(path.joinpath(_root, "icons/exit.png"))), "Exit", self
|
||||||
|
)
|
||||||
self._rlx_exitaction.setStatusTip("Close relacs")
|
self._rlx_exitaction.setStatusTip("Close relacs")
|
||||||
self._rlx_exitaction.setShortcut(QKeySequence("Alt+q"))
|
self._rlx_exitaction.setShortcut(QKeySequence("Alt+q"))
|
||||||
self._rlx_exitaction.triggered.connect(self.on_exit)
|
self._rlx_exitaction.triggered.connect(self.on_exit)
|
||||||
|
|
||||||
self._rlx_aboutaction = QAction("about")
|
self._rlx_aboutaction = QAction("about")
|
||||||
self._rlx_aboutaction.setStatusTip("Show about dialog")
|
self._rlx_aboutaction.setStatusTip("Show about dialog")
|
||||||
self._rlx_aboutaction.setEnabled(True)
|
self._rlx_aboutaction.setEnabled(True)
|
||||||
self._rlx_aboutaction.triggered.connect(self.on_about)
|
self._rlx_aboutaction.triggered.connect(self.on_about)
|
||||||
|
|
||||||
self._daq_connectaction = QAction(QIcon(str(path.joinpath(_root, "icons/connect.png"))), "Connect DAQ", self)
|
self._daq_connectaction = QAction(
|
||||||
|
QIcon(str(path.joinpath(_root, "icons/connect.png"))), "Connect DAQ", self
|
||||||
|
)
|
||||||
self._daq_connectaction.setStatusTip("Connect to daq device")
|
self._daq_connectaction.setStatusTip("Connect to daq device")
|
||||||
# self._daq_connectaction.setShortcut(QKeySequence("Alt+d"))
|
# self._daq_connectaction.setShortcut(QKeySequence("Alt+d"))
|
||||||
self._daq_connectaction.triggered.connect(self.connect_dac)
|
self._daq_connectaction.triggered.connect(self.connect_dac)
|
||||||
|
|
||||||
self._daq_disconnectaction = QAction(QIcon(str(path.joinpath(_root, "icons/disconnect.png"))), "Disconnect DAQ", self)
|
self._daq_disconnectaction = QAction(
|
||||||
|
QIcon(str(path.joinpath(_root, "icons/disconnect.png"))),
|
||||||
|
"Disconnect DAQ",
|
||||||
|
self,
|
||||||
|
)
|
||||||
self._daq_disconnectaction.setStatusTip("Disconnect the DAQ device")
|
self._daq_disconnectaction.setStatusTip("Disconnect the DAQ device")
|
||||||
# self._daq_connectaction.setShortcut(QKeySequence("Alt+d"))
|
# self._daq_connectaction.setShortcut(QKeySequence("Alt+d"))
|
||||||
self._daq_disconnectaction.triggered.connect(self.disconnect_dac)
|
self._daq_disconnectaction.triggered.connect(self.disconnect_dac)
|
||||||
|
|
||||||
self._daq_calibaction = QAction(QIcon(str(path.joinpath(_root, "icons/calibration.png"))), "Plot calibration", self)
|
self._daq_calibaction = QAction(
|
||||||
|
QIcon(str(path.joinpath(_root, "icons/calibration.png"))),
|
||||||
|
"Plot calibration",
|
||||||
|
self,
|
||||||
|
)
|
||||||
self._daq_calibaction.setStatusTip("Calibrate the attenuator device")
|
self._daq_calibaction.setStatusTip("Calibrate the attenuator device")
|
||||||
# self._daq_calibaction.setShortcut(QKeySequence("Alt+d"))
|
# self._daq_calibaction.setShortcut(QKeySequence("Alt+d"))
|
||||||
self._daq_calibaction.triggered.connect(self.plot_calibration)
|
self._daq_calibaction.triggered.connect(self.plot_calibration)
|
||||||
@ -98,19 +104,28 @@ class PyRelacs(QMainWindow):
|
|||||||
|
|
||||||
def create_menu(self):
|
def create_menu(self):
|
||||||
menu = self.menuBar()
|
menu = self.menuBar()
|
||||||
file_menu = menu.addMenu("&File")
|
if menu is not None:
|
||||||
file_menu.addAction(self._rlx_exitaction)
|
file_menu = menu.addMenu("&File")
|
||||||
file_menu.addAction(self._rlx_aboutaction)
|
device_menu = menu.addMenu("&DAQ")
|
||||||
|
help_menu = menu.addMenu("&Help")
|
||||||
device_menu = menu.addMenu("&DAQ")
|
|
||||||
device_menu.addAction(self._daq_connectaction)
|
if file_menu is not None:
|
||||||
device_menu.addAction(self._daq_disconnectaction)
|
file_menu.addAction(self._rlx_exitaction)
|
||||||
device_menu.addSeparator()
|
file_menu.addAction(self._rlx_aboutaction)
|
||||||
device_menu.addAction(self._daq_calibaction)
|
|
||||||
|
if device_menu is not None:
|
||||||
help_menu = menu.addMenu("&Help")
|
device_menu.addAction(self._daq_connectaction)
|
||||||
help_menu.addSeparator()
|
device_menu.addAction(self._daq_disconnectaction)
|
||||||
# help_menu.addAction(self._help_action)
|
device_menu.addSeparator()
|
||||||
|
device_menu.addAction(self._daq_calibaction)
|
||||||
|
|
||||||
|
if help_menu is not None:
|
||||||
|
help_menu.addSeparator()
|
||||||
|
# help_menu.addAction(self._help_action)
|
||||||
|
else:
|
||||||
|
log.error("could not create file menu and device menu")
|
||||||
|
self.on_exit()
|
||||||
|
|
||||||
self.setMenuBar(menu)
|
self.setMenuBar(menu)
|
||||||
|
|
||||||
def create_toolbars(self):
|
def create_toolbars(self):
|
||||||
@ -217,12 +232,20 @@ class PyRelacs(QMainWindow):
|
|||||||
try:
|
try:
|
||||||
self.daq_device = uldaq.DaqDevice(devices[0])
|
self.daq_device = uldaq.DaqDevice(devices[0])
|
||||||
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
||||||
self.daq_device.connect()
|
|
||||||
log.debug("Connected")
|
|
||||||
except IndexError:
|
except IndexError:
|
||||||
log.debug("DAQ is not connected, closing")
|
log.error("DAQ is not connected")
|
||||||
self.on_exit()
|
log.error("Please connect a DAQ device to the system")
|
||||||
self.daq_connect_button.setDisabled(True)
|
|
||||||
|
if hasattr(PyRelacs, "daq_device"):
|
||||||
|
try:
|
||||||
|
self.daq_device.connect()
|
||||||
|
log.debug("Connected")
|
||||||
|
except uldaq.ul_exception.ULException as e:
|
||||||
|
log.error(f"Could not Connect to DAQ: {e}")
|
||||||
|
self.daq_connect_button.setDisabled(True)
|
||||||
|
else:
|
||||||
|
log.debug("Already handeld the error")
|
||||||
|
pass
|
||||||
|
|
||||||
def disconnect_dac(self):
|
def disconnect_dac(self):
|
||||||
try:
|
try:
|
||||||
@ -235,16 +258,6 @@ class PyRelacs(QMainWindow):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
log.debug("DAQ was not connected")
|
log.debug("DAQ was not connected")
|
||||||
|
|
||||||
def repros_to_toolbar(self):
|
|
||||||
repro_names, file_names = self.repros.names_of_repros()
|
|
||||||
for rep, fn in zip(repro_names, file_names):
|
|
||||||
individual_repro_button = QAction(rep, self)
|
|
||||||
individual_repro_button.setStatusTip("Button")
|
|
||||||
individual_repro_button.triggered.connect(
|
|
||||||
lambda checked, n=rep, f=fn: self.run_repro(n, f)
|
|
||||||
)
|
|
||||||
self.toolbar.addAction(individual_repro_button)
|
|
||||||
|
|
||||||
def run_repro(self, n, fn):
|
def run_repro(self, n, fn):
|
||||||
self.text.appendPlainText(f"started Repro {n}, {fn}")
|
self.text.appendPlainText(f"started Repro {n}, {fn}")
|
||||||
worker = Worker(self.repros.run_repro, self.nix_file, n, fn)
|
worker = Worker(self.repros.run_repro, self.nix_file, n, fn)
|
||||||
@ -257,7 +270,7 @@ class PyRelacs(QMainWindow):
|
|||||||
def on_exit(self):
|
def on_exit(self):
|
||||||
print("exit button!")
|
print("exit button!")
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def on_about(self, e):
|
def on_about(self, e):
|
||||||
about = AboutDialog(self)
|
about = AboutDialog(self)
|
||||||
about.show()
|
about.show()
|
||||||
@ -269,4 +282,4 @@ class PyRelacs(QMainWindow):
|
|||||||
print("THREAD COMPLETE!")
|
print("THREAD COMPLETE!")
|
||||||
|
|
||||||
def progress_fn(self, n):
|
def progress_fn(self, n):
|
||||||
print("%d%% done" % n)
|
print("%d%% done" % n)
|
||||||
|
Loading…
Reference in New Issue
Block a user