diff --git a/addon/globalPlugins/webAccess/gui/rule/criteriaEditor.py b/addon/globalPlugins/webAccess/gui/rule/criteriaEditor.py index 2e96a6b5..587feea4 100644 --- a/addon/globalPlugins/webAccess/gui/rule/criteriaEditor.py +++ b/addon/globalPlugins/webAccess/gui/rule/criteriaEditor.py @@ -251,11 +251,11 @@ def getSummary_selector_unit(data) -> Sequence[str]: def getSummary(context, data, indent="", condensed=False) -> str: parts = [] - + parts.extend(getSummary_selector_full( data.get("selector", {}), condensed=condensed )) - + # Properties subParts = [] props = Properties(context, data.get("properties", {}), iterOnlyFirstMap=True) @@ -361,7 +361,7 @@ def convertToSingleNode(data): class CriteriaEditorPanel(RuleAwarePanelBase): - + def getData(self): # Should always be initialized, as the Rule Editor populates it with at least # the index of this Alternative Criteria Set ("criteriaIndex"). @@ -371,11 +371,11 @@ def getData(self): class GeneralPanel(CriteriaEditorPanel): # Translators: The label for a Criteria editor category. title = _("General") - + def __init__(self, parent): self.hideable: Mapping[Sequence[wx.Window]] = {} super().__init__(parent) - + def makeSettings(self, settingsSizer): scale = self.scale gbSizer = wx.GridBagSizer() @@ -463,7 +463,7 @@ def makeSettings(self, settingsSizer): item.Show(False) gbSizer.AddGrowableCol(2) - + def initData(self, context): super().initData(context) self.sequenceOrderChoice.Clear() @@ -475,9 +475,13 @@ def initData(self, context): for item in self.hideable["order"]: item.Show(False) else: + for item in self.hideable["order"]: + item.Show(True) for index in range(nbAlternatives): self.sequenceOrderChoice.Append(str(index + 1)) - index = data.get("criteriaIndex", nbAlternatives + 1) + index = data.get("criteriaIndex", nbAlternatives - 1) + if index < 0 or index >= nbAlternatives: + index = nbAlternatives - 1 self.sequenceOrderChoice.SetSelection(index) if self.getRuleType() == ruleTypes.ZONE: key = "convert.single" if isDualNode(data) else "convert.dual" @@ -519,11 +523,11 @@ def onSave(self): class CriteriaPanel(CriteriaEditorPanel): """Criteria Panel of the Alternative Criteria Set Editor - + To accomodate with the Rule Creation Wizard which reuses this panel split on two different pages, several method are split in two: "_context" and "_others". """ - + # Translators: The label for a Criteria editor category. title = _("Criteria") @@ -769,7 +773,7 @@ def initData(self, context): super().initData(context) self.initData_context(context) self.initData_others(context) - + def initData_context(self, context): data = self.getData() self.contextPageTitleCombo.Set([context["pageTitle"]]) @@ -790,7 +794,7 @@ def initData_context(self, context): self.contextPageTitleCombo.Value = data.get("contextPageTitle", "") self.contextPageTypeCombo.Value = data.get("contextPageType", "") self.contextParentCombo.Value = data.get("contextParent", "") - + def initData_others(self, context): data = self.getData() mgr = context["webModule"].ruleManager @@ -804,7 +808,7 @@ def initData_others(self, context): textChoices = [t] if node.previousTextNode is not None: textChoices.append("<" + node.previousTextNode.text) - + roleChoices = [] tagChoices = [] idChoices = [] @@ -822,7 +826,7 @@ def initData_others(self, context): srcChoices.append(node.src or "") urlChoices.append(node.url or "") node = node.parent - + self.textCombo.Set(textChoices) self.roleCombo.Set(roleChoices) self.tagCombo.Set(tagChoices) @@ -831,7 +835,7 @@ def initData_others(self, context): self.statesCombo.Set(statesChoices) self.srcCombo.Set(srcChoices) self.urlCombo.Set(urlChoices) - + self.textCombo.Value = data.get("text", "") value = data.get("role", "") if isinstance(value, InvalidValue): @@ -858,13 +862,13 @@ def initData_others(self, context): def updateData(self): self.updateData_context() self.updateData_others() - + def updateData_context(self): data = self.getData() updateOrDrop(data, "contextPageTitle", self.contextPageTitleCombo.Value) updateOrDrop(data, "contextPageType", self.contextPageTypeCombo.Value) updateOrDrop(data, "contextParent", self.contextParentCombo.Value) - + def updateData_others(self): data = self.getData() updateOrDrop(data, "text", self.textCombo.Value) @@ -942,27 +946,27 @@ def onContextMacroChoice(self, evt): def onTestCriteria(self, evt): self.updateData() testCriteria(self.context) - + def onPanelActivated(self): self.refreshContextMacroChoices() super().onPanelActivated() - + def onTestCriteria(self, evt): self.updateData() testCriteria(self.context) - + def isValid(self): - self.updateData() + self.updateData() return self.isValid_context() and self.isValid_others() - + def isValid_context(self): # TODO: Check the syntax of expressions return True - + def isValid_others(self): # TODO: Check the syntax of expressions data = self.getData() - + if not data: gui.messageBox( # Translators: An error message on the Criteria Editor @@ -973,7 +977,7 @@ def isValid_others(self): ) self.SetFocus() return False - + roleLblExpr = self.roleCombo.Value if roleLblExpr.strip(): if not EXPR.match(roleLblExpr): @@ -1055,10 +1059,10 @@ def isValid_others(self): class StartCriteriaPanel(CriteriaPanel): # Translators: The label for a Criteria editor category. title = _("Start Criteria") - + def getData(self): return super().getData()["start"] - + def onTestCriteria(self, evt): self.updateData() testCriteria(self.context, restrictDualNodeTo=="start") @@ -1067,10 +1071,10 @@ def onTestCriteria(self, evt): class EndCriteriaPanel(CriteriaPanel): # Translators: The label for a Criteria editor category. title = _("End Criteria") - + def getData(self): return super().getData()["end"] - + def onTestCriteria(self, evt): self.updateData() testCriteria(self.context, restrictDualNodeTo="end") @@ -1083,7 +1087,7 @@ class GesturesPanel(GesturesPanelBase, CriteriaEditorPanel): class PropertyOverrideSelectMenu(wx.Menu): """Menu to select a property to override on the CriteriaPropertiesPanel """ - + def __init__(self, menuIdProps: Mapping[int, Property]): super().__init__(title=_("Select a property to override")) for menuId, prop in menuIdProps.items(): @@ -1091,12 +1095,12 @@ def __init__(self, menuIdProps: Mapping[int, Property]): class PropertiesPanel(PropertiesPanelBase, CriteriaEditorPanel): - + def makeSettings(self, settingsSizer): super().makeSettings(settingsSizer) scale = self.scale gbSizer = self.gbSizer - + # Translators: The label for a list on the Criteria Editor dialog self.listLabel.Label = _("Properties specific to this criteria set") listCtrl = self.listCtrl @@ -1125,7 +1129,7 @@ def makeSettings(self, settingsSizer): item.Enable(False) item.Bind(wx.EVT_BUTTON, self.onDelPropBtn) gbSizer.Add(item, pos=(row, col)) - + # Called by PropertiesPanelBase.initData def initData_properties(self): context = self.context @@ -1135,7 +1139,7 @@ def initData_properties(self): context["data"]["rule"].setdefault("properties", {}), iterOnlyFirstMap=True, ) - + def listCtrl_insert(self, index: int, prop: Property) -> None: super().listCtrl_insert(index, prop) self.listCtrl.SetStringItem(index, 2, prop.displayDefault) @@ -1179,14 +1183,14 @@ def onAddPropBtn(self, evt): self.editor.SetFocus() else: self.listCtrl.SetFocus() - + @guarded def onDelPropBtn(self, evt): self.prop.reset() self.listCtrl_update_all() if not self.props: self.addPropBtn.SetFocus() - + def prop_reset(self): # Using Property.reset would actually remove the overridden property from the list. # Manually reset to its default instead. @@ -1205,7 +1209,7 @@ class CriteriaEditorDialog(ContextualMultiCategorySettingsDialog): title = _("WebAccess Criteria Set editor") categoryClasses = [GeneralPanel, CriteriaPanel, GesturesPanel, PropertiesPanel] INITIAL_SIZE = (900, 580) - + def __init__( self, parent, @@ -1225,12 +1229,12 @@ def __init__( catList.append(GesturesPanel) catList.append(PropertiesPanel) super().__init__(parent, *args, **kwargs) - + def getData(self): # Should always be initialized, as the Rule Editor populates it with at least # the index of this Alternative Criteria Set ("criteriaIndex"). return self.context["data"]["criteria"] - + def initData(self, context): super().initData(context) reload = context.pop("CriteriaEditorFocusOnReload", None) @@ -1245,10 +1249,10 @@ def initData(self, context): catList.SetFocus() else: self.currentCategory.SetFocus() - + def makeSettings(self, settingsSizer): super().makeSettings(settingsSizer) - + def onCharHook(self, evt): # Bound by MultiCategorySettingsDialog.makeSettings keycode = evt.GetKeyCode() @@ -1276,11 +1280,11 @@ def onCharHook(self, evt): self.switchToFullEditor() return super().onCharHook(evt) - + def onConvertToDualNode(self, evt): convertToDualNode(self.getData()) self.EndModal(wx.ID_CONVERT) - + def onConvertToSingleNode(self, evt): if gui.messageBox( _( @@ -1296,7 +1300,7 @@ def onConvertToSingleNode(self, evt): return convertToSingleNode(self.getData()) self.EndModal(wx.ID_CONVERT) - + def switchToFullEditor(self): if not self.simpleMode: wx.Bell() @@ -1308,19 +1312,19 @@ def switchToFullEditor(self): "catList.focus": self.catListCtrl.HasFocus(), } self.EndModal(wx.ID_MORE) - + def _validateAllPanels(self): # Ensure all panels are loaded, hence validated for catId in range(len(self.categoryClasses)): self._getCategoryPanel(catId) super()._validateAllPanels() - + def _saveAllPanels(self): super()._saveAllPanels() - + critData = self.getData() ruleData = self.context["data"]["rule"] - + if set(critData.get("selector", {}).keys()) == {"start", "end"} and ( any( key == "mutation" and value @@ -1343,7 +1347,7 @@ def _saveAllPanels(self): style=wx.ICON_WARNING | wx.YES_NO | wx.CANCEL | wx.NO_DEFAULT ) != wx.YES: raise ValidationError() # Cancels closing of the dialog - + if createMissingSubModule(self.context, self.getData(), self) is False: raise ValidationError() # Cancels closing of the dialog