Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
beniroquai committed Sep 8, 2022
2 parents 4c2bb4c + c8f1c13 commit fcb2b94
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 10 deletions.
2 changes: 1 addition & 1 deletion imswitch/imcommon/view/guitools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .BetterSlider import BetterSlider
from .CheckableComboBox import CheckableComboBox
from .FloatSlider import FloatSlider
from .dialogtools import askYesNoQuestion, askForFilePath, askForFolderPath, askForTextInput
from .dialogtools import askYesNoQuestion, askForFilePath, askForFolderPath, askForTextInput, informationDisplay
from .imagetools import bestLevels, minmaxLevels
from .stylesheet import getBaseStyleSheet
from .texttools import ordinalSuffix
4 changes: 4 additions & 0 deletions imswitch/imcommon/view/guitools/dialogtools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from qtpy import QtCore, QtWidgets

def informationDisplay(widget, title):
"""Inform User about something"""
QtWidgets.QMessageBox.information(widget, 'Ok', title)


def askYesNoQuestion(widget, title, question):
""" Asks the user a yes/no question and returns whether "yes" was clicked. """
result = QtWidgets.QMessageBox.question(widget, title, question,
Expand Down
20 changes: 20 additions & 0 deletions imswitch/imcontrol/controller/ImConMainController.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .CommunicationChannel import CommunicationChannel
from .MasterController import MasterController
from .PickSetupController import PickSetupController
from .PickUC2BoardConfigController import PickUC2BoardConfigController
from .basecontrollers import ImConWidgetControllerFactory


Expand All @@ -28,6 +29,7 @@ def __init__(self, options, setupInfo, mainView, moduleCommChannel):
# Connect view signals
self.__mainView.sigLoadParamsFromHDF5.connect(self.loadParamsFromHDF5)
self.__mainView.sigPickSetup.connect(self.pickSetup)
self.__mainView.sigPickConfig.connect(self.pickUC2Config)
self.__mainView.sigClosing.connect(self.closeEvent)

# Init communication channel and master controller
Expand All @@ -45,6 +47,9 @@ def __init__(self, options, setupInfo, mainView, moduleCommChannel):
self.pickDatasetsController = self.__factory.createController(
PickDatasetsController, self.__mainView.pickDatasetsDialog
)
self.PickUC2BoardConfigController = self.__factory.createController(
PickUC2BoardConfigController, self.__mainView.PickUC2BoardConfigDialog
)

self.controllers = {}

Expand Down Expand Up @@ -135,7 +140,22 @@ def closeEvent(self):
self.__factory.closeAllCreatedControllers()
self.__masterController.closeEvent()

def pickUC2Config(self):
""" Let the user change which UC2 Board config is used. """

options, _ = configfiletools.loadUC2BoardConfigs()

self.pickSetupController.setSetups(configfiletools.getBoardConfigList())
self.pickSetupController.setSelectedSetup(options.setupFileName)
if not self.__mainView.showPickSetupDialogBlocking():
return
setupFileName = self.pickSetupController.getSelectedSetup()
if not setupFileName:
return

guitools.informationDisplay(self.__mainView, "Now select 'load from file' in the UC2 Config Widget and flash the pin-configuration")


# Copyright (C) 2020-2021 ImSwitch developers
# This file is part of ImSwitch.
#
Expand Down
32 changes: 32 additions & 0 deletions imswitch/imcontrol/controller/PickUC2BoardConfigController.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from .basecontrollers import ImConWidgetController


class PickUC2BoardConfigController(ImConWidgetController):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def setUC2BoardConfig(self, setupList):
self._widget.setC2BoardConfig(setupList)

def getSelectedC2BoardConfig(self):
return self._widget.getSelectedC2BoardConfig()

def setSelectedC2BoardConfig(self, UC2BoardConfig):
self._widget.setSelectedC2BoardConfig(UC2BoardConfig)


# Copyright (C) 2020-2021 ImSwitch developers
# This file is part of ImSwitch.
#
# ImSwitch is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ImSwitch is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
10 changes: 5 additions & 5 deletions imswitch/imcontrol/controller/controllers/UC2ConfigController.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ def __init__(self, *args, **kwargs):
if len(self.mConfigDevice)<4:
self.mConfigDevice = self.loadDefaultConfig()
self._widget.controlPanel.updateFirmwareDeviceLabel.setText("Something's wrong with the \n device/firmware, please reflash/reconnect!")

# display device configs
self.loadParams(config=self.mConfigDevice)

# save parameters on the disk
self.defaultPinDefFile = "pinDef.json"

if self._setupInfo.uc2Config is None:
Expand All @@ -52,14 +54,12 @@ def loadConfigToDevice(self, config):

def saveParams(self):
UC2Config_info_dict = self.getInfoDict(self._widget.UC2ConfigParameterTree.p,
self._widget.pinDefParameterTree.p,
self._master.UC2ConfigManager.getCenters())
self._widget.pinDefParameterTree.p)
with open(os.path.join(self.UC2ConfigDir, self.defaultPinDefFile), 'w') as f:
json.dump(UC2Config_info_dict, f, indent=4)

