I was looking for a way to share a function across different classes to specific objects after their initialisation. I stumbled across some code, after some modification, that works exactly and efficiently for my app needs. The magic ingredient was to precede the function (initialised in a another function) with _,
I get the significance of the _ underscore operator and the , comma operator in some circumstances but I have never seen _, as an operator and can't find any info on searches. I really want to understand because it solved a major issue issue for me.
Some sample code (python/PyQt)
def setup_video(self):
self.capture = cv2.VideoCapture("capture1.mp4")
self.capture.set(cv2.CAP_PROP_FRAME_WIDTH, self.video_size.width())
self.capture.set(cv2.CAP_PROP_FRAME_HEIGHT, self.video_size.height())
self.timer = QTimer()
self.timer.timeout.connect(self.display_video_stream)
self.timer.start(30)
def display_video_stream(self):
"""repaint QLabel widget.
"""
_, frame = self.capture.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image = QImage(frame, frame.shape[1], frame.shape[0],
frame.strides[0], QImage.Format_RGB888)
self.image_label.setPixmap(QPixmap.fromImage(image))