Quantcast
Channel: User Graygood - Stack Overflow
Viewing all articles
Browse latest Browse all 32

How to call the function after UI loads? PyQt5

$
0
0

I'm building the desktop app. Before class MyMainWindow(QMainWindow, Ui_MainWindow): I have a section, that processes some initial data (code 1)

sample_directory_2 = []sample_files_2 = []for (dirpath, dirnames, filenames) in walk('./Processed'):    filenames = [f for f in filenames if not f[0] == '.']    sample_files_2.extend(filenames)    breakthe_dir = "Processed"paths_2 = [os.path.abspath(os.path.join(the_dir,filename)) for filename in os.listdir(the_dir) if not filename.startswith('.')]    sample_directory_2.append(sample_files_2)sample_directory_2.append(paths_2)processed_info = []for i in range(len(sample_directory_2[0])):    file_info = []    sample_file_2 = sample_directory_2[0][i]    sample_path_2 = sample_directory_2[1][i]                sample_info_2 = pd.read_excel(ospath(sample_path_2), header = None, sheetname = 3)    sample_info_2 = sample_info_2.iloc[0][0:3]    file_info.append(sample_file_2)    sample_info_2_list = numpy.array(sample_info_2).tolist()     file_info.extend(sample_info_2_list)    processed_info.append(file_info)

After this section in class MyMainWindow(QMainWindow, Ui_MainWindow): I have the code that creates QTableList and sets values to its items(code 2):

        self.clickSample_list.setRowCount(len(processed_info))        self.clickSample_list.setColumnCount(len(processed_info[0]))        labels = ['Имя', 'Массовыеотклики', 'Процентранг', 'Валидность']        self.clickSample_list.setHorizontalHeaderLabels(labels)        for row in range(len(processed_info)):            for column in range(len(processed_info[row])):                self.clickSample_list.setItem(row, column, QTableWidgetItem(str(processed_info[row][column])))

Code 1 section takes pretty long time, and only after that, the UI begins to load.

I guess, what I need to do is: to make Code 1 a separate function and call it after UI loads. How to do that? Is there a command that calls the function after the loading of UI?


Viewing all articles
Browse latest Browse all 32

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>