def getInfoDict(self, generalParams=None, pinDefParams=None, centers=None):
def getInfoDict(self, generalParams=None, pinDefParams=None):
state_general = None
state_pos = None
state_pinDef = None

if generalParams is not None:
Expand All @@ -83,7 +83,7 @@ def getInfoDict(self, generalParams=None, pinDefParams=None, centers=None):
return info_dict

def loadParams(self, config=None):
if config is not None:
if config is not None and config:
state_general = None # TODO: Implement
state_pinDef = config

Expand Down
32 changes: 31 additions & 1 deletion imswitch/imcontrol/model/configfiletools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
def getSetupList():
return [Path(file).name for file in glob.glob(os.path.join(_setupFilesDir, '*.json'))]

def getBoardConfigList():
return [Path(file).name for file in glob.glob(os.path.join(_setupBoardConfigDir, '*.json'))]

def loadSetupInfo(options, setupInfoType):
with open(os.path.join(_setupFilesDir, options.setupFileName)) as setupFile:
return setupInfoType.from_json(setupFile.read(), infer_missing=True)


def saveSetupInfo(options, setupInfo):
with open(os.path.join(_setupFilesDir, options.setupFileName), 'w') as setupFile:
setupFile.write(setupInfo.to_json(indent=4))
Expand All @@ -38,6 +39,24 @@ def loadOptions():

return _options, optionsDidNotExist

def loadUC2BoardConfigs():
global _configs

if _configs is not None:
return _configs, False

optionsDidNotExist = False
if not os.path.isfile(_configsFilePath):
_configs = Options(
setupFileName=getBoardConfigList()[0]
)
optionsDidNotExist = True
else:
with open(_configsFilePath, 'r') as configsFile:
_configs = Options.from_json(configsFile.read(), infer_missing=True)

return _options, optionsDidNotExist


def saveOptions(options):
global _options
Expand All @@ -46,13 +65,24 @@ def saveOptions(options):
with open(_optionsFilePath, 'w') as optionsFile:
optionsFile.write(_options.to_json(indent=4))

def saveConfigs(configs):
global _configs

_configs = configs
with open(_optionsFilePath, 'w') as configsFile:
configsFile.write(_configs.to_json(indent=4))



dirtools.initUserFilesIfNeeded()
_setupFilesDir = os.path.join(dirtools.UserFileDirs.Root, 'imcontrol_setups')
_setupBoardConfigDir = os.path.join(dirtools.UserFileDirs.Root, 'imcontrol_UC2Config')
os.makedirs(_setupFilesDir, exist_ok=True)
_optionsFilePath = os.path.join(dirtools.UserFileDirs.Config, 'imcontrol_options.json')
_configsFilePath = os.path.join(dirtools.UserFileDirs.Config, 'imcontrol_options.json')

_options = None
_configs = None


# Copyright (C) 2020-2021 ImSwitch developers
Expand Down
4 changes: 3 additions & 1 deletion imswitch/imcontrol/model/interfaces/gxipy/dxwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
dll = CDLL('/usr/lib/libgxiapi.so')
except OSError:
print('Cannot find libgxiapi.so.')
else:
elif sys.platform == 'win32':
try:
dll = WinDLL('DxImageProc.dll')
except OSError:
print('Cannot find DxImageProc.dll.')

else:
dll = -1

# status definition
class DxStatus:
Expand Down
5 changes: 3 additions & 2 deletions imswitch/imcontrol/model/interfaces/gxipy/gxwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
dll = CDLL('/usr/lib/libgxiapi.so')
except OSError:
print("Cannot find libgxiapi.so.")
else:
elif sys.platform == 'win32':
try:
import os
os.add_dll_directory("C:\\Program Files\\Daheng Imaging\\GalaxySDK\\APIDll\\Win64\\")
Expand All @@ -20,7 +20,8 @@

