Пример #1
0
    def __init__(self, experiment, **kwargs):
        """ """
        super().__init__(**kwargs)
        self.experiment = experiment

        self.setWindowTitle("Stytra | " +
                            pretty_name(type(experiment.protocol).name))

        self.docks = dict()

        # self.label_debug = DebugLabel(debug_on=experiment.debug_mode)
        # if not self.experiment.offline:
        #     self.widget_projection = ProjectorAndCalibrationWidget(experiment)
        self.toolbar_control = ProtocolControlToolbar(
            experiment.protocol_runner, self)
        self.toolbar_control.setObjectName("toolbar")

        # Connect signals from the protocol_control:
        self.toolbar_control.sig_start_protocol.connect(
            experiment.start_protocol)
        self.toolbar_control.sig_stop_protocol.connect(experiment.end_protocol)

        self.btn_metadata = IconButton(icon_name="edit_fish",
                                       action_name="Edit metadata")
        self.btn_metadata.clicked.connect(self.show_metadata_gui)
        self.toolbar_control.addWidget(self.btn_metadata)

        self.act_folder = self.toolbar_control.addAction("Save in {}".format(
            self.experiment.base_dir))
        self.act_folder.triggered.connect(self.change_folder_gui)

        if self.experiment.database is not None:
            self.chk_db = ToggleIconButton(
                action_on="Use DB",
                icon_on="dbON",
                icon_off="dbOFF",
                on=self.experiment.use_db,
            )
            self.chk_db.toggled.connect(self.toggle_db)
            self.toolbar_control.addWidget(self.chk_db)

        if experiment.trigger is not None:
            self.chk_scope = QCheckBox("Wait for trigger signal")

        self.logger = QPlainTextEditLogger()
        self.experiment.logger.addHandler(self.logger)

        self.status_display = StatusMessageDisplay()
        self.statusBar().addWidget(self.status_display)

        self.plot_framerate = MultiFrameratesWidget()
        self.plot_framerate.add_framerate(
            self.experiment.protocol_runner.framerate_acc)

        self.metadata_win = None
Пример #2
0
class ExperimentWindow(QMainWindow):
    """Window for controlling a simple experiment including only a monitor
    the relative controls and the buttons for data_log and protocol control.
    All widgets objects are created and connected in the `__init__` and then added
    ti the GUI in the `construct_ui` method

    Parameters
    ----------
    experiment : `Experiment <stytra.experiments.Experiment>` object
        experiment for which the window is built.

    Returns
    -------

    """
    def __init__(self, experiment, **kwargs):
        """ """
        super().__init__(**kwargs)
        self.experiment = experiment

        self.setWindowTitle("Stytra | " +
                            pretty_name(type(experiment.protocol).name))

        self.docks = dict()

        self.toolbar_control = ProtocolControlToolbar(
            experiment.protocol_runner, self)
        self.toolbar_control.setObjectName("toolbar")

        # Connect signals from the protocol_control:
        self.toolbar_control.sig_start_protocol.connect(
            experiment.start_protocol)
        self.toolbar_control.sig_stop_protocol.connect(experiment.end_protocol)

        self.btn_metadata = IconButton(icon_name="edit_fish",
                                       action_name="Edit metadata")
        self.btn_metadata.clicked.connect(self.show_metadata_gui)
        self.toolbar_control.addWidget(self.btn_metadata)

        self.act_folder = self.toolbar_control.addAction("Save in {}".format(
            self.experiment.base_dir))
        self.act_folder.triggered.connect(self.change_folder_gui)

        if self.experiment.database is not None:
            self.chk_db = ToggleIconButton(
                action_on="Use DB",
                icon_on="dbON",
                icon_off="dbOFF",
                on=self.experiment.use_db,
            )
            self.chk_db.toggled.connect(self.toggle_db)
            self.toolbar_control.addWidget(self.chk_db)

        if experiment.trigger is not None:
            self.chk_scope = QCheckBox("Wait for trigger signal")

        self.logger = QPlainTextEditLogger()
        self.experiment.logger.addHandler(self.logger)

        self.status_display = StatusMessageDisplay()
        self.statusBar().addWidget(self.status_display)

        self.plot_framerate = MultiFrameratesWidget()
        self.plot_framerate.add_framerate(
            self.experiment.protocol_runner.framerate_acc)

        self.metadata_win = None

    def change_folder_gui(self):
        """Open dialog window to specify a new saving directory."""
        folder = QFileDialog.getExistingDirectory(
            caption="Results folder", directory=self.experiment.base_dir)
        print(folder)
        if folder is not None:
            self.experiment.base_dir = folder
            self.act_folder.setText("Save in {}".format(
                self.experiment.base_dir))

    def show_metadata_gui(self):
        """Open Param GUI to control general experiment and animal metadata."""
        # Create widget, horizontal layout
        self.metadata_win = QWidget()
        self.metadata_win.setLayout(QHBoxLayout())
        # Add metadata widgets to the main one
        self.metadata_win.layout().addWidget(
            ParameterGui(self.experiment.metadata))
        self.metadata_win.layout().addWidget(
            ParameterGui(self.experiment.metadata_animal))
        self.metadata_win.show()

    def add_dock(self, item: QDockWidget):
        """Adding a new DockWidget updating the docks dictionary."""
        self.docks[item.objectName()] = item

    def construct_ui(self):
        """UI construction function."""
        self.addToolBar(Qt.TopToolBarArea, self.toolbar_control)

        log_dock = QDockWidget("Log", self)
        log_dock.setObjectName("dock_log")
        log_dock.setWidget(self.logger.widget)
        self.add_dock(log_dock)
        self.addDockWidget(Qt.RightDockWidgetArea, log_dock)

        dockFramerate = QDockWidget("Frame rates", self)
        dockFramerate.setWidget(self.plot_framerate)
        dockFramerate.setObjectName("dock_framerates")
        self.addDockWidget(Qt.RightDockWidgetArea, dockFramerate)
        self.add_dock(dockFramerate)

        if self.experiment.trigger is not None:
            self.toolbar_control.addWidget(self.chk_scope)

        self.experiment.gui_timer.timeout.connect(self.plot_framerate.update)

        self.toolbar_control.setObjectName("toolbar_control")
        self.setCentralWidget(None)

    def write_log(self, msg):
        """Write something in the log window."""
        self.log_widget.textCursor().appendPlainText(msg)

    def toggle_db(self, tg):
        """Toggle database button."""
        if self.chk_db.isChecked():
            self.experiment.use_db = True
        else:
            self.experiment.use_db = False

    def closeEvent(self, *args, **kwargs):
        """

        Parameters
        ----------
        *args :

        **kwargs :


        Returns
        -------

        """
        self.experiment.wrap_up()