-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
138 lines (108 loc) · 5.38 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
if __name__ == "__main__":
import sys, os
from PyQt4 import QtCore, QtGui
from installer.core import Core
if not hasattr(sys, "frozen"):
from PyQt4 import uic
form_class, base_class = uic.loadUiType(r"installer\gui_main.ui")
else:
from installer.gui_main import Ui_Wizard as form_class
def makeDirExist(dir):
if os.path.exists(dir):
if os.path.isdir(dir):
return True
else:
return False
else:
try:
os.makedirs(dir)
return True
except:
return False
class MainForm(QtGui.QWizard, form_class):
def __init__(self, core, parent=None):
super(self.__class__, self).__init__(parent)
self.setupUi(self)
self.core = core
self.installerTreeView.clicked.connect(self.itemClicked)
self.installerTreeView.entered.connect(self.itemEntered)
self.installerTreeView.model.checkStateChangeRequest.connect(self.itemChecked)
self.introPage.setPixmap(QtGui.QWizard.WatermarkPixmap,
QtGui.QPixmap(':/App/images/watermark1.png'))
self.btnLoadPreset.clicked.connect(self.loadPreset)
def itemClicked(self, item):
i = item.internalPointer()
self.helpPanel.setHtml(i.helptext)
def itemEntered(self, item):
i = item.internalPointer()
pass
def itemChecked(self, thisitem, newstate):
docheck = True
missingdeps = []
dependedby = []
disableddeps = []
depends = self.core.installerItems().deps(thisitem.id)
if newstate == True:
for dep in depends:
if not dep in self.core.installerItems():
missingdeps.append(dep)
docheck = False
else:
for dep in thisitem.dependedby:
if self.core.installerItems().isChecked(dep):
dependedby.append(dep)
docheck = False
if docheck:
if depends:
if newstate == True:
for dep in depends:
if not self.core.installerItems().isChecked(dep):
disableddeps.append(dep)
if disableddeps:
q = QtGui.QMessageBox.question(self, "Required dependencies!",
"Do you wish to check the following dependencies?\n\n%s" %
", ".join(disableddeps), "No", "Yes", "Ignore")
if q == 1: # Yes
for dep in disableddeps:
self.core.installerItems().setChecked(dep, True)
elif q == 0: # No
docheck = False
if docheck:
self.core.installerItems().setChecked(thisitem.id, newstate)
else:
if newstate == True:
QtGui.QMessageBox.critical(self, "Missing dependencies!",
"Can't install this item due to the\nfollowing missing dependencies:\n\n%s" %
", ".join(missingdeps))
else:
q = QtGui.QMessageBox.question(self, "Orphaned dependencies!",
"Unchecking will uncheck the following dependents:\n\n%s\n\nContinue?" %
", ".join(dependedby), "No", "Yes", "Ignore")
if q == 1 or q == 2: # Yes or Ignore
if q == 1: # Yes
for dep in dependedby:
self.core.installerItems().setChecked(dep, False)
self.core.installerItems().setChecked(thisitem.id, False)
def parseConfig(self):
self.installerTreeView.parseData(self.core)
for key, value in self.core.presetItems().iteritems():
self.cmbPresets.addItem(value.name, key)
if "default" in self.core.presetItems():
self.btnLoadPreset.click()
def loadPreset(self):
presetid = str(self.cmbPresets.itemData(self.cmbPresets.currentIndex()).toString())
preset = self.core.presetItems()[presetid]
for x in preset.includes:
item = self.core.installerItems().setChecked(x, True)
for x in preset.excludes:
item = self.core.installerItems().setChecked(x, False)
app = QtGui.QApplication(sys.argv)
makeDirExist("Installers")
makeDirExist("Presets")
core = Core()
core.getItems("Installers")
core.getPresets("Presets")
myapp = MainForm(core)
myapp.parseConfig()
myapp.show()
sys.exit(app.exec_())