Skip to content

data_file_view

frog.gui.data_file_view ¤

Provides a panel which lets the user start and stop recording of data files.

Attributes¤

Classes¤

DataFileControl() ¤

Bases: QGroupBox

A panel which lets the user start and stop recording of data files.

Create a new DataFileControl.

Source code in frog/gui/data_file_view.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
def __init__(self) -> None:
    """Create a new DataFileControl."""
    super().__init__("Data file")

    layout = QGridLayout()

    self._open_dir_widget = OpenDirectoryWidget(
        parent=self,
        caption="Choose destination for data file",
        dir=str(DEFAULT_DATA_FILE_PATH),
    )
    """Lets the user choose the destination for data files."""
    self._open_dir_widget.set_path(_get_previous_destination_dir())
    layout.addWidget(QLabel("Destination directory:"), 0, 0)
    layout.addWidget(self._open_dir_widget, 0, 1)

    layout.addWidget(QLabel("Filename prefix:"), 1, 0)

    self._filename_prefix_widget = QLineEdit()
    self._filename_prefix_widget.setText(_get_previous_filename_prefix())
    layout.addWidget(self._filename_prefix_widget, 1, 1)

    self._record_widget = RecordingWidget()
    self._record_widget.start_recording.connect(self._try_start_recording)
    self._record_widget.stop_recording.connect(
        lambda: pub.sendMessage("data_file.close")
    )
    self._record_widget.setSizePolicy(
        QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Minimum
    )
    layout.addWidget(self._record_widget, 2, 0, 1, 2, Qt.AlignmentFlag.AlignCenter)

    self.setLayout(layout)

    self.setSizePolicy(
        QSizePolicy.Policy.Preferred,
        QSizePolicy.Policy.Fixed,
    )

    # Update GUI on file open/close
    pub.subscribe(self._on_file_open, "data_file.opened")
    pub.subscribe(self._on_file_close, "data_file.close")

    # Show an error message if writing fails
    pub.subscribe(self._show_error_message, "data_file.error")
Functions¤

RecordingWidget() ¤

Bases: QWidget

A widget to start/stop recording and display recording status.

When the user clicks the button to start/stop recording the start_recording or stop_recording signals, respectively, are triggered.

Whether or not data is currently being recorded is shown by a text label and a flashing LED indicator.

Create a new RecordingWidget.

Source code in frog/gui/data_file_view.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def __init__(self) -> None:
    """Create a new RecordingWidget."""
    super().__init__()

    layout = QHBoxLayout()
    layout.setContentsMargins(0, 0, 0, 0)
    self.setLayout(layout)

    self._led = LEDIcon.create_red_icon()
    """Icon to indicate whether recording is taking place."""
    pub.subscribe(self._led.flash, "data_file.writing")
    layout.addWidget(self._led)

    self._label = QLabel("NOT RECORDING")
    """Label to show recording status."""
    # Put a margin on the right so that the button isn't too close
    self._label.setContentsMargins(0, 0, 50, 0)
    layout.addWidget(self._label)

    self._btn = QPushButton("Start recording")
    """Send signal to start/stop recording."""
    self._btn.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Minimum)
    self._btn.clicked.connect(self._on_button_clicked)
    layout.addWidget(self._btn)

    self._is_recording = False
    """Whether data is being recorded."""

    # Update widget on file open/close
    pub.subscribe(self._on_file_open, "data_file.opened")
    pub.subscribe(self._on_file_close, "data_file.close")
Functions¤

Functions¤