This repository has been archived by the owner on Jan 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
qua2osu-gui.py
204 lines (145 loc) · 6.18 KB
/
qua2osu-gui.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import os
import sys
import time
import webbrowser # to open the explorer cross-platform
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from conversion import convertMapset
# gui.py is autogenerated from gui.ui (qt designer)
# use "pyuic5 -x gui/gui.ui -o gui/gui.py" after editing gui.ui with qt designer
from gui.gui import Ui_MainWindow
class IceMainWindow(QMainWindow, Ui_MainWindow):
"""Custom window class with all of the GUI functionality
All of the objects themselves are managed by QT designer in the gui.ui (gui.py) file
"""
def __init__(self):
QMainWindow.__init__(self)
self.setupUi(self)
self.inputToolButton.clicked.connect(self.openInputDirectoryDialog)
self.outputToolButton.clicked.connect(self.openOutputDirectoryDialog)
self.convertPushButton.clicked.connect(self.convertOnClick)
self.updateStatus("Finished setup")
def openInputDirectoryDialog(self):
"""Opens the input directory dialog and sets the input path in the GUI"""
path = str(QFileDialog.getExistingDirectory(
self, "Select Input Folder"))
self.inputLineEdit.setText(path)
self.updateStatus("Set input path to " + path)
def openOutputDirectoryDialog(self):
"""Opens the output directory dialog and sets the input path in the GUI"""
path = str(QFileDialog.getExistingDirectory(
self, "Select Output Folder"))
self.outputLineEdit.setText(path)
self.updateStatus("Set output path to " + path)
def updateStatus(self, status):
"""Wrapper for updating the status label, always shows the two last lines"""
currentText = self.statusLabel.text()
lastLine = currentText.split("\n")[-1]
self.statusLabel.setText(lastLine + "\n" + status)
def updateProgressBarMax(self, maximum):
"""Wrapper for updating the progress bar maximum"""
self.progressBar.setMaximum(maximum)
def incrementProgressBarValue(self):
"""Increments the progress bar by one unit total, adds a smooth animation"""
self.progressBar.setValue(self.progressBar.value() + 1)
def initiateConverterThread(self, inputPath, outputPath, options):
"""Sets up the converter thread"""
converterThread = ConverterThread(inputPath, outputPath, options)
converterThread.updateStatus.connect(self.updateStatus)
converterThread.updateProgressbarMax.connect(
self.updateProgressBarMax)
converterThread.incrementProgressbarValue.connect(
self.incrementProgressBarValue)
return converterThread
def convertOnClick(self):
"""Starts the map conversion of the folder"""
inputPath = self.inputLineEdit.text()
outputPath = self.outputLineEdit.text()
if inputPath == "" or outputPath == "":
self.updateStatus("Empty paths detected, using defaults")
if inputPath == "":
inputPath = "input"
if outputPath == "":
outputPath = "output"
selectedOd = self.odDoubleSpinBox.value()
selectedHp = self.hpDoubleSpinBox.value()
selectedHitSoundVolume = self.hsVolumeSpinBox.value()
# please tell me if there's an easier way to lookup
# which radio button is checked because this is horrible
selectedSampleSet = ""
sampleSetButtons = [
self.sampleSetNormalRadioButton,
self.sampleSetSoftRadioButton,
self.sampleSetDrumRadioButton
]
for button in sampleSetButtons:
if button.isChecked():
selectedSampleSet = button.text()
break
options = {
"od": selectedOd,
"hp": selectedHp,
"hitSoundVolume": selectedHitSoundVolume,
"sampleSet": selectedSampleSet
}
self.progressBar.setValue(0)
self.converterThread = self.initiateConverterThread(
inputPath, outputPath, options)
self.converterThread.start()
class ConverterThread(QThread):
"""Using a different thread for the map conversion
Otherwise the UI would freeze and become unresponsive during the conversion
"""
updateStatus = pyqtSignal(str)
incrementProgressbarValue = pyqtSignal()
updateProgressbarMax = pyqtSignal(int)
def __init__(self, inputPath, outputPath, options):
QThread.__init__(self)
self.inputPath = inputPath
self.outputPath = outputPath
self.options = options
def __del__(self):
self.wait()
def run(self):
qpFilesInInputDir = []
for file in os.listdir(self.inputPath):
path = os.path.join(self.inputPath, file)
if file.endswith('.qp') and os.path.isfile(path):
qpFilesInInputDir.append(file)
numberOfQpFiles = len(qpFilesInInputDir)
if numberOfQpFiles == 0:
self.updateStatus.emit("No mapsets found in " + self.inputPath)
return
self.updateProgressbarMax.emit(numberOfQpFiles)
start = time.time()
count = 1
for file in qpFilesInInputDir:
filePath = os.path.join(self.inputPath, file)
self.updateStatus.emit(f"({count}/{numberOfQpFiles}) "
f"Converting {filePath}")
convertMapset(filePath, self.outputPath, self.options)
count += 1
self.incrementProgressbarValue.emit()
end = time.time()
timeElapsed = round(end - start, 2)
self.updateStatus.emit(
f"Finished converting all mapsets,"
f"total time elapsed: {timeElapsed} seconds"
)
# Opens output folder in explorer
absoluteOutputPath = os.path.realpath(self.outputPath)
webbrowser.open("file:///" + absoluteOutputPath)
return
class IceApp(QApplication):
"""Custom QApplication class for the sole purpose of applying the Fusion style"""
def __init__(self):
super().__init__(sys.argv)
self.setStyle("Fusion")
def main():
app = IceApp()
iceApp = IceMainWindow()
iceApp.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()