-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SubModules: GUI: Editor: Prompt for creation of a missing SubModule
- WebModule Editor: Do not require a trigger when creating from the Rule Editor - WebModule Manager: Add key shortcuts `F2`, `F3` and `delete` to edit, manage rules and delete, respectively (#38) - WebModule Manager: Set "no" as the default when prompting for deletion - Refactor `gui.actions` into `gui.rule.actions` - Refactor `gui.criteriaEditor` into `gui.rule.criteriaEditor` - Refactor `gui.gestureBinding` into `gui.rule.gestureBinding` - Refactor `gui.properties` into `gui.rule.properties` - Refactor `gui.webModulesManager` into `gui.webModule.manager` - Refactor `gui.webModuleEditor` into `gui.webModule.editor` - Refactor `gui.webModuleManager.promptDelete` into `gui.webModule.promptDelete` - GUI: Refactor `gui.webModuleManager.promptMask` into `gui.webModule.promptMask`
- Loading branch information
1 parent
b6a6e6c
commit 2d95649
Showing
11 changed files
with
297 additions
and
125 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# globalPlugins/webAccess/gui/rule/__init__.py | ||
# -*- coding: utf-8 -*- | ||
|
||
# This file is part of Web Access for NVDA. | ||
# Copyright (C) 2015-2024 Accessolutions (http://accessolutions.fr) | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# See the file COPYING.txt at the root of this distribution for more details. | ||
|
||
|
||
__author__ = "Julien Cochuyt <[email protected]>" | ||
|
||
|
||
from collections.abc import Mapping | ||
from typing import Any | ||
|
||
import wx | ||
|
||
import addonHandler | ||
import gui | ||
from logHandler import log | ||
|
||
|
||
addonHandler.initTranslation() | ||
|
||
|
||
def createMissingSubModule( | ||
context: Mapping[str, Any], | ||
data: Mapping[str, Any], | ||
parent: wx.Window | ||
) -> bool: | ||
"""Create the missing SubModule from Rule or Criteria data | ||
If a SubModule is specified in the provided data, it is looked-up in the catalog. | ||
If it is missing from the catalog, the user is prompted for creating it. | ||
This function returns: | ||
- `None` if no creation was necessary or if the user declined the prompt. | ||
- `False` if the user canceled the prompt or if the creation failed or has been canceled. | ||
- `True` if the creation succeeded. | ||
""" | ||
name = data.get("properties", {}).get("subModule") | ||
if not name: | ||
return None | ||
from ...webModuleHandler import getCatalog | ||
if any(meta["name"] == name for ref, meta in getCatalog()): | ||
return True | ||
res = gui.messageBox( | ||
message=( | ||
# Translators: A prompt for creation of a missing SubModule | ||
_(f"""SubModule {name} could not be found. | ||
Do you want to create it now?""") | ||
), | ||
style=wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION, | ||
parent=parent, | ||
) | ||
if res is wx.NO: | ||
return None | ||
elif res is wx.CANCEL: | ||
return False | ||
context = context.copy() | ||
context["new"] = True | ||
context["data"] = {"webModule": {"name": name, "subModule": True}} | ||
from ..webModule.editor import show | ||
res = show(context, parent) | ||
if res: | ||
newName = context["webModule"].name | ||
if newName != name: | ||
data["properties"]["subModule"] = newName | ||
return res |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# globalPlugins/webAccess/gui/criteriaEditor.py | ||
# globalPlugins/webAccess/gui/rule/criteria.py | ||
# -*- coding: utf-8 -*- | ||
|
||
# This file is part of Web Access for NVDA. | ||
|
@@ -21,7 +21,7 @@ | |
|
||
|
||
|
||
__version__ = "2024.08.29" | ||
__version__ = "2024.08.30" | ||
__authors__ = ( | ||
"Shirley Noël <[email protected]>", | ||
"Julien Cochuyt <[email protected]>", | ||
|
@@ -48,9 +48,9 @@ | |
import ui | ||
|
||
import addonHandler | ||
from ..ruleHandler import builtinRuleActions, ruleTypes | ||
from ..utils import guarded, notifyError, updateOrDrop | ||
from . import ( | ||
from ...ruleHandler import builtinRuleActions, ruleTypes | ||
from ...utils import guarded, notifyError, updateOrDrop | ||
from .. import ( | ||
ContextualMultiCategorySettingsDialog, | ||
ContextualSettingsPanel, | ||
DropDownWithHideableChoices, | ||
|
@@ -61,8 +61,9 @@ | |
stripAccel, | ||
stripAccelAndColon, | ||
) | ||
from . import createMissingSubModule | ||
from .abc import RuleAwarePanelBase | ||
from .actions import ActionsPanelBase | ||
from .rule.abc import RuleAwarePanelBase | ||
from .properties import Properties, PropertiesPanelBase, Property | ||
|
||
|
||
|
@@ -239,7 +240,7 @@ def testCriteria(context): | |
ruleData.setdefault("properties", {})['multiple'] = True | ||
critData.setdefault("properties", {}).pop("multiple", None) | ||
mgr = context["webModule"].ruleManager | ||
from ..ruleHandler import Rule | ||
from ...ruleHandler import Rule | ||
rule = Rule(mgr, ruleData) | ||
import time | ||
start = time.time() | ||
|
@@ -257,7 +258,9 @@ def testCriteria(context): | |
class CriteriaEditorPanel(RuleAwarePanelBase): | ||
|
||
def getData(self): | ||
return self.context["data"].setdefault("criteria", {}) | ||
# 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"] | ||
|
||
|
||
class GeneralPanel(CriteriaEditorPanel): | ||
|
@@ -1017,6 +1020,11 @@ class CriteriaEditorDialog(ContextualMultiCategorySettingsDialog): | |
categoryClasses = [GeneralPanel, CriteriaPanel, ActionsPanel, PropertiesPanel] | ||
INITIAL_SIZE = (900, 580) | ||
|
||
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 makeSettings(self, settingsSizer): | ||
super().makeSettings(settingsSizer) | ||
idTestCriteria = wx.NewId() | ||
|
@@ -1028,8 +1036,13 @@ def makeSettings(self, settingsSizer): | |
def onTestCriteria(self, evt): | ||
self.currentCategory.updateData() | ||
testCriteria(self.context) | ||
|
||
def _saveAllPanels(self): | ||
super()._saveAllPanels() | ||
if createMissingSubModule(self.context, self.getData(), self) is False: | ||
raise ValidationError() # Cancels closing of the dialog | ||
|
||
|
||
def show(context, parent=None): | ||
from . import showContextualDialog | ||
from .. import showContextualDialog | ||
return showContextualDialog(CriteriaEditorDialog, context, parent) |
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
Oops, something went wrong.