-
Notifications
You must be signed in to change notification settings - Fork 1
/
moodloader_ui.py
249 lines (197 loc) · 9.74 KB
/
moodloader_ui.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# ########################## Copyrights and License ##############################
# #
# This file is part of MoodLoader. http://github.com/JamesWrigley/MoodLoader/ #
# #
# MoodLoader 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. #
# #
# MoodLoader 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 #
# MoodLoader. If not, see <http://www.gnu.org/licenses/>. #
# #
# ################################################################################
import os
import re
import zipfile
from PyQt4 import QtGui
import properties_dialog
class MoodLoader(QtGui.QWidget):
"""
This class contains the GUI for MoodLoader, it's meant to be imported
and subclassed from a starter file. Note that the starter file must
implement an '__init__()' method.
"""
def center(self):
"""
A little function to center the program window
"""
qr = self.frameGeometry()
cp = QtGui.QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def initUI(self):
### Make all the layouts ###
main_vbox = QtGui.QVBoxLayout()
header_image_hbox = QtGui.QHBoxLayout()
addons_hbox = QtGui.QHBoxLayout()
maps_vbox = QtGui.QVBoxLayout()
cam_mods_vbox = QtGui.QVBoxLayout()
global_mods_vbox = QtGui.QVBoxLayout()
multiplayer_mods_vbox = QtGui.QVBoxLayout()
### Stylesheet for the addons QGroupBox's ###
addons_stylesheet = "QGroupBox {border: 2px solid gray; font-family: Inconsolata; font-size: 21px; margin-top: .5em;} QGroupBox::title {subcontrol-origin: margin; subcontrol-position: top center; padding:0px 5px;}"
### Make status bar ###
self.statusbar = QtGui.QStatusBar(self)
self.statusbar.showMessage("Ready")
### Make all the widgets ###
# Make the header image
header_image = QtGui.QPixmap("header.png")
header_image_label = QtGui.QLabel()
header_image_label.setPixmap(header_image)
# Map widgets
self.install_map_button = QtGui.QPushButton("Install Map")
maps_gbox = QtGui.QGroupBox("Maps")
maps_gbox.setStyleSheet(addons_stylesheet)
maps_gbox.setLayout(maps_vbox)
# Campaign mod widgets
self.install_cam_mod_button = QtGui.QPushButton("Install Campaign Mod")
cam_mods_gbox = QtGui.QGroupBox("Campaign Mods")
cam_mods_gbox.setStyleSheet(addons_stylesheet)
cam_mods_gbox.setLayout(cam_mods_vbox)
# Global mod widgets
self.install_global_mod_button = QtGui.QPushButton("Install Global Mod")
global_mods_gbox = QtGui.QGroupBox("Global Mods")
global_mods_gbox.setStyleSheet(addons_stylesheet)
global_mods_gbox.setLayout(global_mods_vbox)
# Multiplayer mod widgets
self.install_multiplayer_mod_button = QtGui.QPushButton("Install Multiplayer Mod")
multiplayer_mods_gbox = QtGui.QGroupBox("Multiplayer Mods")
multiplayer_mods_gbox.setStyleSheet(addons_stylesheet)
multiplayer_mods_gbox.setLayout(multiplayer_mods_vbox)
### QListViews to display existing addons ###
self.maps_listview = QtGui.QListView()
self.map_data_model = QtGui.QStandardItemModel(self.maps_listview)
self.maps_listview.setModel(self.map_data_model)
self.maps_listview.setTextElideMode(2)
self.maps_listview.setSelectionMode(3)
self.cam_mods_listview = QtGui.QListView()
self.cam_data_model = QtGui.QStandardItemModel(self.cam_mods_listview)
self.cam_mods_listview.setModel(self.cam_data_model)
self.cam_mods_listview.setTextElideMode(2)
self.cam_mods_listview.setSelectionMode(3)
self.global_mods_listview = QtGui.QListView()
self.global_data_model = QtGui.QStandardItemModel(self.global_mods_listview)
self.global_mods_listview.setModel(self.global_data_model)
self.global_mods_listview.setTextElideMode(2)
self.global_mods_listview.setSelectionMode(3)
self.multiplayer_mods_listview = QtGui.QListView()
self.multiplayer_data_model = QtGui.QStandardItemModel(self.multiplayer_mods_listview)
self.multiplayer_mods_listview.setModel(self.multiplayer_data_model)
self.multiplayer_mods_listview.setTextElideMode(2)
self.multiplayer_mods_listview.setSelectionMode(3)
### Pack everything ###
# Pack mod buttons into their vbox's
maps_vbox.insertSpacing(0, 10)
maps_vbox.addWidget(self.install_map_button)
maps_vbox.addWidget(self.maps_listview)
cam_mods_vbox.insertSpacing(0, 10)
cam_mods_vbox.addWidget(self.install_cam_mod_button)
cam_mods_vbox.addWidget(self.cam_mods_listview)
global_mods_vbox.insertSpacing(0, 10)
global_mods_vbox.addWidget(self.install_global_mod_button)
global_mods_vbox.addWidget(self.global_mods_listview)
multiplayer_mods_vbox.insertSpacing(0, 10)
multiplayer_mods_vbox.addWidget(self.install_multiplayer_mod_button)
multiplayer_mods_vbox.addWidget(self.multiplayer_mods_listview)
# Pack group boxes into the main 'addons_hbox'
addons_hbox.addWidget(maps_gbox)
addons_hbox.addWidget(cam_mods_gbox)
addons_hbox.addWidget(global_mods_gbox)
addons_hbox.addWidget(multiplayer_mods_gbox)
# Pack the header image
header_image_hbox.addStretch()
header_image_hbox.addWidget(header_image_label)
header_image_hbox.addStretch()
# Pack everything into 'main_vbox'
main_vbox.addLayout(header_image_hbox)
main_vbox.addLayout(addons_hbox)
main_vbox.addWidget(self.statusbar)
self.setLayout(main_vbox)
self.setWindowTitle("Warzone 2100 Mood Loader")
self.resize(1050, 530)
self.setFixedWidth(1050)
self.center()
self.show()
class PropertiesDialog(QtGui.QDialog):
"""
This is the class that creates the properties dialog for an addon. We just
subclass a QDialog and work from there. To call it, just run something like,
'PropertiesDialog("/path/to/addon/").
"""
def __init__(self, addon_path):
super(PropertiesDialog, self).__init__()
self.addon_path = addon_path
self.initUI()
def condense_addon(self, addon_name):
"""
A little helper function that removes the hash (if there is one) and
extension from a file name.
"""
# The hash length is always 64 chars, so by this we check if one is in the name
if len(addon_name) > 64:
addon_name = re.findall(".*-", addon_name)[0]
return(addon_name[:-1]) # Removes the trailing dash before returning
else:
return(addon_name.replace(".wz", ""))
def initUI(self):
### Make all the layouts ###
main_vbox = QtGui.QVBoxLayout()
main_label_hbox = QtGui.QHBoxLayout()
info_hbox = QtGui.QHBoxLayout()
info_labels_vbox = QtGui.QVBoxLayout()
info_data_vbox = QtGui.QVBoxLayout()
### Create widgets ###
# Main label, displaying the addon name
main_label = QtGui.QLabel(self.condense_addon(os.path.basename(self.addon_path)))
main_label.setFont(QtGui.QFont("Liberation Mono", 20))
# Create info labels
map_stats = properties_dialog.get_map_stats(self.addon_path)
addon_info_labels_list = []
addon_info_list = []
addon_type_label = QtGui.QLabel("Addon Type:")
addon_type_info = QtGui.QLabel(properties_dialog.get_addon_type(self.addon_path))
addon_info_labels_list.append(addon_type_label)
addon_info_list.append(addon_type_info)
players_label = QtGui.QLabel("Number of players:")
players_count = QtGui.QLabel(map_stats["players"])
addon_info_labels_list.append(players_label)
addon_info_list.append(players_count)
oil_count_label = QtGui.QLabel("Number of oils per player:")
oil_count = QtGui.QLabel(map_stats["oils"])
addon_info_labels_list.append(oil_count_label)
addon_info_list.append(oil_count)
### Pack everything ###
# Pack the main label
main_label_hbox.addStretch()
main_label_hbox.addWidget(main_label)
main_label_hbox.addStretch()
# Pack the info labels/data
for label in addon_info_labels_list:
info_labels_vbox.addWidget(label)
for label in addon_info_list:
info_data_vbox.addWidget(label)
info_hbox.addLayout(info_labels_vbox)
info_hbox.addLayout(info_data_vbox)
# Pack it all into main_vbox
main_vbox.addLayout(main_label_hbox)
main_vbox.insertSpacing(1, 20)
main_vbox.addLayout(info_hbox)
main_vbox.addStretch()
self.setLayout(main_vbox)
self.setFixedSize(420, 350)
self.exec_()