I have created a GUI that displays a list of profiles retrieved from a database.

The issue is when adding a new profile. It opens a new Dialog Window where the details of the new profile are inserted. Upon clicking to save the profile, data is saved in the database and a function to re-render the main gui with the new data (in which the new profile is added) is called.

The issue is that the main window with the list of profiles doesn't load the newly added data.

from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtPrintSupport import *
from account_class import Account
from database_class import Database as db

import os
import sys
import time

"""
MAIN WINDOW
"""
class MainWindow(QMainWindow):

    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)

        #initial load of existing profiles
        DB = db('accounts_data.db')    
        DB.db_connect()
        profiles = DB.get_profiles_list()

        #Communication with the chid window
        self.dialog = Add_New_Profile_Dialog()
        self.load_profiles_list(profiles)


    def load_profiles_list(self, profiles):

        layout = QVBoxLayout()

        #profiles added to GUI        
        for profile in self.profiles:
            #print(profile[0])
            profile_layout = QHBoxLayout()
            profile_label = QLabel()
            profile_label.setText(str(profile[0]))
            btn = QPushButton("Launch")         
            self.create_horizontal_layout(profile[0], profile[1], 'Proxy Name')
            scrollLayout.addWidget(self.horizontalGroupBox)

        container = QWidget()
        container.setLayout(layout)
        print("from load_profile")
        self.setCentralWidget(container)

    """Function called from child window to update the profile list of gui with newly added profile"""
    def update_profiles_list(self):

        DB = db('accounts_data.db')    
        DB.db_connect()
        profiles = DB.get_profiles_list()
        self.load_profiles_list(profiles)     
        print("check from update_profiles_list")
        return

"""Child window when new profile is inserted"""
class ChildWidowDialog(QMainWindow):

    def save_profile_db(self):    
        #Adding new data to Database
        DB = db('accounts_data.db')    
        DB.db_connect()
        DB.add_profile(profile_name, device_selected, os_browser[1], os_browser[0], proxy)

        #function from main window called to update profile
        MainWindow().update_profiles_list()
        self.close()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    app.setApplicationName("Profiles")

    window = MainWindow()

app.exec_()

The function update_profiles_list from MainWindow is called and the Terminal message "check from update_profiles_list" is displayed, meaning that communication between the windows is established.

However, the GUI of MainWindow doesn't load when the self.load_profiles_list() function is called from within update_profiles_list

0 Answers