Sayan
Sayan

Reputation: 13

Qwidget elements not showing in secondary window

I am trying to open a QWidget when close even in QMainWindow is triggered. The QWidget need to stay open until the for loop gets completed. The QWidget is showing up, but the elements in the widget is kept being invisible. Please help.

import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QLabel
from PySide6.QtGui import QFont
from PySide6.QtCore import Qt

class Loader(QWidget):
    def __init__(self):
        super().__init__()

        self.setWindowTitle('ManagerBee - Loader') 
        self.resize(250, 130)
        self.h1 = QFont()
        self.h1.setPointSize(9)
        self.h1.setBold(True)


        self.itemVL_1 = QVBoxLayout(self)

        self.loaderText = QLabel("Auto Backup is in progress.<br/>System will close automatically.")
        self.loaderText.setFont(self.h1)
        self.loaderText.setAlignment(Qt.AlignCenter)
        self.itemVL_1.addWidget(self.loaderText)

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("My Main Window")
        self.closeEvent = self.close_event

    def close_event(self,event):
        self.closingLoader = Loader()
        self.closingLoader.setWindowFlags(self.closingLoader.windowFlags() | Qt.WindowStaysOnTopHint)
        self.closingLoader.show()
        upload.uploadFile('db.sqlite3',str(self.userData[0]))
        self.closingLoader.close()

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

    window = MainWindow()
    window.show()

    app.exec()

Here I add the upload code.

import ftplib
import os
import shutil
import datetime
from alertbox import AlertBox
import db

FTP_HOST = "ftp.domain.com"
FTP_USER = "[email protected]"
FTP_PASS = "iCQL^7;eIpbD"


def uploadFile(filename, index):
     try:
          ftp = ftplib.FTP(FTP_HOST, FTP_USER, FTP_PASS)
     except:
          alert_box = AlertBox("Unable to Connect Network", "No internet connection. Auto backup failed.")
          alert_box.exec()
          return
     ftp.encoding = "utf-8"
     os.getcwd()
     shutil.copy(filename,index+'_'+filename) 
     local_file = index+'_'+filename

     with open(local_file, "rb") as file:
          ftp.storbinary(f"STOR {local_file}", file)

     os.remove(index+'_'+filename)

     ftp.quit()

def downloadFile(filename):
     try:
          ftp = ftplib.FTP(FTP_HOST, FTP_USER, FTP_PASS)
     except:
          alert_box = AlertBox("Unable to Connect Network", "No internet connection. Restoration Failed.")
          alert_box.exec()
          return
     ftp.encoding = "utf-8"
     with open(filename, "wb") as file:
      #use FTP's RETR command to downlohad the file
          ftp.retrbinary(f"RETR {filename}", file.write)

     db.db.close()
     os.getcwd()
     shutil.copy("db.sqlite3", str(datetime.datetime.now().strftime('%Y%m%d%H%M')) + "_" + "db.sqlite3")
     os.remove("db.sqlite3")
   
     os.rename(filename, "db.sqlite3")

     db.db = db.QtSql.QSqlDatabase.addDatabase('QSQLITE')
     db.db.setDatabaseName('db.sqlite3')
     if not db.db.open():
          db.exit()
     db.query = db.QtSql.QSqlQuery()

     ftp.quit()

This is what I am getting as an output now: This is what I am getting

This is what the secondary widget should look like. This the secondary widget design

Upvotes: 0

Views: 67

Answers (0)

Related Questions