-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathfirstRunWizard.py
171 lines (121 loc) · 5.35 KB
/
firstRunWizard.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Miyamoto! Level Editor - New Super Mario Bros. U Level Editor
# Copyright (C) 2009-2021 Treeki, Tempus, angelsl, JasonP27, Kinnay,
# MalStar1000, RoadrunnerWMC, MrRean, Grop, AboodXD, Gota7, John10v10,
# mrbengtsson
# This file is part of Miyamoto!.
# Miyamoto! is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Miyamoto! is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Miyamoto!. If not, see <http://www.gnu.org/licenses/>.
# firstRunWizard.py
# Cointains code for the first run wizard
################################################################
################################################################
import json
import os
from PyQt5 import QtGui, QtWidgets
import sys
from dialogs import PreferencesDialog
import globals
from misc import setting
from ui import SetAppStyle
from verifications import isValidGamePath, isValidObjectsPath
class PathPage(QtWidgets.QWizardPage):
def __init__(self):
super().__init__()
self.pathLabel = QtWidgets.QLabel()
self.pathLineEdit = QtWidgets.QLineEdit()
self.pathButton = QtWidgets.QPushButton()
self.pathButton.setDefault(False)
self.pathButton.setFlat(False)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.addWidget(self.pathLabel)
self.horizontalLayout.addWidget(self.pathLineEdit)
self.horizontalLayout.addWidget(self.pathButton)
font = QtGui.QFont()
font.setPointSize(10)
font.setBold(True)
font.setItalic(True)
font.setWeight(75)
self.isValidLabel = QtWidgets.QLabel()
self.isValidLabel.setFont(font)
self.isValidLabel.setStyleSheet("color: rgb(255, 0, 0);")
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.addLayout(self.horizontalLayout)
self.verticalLayout.addWidget(self.isValidLabel)
self.setLayout(self.verticalLayout)
self.pathLabel.setText("Path:")
self.pathButton.setText("...")
self.isValidLabel.setText("Invalid path!")
self.isValid = False
self.requireFinish = True
self.isValidPathMethod = None
self.pathLineEdit.textChanged.connect(self.isValidPath)
self.pathButton.clicked.connect(self.openPath)
def isValidPath(self):
if not self.isValidPathMethod:
return
self.isValid = self.isValidPathMethod(self.pathLineEdit.text())
if not self.isValid:
self.isValidLabel.setText("Invalid path!")
self.isValidLabel.setStyleSheet("color: rgb(255, 0, 0);")
else:
self.isValidLabel.setText("Path validated!")
self.isValidLabel.setStyleSheet("color: rgb(0, 127, 0);")
self.completeChanged.emit()
def openPath(self):
self.pathLineEdit.setText(QtWidgets.QFileDialog.getExistingDirectory(None, self.subTitle()))
def isComplete(self):
return self.isValid or not self.requireFinish
class GamePathPage(PathPage):
def __init__(self):
super().__init__()
self.setTitle("Game Path (required)")
self.setSubTitle(globals.trans.string('ChangeGamePath', 0, '[game]', globals.gamedef.name))
self.isValidPathMethod = isValidGamePath
path = globals.gamedef.GetGamePath()
if path:
self.pathLineEdit.setText(path)
class ObjectsPathPage(PathPage):
def __init__(self):
super().__init__()
self.setTitle("Objects Path (optional)")
self.setSubTitle("Choose the folder containing object folders")
self.requireFinish = False
self.isValidPathMethod = isValidObjectsPath
path = setting('ObjPath')
if path:
self.pathLineEdit.setText(path)
ThemesTab = PreferencesDialog.getThemesTab(QtWidgets.QWizardPage)
class ThemesPage(ThemesTab):
def __init__(self):
super().__init__()
self.setTitle("Set the theme (optional)")
self.setSubTitle("Can be changed later from Miyamoto! Preferences\nYou have to launch the editor for the theme to apply")
self.NonWinStyle.currentIndexChanged.connect(self.setStyle); self.setStyle()
def setStyle(self):
SetAppStyle(self.NonWinStyle.currentText())
class Wizard(QtWidgets.QWizard):
def __init__(self):
super().__init__()
self.setWizardStyle(QtWidgets.QWizard.ClassicStyle)
self.setOptions(QtWidgets.QWizard.IndependentPages|QtWidgets.QWizard.NoBackButtonOnStartPage)
self.gamePathPage = GamePathPage()
self.objectsPathPage = ObjectsPathPage()
self.themesPage = ThemesPage()
self.addPage(self.gamePathPage)
self.addPage(self.objectsPathPage)
self.addPage(self.themesPage)
self.finished = False
self.button(QtWidgets.QWizard.FinishButton).clicked.connect(self.finishClicked)
def finishClicked(self):
self.finished = True