V
V
vadimeasy2021-12-12 17:44:05
Building projects
vadimeasy, 2021-12-12 17:44:05

How to compile 2 or more Python files to EXE?

I am making a program for automation in PyQT5, I have implemented the download of the necessary programs and progress barr in a new window. Roughly speaking, I call a new program from the main window that has a progress bar and a download button. The problem is that I was compiling everything with pyinstaller into an java file. But when you try to call a new download window, the program just closes, no messages appear in the console.
The function that is called from the main window:

from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import shutil
import glob
import urllib.request
import sys
import threading
import os

url_1 = 'https://download.rutoken.ru/Rutoken/Drivers/Current/rtDrivers.exe'
dlThread = 0
hWindow = 0
fProgressCounter = 0.0

class Form(QWidget):
    def __init__(self, parent=None):
        super(Form, self).__init__(parent)
        self.resize(300, 100)
        global hWindow
        hWindow = self

        lblUrl = QLabel("Скчать rtDriver.exe?")
        self.bttDL = QPushButton("Скачать")
        self.pbar = QProgressBar()

        self.pbar.setMinimum(0)
        self.pbar.setMaximum(100)

        buttonLayout1 = QVBoxLayout()
        buttonLayout1.addWidget(lblUrl)
        buttonLayout1.addWidget(self.bttDL)
        buttonLayout1.addWidget(self.pbar)

        self.bttDL.clicked.connect(self.bttPush)

        mainLayout = QGridLayout()
        mainLayout.addLayout(buttonLayout1, 0, 1)

        self.setLayout(mainLayout)
        self.setWindowTitle("Скачать Рутокен")
    def bttPush(self):
        global dlThread

        hSignals = sigHandling()
        hSignals.dlProgress_update.connect(hSignals.pbar_incrementer)
        hSignals.dlProgress_done.connect(hSignals.dlDone)

        url = url_1
        filename = 'rtDrivers.exe'
        # filename = filename[:-6]
        # filename = filename.split("('", maxsplit=1)[1]

        # self.bttDL.setEnabled(False)
        dlThread = threading.Thread(target=hSignals.runDL, args=(url, filename))
        dlThread.start()
        return

    def pbarIncValue(self, val):
        global fProgressCounter

        if self.pbar.value() >= 100:
            self.dlProgress_done.emit()
            return
        if fProgressCounter > 1.0:
            self.pbar.setValue(self.pbar.value() + 1)
            fProgressCounter -= 1.0
            fProgressCounter += val
        else:
            fProgressCounter += val

class sigHandling(QObject):
    dlProgress_update = pyqtSignal(float)
    dlProgress_done = pyqtSignal()

    @pyqtSlot(float)
    def pbar_incrementer(self, val):
        hWindow.pbarIncValue(val)

    @pyqtSlot()
    def dlDone(self):
        print("in dlDone")
        hWindow.pbar.setValue(100)
        hWindow.bttDL.setEnabled(True)

    def runDL(self, dlLink, filename):
        #print("in run")
        global dlThread, hWindow
        def report(block_count, block_size, total_size):
            if block_count == 0:
                #print("block_count == 0")
                self.dlProgress_update.emit(0)
            if (block_count * block_size) == total_size:
                self.dlProgress_done.emit()
            incAmount = float((101*block_size) / total_size)
            #print("BS={0} TS={1} incAmount={2}".format(block_size,total_size,incAmount))
            self.dlProgress_update.emit(incAmount)


        urllib.request.urlretrieve(dlLink, filename, reporthook=report)
        #print("emit dlProgress_done")
        self.dlProgress_done.emit()
        #print("about to leave dlThread")
        rt_to_move = glob.glob('rtDrivers.exe')
        desktop_dir = os.path.expanduser("~\\UTM_Set")
        some_file_on_desktop = os.path.join(desktop_dir, 'N')
        for file in rt_to_move:
            shutil.move(file, some_file_on_desktop)
        app.quit()



