-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.py
More file actions
297 lines (214 loc) · 10.8 KB
/
window.py
File metadata and controls
297 lines (214 loc) · 10.8 KB
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
import wx
import wx.xrc
import xml.etree.ElementTree as ET
from confg import *
CFG = read_config() # JSON object
def WoTVersion(text):
version = dict( CFG["wot"]["versions"] )
for item in text:
if item.split('=')[0] in version:
version[item.split('=')[0]] = item.split('=')[-1]
if version["hdcontent_ver"] != "unknown":
version["selected_target"] = "hd"
else:
version["selected_target"] = "sd"
return version
def WoWPVersion(text):
version = dict( CFG["wowp"]["versions"] )
for item in text:
if item.split('=')[0] in version:
version[item.split('=')[0]] = item.split('=')[-1]
if version["hdcontent_ver"] != "unknown":
version["selected_target"] = "hd"
else:
version["selected_target"] = "sd"
return version
def WoWSVersion(text):
version = dict( CFG["wows"]["versions"] )
for item in text:
if item.split('=')[0] in version:
version[item.split('=')[0]] = item.split('=')[-1]
return version
def CreateCFG(filePath, Versions):
filePath.replace("/", "\\")
cfg_file = filePath.split('\\')[-1]
try:
tree = ET.parse(filePath)
except:
return "\nERROR! Can't open " + filePath + ". =(\n"
root = tree.getroot()
for item in root:
if item.tag in Versions:
# print item.tag, item.text, Versions[item.tag]
item.text = Versions[item.tag]
tree.write(CFG["output"] + cfg_file, xml_declaration=True, encoding="utf-8")
return "\n" + CFG["output"] + cfg_file + ' has been created.'
def SelectGame(link):
link = link.strip().replace('"', '')
link = link.split('&')
if "wot" in link[0].lower() or "tank" in link[0].lower():
Versions = WoTVersion(link)
filePath = CFG["wot"]["path"]
return "WoT detected...", Versions, filePath
elif "wowp" in link[0].lower() or "plane" in link[0].lower():
Versions = WoWPVersion(link)
filePath = CFG["wowp"]["path"]
return "WoWP detected...", Versions, filePath
elif "wows" in link[0].lower() or "ship" in link[0].lower():
Versions = WoWSVersion(link)
filePath = CFG["wows"]["path"]
return "WoWS detected...", Versions, filePath
else:
return "Can't detect project.", {}, ""
# raw_input("ERROR! Can't detect project.")
# exit()
class MyFrame1(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=u"cfgHelper", pos=wx.DefaultPosition,
size=wx.Size(500, 270), style=(wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) ^ (wx.MAXIMIZE_BOX | wx.RESIZE_BORDER))
self.SetIcon(icon_32.GetIcon())
self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)
bSizer1 = wx.BoxSizer(wx.VERTICAL)
self.m_panel1 = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL)
bSizer2 = wx.BoxSizer(wx.VERTICAL)
bSizer3 = wx.BoxSizer(wx.HORIZONTAL)
self.m_textCtrl1 = wx.TextCtrl(self.m_panel1, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize,
wx.TE_MULTILINE)
bSizer3.Add(self.m_textCtrl1, 1, wx.ALL | wx.EXPAND, 5)
bSizer2.Add(bSizer3, 1, wx.EXPAND, 5)
bSizer4 = wx.BoxSizer(wx.HORIZONTAL)
self.m_buttonSettings = wx.Button(self.m_panel1, wx.ID_ANY, u"Settings", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer4.Add(self.m_buttonSettings, 0, wx.ALL, 5)
bSizer4.AddSpacer((0, 0), 1, wx.EXPAND, 5)
self.m_buttonCreateCFG = wx.ToggleButton(self.m_panel1, wx.ID_ANY, u"Create CFG!", wx.DefaultPosition,
wx.DefaultSize, 0)
self.m_buttonCreateCFG.SetValue(True)
bSizer4.Add(self.m_buttonCreateCFG, 0, wx.ALL | wx.ALIGN_RIGHT, 5)
bSizer2.Add(bSizer4, 0, wx.EXPAND, 5)
self.m_panel1.SetSizer(bSizer2)
self.m_panel1.Layout()
bSizer2.Fit(self.m_panel1)
bSizer1.Add(self.m_panel1, 1, wx.EXPAND, 5)
self.SetSizer(bSizer1)
self.Layout()
self.m_statusBar1 = self.CreateStatusBar(2, wx.ST_SIZEGRIP, wx.ID_ANY)
self.SetStatusWidths([-2,-7])
self.Centre(wx.BOTH)
# Connect Events
self.Bind(wx.EVT_CLOSE, self.OnExit)
self.m_buttonSettings.Bind(wx.EVT_BUTTON, self.SettingsShow)
self.m_buttonCreateCFG.Bind(wx.EVT_TOGGLEBUTTON, self.CreateCFG)
self.m_textCtrl1.Bind( wx.EVT_TEXT, self.textAdded )
def __del__(self):
pass
# Virtual event handlers, overide them in your derived class
def OnExit(self, event):
myApp.Exit()
def textAdded( self, event ):
myApp.frame.m_buttonCreateCFG.Enable(True)
result, _, _ = SelectGame( myApp.frame.m_textCtrl1.GetRange(0,-1) )
myApp.frame.m_statusBar1.SetStatusText(result, 0)
myApp.frame.m_statusBar1.SetStatusText('', 1)
def SettingsShow(self, event):
CFG = read_config()
myApp.settings.m_filePicker_wot.SetPath(CFG["wot"]["path"])
myApp.settings.m_filePicker_wowp.SetPath(CFG["wowp"]["path"])
myApp.settings.m_filePicker_wows.SetPath(CFG["wows"]["path"])
myApp.settings.m_dirPicker_output.SetPath(CFG["output"])
myApp.settings.Show()
def CreateCFG(self, event):
link = myApp.frame.m_textCtrl1.GetRange(0, -1).replace('"','') # norm!
result, Versions, filePath = SelectGame(link)
myApp.frame.m_textCtrl1.Clear()
#myApp.frame.m_textCtrl1.AppendText( result + "\n")
if 'ERROR' not in result:
myApp.frame.m_statusBar1.SetStatusText( CreateCFG(filePath, Versions) , 1)
myApp.frame.m_textCtrl1.AppendText( '\n'.join(link.split('&')) )
myApp.frame.m_buttonCreateCFG.SetValue(0)
myApp.frame.m_buttonCreateCFG.Enable(False)
class MyFrame2(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=u"Settings", pos=wx.DefaultPosition, size=wx.Size(480, 250),
style=(wx.FRAME_TOOL_WINDOW | wx.STAY_ON_TOP) ^ (wx.CAPTION | wx.CLOSE_BOX))
self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)
# self.config = read_config()
bSizer5 = wx.BoxSizer(wx.VERTICAL)
self.m_panel2 = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL)
bSizer6 = wx.BoxSizer(wx.VERTICAL)
self.m_staticSettingsWindowText = wx.StaticText(self.m_panel2, wx.ID_ANY, u"Launcher.cfg paths:",
wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticSettingsWindowText.Wrap(-1)
bSizer6.Add(self.m_staticSettingsWindowText, 0, wx.ALL, 5)
self.m_filePicker_wot = wx.FilePickerCtrl(self.m_panel2, wx.ID_ANY, CFG["wot"]["path"], u"Select a file",
u"WoTLauncher.cfg", wx.DefaultPosition, wx.DefaultSize,
wx.FLP_DEFAULT_STYLE)
bSizer6.Add(self.m_filePicker_wot, 0, wx.EXPAND | wx.BOTTOM | wx.RIGHT | wx.LEFT, 5)
self.m_filePicker_wowp = wx.FilePickerCtrl(self.m_panel2, wx.ID_ANY, CFG["wowp"]["path"], u"Select a file",
u"WoWPLauncher.cfg", wx.DefaultPosition, wx.DefaultSize,
wx.FLP_DEFAULT_STYLE)
bSizer6.Add(self.m_filePicker_wowp, 0, wx.EXPAND | wx.BOTTOM | wx.RIGHT | wx.LEFT, 5)
self.m_filePicker_wows = wx.FilePickerCtrl(self.m_panel2, wx.ID_ANY, CFG["wows"]["path"], u"Select a file",
u"WoWSLauncher.cfg", wx.DefaultPosition, wx.DefaultSize,
wx.FLP_DEFAULT_STYLE)
bSizer6.Add(self.m_filePicker_wows, 0, wx.EXPAND | wx.BOTTOM | wx.RIGHT | wx.LEFT, 5)
self.m_staticline1 = wx.StaticLine(self.m_panel2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
wx.LI_HORIZONTAL)
bSizer6.Add(self.m_staticline1, 0, wx.EXPAND | wx.ALL, 5)
self.m_staticText5 = wx.StaticText(self.m_panel2, wx.ID_ANY, u"Output path:", wx.DefaultPosition,
wx.DefaultSize, 0)
self.m_staticText5.Wrap(-1)
bSizer6.Add(self.m_staticText5, 0, wx.ALL, 5)
self.m_dirPicker_output = wx.DirPickerCtrl(self.m_panel2, wx.ID_ANY, CFG["output"], u"Select a folder",
wx.DefaultPosition, wx.DefaultSize, wx.DIRP_DEFAULT_STYLE)
bSizer6.Add(self.m_dirPicker_output, 0, wx.EXPAND | wx.BOTTOM | wx.RIGHT | wx.LEFT, 5)
bSizer6.AddSpacer((0, 0), 1, wx.EXPAND, 5)
bSizer_buttons = wx.BoxSizer(wx.HORIZONTAL)
bSizer_buttons.AddSpacer((0, 0), 1, wx.EXPAND, 5)
self.m_button_save = wx.Button(self.m_panel2, wx.ID_ANY, u"Save", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer_buttons.Add(self.m_button_save, 0, wx.ALL, 5)
self.m_button_close = wx.Button(self.m_panel2, wx.ID_ANY, u"Close", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer_buttons.Add(self.m_button_close, 0, wx.ALL, 5)
bSizer6.Add(bSizer_buttons, 0, wx.EXPAND, 5)
self.m_panel2.SetSizer(bSizer6)
self.m_panel2.Layout()
bSizer6.Fit(self.m_panel2)
bSizer5.Add(self.m_panel2, 1, wx.EXPAND, 5)
self.SetSizer(bSizer5)
self.Layout()
self.Centre(wx.BOTH)
# Connect Events
self.Bind(wx.EVT_CLOSE, self.OnExit)
self.m_button_save.Bind(wx.EVT_BUTTON, self.SettingsSave)
self.m_button_close.Bind(wx.EVT_BUTTON, self.SettingsHide)
def __del__(self):
pass
# Virtual event handlers, overide them in your derived class
def OnExit(self, event):
myApp.settings.Hide()
def SettingsSave(self, event):
# save settings
CFG["wot"]["path"] = self.m_filePicker_wot.GetPath()
CFG["wowp"]["path"] = self.m_filePicker_wowp.GetPath()
CFG["wows"]["path"] = self.m_filePicker_wows.GetPath()
CFG["output"] = self.m_dirPicker_output.GetPath()
if len(CFG["output"]) != 0 and CFG["output"][-1] != '\\':
CFG["output"] += '\\'
write_config(CFG)
myApp.settings.Hide()
def SettingsHide(self, event):
myApp.settings.Hide()
class myApp(wx.App):
""" app"""
def __init__(self, redirect=True):
wx.App.__init__(self, redirect)
def OnInit(self):
self.frame = MyFrame1(parent=None)
self.frame.Show()
self.settings = MyFrame2(parent=None)
self.SetTopWindow(self.frame)
return True
if __name__ == '__main__':
# (1) Text redirection starts here
myApp = myApp(redirect=True)
# (2) The main event loop is entered here
myApp.MainLoop()