except OSError:
print('Cannot find GxIAPI.dll.')

else:
dll = -1

# Error code
class GxStatusList:
Expand Down
2 changes: 2 additions & 0 deletions imswitch/imcontrol/model/managers/UC2ConfigManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def __init__(self, UC2ConfigInfo, lowLevelManagers, *args, **kwargs):

if UC2ConfigInfo is None:
return

self.UC2ConfigInfo = UC2ConfigInfo

#TODO: HARDCODED!!
self.ESP32 = lowLevelManagers["rs232sManager"]["ESP32"]._esp32
Expand Down
11 changes: 11 additions & 0 deletions imswitch/imcontrol/view/ImConMainView.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
from imswitch.imcommon.view import PickDatasetsDialog
from . import widgets
from .PickSetupDialog import PickSetupDialog
from .PickUC2BoardConfigDialog import PickUC2BoardConfigDialog


class ImConMainView(QtWidgets.QMainWindow):
sigLoadParamsFromHDF5 = QtCore.Signal()
sigPickSetup = QtCore.Signal()
sigPickConfig = QtCore.Signal()
sigClosing = QtCore.Signal()

def __init__(self, options, viewSetupInfo, *args, **kwargs):
Expand All @@ -21,6 +23,7 @@ def __init__(self, options, viewSetupInfo, *args, **kwargs):
super().__init__(*args, **kwargs)

self.pickSetupDialog = PickSetupDialog(self)
self.PickUC2BoardConfigDialog = PickUC2BoardConfigDialog(self)
self.pickDatasetsDialog = PickDatasetsDialog(self, allowMultiSelect=False)

# Widget factory
Expand All @@ -44,6 +47,10 @@ def __init__(self, options, viewSetupInfo, *args, **kwargs):
self.pickSetupAction.triggered.connect(self.sigPickSetup)
tools.addAction(self.pickSetupAction)

self.pickConfigAction = QtWidgets.QAction('Pick hardware config', self)
self.pickConfigAction.triggered.connect(self.sigPickConfig)
tools.addAction(self.pickConfigAction)

# Window
self.setWindowTitle('ImSwitch')

Expand Down Expand Up @@ -144,6 +151,10 @@ def showPickDatasetsDialogBlocking(self):
result = self.pickDatasetsDialog.exec_()
return result == QtWidgets.QDialog.Accepted

def showConfigSetupDialogBlocking(self):
result = self.PickUC2BoardConfigDialog.exec_()
return result == QtWidgets.QDialog.Accepted

def closeEvent(self, event):
self.sigClosing.emit()
event.accept()
Expand Down
59 changes: 59 additions & 0 deletions imswitch/imcontrol/view/PickUC2BoardConfigDialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from qtpy import QtCore, QtWidgets


class PickUC2BoardConfigDialog(QtWidgets.QDialog):
""" Dialog for picking the setup to use for imcontrol. """

def __init__(self, parent=None, *args, **kwargs):
super().__init__(parent, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint,
*args, **kwargs)
self.setWindowTitle('Select pin configuration for the board')

self.informationLabel = QtWidgets.QLabel(
'Select the configuration file for your UC2 Board setup:'
)
self.configPicker = QtWidgets.QComboBox()

self.buttons = QtWidgets.QDialogButtonBox(
QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel,
QtCore.Qt.Horizontal,
self
)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)

layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.informationLabel)
layout.addWidget(self.configPicker)
layout.addWidget(self.buttons)
self.setLayout(layout)

def setUC2BoardConfig(self, configList):
self.configPicker.clear()
for config in configList:
self.configPicker.addItem(config)

def getSelectedConfig(self):
return self.configPicker.currentText()

def setSelectedConfig(self, config):
index = self.configPicker.findText(config)
if index > -1:
self.configPicker.setCurrentIndex(index)


# Copyright (C) 2020-2021 ImSwitch developers
# This file is part of ImSwitch.
#
# ImSwitch is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ImSwitch is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1 change: 1 addition & 0 deletions imswitch/imcontrol/view/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .ImConMainView import ImConMainView
from .PickSetupDialog import PickSetupDialog
from .PickUC2BoardConfigDialog import PickUC2BoardConfigDialog
from .SLMDisplay import SLMDisplay
from .SIMDisplay import SIMDisplay
from .guitools import ViewSetupInfo

0 comments on commit fcb2b94

Please sign in to comment.