From 0549eb1d62fd8aff87bd86e709f9bcd5961dadf1 Mon Sep 17 00:00:00 2001 From: Russell Pickett Date: Fri, 7 Jun 2024 15:57:17 -0400 Subject: [PATCH] Further work on checking conflicts and correctly making buttons red --- UI/ComplexBindPane.py | 17 ++++++++++++++--- UI/KeySelectDialog.py | 7 ++++++- UI/SimpleBindPane.py | 8 +++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/UI/ComplexBindPane.py b/UI/ComplexBindPane.py index 4cba41ae..c3a39889 100644 --- a/UI/ComplexBindPane.py +++ b/UI/ComplexBindPane.py @@ -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) @@ -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() @@ -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}:") diff --git a/UI/KeySelectDialog.py b/UI/KeySelectDialog.py index 0a1a802d..4285006b 100644 --- a/UI/KeySelectDialog.py +++ b/UI/KeySelectDialog.py @@ -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) @@ -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. @@ -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 diff --git a/UI/SimpleBindPane.py b/UI/SimpleBindPane.py index 955b751e..47095125 100644 --- a/UI/SimpleBindPane.py +++ b/UI/SimpleBindPane.py @@ -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() @@ -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) @@ -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: