Skip to content

Commit 67266d6

Browse files
authored
Merge pull request #19 from SchwarzNeuroconLab/black_codeformat
reformetted code with black
2 parents 1160a0a + 094db08 commit 67266d6

23 files changed

+2115
-1251
lines changed

DeepLabStream.py

Lines changed: 208 additions & 96 deletions
Large diffs are not rendered by default.

app.py

Lines changed: 94 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class AThread(QThread):
2525
QThread is just one of the many PyQt ways to do multitasking
2626
This is, for most intents and purposes, identical to Python multithreading
2727
"""
28+
2829
def start(self, **kwargs):
2930
"""
3031
Setting thread to active, creating a QFrames dictionary
@@ -46,7 +47,7 @@ def run(self):
4647
all_frames = stream_manager.get_frames()
4748
except MissingFrameError as e:
4849
"""catch missing frame, stop Thread and save what can be saved"""
49-
print(*e.args, '\nShutting down DLStream and saving data...')
50+
print(*e.args, "\nShutting down DLStream and saving data...")
5051
stream_manager.finish_streaming()
5152
stream_manager.stop_cameras()
5253
self.stop()
@@ -62,7 +63,9 @@ def run(self):
6263
# outputting the frames
6364
res_frames, res_time = stream_manager.get_analysed_frames()
6465
# inputting the frames
65-
stream_manager.input_frames_for_analysis(all_frames, stream_manager.frame_index)
66+
stream_manager.input_frames_for_analysis(
67+
all_frames, stream_manager.frame_index
68+
)
6669
# streaming the stream
6770
if res_frames:
6871
self._stream_frames(res_frames)
@@ -85,7 +88,7 @@ def _stream_frames(self, frames):
8588
Unix -> thought PyQt with some widget window
8689
:param frames: dictionary of frames in format of {camera:frame}
8790
"""
88-
if os.name == 'nt':
91+
if os.name == "nt":
8992
show_stream(frames)
9093
# very important line for openCV to work correctly
9194
# actually does nothing, but do NOT delete
@@ -98,57 +101,68 @@ class ButtonWindow(QWidget):
98101
def __init__(self):
99102
super().__init__()
100103
# setting the icon for window
101-
self.setWindowIcon(QIcon('misc/DLStream_Logo_small.png'))
102-
self.setWindowTitle('DeepLabStream')
103-
self.title = 'ButtonWindow'
104+
self.setWindowIcon(QIcon("misc/DLStream_Logo_small.png"))
105+
self.setWindowTitle("DeepLabStream")
106+
self.title = "ButtonWindow"
104107
# next is the complete buttons dictionary with buttons, icons, functions and layouts
105-
self._buttons_dict = {'Start_Stream': {"Button": QPushButton('Start Stream'),
106-
"Icon": QIcon('misc/StartStream2.png'),
107-
"Function": self.start_stream,
108-
"Layout": (0, 0, 2, 2),
109-
"State": True},
110-
111-
'Start_Analysis': {"Button": QPushButton('Start Analysis'),
112-
"Icon": QIcon('misc/StartAnalysis2.png'),
113-
"Function": self.start_analysis,
114-
"Layout": (2, 0, 2, 1),
115-
"State": False},
116-
117-
'Start_Experiment': {"Button": QPushButton('Start Experiment'),
118-
"Icon": QIcon('misc/StartExperiment2.png'),
119-
"Function": self.start_experiment,
120-
"Layout": (4, 0, 2, 1),
121-
"State": False},
122-
123-
'Start_Recording': {"Button": QPushButton('Start Recording'),
124-
"Icon": QIcon('misc/StartRecording2.png'),
125-
"Function": self.start_recording,
126-
"Layout": (6, 0, 2, 1),
127-
"State": False},
128-
129-
'Stop_Stream': {"Button": QPushButton('Stop Stream'),
130-
"Icon": QIcon('misc/StopStream2.png'),
131-
"Function": self.stop_stream,
132-
"Layout": (8, 0, 2, 2),
133-
"State": False},
134-
135-
'Stop_Analysis': {"Button": QPushButton('Stop Analysis'),
136-
"Icon": QIcon('misc/StopAnalysis2.png'),
137-
"Function": self.stop_analysis,
138-
"Layout": (2, 1, 2, 1),
139-
"State": False},
140-
141-
'Stop_Experiment': {"Button": QPushButton('Stop Experiment'),
142-
"Icon": QIcon('misc/StopExperiment2.png'),
143-
"Function": self.stop_experiment,
144-
"Layout": (4, 1, 2, 1),
145-
"State": False},
146-
147-
'Stop_Recording': {"Button": QPushButton('Stop Recording'),
148-
"Icon": QIcon('misc/StopRecording2.png'),
149-
"Function": self.stop_recording,
150-
"Layout": (6, 1, 2, 1),
151-
"State": False}}
108+
self._buttons_dict = {
109+
"Start_Stream": {
110+
"Button": QPushButton("Start Stream"),
111+
"Icon": QIcon("misc/StartStream2.png"),
112+
"Function": self.start_stream,
113+
"Layout": (0, 0, 2, 2),
114+
"State": True,
115+
},
116+
"Start_Analysis": {
117+
"Button": QPushButton("Start Analysis"),
118+
"Icon": QIcon("misc/StartAnalysis2.png"),
119+
"Function": self.start_analysis,
120+
"Layout": (2, 0, 2, 1),
121+
"State": False,
122+
},
123+
"Start_Experiment": {
124+
"Button": QPushButton("Start Experiment"),
125+
"Icon": QIcon("misc/StartExperiment2.png"),
126+
"Function": self.start_experiment,
127+
"Layout": (4, 0, 2, 1),
128+
"State": False,
129+
},
130+
"Start_Recording": {
131+
"Button": QPushButton("Start Recording"),
132+
"Icon": QIcon("misc/StartRecording2.png"),
133+
"Function": self.start_recording,
134+
"Layout": (6, 0, 2, 1),
135+
"State": False,
136+
},
137+
"Stop_Stream": {
138+
"Button": QPushButton("Stop Stream"),
139+
"Icon": QIcon("misc/StopStream2.png"),
140+
"Function": self.stop_stream,
141+
"Layout": (8, 0, 2, 2),
142+
"State": False,
143+
},
144+
"Stop_Analysis": {
145+
"Button": QPushButton("Stop Analysis"),
146+
"Icon": QIcon("misc/StopAnalysis2.png"),
147+
"Function": self.stop_analysis,
148+
"Layout": (2, 1, 2, 1),
149+
"State": False,
150+
},
151+
"Stop_Experiment": {
152+
"Button": QPushButton("Stop Experiment"),
153+
"Icon": QIcon("misc/StopExperiment2.png"),
154+
"Function": self.stop_experiment,
155+
"Layout": (4, 1, 2, 1),
156+
"State": False,
157+
},
158+
"Stop_Recording": {
159+
"Button": QPushButton("Stop Recording"),
160+
"Icon": QIcon("misc/StopRecording2.png"),
161+
"Function": self.stop_recording,
162+
"Layout": (6, 1, 2, 1),
163+
"State": False,
164+
},
165+
}
152166

153167
# creating button layout with icons and functionality
154168
self.initialize_buttons()
@@ -171,19 +185,27 @@ def initialize_buttons(self):
171185
# setting icon
172186
self._buttons_dict[func]["Button"].setIcon(self._buttons_dict[func]["Icon"])
173187
# setting function
174-
self._buttons_dict[func]["Button"].clicked.connect(self._buttons_dict[func]["Function"])
188+
self._buttons_dict[func]["Button"].clicked.connect(
189+
self._buttons_dict[func]["Function"]
190+
)
175191
# setting position
176-
layout.addWidget(self._buttons_dict[func]["Button"], *self._buttons_dict[func]["Layout"])
192+
layout.addWidget(
193+
self._buttons_dict[func]["Button"], *self._buttons_dict[func]["Layout"]
194+
)
177195
# setting default state
178-
self._buttons_dict[func]["Button"].setEnabled(self._buttons_dict[func]["State"])
196+
self._buttons_dict[func]["Button"].setEnabled(
197+
self._buttons_dict[func]["State"]
198+
)
179199
# setting button size
180200
self._buttons_dict[func]["Button"].setMinimumHeight(100)
181201
# setting window layout for all buttons
182202
self.setLayout(layout)
183203

184204
def buttons_toggle(self, *buttons):
185205
for button in buttons:
186-
self._buttons_dict[button]["Button"].setEnabled(not self._buttons_dict[button]["Button"].isEnabled())
206+
self._buttons_dict[button]["Button"].setEnabled(
207+
not self._buttons_dict[button]["Button"].isEnabled()
208+
)
187209

188210
""" Button functions"""
189211

@@ -197,16 +219,17 @@ def start_stream(self):
197219
print("Streaming started")
198220

199221
# flipping the state of the buttons
200-
self.buttons_toggle("Start_Analysis",
201-
"Start_Recording",
202-
"Start_Stream",
203-
"Stop_Stream")
222+
self.buttons_toggle(
223+
"Start_Analysis", "Start_Recording", "Start_Stream", "Stop_Stream"
224+
)
204225

205226
# initializing image windows for Unix systems via PyQt
206-
if os.name != 'nt':
227+
if os.name != "nt":
207228
for camera in stream_manager.enabled_cameras:
208229
self.image_windows[camera] = ImageWindow(camera)
209-
self._thread.qframes[camera].signal.connect(self.image_windows[camera].set_image)
230+
self._thread.qframes[camera].signal.connect(
231+
self.image_windows[camera].set_image
232+
)
210233
self.image_windows[camera].show()
211234
else:
212235
# for Windows it is taken care by openCV
@@ -218,9 +241,11 @@ def stop_stream(self):
218241

219242
# flipping the state of the buttons
220243
for func in self._buttons_dict:
221-
self._buttons_dict[func]["Button"].setEnabled(self._buttons_dict[func]["State"])
244+
self._buttons_dict[func]["Button"].setEnabled(
245+
self._buttons_dict[func]["State"]
246+
)
222247

223-
if os.name != 'nt':
248+
if os.name != "nt":
224249
for camera in self.image_windows:
225250
self.image_windows[camera].hide()
226251
else:
@@ -244,31 +269,27 @@ def stop_analysis(self):
244269

245270
def start_experiment(self):
246271
print("Experiment started")
247-
self.buttons_toggle("Stop_Experiment",
248-
"Start_Experiment")
272+
self.buttons_toggle("Stop_Experiment", "Start_Experiment")
249273
stream_manager.set_up_experiment()
250274
stream_manager.start_experiment()
251275
if RECORD_EXP:
252276
self.start_recording()
253277

254278
def stop_experiment(self):
255279
print("Experiment stopped")
256-
self.buttons_toggle("Stop_Experiment",
257-
"Start_Experiment")
280+
self.buttons_toggle("Stop_Experiment", "Start_Experiment")
258281
stream_manager.stop_experiment()
259282
if RECORD_EXP:
260283
self.stop_recording()
261284

262285
def start_recording(self):
263286
print("Recording started")
264-
self.buttons_toggle("Stop_Recording",
265-
"Start_Recording")
287+
self.buttons_toggle("Stop_Recording", "Start_Recording")
266288
stream_manager.start_recording()
267289

268290
def stop_recording(self):
269291
print("Recording stopped")
270-
self.buttons_toggle("Stop_Recording",
271-
"Start_Recording")
292+
self.buttons_toggle("Stop_Recording", "Start_Recording")
272293
stream_manager.stop_recording()
273294

274295

0 commit comments

Comments
 (0)