1

I am trying to create a GUI application using Pyqt5. The issue I am facing is that the code is running well but record window is not opening. I am attaching the whole code below and the snippet of the function which I am referring to. I have tried going through the whole code but haven't found any flaws in the same.

import sys
from random import randint

from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow, QPushButton, QVBoxLayout, QWidget
import time
#from libsonyapi.camera import Camera
#from libsonyapi.actions import Actions
#from pysony import SonyAPI, ControlPoint, common_header
#search = ControlPoint()
#cameras =  search.discover(1) 
#camera = SonyAPI(QX_ADDR=cameras[0])
 # create camera instance
#camerass = Camera()

###############################SECONDARY WINDOWS###############################################################################
        
class recording(QWidget):


    def __init__(self):
        super().__init__()
        layout = QVBoxLayout(self)
        
        # THIS BUTTON IS USED TO START RECORDING #
        start_recording_button = QPushButton(" START RECORDING ")
        start_recording_button.clicked.connect(self.start_recording)
        layout.addWidget(start_recording_button)

        # THIS BUTTON IS USED TO STOP RECORDING #
        stop_recording_button = QPushButton(" STOP RECORDING ")
        stop_recording_button.clicked.connect(self.stop_recording)
        layout.addWidget(stop_recording_button)
        
        self.show()
        
    def start_recording(self):
        camerass.do(Actions.startMovieRec)
        time.sleep(2)

    def stop_recording(self):
        camerass.do(Actions.stopMovieRec)
        time.sleep(2)
        
        
class zoom(QWidget):


    def __init__(self):
        super().__init__()
        layout = QVBoxLayout(self)
        
        # THIS BUTTON IS USED AS ZOOM IN #
        zoom_in_button = QPushButton(" ZOOM IN ")
        zoom_in_button.clicked.connect(self.zoom_in)
        layout.addWidget(zoom_in_button)

        # THIS BUTTON IS USED AS ZOOM OUT #
        zoom_out_button = QPushButton(" ZOOM OUT ")
        zoom_out_button.clicked.connect(self.zoom_out)
        layout.addWidget(zoom_out_button)

        # THIS BUTTON IS USED TO STOP THE ZOOM IN #
        stop_zoom_in_button = QPushButton(" STOP ZOOM IN ")
        stop_zoom_in_button.clicked.connect(self.stop_zoom_in)
        layout.addWidget(stop_zoom_in_button)
        
        # THIS BUTTON IS USED TO STOP THE ZOOM OUT #
        stop_zoom_out_button = QPushButton(" STOP ZOOM OUT ")
        stop_zoom_out_button.clicked.connect(self.stop_zoom_out)
        layout.addWidget(stop_zoom_out_button)
        
        self.show()
        
    def zoom_in(self):
        camera.actZoom(param=["in", "start"])
        time.sleep(2)
    
    def zoom_out(self):
        camera.actZoom(param=["out", "start"])
        time.sleep(2)
    
    def stop_zoom_in(self):
        camera.actZoom(param=["in", "stop"])
        time.sleep(2)

    def stop_zoom_out(self):
        camera.actZoom(param=["out", "stop"])
        time.sleep(2)
################################MAIN WINDOW 1##################################################################################
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.windows = []

        l = QVBoxLayout()
        button1 = QPushButton("CAMERA CONTROLS")
        button1.clicked.connect(self.open_newWindow)
        l.addWidget(button1)

        w = QWidget()
        w.setLayout(l)
        self.setCentralWidget(w)

    def open_newWindow(self):
        window = MainWindow2()
        self.windows.append(window)
        window.show()

###########################MAIN WINDOW 3########################################################################################
class MainWindow3(QMainWindow):
    def __init__(self):
        super().__init__()
        self.windows = []

        l = QVBoxLayout()
        zoom_controls_button = QPushButton("RECORDING")
        zoom_controls_button.clicked.connect(self.open_newWindow3)
        l.addWidget(zoom_controls_button)

        s = QWidget()
        s.setLayout(l)
        self.setCentralWidget(s)

    def open_newWindow3(self):
        window = recording()
        self.windows.append(window)
        window.show()
        

################################MAIN WINDOW 2##################################################################################

class MainWindow2(QMainWindow):
    def __init__(self):
        super().__init__()
        self.windows = []

        l = QVBoxLayout()
        zoom_controls_button = QPushButton("ZOOM CONTROLS")
        zoom_controls_button.clicked.connect(self.open_newWindow2)
        l.addWidget(zoom_controls_button)

        s = QWidget()
        s.setLayout(l)
        self.setCentralWidget(s)

    def open_newWindow2(self):
        window = zoom()
        self.windows.append(window)
        window.show()



app = QApplication(sys.argv)
w = MainWindow()
w.show()
app.exec_()

And the function is

