-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBindControl.py
executable file
·647 lines (520 loc) · 28 KB
/
BindControl.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
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
#!/usr/bin/env python3
import sys
MIN_PYTHON = (3, 13)
if sys.version_info < MIN_PYTHON:
sys.exit("Python %s.%s or later is required.\n" % MIN_PYTHON)
import wx, re
MIN_WX = (4, 2, 2)
wxver = tuple(map(int, re.split(r'\.', wx.__version__))) # oogly
if wxver < MIN_WX:
sys.exit("wxPython %s.%s.%s or later is required.\n" % MIN_WX)
import os, platform
from pathlib import Path
import webbrowser
import wx.lib.mixins.inspection
import wx.adv
import wx.html
from bcLogging import bcLogging
from bcVersion import current_version
from Icon import GetIcon
import Profile
from UI.BindDirsWindow import BindDirsWindow
from UI.PrefsDialog import PrefsDialog
from Help import ShowHelpWindow
from UI.ControlGroup import cgTextCtrl, cgButton
###################
# Main Window Class
###################
class Main(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, title = "BindControl")
self.Profile = None
self.StartupPanel = None
self.about_info = None
# TODO - most (NOT ALL) of this code can be deleted eventually.
if platform.system() == "Linux":
# First connect with the old-style .bindcontrol if it's there.
oldconfig = wx.FileConfig('bindcontrol')
# Set up XDG. KEEP THIS LINE even if we remove the migration code
wx.StandardPaths.Get().SetFileLayout(wx.StandardPaths.Get().FileLayout.FileLayout_XDG)
# Then connect to the new location
config = wx.FileConfig('bindcontrol')
if oldconfig.Exists('ResetKey'):
wx.LogMessage("Migrating old-style .bindcontrol config to XDG path")
entries = {}
more, value, index = oldconfig.GetFirstEntry()
while more:
entries[value] = oldconfig.GetEntryType(value)
more, value, index = oldconfig.GetNextEntry(index)
for entry, type in entries.items():
if type == wx.ConfigBase.Get().EntryType.Type_String:
config.Write(entry, oldconfig.Read(entry))
elif type == wx.ConfigBase.Get().EntryType.Type_Boolean:
config.WriteBool(entry, oldconfig.ReadBool(entry))
elif type == wx.ConfigBase.Get().EntryType.Type_Integer:
config.WriteInt(entry, oldconfig.ReadInt(entry))
elif type == wx.ConfigBase.Get().EntryType.Type_Float:
config.WriteFloat(entry, oldconfig.ReadFloat(entry))
config.Flush()
oldconfig.DeleteAll()
# OK, all that ugliness out of the way, re-open config and let's proceed.
config = wx.FileConfig('bindcontrol')
wx.ConfigBase.Set(config)
# Check each config bit for existence and set to default if no
if not config.Exists('GamePath'):
if platform.system() == 'Windows':
gamepath = "C:\\Games\\Homecoming\\"
else:
gamepath = str(Path.home() / '.wine' / 'drive_c' / 'Games' / 'Homecoming')
config.Write('GamePath', gamepath)
if not config.Exists('GameLang'): config.Write('GameLang', 'English')
if not config.Exists('BindPath'):
if platform.system() == 'Windows':
bindpath = "C:\\coh\\"
else:
bindpath = str(Path.home() / '.wine' / 'drive_c' / 'coh')
config.Write('BindPath', bindpath)
if not config.Exists('GameBindPath'):
if platform.system() != 'Windows':
config.Write('GameBindPath', "c:\\coh\\")
if not config.Exists('ResetKey') : config.Write('ResetKey', 'CTRL+R')
if not config.Exists('UseSplitModKeys') : config.WriteBool('UseSplitModKeys', False)
if not config.Exists('FlushAllBinds') : config.WriteBool('FlushAllBinds', True)
if not config.Exists('ProfilePath') : config.Write('ProfilePath', str(Path(wx.StandardPaths.Get().GetDocumentsDir()) / "bindcontrol"))
if not config.Exists('StartWithLastProfile'): config.WriteBool('StartWithLastProfile', True)
if not config.Exists('SaveSizeAndPosition') : config.WriteBool('SaveSizeAndPosition', True)
if not config.Exists('VerboseBLF') : config.WriteBool('VerboseBLF', False)
if not config.Exists('CrashOnBindError') : config.WriteBool('CrashOnBindError', False)
if not config.Exists('ShowInspector') : config.WriteBool('ShowInspector', False)
if not config.Exists('ShowDebugMessages') : config.WriteBool('ShowDebugMessages', False)
if not config.Exists('WinH') : config.WriteInt('WinH', 1000)
if not config.Exists('WinW') : config.WriteInt('WinW', 1000)
# migrate old "start with" preference. Maybe remove this someday
if config.Exists('StartWith'):
config.WriteBool('StartWithLastProfile', config.Read('StartWith') == "Last Profile")
config.DeleteEntry('StartWith')
config.Flush()
# set up the custom logger with the infobar
self.Logger = bcLogging(self)
if config.ReadBool('ShowDebugMessage'):
wx.Log.SetLogLevel(wx.LOG_Debug)
else:
wx.Log.SetLogLevel(wx.LOG_Status)
self.Sizer = wx.BoxSizer(wx.VERTICAL)
# "Profile" Menu
ProfMenu = wx.Menu()
Profile_new = ProfMenu.Append(wx.ID_NEW, "&New Profile\tCTRL-N", "Create a new profile")
Profile_load = ProfMenu.Append(wx.ID_OPEN, "&Load Profile...\tCTRL-L", "Load an existing profile")
self.Profile_save = ProfMenu.Append(wx.ID_SAVE, "&Save Profile\tCTRL-S", "Save the current profile")
self.Profile_saveas = ProfMenu.Append(wx.ID_SAVEAS, "Save Profile As...", "Save the current profile under a new filename")
ProfMenu.AppendSeparator()
self.Profile_savedefault = ProfMenu.Append(wx.ID_ANY, "Save Profile As Default", "Save the current profile as the default for new profiles")
ProfMenu.AppendSeparator()
Profile_preferences = ProfMenu.Append(wx.ID_PREFERENCES, "&Preferences", "Configure BindControl")
Profile_exit = ProfMenu.Append(wx.ID_EXIT)
# "Help" Menu
HelpMenu = wx.Menu()
Help_manual = HelpMenu.Append(wx.ID_ANY,"Manual","User's Manual")
Help_guide = HelpMenu.Append(wx.ID_ANY,"Getting Started","Getting Started Guide on the BindControl wiki")
Help_files = HelpMenu.Append(wx.ID_ANY,"Files","About BindControl's Output Files")
Help_bindDirs = HelpMenu.Append(wx.ID_ANY, "Bind Directories", "Location of each Profile's bind files")
Help_license = HelpMenu.Append(wx.ID_ANY,"License Info","")
Help_about = HelpMenu.Append(wx.ID_ABOUT)
LogMenu = wx.Menu()
Log_window = LogMenu.Append(wx.ID_ANY, "Log Window", "Show the log window")
# cram the separate menus into a menubar
MenuBar = wx.MenuBar()
MenuBar.Append(ProfMenu, 'Profile')
MenuBar.Append(HelpMenu, 'Help')
MenuBar.Append(LogMenu, 'Log')
# glue the menubar into the main window
self.SetMenuBar(MenuBar)
# MENUBAR EVENTS
self.Bind(wx.EVT_MENU , self.OnProfileNew , Profile_new)
self.Bind(wx.EVT_MENU , self.OnProfileLoad , Profile_load)
self.Bind(wx.EVT_MENU , self.OnProfileSave , self.Profile_save)
self.Bind(wx.EVT_MENU , self.OnProfileSaveAs , self.Profile_saveas)
self.Bind(wx.EVT_MENU , self.OnProfileSaveDefault , self.Profile_savedefault)
self.Bind(wx.EVT_MENU , self.OnMenuPrefsDialog , Profile_preferences)
self.Bind(wx.EVT_MENU , self.OnMenuExitApplication , Profile_exit)
self.Bind(wx.EVT_MENU, self.OnHelpManual, Help_manual)
self.Bind(wx.EVT_MENU, self.OnHelpGettingStarted, Help_guide)
self.Bind(wx.EVT_MENU, self.OnHelpFiles, Help_files)
self.Bind(wx.EVT_MENU, self.OnHelpBindDirs, Help_bindDirs)
self.Bind(wx.EVT_MENU, self.OnHelpLicense, Help_license)
self.Bind(wx.EVT_MENU, self.OnMenuAboutBox, Help_about)
self.Bind(wx.EVT_MENU, self.OnMenuLogWindow, Log_window)
self.AppIcon = wx.IconBundle()
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
filename = f"{base_path}/icons/BindControl.ico"
self.AppIcon.AddIcon(filename, wx.BITMAP_TYPE_ANY)
self.SetIcons(self.AppIcon)
# Infobar for showing errors and other messages
self.Sizer.Add(self.Logger.InfoBar, 0, wx.EXPAND)
# Bottom Buttons
# BUTTONS
self.BottomButtonPanel = wx.Panel(self)
self.ProfDirButton = cgButton(self.BottomButtonPanel, -1, "Set Binds Location")
self.ProfDirButton.SetToolTip("Configure the location where this Profile will write bindfiles")
self.ProfDirButton.DefaultToolTip = "Configure the location where this Profile will write bindfiles"
self.WriteButton = wx.Button(self.BottomButtonPanel, -1, "Write Binds")
self.WriteButton.SetToolTip("Write out the bindfiles to the configured binds directory")
self.DeleteButton = wx.Button(self.BottomButtonPanel, -1, "Delete All Binds")
self.DeleteButton.SetToolTip("Delete all BindControl-managed files in the configured binds directory")
BottomButtonSizer = wx.BoxSizer(wx.HORIZONTAL)
self.BottomButtonPanel.SetSizer(BottomButtonSizer)
BottomButtonSizer.Add(self.ProfDirButton, 0, wx.EXPAND)
BottomButtonSizer.Add(self.WriteButton, 1, wx.EXPAND)
BottomButtonSizer.Add(self.DeleteButton, 0, wx.EXPAND)
self.ProfDirButton.Bind(wx.EVT_BUTTON, self.OnProfDirButton)
self.WriteButton .Bind(wx.EVT_BUTTON, self.OnWriteBindsButton)
self.DeleteButton .Bind(wx.EVT_BUTTON, self.OnDeleteBindsButton)
self.Sizer.Add(self.BottomButtonPanel, 0, wx.EXPAND | wx.ALL, 10)
# Do not SetSizerAndFit() - Fit() is poison
self.SetSizer(self.Sizer)
self.Bind(wx.EVT_CLOSE, self.OnWindowClosing)
def SetupProfile(self):
config = wx.FileConfig('bindcontrol')
# Load up the last profile if the pref says to and if it's there
filename = config.Read('LastProfile')
if (config.Read('StartWith') == 'Last Profile' or config.ReadBool('StartWithLastProfile')) and filename:
if profile := Profile.Profile(self, filename):
self.Profile = profile
self.Sizer.Insert(0, self.Profile, 1, wx.EXPAND)
self.CheckProfDirButtonErrors()
else:
self.Profile = None
self.StartupPanel = self.MakeStartupPanel()
self.Sizer.Insert(0, self.StartupPanel, 1, wx.EXPAND)
# otherwise show the two big buttons
else:
self.StartupPanel = self.MakeStartupPanel()
self.Sizer.Insert(0, self.StartupPanel, 1, wx.EXPAND)
(width, height) = (1100, 800)
if config.ReadBool('SaveSizeAndPosition') and config.HasEntry('WinH') and config.HasEntry('WinW'):
height = config.ReadInt('WinH')
width = config.ReadInt('WinW')
elif self.Profile:
height = self.Profile.GetBestSize().height
width = self.Profile.GetBestSize().width + 24 # account for Profile's padding
if width and height:
self.SetSize((width, height))
if config.ReadBool('SaveSizeAndPosition') and config.HasEntry('WinX') and config.HasEntry('WinY'):
self.SetPosition((config.ReadInt('WinX'), config.ReadInt('WinY')))
self.BindDirsWindow = None
self.SetupProfileUI()
# This is the two-button "start new profile" vs "load existing profile" panel
def MakeStartupPanel(self):
StartupPanel = wx.Panel(self)
StartupSizer = wx.BoxSizer(wx.VERTICAL)
ButtonSizer = wx.GridSizer(2, 10, 10)
newButton = wx.Button(StartupPanel, -1, "Start New Profile")
newButton.SetBitmap(GetIcon('UI/new_profile'))
newButton.SetBitmapPosition(wx.TOP)
loadButton = wx.Button(StartupPanel, -1, "Load Existing Profile")
loadButton.SetBitmap(GetIcon('UI/load_profile'))
loadButton.SetBitmapPosition(wx.TOP)
ButtonSizer.Add(newButton, 1, wx.EXPAND)
ButtonSizer.Add(loadButton, 1, wx.EXPAND)
newButton.Bind(wx.EVT_BUTTON, self.OnProfileNew)
loadButton.Bind(wx.EVT_BUTTON, self.OnProfileLoad)
StartupSizer.AddStretchSpacer(1)
StartupSizer.Add(ButtonSizer, 0, wx.ALIGN_CENTER|wx.LEFT|wx.RIGHT, 50)
StartupSizer.AddStretchSpacer(1)
StartupPanel.SetSizer(StartupSizer)
StartupPanel.Layout()
return StartupPanel
def SetupProfileUI(self):
enable = self.Profile != None
self.Profile_save.Enable(enable)
self.Profile_saveas.Enable(enable)
self.Profile_savedefault.Enable(enable)
self.ProfDirButton.Enable(enable)
# TODO - do smarter things with enabling the write and delete buttons
self.WriteButton.Enable(enable)
self.DeleteButton.Enable(enable)
def OnPageChanged(self, evt):
if evt.GetSelection() == 6:
self.BottomButtonPanel.Hide()
if self.Profile:
self.Profile.PopmenuEditor.SynchronizeUI()
else:
self.BottomButtonPanel.Show(True)
self.Layout()
def OnProfileNew(self, _ = None):
if self.CheckIfProfileNeedsSaving() == wx.CANCEL: return
# loop eternally until we get a name we like
while True:
with wx.TextEntryDialog(self, message = 'Enter name for new profile, for instance, the name of a character:', caption = "New Profile") as dlg:
result = dlg.ShowModal()
if result == wx.ID_OK:
newname = dlg.GetValue()
if not newname:
continue
checkprofile = Path(wx.ConfigBase.Get().Read('ProfilePath'))/ f"{newname}.bcp"
if checkprofile.exists():
wx.MessageBox(f"A profile called {newname} already exists. Please select another name.")
continue
break
else:
return result
self.Freeze()
try:
with wx.WindowDisabler():
_ = wx.BusyInfo(wx.BusyInfoFlags().Parent(self).Text(f'Creating New Profile {newname}...'))
wx.GetApp().Yield()
self.Sizer.Remove(0)
if self.Profile: self.Profile.Destroy()
# destroy the Startup Panel if it's there. This is only needed on Windows dunno why.
if self.StartupPanel: self.StartupPanel.Destroy()
self.Profile = Profile.Profile(self, newname = newname)
wx.LogMessage(f'Created New Profile "{newname}".')
self.Sizer.Insert(0, self.Profile, 1, wx.EXPAND)
except Exception as e:
wx.LogError(f"Something broke in new profile: {e}. This is a bug.")
finally:
self.SetupProfileUI()
self.CheckProfDirButtonErrors()
self.Layout()
self.Thaw()
def OnProfileLoad(self, _):
if self.CheckIfProfileNeedsSaving() == wx.CANCEL: return
newProfile = Profile.LoadFromFile(self)
# Try to load; if the user hits "cancel" or the load fails, go back to where we were
if newProfile:
self.InsertProfile(newProfile)
# we use this in the Binds Directory Window also
def InsertProfile(self, newProfile):
try:
self.Freeze()
# OK, we're either at the startup panel or we have an existing profile. Either way, remove it:
self.Sizer.Remove(0)
# delete any existing Profile and all its subwidgets and geegaws
if self.Profile: self.Profile.Destroy()
# destroy the Startup Panel if it's there. This is only needed on Windows dunno why.
if self.StartupPanel: self.StartupPanel.Destroy()
# and set up our new profile as the current one
self.Profile = newProfile
self.Sizer.Insert(0, self.Profile, 1, wx.EXPAND)
self.Layout()
except Exception as e:
wx.LogError(f"Something broke while setting up profile load: {e}")
return
finally:
if self.IsFrozen(): self.Thaw()
# OK, we made it, set up the UI bits etc.
self.SetupProfileUI()
self.CheckProfDirButtonErrors()
wx.ConfigBase.Get().Write('LastProfile', str(newProfile.Filename))
wx.ConfigBase.Get().Flush()
def OnProfileSave(self, _):
if not self.Profile: return
self.Profile.doSaveToFile()
def OnProfileSaveAs(self, _):
if not self.Profile: return
self.Profile.SaveToFile()
def OnProfileSaveDefault(self, _):
if not self.Profile: return
self.Profile.SaveAsDefault()
def OnProfDirButton(self, _ = None):
if not self.Profile: return # should try not to get here in the first place
ProfDirDialog = wx.Dialog(self, -1, "Set Binds Location")
sizer = wx.BoxSizer(wx.VERTICAL)
ProfDirDialog.SetSizer(sizer)
sizer.Add(wx.StaticText(ProfDirDialog, -1, "Select the location where this profile will write its bindfiles:"), 1, wx.EXPAND|wx.ALL, 10)
config = wx.ConfigBase.Get()
bindpath = config.Read('BindPath')
separator = "\\" if platform.system() == "Windows" else "/"
if bindpath[-1:] == separator: separator = ''
dirSizer = wx.BoxSizer(wx.HORIZONTAL)
dirSizer.Add(wx.StaticText(ProfDirDialog, -1,
f"{bindpath}{separator}"), 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 10)
PathText = cgTextCtrl(ProfDirDialog, -1)
dirSizer.Add(PathText, 1, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 10)
PathText.Bind(wx.EVT_TEXT, self.OnPathTextChanged)
sizer.Add(dirSizer, 1, wx.EXPAND)
sizer.Add(wx.StaticText(ProfDirDialog, -1, "Changing this value will automatically save the Profile,\nincluding any other changes you have made."), 1, wx.EXPAND|wx.ALL, 10)
buttonsizer = ProfDirDialog.CreateSeparatedButtonSizer(wx.OK|wx.CANCEL)
sizer.Add(buttonsizer, 1, wx.EXPAND|wx.ALL, 10)
ProfDirDialog.Layout()
PathText.ClearErrors() # whyyyy?
with ProfDirDialog as dlg:
PathText.SetValue(self.Profile.ProfileBindsDir) # do this here to trigger wx.EVT_TEXT
result = dlg.ShowModal()
if result == wx.ID_OK:
newvalue = PathText.GetValue()
# call us again if we tried to OK an error state
if PathText.HasErrors(): return self.OnProfDirButton()
# if we changed the directory, offer to delete the old one.
otherprofile = Profile.CheckProfileForBindsDir(self.Profile.ProfileBindsDir)
if (
# we changed it to a new value:
self.Profile.ProfileBindsDir and (newvalue != self.Profile.ProfileBindsDir)
and
# the old one isn't owned by another profile:
((not otherprofile) or (otherprofile and (otherprofile == self.Profile.Name())))
):
answer = wx.MessageBox(
f'Binds Location changed. Delete all binds in old binds directory?\n{self.Profile.BindsDir()}',
'Binds Location Changed',wx.YES_NO, self
)
if answer == wx.YES:
self.Profile.DeleteBindFiles()
self.Profile.ProfileBindsDir = newvalue
self.Profile.doSaveToFile()
# need this out here in case we cancelled on a previously-blank one.
# This is very very unlikely to happen and awful if it does.
# TODO: yes later on I see that this is indeed awful. Fix it.
#
# TODO-ish: if they erase an existing valid one or otherwise cause an
# error, and then hit "cancel" this gets triggered, which is not
# perfect - this logic needs a little smartening.
if PathText.HasErrors(): return self.OnProfDirButton()
self.CheckProfDirButtonErrors()
def CheckIfProfileNeedsSaving(self):
result = wx.OK
if self.Profile:
if self.Profile.Modified:
result = wx.MessageBox(f"Profile {self.Profile.Name()} not saved, save now?", "Profile modified", wx.YES_NO|wx.CANCEL)
if result == wx.YES:
self.Profile.doSaveToFile()
if self.Profile.PopmenuEditor.CheckForModifiedMenus():
result = wx.MessageBox("Some popmenus contain unsaved changes, return to editor?", "Popmenus modified", wx.YES_NO)
if result == wx.YES:
result = wx.CANCEL
self.Profile.SetSelection(6) # TODO - hardcoded "6" is ugly but meh
return result
def CheckProfDirButtonErrors(self):
if not self.Profile: return
if self.Profile.ProfileBindsDir:
self.ProfDirButton.RemoveError('undef')
else:
self.ProfDirButton.AddError('undef', 'Your binds directory is unset. Binds cannot be written.')
if len(self.Profile.ProfileBindsDir) <= 8:
self.ProfDirButton.RemoveWarning('toolong')
else:
self.ProfDirButton.AddWarning('toolong', 'Your binds directory name is rather long. This is not an error but can lead to some binds being too long for the game to use.')
otherprofile = Profile.CheckProfileForBindsDir(self.Profile.ProfileBindsDir)
if otherprofile and (otherprofile != self.Profile.Name()):
self.ProfDirButton.AddWarning('owned', f'The binds directory you have chosen is marked as owned by the profile "{otherprofile}." This is not an error, but be sure this is what you want to do.')
else:
self.ProfDirButton.RemoveWarning('owned')
self.DeleteButton.Enable(not self.ProfDirButton.HasErrors())
self.WriteButton.Enable(not self.ProfDirButton.HasErrors())
def OnPathTextChanged(self, evt):
textctrl = evt.EventObject
value = textctrl.GetValue()
if not value:
textctrl.AddError('undef', 'You must specify a bindfile directory name.')
else:
textctrl.RemoveError('undef')
if re.search(r'[^A-Za-z0-9_]', value):
textctrl.AddError('unicode', 'The binds directory must contain only A-Z, a-z, 0-9, and _ characters.')
else:
textctrl.RemoveError('unicode')
if re.search(r'\s', value):
textctrl.AddError('spaces', 'The binds directory cannot contain spaces.')
else:
textctrl.RemoveError('spaces')
if platform.system() == 'Windows':
if os.path.isreserved(value): # pyright: ignore
textctrl.AddError('reserved', 'The name you have selected is a reserved filename in Windows. Please select another.')
else:
textctrl.RemoveError('reserved')
if value: # don't do this check if it's blank
exists = None
# look at the existing bindsdirs and see if we match
for bindsdir in Profile.GetAllProfileBindsDirs():
# check case-insensitive because Windows
if bindsdir.lower() == value.lower():
# but stash it away as the case-sensitive version because Linux
exists = bindsdir
break
if exists and self.Profile:
existingProfile = Profile.CheckProfileForBindsDir(exists)
if existingProfile != self.Profile.Name():
existingProfileWarning = f', and is managed by the profile {existingProfile}' if existingProfile else ''
textctrl.AddWarning('exists', f'The directory you have selected already exists{existingProfileWarning}. This is not an error, but be sure this is where you want to save your binds.')
else:
textctrl.RemoveWarning('exists')
def OnWriteBindsButton(self, _):
if not self.Profile: return
self.Profile.WriteBindFiles()
def OnDeleteBindsButton(self, _):
if not self.Profile: return
self.Profile.DeleteBindFiles()
def OnMenuPrefsDialog(self, _ = None):
with PrefsDialog(self) as dlg:
dlg.ShowAndUpdatePrefs()
def OnMenuAboutBox(self, _):
from datetime import datetime
this_year = datetime.now().year
if self.about_info is None:
info = wx.adv.AboutDialogInfo()
info.AddDeveloper('R Pickett ([email protected])')
info.SetName('BindControl')
info.SetVersion(current_version())
info.SetDescription((
"BindControl can help you set up custom keybinds and popmenus in City of Heroes.\n\n"
"Based on CityBinder 0.76, Copyright \u00A9 2005-2006 Jeff Sheets,\nand CityBinder for Homecoming 0.2, Copyright \u00A9 2021-2023 tailcoat\n\n"
"Speed-On-Demand binds originally created by Gnarley's Speed On Demand Binds,\nupdated for Homecoming by emerson. Advanced Teleport Binds originally by\nDrLetharga, updated for Homecoming by emerson.\n\n"
"Mastermind binds by Sandolphan in CoV beta, updated by Konoko and emerson.\n\n"
"Inspiration Popper design adapted from CityBinder for Homecoming by Tailcoat."
))
info.SetCopyright(f'\u00A9 2010-{this_year} R Pickett <[email protected]>')
info.SetWebSite('https://github.com/emersonrp/bindcontrol')
self.about_info = info
wx.adv.AboutBox(self.about_info)
def OnMenuLogWindow(self, _):
self.Logger.LogWindow.Show()
def OnMenuExitApplication(self, _):
self.Close()
def OnHelpManual(self, _):
ShowHelpWindow(self, 'Manual.html')
def OnHelpGettingStarted(self, _):
webbrowser.open('https://github.com/emersonrp/bindcontrol/wiki/Getting-Started-With-BindControl')
def OnHelpLicense(self, _):
ShowHelpWindow(self, 'LICENSE.html')
def OnHelpFiles(self, _):
ShowHelpWindow(self, 'OutputFiles.html')
# TODO - make just one window instead of a new one every time the menu item is picked
def OnHelpBindDirs(self, _):
window = BindDirsWindow(self, title = "Bind Directories", style = wx.TINY_CAPTION|wx.CLOSE_BOX|wx.CAPTION)
window.Show()
def OnWindowClosing(self, evt):
if self.CheckIfProfileNeedsSaving() == wx.CANCEL: return
config = wx.ConfigBase.Get()
if config.ReadBool('SaveSizeAndPosition'):
config.WriteInt('WinX', self.GetPosition().x)
config.WriteInt('WinY', self.GetPosition().y)
config.WriteInt('WinH', self.GetSize().height)
config.WriteInt('WinW', self.GetSize().width)
config.Flush()
evt.Skip()
class MyApp(wx.App, wx.lib.mixins.inspection.InspectionMixin):
def OnInit(self):
# Let's try to unbuffer "print" for easier debug
# This per "Perkins"' comment on https://stackoverflow.com/questions/107705/disable-output-buffering
import builtins
import functools
builtins.print = functools.partial(print, flush=True)
self.Profile = None # needed inside Main()
self.Init()
with wx.WindowDisabler():
_ = wx.BusyInfo('Initializing BindControl...')
wx.GetApp().Yield()
self.Main = Main(None)
self.Main.SetupProfile()
# TODO bootstrapping problem, can't do this inside Profile's "__init__" because
# Profile needs to be defined/initialized deep inside its innards.
if self.Main.Profile:
self.Main.Profile.CheckAllConflicts()
self.Main.Show()
return True
if __name__ == "__main__":
app = MyApp(redirect=False)
config = wx.ConfigBase.Get()
if config.ReadBool('ShowInspector'):
import wx.lib.inspection
wx.lib.inspection.InspectionTool().Show()
app.MainLoop()