mirror of
https://github.com/nqrduck/nqrduck-spectrometer.git
synced 2024-12-22 08:17:49 +00:00
Made spectrometer selection selectable.
This commit is contained in:
parent
9c479a11fd
commit
dc0fe9bc20
1 changed files with 18 additions and 5 deletions
|
@ -14,6 +14,7 @@ class SpectrometerView(ModuleView):
|
|||
self._ui_form = Ui_Form()
|
||||
self.widget = widget
|
||||
self._ui_form.setupUi(self)
|
||||
self._actions = dict()
|
||||
|
||||
def on_active_spectrometer_changed(self, module):
|
||||
self._ui_form.stackedWidget.setCurrentWidget(module._inner_view)
|
||||
|
@ -34,17 +35,29 @@ class SpectrometerView(ModuleView):
|
|||
menu_item = QMenu("Hardware")
|
||||
logger.debug("Available spectrometer models: %s", self._module.model._available_spectrometers)
|
||||
|
||||
actions = []
|
||||
|
||||
for spectrometer_name, spectrometer_module in self._module.model._available_spectrometers.items():
|
||||
logger.debug("Adding module to menu: %s", spectrometer_name)
|
||||
select_action = QAction(spectrometer_module.model.toolbar_name, menu_item)
|
||||
select_action.triggered.connect(spectrometer_module.set_active)
|
||||
actions.append(select_action)
|
||||
self._actions[spectrometer_name] = QAction(spectrometer_module.model.toolbar_name, menu_item)
|
||||
self._actions[spectrometer_name].triggered.connect(spectrometer_module.set_active)
|
||||
# Make it checkable
|
||||
self._actions[spectrometer_name].setCheckable(True)
|
||||
|
||||
self.add_menubar_item.emit("Hardware", actions)
|
||||
# Get last added action and check it
|
||||
last_added_action = self._actions[list(self._actions.keys())[-1]]
|
||||
last_added_action.setChecked(True)
|
||||
|
||||
self.add_menubar_item.emit("Hardware", list(self._actions.values()))
|
||||
|
||||
@pyqtSlot(str)
|
||||
def on_menu_button_clicked(self, spectrometer_name):
|
||||
"""This method is called when a menu button is clicked. It changes the active spectrometer to the one that was clicked.
|
||||
It also unchecks all other menu buttons.
|
||||
|
||||
:param spectrometer_name: The name of the spectrometer that was clicked."""
|
||||
logger.debug("Active module changed to: %s", spectrometer_name)
|
||||
for action in self._actions.values():
|
||||
action.setChecked(False)
|
||||
self._actions[spectrometer_name].setChecked(True)
|
||||
self._module.model.active_spectrometer = self._module.model.available_spectrometers[spectrometer_name]
|
||||
|
||||
|
|
Loading…
Reference in a new issue