-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstallatorUI.py
66 lines (53 loc) · 2.15 KB
/
InstallatorUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""Handle the user interface."""
import PyQt5.QtWidgets as qtw
import sys
from Installator import Installator
from GenericUI import UiWizard
class InstallatorUI(qtw.QWizard):
"""Main window of the installator."""
def __init__(self):
"""Constructor."""
super(InstallatorUI, self).__init__()
self.ui = UiWizard()
self.__installator = Installator()
self.ui.setupUi(self)
# Initial values
self.ui.urlLineEdit.setText('https://yourURL.com/file.exe')
self.ui.urlLineEdit.setEnabled(False)
# Connect the signals
self.ui.browseBtn.clicked.connect(self.__showBrowseDialog)
self.currentIdChanged.connect(self.__pageChange)
self.ui.intallBtn.clicked.connect(self.__install)
# self.ui.
def __showBrowseDialog(self):
"""Show the file browser dialog."""
dirPath = qtw.QFileDialog.getExistingDirectory(options=qtw.QFileDialog.ShowDirsOnly)
urlFile = self.ui.urlLineEdit.text().split('/')[-1]
self.ui.destLineEdit.setText('{dirPath}/{urlFile}'.format(dirPath=dirPath, urlFile=urlFile))
def __pageChange(self, idPage):
"""Handle the signal when a page change."""
# ID 1 going to the install page
if idPage == 1:
self.button(self.CustomButton1).setVisible(True)
def __install(self):
"""Start the installation process."""
self.ui.intallBtn.setEnabled(False)
url = self.ui.urlLineEdit.text()
destination = self.ui.destLineEdit.text()
try:
self.__installator.install(url, destination, ui=self.ui)
self.ui.intallBtn.setEnabled(True)
self.ui.intallBtn.setText('Re-Install')
except Exception as err:
import traceback
_, _, ex_traceback = sys.exc_info()
stack = "".join(traceback.extract_tb(ex_traceback).format())
self.ui.progressText.append('Installation fatal Error:\n{error}\n\n{e}'.format(error=err, e=stack))
def main():
"""Main function."""
app = qtw.QApplication(sys.argv)
ui = InstallatorUI()
ui.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()