if __name__ == '__main__':
    app = QApplication(sys.argv)
    screen = Form()
    screen.show()
    sys.exit(app.exec_())

Main window:
from subprocess import call
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QLabel
import glob
import shutil

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(348, 405)
        Dialog.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
        self.pushButton = QtWidgets.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(110, 20, 131, 41))
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtWidgets.QPushButton(Dialog)
        self.pushButton_2.setGeometry(QtCore.QRect(110, 70, 131, 41))
        self.pushButton_2.setObjectName("pushButton_2")
        self.pushButton_3 = QtWidgets.QPushButton(Dialog)
        self.pushButton_3.setGeometry(QtCore.QRect(110, 120, 131, 41))
        self.pushButton_3.setObjectName("pushButton_3")
        self.pushButton_4 = QtWidgets.QPushButton(Dialog)
        self.pushButton_4.setGeometry(QtCore.QRect(110, 170, 131, 41))
        self.pushButton_4.setObjectName("pushButton_4")
        self.pushButton_5 = QtWidgets.QPushButton(Dialog)
        self.pushButton_5.setGeometry(QtCore.QRect(110, 220, 131, 41))
        self.pushButton_5.setObjectName("pushButton_5")
        self.pushButton_6 = QtWidgets.QPushButton(Dialog)
        self.pushButton_6.setGeometry(QtCore.QRect(110, 270, 131, 41))
        self.pushButton_6.setObjectName("pushButton_6")
        self.pushButton_7 = QtWidgets.QPushButton(Dialog)
        self.pushButton_7.setGeometry(QtCore.QRect(110, 320, 131, 41))
        self.pushButton_7.setObjectName("pushButton_7")
        self.line = QtWidgets.QFrame(Dialog)
        self.line.setGeometry(QtCore.QRect(10, 210, 331, 16))
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")
        self.labl = QLabel(Dialog)
        self.labl.setText('abc')
        self.labl.setGeometry(10, 10, 10, 10)

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)



        self.download_rt()
        self.download_des()
        self.download_utm()
        self.move_to_config()

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "UTM Настройка"))
        self.pushButton.setText(_translate("Dialog", "Скачать Open VPN"))
        self.pushButton_2.setText(_translate("Dialog", "Скачать Рутокен"))
        self.pushButton_3.setText(_translate("Dialog", "Скачать DXBX Desktop"))
        self.pushButton_4.setText(_translate("Dialog", "Скачать UTM"))
        self.pushButton_5.setText(_translate("Dialog", "Настроить Брандмауэр"))
        self.pushButton_6.setText(_translate("Dialog", "Перезапустить службы"))
        self.pushButton_7.setText(_translate("Dialog", "Config и Transport"))

    # Download rtDriver
    def download_rt(self):
        self.pushButton_2.clicked.connect(self.rutoken_download)

    def rutoken_download(self):
        call(['python', 'rt_download.py'])

    # Download DXBX Deskotop
    def download_des(self):
        self.pushButton_3.clicked.connect(self.desktop_download)

    def desktop_download(self):
        call(['python', 'desktop_download.py'])

#     Download UTM
    def download_utm(self):
        self.pushButton_4.clicked.connect(self.utm_download)

    def utm_download(self):
        call(['python', 'UTM_download.py'])

#     move to trasport and config
    def move_to_config(self):
        self.pushButton_7.clicked.connect(self.trans_conf)

    def trans_conf(self):
        if True:
            transport_to_copy = glob.glob('*.properties')
            destination_trans = (r'C:/UTM/transporter/conf')
            for file in transport_to_copy:
                shutil.copy(file, destination_trans)

        if True:
            ovpn_to_copy = glob.glob('*.ovpn')
            destination = (r'C:/Program Files/OpenVPN/config')
            for file in ovpn_to_copy:
                shutil.copy(file, destination)




if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Dialog = QtWidgets.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())


Tell me why this might be. I mean the problem is that another window run cycle is called in the second one. If I'm right, tell me where to read about new windows in pyqt.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question