def create_main_pane(self): """ Create the main pane for the user to connect or wait for connection """ # Create a pane with the choice to connect or listen to others # provide choice to connect or wait for connection rad_connect = QRadioButton("Connect") rad_listen = QRadioButton("Wait for Connection") # initialise the connect radio button as checked rad_connect.setChecked(True) ## The connect pane # Create the ip address txt box for ip input lbl_connection_address = QLabel('IP address') inp_connection_address = QLineEdit() inp_connection_address.setText('localhost') # the button to initiate the connection btn_connect = QPushButton('Connect') btn_connect.clicked.connect(self.btn_connect_clicked) # asseble everything of connection pane into a container layout connect_pane = create_widget_container( [lbl_connection_address, inp_connection_address, btn_connect]) ## The listening pane # Show the ip address of current machine lbl_ip_address = QLabel(Networking.get_ip()) btn_listening = QPushButton("Wait for connection") btn_listening.clicked.connect(self.btn_listen_clicked) # assemble all listening widget into a container listen_pane = create_widget_container([lbl_ip_address, btn_listening]) connection_pane = create_widget_container( [rad_connect, rad_listen, connect_pane, listen_pane]) # set up a method to show or hide based on user choice def show_connect_pane(): """ show the connection pane when user click the connect to radiobutton """ listen_pane.hide() connection_pane.adjustSize() connect_pane.show() def show_listen_pane(): """ show the listening pane when user click the listen radiobutton """ connect_pane.hide() connection_pane.adjustSize() listen_pane.show() rad_connect.clicked.connect(show_connect_pane) rad_listen.clicked.connect(show_listen_pane) show_connect_pane() self.connection_pane = connection_pane self.inp_connection_address = inp_connection_address