class recording(QWidget):


    def __init__(self):
        super().__init__()
        layout = QVBoxLayout(self)
        
        # THIS BUTTON IS USED TO START RECORDING #
        start_recording_button = QPushButton(" START RECORDING ")
        start_recording_button.clicked.connect(self.start_recording)
        layout.addWidget(start_recording_button)

        # THIS BUTTON IS USED TO STOP RECORDING #
        stop_recording_button = QPushButton(" STOP RECORDING ")
        stop_recording_button.clicked.connect(self.stop_recording)
        layout.addWidget(stop_recording_button)
        
        self.show()
        
    def start_recording(self):
        camerass.do(Actions.startMovieRec)
        time.sleep(2)

    def stop_recording(self):
        camerass.do(Actions.stopMovieRec)
        time.sleep(2)
4

2 回答 2

1

In your code you never create MainWindow3 where the recording class / window would be created after clicking the "RECORDING" button.

After creating MainWindow3 the recording window shows up after button press. To test this you can just replace

w = MainWindow()

with

w = MainWindow3()

in your "main" (third last line)

于 2021-08-05T11:28:54.610 回答
0

I have run it in my system and made a few changes. I am pasting the code below.

from random import randint

from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow, QPushButton, QVBoxLayout, QWidget
import time
#from libsonyapi.camera import Camera
#from libsonyapi.actions import Actions
#from pysony import SonyAPI, ControlPoint, common_header
#search = ControlPoint()
#cameras =  search.discover(1) 
#camera = SonyAPI(QX_ADDR=cameras[0])
 # create camera instance
#camerass = Camera()

###############################SECONDARY WINDOWS###############################################################################
        
class recording(QWidget):


    def __init__(self):
        super().__init__()
        layout = QVBoxLayout(self)
        
        # THIS BUTTON IS USED TO START RECORDING #
        start_recording_button = QPushButton(" START RECORDING ")
        start_recording_button.clicked.connect(self.start_recording)
        layout.addWidget(start_recording_button)

        # THIS BUTTON IS USED TO STOP RECORDING #
        stop_recording_button = QPushButton(" STOP RECORDING ")
        stop_recording_button.clicked.connect(self.stop_recording)
        layout.addWidget(stop_recording_button)
        
        self.show()
        
    def start_recording(self):
        camerass.do(Actions.startMovieRec)
        time.sleep(2)

    def stop_recording(self):
        camerass.do(Actions.stopMovieRec)
        time.sleep(2)
        
        
class zoom(QWidget):


    def __init__(self):
        super().__init__()
        layout = QVBoxLayout(self)
        
        # THIS BUTTON IS USED AS ZOOM IN #
        zoom_in_button = QPushButton(" ZOOM IN ")
        zoom_in_button.clicked.connect(self.zoom_in)
        layout.addWidget(zoom_in_button)

        # THIS BUTTON IS USED AS ZOOM OUT #
        zoom_out_button = QPushButton(" ZOOM OUT ")
        zoom_out_button.clicked.connect(self.zoom_out)
        layout.addWidget(zoom_out_button)

        # THIS BUTTON IS USED TO STOP THE ZOOM IN #
        stop_zoom_in_button = QPushButton(" STOP ZOOM IN ")
        stop_zoom_in_button.clicked.connect(self.stop_zoom_in)
        layout.addWidget(stop_zoom_in_button)
        
        # THIS BUTTON IS USED TO STOP THE ZOOM OUT #
        stop_zoom_out_button = QPushButton(" STOP ZOOM OUT ")
        stop_zoom_out_button.clicked.connect(self.stop_zoom_out)
        layout.addWidget(stop_zoom_out_button)
        
        self.show()
        
    def zoom_in(self):
        camera.actZoom(param=["in", "start"])
        time.sleep(2)
    
    def zoom_out(self):
        camera.actZoom(param=["out", "start"])
        time.sleep(2)
    
    def stop_zoom_in(self):
        camera.actZoom(param=["in", "stop"])
        time.sleep(2)

    def stop_zoom_out(self):
        camera.actZoom(param=["out", "stop"])
        time.sleep(2)
################################MAIN WINDOW 1##################################################################################
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.windows = []

        l = QVBoxLayout()
        camera_controls_button = QPushButton("CAMERA CONTROLS")
        camera_controls_button.clicked.connect(self.open_newWindow)
        l.addWidget(camera_controls_button)

        w = QWidget()
        w.setLayout(l)
        self.setCentralWidget(w)

    def open_newWindow(self):
        window = MainWindow2()
        self.windows.append(window)
        window.show()

################################MAIN WINDOW 2##################################################################################

class MainWindow2(QMainWindow):
    def __init__(self):
        super().__init__()
        self.windows = []

        l = QVBoxLayout()
        zoom_controls_button = QPushButton("ZOOM CONTROLS")
        zoom_controls_button.clicked.connect(self.open_newWindow2)
        l.addWidget(zoom_controls_button)
        record_controls_button = QPushButton("RECORDING")
        record_controls_button.clicked.connect(self.open_newWindow3)
        l.addWidget(record_controls_button)

        s = QWidget()
        s.setLayout(l)
        self.setCentralWidget(s)

    def open_newWindow2(self):
        window1 = zoom()
        self.windows.append(window1)
        window1.show()
        
    def open_newWindow3(self):
        window2 = recording()
        self.windows.append(window2)
        window2.show()
        
####################END#########################################################################################################
app = QApplication(sys.argv)
w = MainWindow()
w.show()
app.exec_()

于 2021-08-06T08:42:05.150 回答