-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ComplexBinds to CustomBinds page. Squashed commits:
commit fba1fd0 Author: Russell Pickett <[email protected]> Date: Sun Nov 6 00:54:01 2022 -0400 Correctly relayout page/CollapsiblePane when steps are added or deleted commit b404da1 Author: Russell Pickett <[email protected]> Date: Thu Nov 3 02:46:27 2022 -0400 Add ComplexBinds to Manual commit 2f7f434 Author: Russell Pickett <[email protected]> Date: Thu Nov 3 02:29:50 2022 -0400 ComplexBinds: Removing steps now renumbers the remaining ones commit 5ce4700 Author: Russell Pickett <[email protected]> Date: Thu Nov 3 02:08:02 2022 -0400 ComplexBinds: Delete steps; write binds. commit b2f3436 Author: Russell Pickett <[email protected]> Date: Thu Nov 3 00:37:33 2022 -0400 First work on ComplexBinds. UI done, save/load done, PopulateBinds not
- Loading branch information
Showing
6 changed files
with
159 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import wx | ||
import UI | ||
from UI.CustomBindPaneParent import CustomBindPaneParent | ||
from UI.KeySelectDialog import bcKeyButton, EVT_KEY_CHANGED | ||
from UI.PowerBinderDialog import PowerBinderButton | ||
|
||
class ComplexBindPane(CustomBindPaneParent): | ||
def __init__(self, page, init = {}): | ||
CustomBindPaneParent.__init__(self, page, init) | ||
|
||
self.Steps = [] | ||
|
||
def Serialize(self): | ||
data = { | ||
'Type' : 'ComplexBind', | ||
'Title': self.Title, | ||
'Key' : self.Ctrls['BindKey'].GetLabel(), | ||
'Steps': [], | ||
} | ||
for step in self.Steps: | ||
if step.BindContents.GetValue(): | ||
data['Steps'].append({ | ||
'contents' : step.BindContents.GetValue(), | ||
'powerbinderdata' : step.PowerBinder.SaveToData() | ||
}) | ||
return data | ||
|
||
def BuildBindUI(self, page): | ||
pane = self.GetPane() | ||
|
||
self.BindSizer = wx.BoxSizer(wx.HORIZONTAL) | ||
self.BindStepSizer = wx.BoxSizer(wx.VERTICAL) | ||
AddBindStepButton = wx.Button(pane, -1, "Add Step...") | ||
AddBindStepButton.Bind(wx.EVT_BUTTON, self.onAddStepButton) | ||
self.BindStepSizer.Add(AddBindStepButton, 0, wx.TOP, 10) | ||
if self.Init.get('Steps', ''): | ||
for step in self.Init['Steps']: | ||
self.onAddStepButton(None, step) | ||
else: | ||
self.onAddStepButton() | ||
|
||
self.BindSizer.Add ( self.BindStepSizer, 1, wx.EXPAND) | ||
|
||
BindKeyCtrl = bcKeyButton(pane, -1, { | ||
'CtlName' : f"{self.bindclass}BindKey", | ||
'Page' : page, | ||
'Key' : self.Init.get('Key', ''), | ||
}) | ||
#BindKeyCtrl.Bind(EVT_KEY_CHANGED, self.onKeyChanged) | ||
BindKeySizer = wx.BoxSizer(wx.HORIZONTAL) | ||
BindKeySizer.Add(wx.StaticText(pane, -1, "Bind Key:"), 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, 5) | ||
BindKeySizer.Add(BindKeyCtrl, 0) | ||
self.BindSizer.Add(BindKeySizer, 0, wx.LEFT|wx.RIGHT, 10) | ||
self.Ctrls['BindKey'] = BindKeyCtrl | ||
UI.Labels[BindKeyCtrl.CtlName] = "Complex Bind " | ||
|
||
self.BindSizer.Layout() | ||
|
||
# border around the addr box | ||
border = wx.BoxSizer(wx.VERTICAL) | ||
border.Add(self.BindSizer, 1, wx.EXPAND|wx.ALL, 10) | ||
pane.SetSizer(border) | ||
|
||
def onAddStepButton(self, _ = None, stepdata = {}): | ||
step = self.MakeBindStepUI(self.GetPane(), stepdata) | ||
self.BindStepSizer.Insert(self.BindStepSizer.GetItemCount()-1, step, 0, wx.EXPAND) | ||
self.Steps.append(step) | ||
self.Page.Layout() | ||
self.Profile.SetModified() | ||
|
||
def MakeBindStepUI(self, parent, step): | ||
stepNumber = self.BindStepSizer.GetItemCount() # is already the next step because of the add button | ||
panel = wx.Panel(parent) | ||
sizer = wx.BoxSizer(wx.HORIZONTAL) | ||
|
||
panel.StepLabel = wx.StaticText(panel, -1, f"Step {stepNumber}:") | ||
sizer.Add(panel.StepLabel, 0, wx.ALIGN_CENTER_VERTICAL) | ||
|
||
panel.BindContents= wx.TextCtrl(panel, -1, step.get('contents', '')) | ||
sizer.Add(panel.BindContents, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, 5) | ||
|
||
panel.PowerBinder = PowerBinderButton(panel, panel.BindContents, step.get('powerbinderdata', {})) | ||
sizer.Add(panel.PowerBinder, 0) | ||
|
||
delButton = wx.Button(panel, -1, "X", size = (40,-1)) | ||
delButton.SetForegroundColour(wx.RED) | ||
delButton.Bind(wx.EVT_BUTTON, self.onDelButton) | ||
sizer.Add(delButton, 0) | ||
|
||
panel.SetSizer(sizer) | ||
|
||
return panel | ||
|
||
def onDelButton(self, evt): | ||
button = evt.EventObject | ||
step = button.GetParent() | ||
self.Steps.remove(step) | ||
step.Destroy() | ||
self.RenumberSteps() | ||
self.Page.Layout() | ||
self.Profile.SetModified() | ||
|
||
def onContentsChanged(self, _ = None): | ||
pass | ||
|
||
def RenumberSteps(self): | ||
for i, step in enumerate(self.Steps, start = 1): | ||
step.StepLabel.SetLabel(f"Step {i}:") | ||
#self.Layout() | ||
|
||
def PopulateBindFiles(self): | ||
resetfile = self.Profile.ResetFile() | ||
# fish out only the steps that have contents | ||
fullsteps = list(filter(lambda x: x.BindContents.GetValue(), self.Steps)) | ||
for i, step in enumerate(fullsteps, start = 1): | ||
cbindfile = self.Profile.GetBindFile("cbinds", f"{self.Title}-{i}.txt") | ||
nextCycle = 1 if (i+1 > len(fullsteps)) else i+1 | ||
|
||
cmd = [step.BindContents.GetValue(), self.Profile.BLF(f'cbinds\\{self.Title}-{nextCycle}.txt')] | ||
key = self.Ctrls['BindKey'].GetLabel() | ||
|
||
if i == 1: resetfile.SetBind(key, self, self.Title, cmd) | ||
cbindfile.SetBind(key, self, self.Title, cmd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters