Skip to content

Commit

Permalink
Further work on checking conflicts and correctly making buttons red
Browse files Browse the repository at this point in the history
  • Loading branch information
emersonrp committed Jun 7, 2024
1 parent 9fed2e6 commit 0549eb1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
17 changes: 14 additions & 3 deletions UI/ComplexBindPane.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,28 @@ def BuildBindUI(self, page):
border.Add(self.BindSizer, 1, wx.EXPAND|wx.ALL, 10)
pane.SetSizer(border)

self.checkIfWellFormed()

def onContentsChanged(self, _):
self.checkIfWellFormed()

def onKeyChanged(self, _):
self.checkIfWellFormed()
if self.Profile:
self.Profile.CheckAllConflicts()

def checkIfWellFormed(self):
isWellFormed = True

# TODO - check each step for > 255 char
firststep = self.Steps[0].BindContents
fullsteps = list(filter(lambda x: x.BindContents.GetValue(), self.Steps))
if fullsteps:
firststep.SetBackgroundColour(wx.NullColour)
else:
firststep.SetBackgroundColour((255,200,200))
isWellFormed = False

bk = self.Ctrls[self.MakeCtlName('BindKey')]
if bk.Key:
bk.SetError(False)
Expand All @@ -85,6 +98,7 @@ def onAddStepButton(self, _ = None, stepdata = {}):
pane = self.GetPane()
pane.Page = self.Page
step = self.MakeBindStepUI(pane, stepdata)
step.BindContents.Bind(wx.EVT_TEXT, self.onContentsChanged)
self.BindStepSizer.Insert(self.BindStepSizer.GetItemCount()-1, step, 0, wx.EXPAND)
self.Steps.append(step)
self.Page.Layout()
Expand Down Expand Up @@ -126,9 +140,6 @@ def onDelButton(self, evt):
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}:")
Expand Down
7 changes: 6 additions & 1 deletion UI/KeySelectDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ def __init__(self, parent, id, init = {}):
self.CtlLabel : ST.GenStaticText | wx.StaticText | None = init.get('CtlLabel', None)
self.Key : str = init.get('Key', '')
self.Page : Page = parent
self.HasError : bool = False

self.SetLabel(self.Key)

Expand Down Expand Up @@ -443,7 +444,8 @@ def CheckConflicts(self, newbinding = None):
if conflicts:
self.SetError(True, conflicts = conflicts)
else:
self.SetError(False)
if not self.HasError: # don't clear errors if we already had one
self.SetError(False)
return conflicts

# TODO - maybe? move this into UI/ControlGroup's mixin so we can 'seterror' on any control.
Expand All @@ -458,9 +460,12 @@ def SetError(self, iserror = True, conflicts = None):
self.SetToolTip('\n'.join(conflictStrings))
else:
self.SetToolTip("This key must be defined to complete your bind.")
self.HasError = True
else:
self.SetOwnBackgroundColour(wx.NullColour)
self.SetToolTip('')
self.HasError = False


def KeySelectEventHandler(self, evt):
button = evt.EventObject
Expand Down
8 changes: 5 additions & 3 deletions UI/SimpleBindPane.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def BuildBindUI(self, page):
BindSizer.Add(wx.StaticText(pane, -1, "Bind Key:"), 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, 5)
BindSizer.Add(BindKeyCtrl, 0, wx.ALIGN_CENTER_VERTICAL)
self.Ctrls[BindKeyCtrl.CtlName] = BindKeyCtrl
UI.Labels[BindKeyCtrl.CtlName] = f'Simple Bind "{pane.Title}"'
UI.Labels[BindKeyCtrl.CtlName] = f'Simple Bind "{self.Title}"'

BindSizer.Layout()

Expand All @@ -66,11 +66,13 @@ def onContentsChanged(self, _):

def onKeyChanged(self, _):
self.checkIfWellFormed()
if self.Profile:
self.Profile.CheckAllConflicts()

def checkIfWellFormed(self):
isWellFormed = True

bc = self.Ctrls['BindContents']
bc = self.Ctrls[self.MakeCtlName('BindContents')]
bc.SetToolTip('')
if bc.GetValue() and len(bc.GetValue()) <= 255:
bc.SetBackgroundColour(wx.NullColour)
Expand All @@ -80,7 +82,7 @@ def checkIfWellFormed(self):
bc.SetToolTip("This bind is longer than 255 characters, which will cause problems in-game.")
isWellFormed = False

bk = self.Ctrls['BindKey']
bk = self.Ctrls[self.MakeCtlName('BindKey')]
if bk.Key:
bk.SetError(False)
else:
Expand Down

0 comments on commit 0549eb1

Please sign in to comment.