def runModule(module_type, setup_name = False): app = QtGui.QApplication(sys.argv) general_parameters = params.halParameters("settings_default.xml") if setup_name: general_parameters.set("setup_name", setup_name) else: setup_name = general_parameters.get("setup_name") hardware = params.hardware("xml/" + setup_name + "_hardware.xml") found = False for module in hardware.get("modules").getProps(): if (module.get("hal_type") == module_type): a_module = __import__(module.get("module_name"), globals(), locals(), [setup_name], -1) a_class = getattr(a_module, module.get("class_name")) instance = a_class(module.get("parameters", False), general_parameters, None) params.setDefaultParameters(general_parameters) setup_parameters = params.halParameters("xml/" + setup_name + "_default.xml") instance.newParameters(setup_parameters) instance.show() found = True break if found: app.exec_() instance.cleanup() else: print module_type, "not found for", setup_name, "setup"
extension = general_parameters.getp("film.extension") if setup_parameters.has("film.extension"): extension.setAllowed(setup_parameters.getp("film.extension").getAllowed()) general_parameters.set("film.logfile", setup_parameters.get("film.logfile", general_parameters.get("film.logfile"))) # Start logger. hdebug.startLogging(general_parameters.get("film.directory") + "logs/", "hal4000") # Setup HAL and all the modules. window = Window(hardware, general_parameters) # Set the general parameters with the additional values # added by HAL and the modules as the default parameters. params.setDefaultParameters(general_parameters) # Re-load setup specific parameters as HAL parameters. setup_parameters = params.halParameters(setup_parameters_filename) # Set the specific parameters as the new default. params.setDefaultParameters(setup_parameters) # Add the specific parameters to the parameters box. window.parameters_box.addParameters(setup_parameters) # Initialize with these parameters. window.toggleSettings() # Hide splash screen and start. splash.hide()
def __init__(self, hardware, parameters, parent = None): QtGui.QMainWindow.__init__(self, parent) # General (alphabetically ordered) self.current_directory = False self.current_length = 0 self.directory = False self.directory_test_mode = False self.filename = "" self.filming = False self.logfile_fp = open(parameters.get("film.logfile"), "a") self.modules = [] self.old_shutters_file = "" self.parameters = parameters self.parameters_test_mode = False self.settings = QtCore.QSettings("Zhuang Lab", "hal-4000_" + parameters.get("setup_name").lower()) self.tcp_message = None self.tcp_requested_movie = False self.ui_mode = "" self.will_overwrite = False self.writer = False self.xml_directory = "" # Logfile setup self.logfile_fp.write("\r\n") self.logfile_fp.flush() setup_name = parameters.get("setup_name").lower() # # UI setup, this is one of: # # 1. single: single window (the classic look). # 2. detached: detached camera window. # self.ui_mode = hardware.get("ui_mode") if (self.ui_mode == "single"): import qtdesigner.hal4000_ui as hal4000Ui elif (self.ui_mode == "detached"): import qtdesigner.hal4000_detached_ui as hal4000Ui else: print "unrecognized mode:", self.ui_mode print " mode should be either single or detached" exit() # Load the ui self.ui = hal4000Ui.Ui_MainWindow() self.ui.setupUi(self) title = self.parameters.get("setup_name") if (hgit.getBranch().lower() != "master"): title += " (" + hgit.getBranch() + ")" self.setWindowTitle(title) self.setWindowIcon(qtAppIcon.QAppIcon()) self.parameters_box = qtParametersBox.QParametersBox(self.ui.settingsScrollArea) self.ui.settingsScrollArea.setWidget(self.parameters_box) self.ui.settingsScrollArea.setWidgetResizable(True) self.parameters_box.addParameters(self.parameters) file_types = writers.availableFileFormats(self.ui_mode) self.parameters.getp("film.filetype").setAllowed(file_types) for type in file_types: self.ui.filetypeComboBox.addItem(type) self.ui.framesText.setText("") self.ui.sizeText.setText("") # # Camera control & signals. # self.camera = control.Camera(hardware.get("control"), parameters) self.camera.reachedMaxFrames.connect(self.stopFilm) self.camera.newFrames.connect(self.newFrames) # # Camera display. # if (self.ui_mode == "single"): n_cameras = 1 else: n_cameras = self.camera.getNumberOfCameras() camera_displays = [] for i in range(n_cameras): which_camera = "camera" + str(i+1) camera_displays.append(cameraDisplay.CameraDisplay(self.ui, self.ui_mode, which_camera, hardware.get("display"), parameters, self)) # This is the classic single-window HAL display. To work properly, the camera # controls UI elements that "belong" to the main window and vice-versa. if (self.ui_mode == "single"): self.ui.recordButton = camera_displays[0].getRecordButton() # Insert additional menu items for the camera display(s) as necessary else: for camera_display in camera_displays: a_action = QtGui.QAction(self.tr(camera_display.getMenuName()), self) self.ui.menuFile.insertAction(self.ui.actionQuit, a_action) a_action.triggered.connect(camera_display.show) # Camera display modules are also standard HAL modules. self.modules += camera_displays # # Other hardware control modules # # Load the requested modules. # add_separator = False for module in hardware.get("modules").getProps(): hdebug.logText("Loading: " + module.get("hal_type")) a_module = halImport(module.get("module_name")) a_class = getattr(a_module, module.get("class_name")) instance = a_class(module.get("parameters", False), parameters, self) instance.hal_type = module.get("hal_type") instance.hal_gui = module.get("hal_gui") if module.get("hal_gui"): add_separator = True a_action = QtGui.QAction(self.tr(module.get("menu_item")), self) self.ui.menuFile.insertAction(self.ui.actionQuit, a_action) a_action.triggered.connect(instance.show) self.modules.append(instance) # Insert a separator into the file menu if necessary. if add_separator: self.ui.menuFile.insertSeparator(self.ui.actionQuit) # Connect signals between modules, HAL and the camera. everything = self.modules + [self] + [self.camera] for from_module in everything: signals = from_module.getSignals() for to_module in everything: to_module.connectSignals(signals) # Finish module initialization everything = self.modules + [self.camera] for module in everything: module.moduleInit() # The modules can add parameters, so update the default. params.setDefaultParameters(parameters) # # More ui stuff # # handling file drops self.ui.centralwidget.__class__.dragEnterEvent = self.dragEnterEvent self.ui.centralwidget.__class__.dropEvent = self.dropEvent # ui signals self.ui.actionDirectory.triggered.connect(self.newDirectory) self.ui.actionSettings.triggered.connect(self.newSettingsFile) self.ui.actionShutter.triggered.connect(self.newShuttersFile) self.ui.actionQuit.triggered.connect(self.handleClose) self.ui.autoIncCheckBox.stateChanged.connect(self.handleAutoInc) self.ui.autoShuttersCheckBox.stateChanged.connect(self.handleAutoShutters) self.ui.extensionComboBox.currentIndexChanged.connect(self.updateFilenameLabel) self.ui.filenameEdit.textChanged.connect(self.updateFilenameLabel) self.ui.filetypeComboBox.currentIndexChanged.connect(self.updateFilenameLabel) self.ui.indexSpinBox.valueChanged.connect(self.updateFilenameLabel) self.ui.lengthSpinBox.valueChanged.connect(self.updateLength) self.ui.modeComboBox.currentIndexChanged.connect(self.handleModeComboBox) self.ui.notesEdit.textChanged.connect(self.updateNotes) self.ui.recordButton.clicked.connect(self.toggleFilm) # other signals self.parameters_box.settingsToggled.connect(self.toggleSettings) # # Load GUI settings # # HAL GUI settings. self.move(self.settings.value("main_pos", QtCore.QPoint(100, 100)).toPoint()) self.resize(self.settings.value("main_size", self.size()).toSize()) self.xml_directory = str(self.settings.value("xml_directory", "").toString()) # Module GUI settings. for module in self.modules: module.loadGUISettings(self.settings) # # start the camera # self.camera.cameraInit()
setup_parameters.getp("film.extension").getAllowed()) general_parameters.set( "film.logfile", setup_parameters.get("film.logfile", general_parameters.get("film.logfile"))) # Start logger. hdebug.startLogging( general_parameters.get("film.directory") + "logs/", "hal4000") # Setup HAL and all the modules. window = Window(hardware, general_parameters) # Set the general parameters with the additional values # added by HAL and the modules as the default parameters. params.setDefaultParameters(general_parameters) # Re-load setup specific parameters as HAL parameters. setup_parameters = params.halParameters(setup_parameters_filename) # Set the specific parameters as the new default. params.setDefaultParameters(setup_parameters) # Add the specific parameters to the parameters box. window.parameters_box.addParameters(setup_parameters) # Initialize with these parameters. window.toggleSettings() # Hide splash screen and start. splash.hide()