Skip to content

Commit

Permalink
SubModules WIP - Very early alpha
Browse files Browse the repository at this point in the history
 - Load child WebModule named via the new subModule Zone property
 - For the child, restrict Node search to its Zone
 - For the parent, exclude child's Node from search
 - For the child, don't respond to Marker or Zone gestures unless caret is in Zone
 - Add new Rule Type "globalMarker" which can be triggered from anywhere, with priority given to children
 - Menu actions target the WebModule at caret position
 - Menu "Edit WebModule" presents when suitable a list of options from caret to root
  • Loading branch information
JulienCochuyt committed Aug 26, 2024
1 parent f95bde3 commit f6b68eb
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 110 deletions.
10 changes: 8 additions & 2 deletions addon/globalPlugins/webAccess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,18 @@ def showWebAccessGui(self):
"webAccess": self,
"focusObject": obj,
}
webModule = obj.webAccess.webModule
if webModule is not None:
if obj.webAccess.webModule:
webModule = obj.treeInterceptor.webAccess.webModuleAtCaret
context["webModule"] = webModule
context["pageTitle"] = webModule.pageTitle
mgr = webModule.ruleManager
context["result"] = mgr.getResultAtCaret(focus=obj)
stack = []
while webModule:
stack.append(webModule)
webModule = webModule.ruleManager.parentModule
if len(stack) > 1:
context["webModuleStackAtCaret"] = stack
menu.show(context)

@script(
Expand Down
4 changes: 2 additions & 2 deletions addon/globalPlugins/webAccess/gui/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def updateGesturesListBox(self, selectId: str = None, focus: bool = False):
@guarded
def onPanelActivated(self):
super().onPanelActivated()
supported = self.getRuleType() in (ruleTypes.ZONE, ruleTypes.MARKER)
supported = self.getRuleType() in ruleTypes.ACTION_TYPES
self.panelDescription = "" if supported else self.descriptionIfNoneSupported
self.Freeze()
for item in self.hideable["IfSupported"]:
Expand All @@ -273,7 +273,7 @@ def onPanelActivated(self):
def onSave(self):
super().onSave()
data = self.getData()
if self.getRuleType() not in (ruleTypes.ZONE, ruleTypes.MARKER):
if self.getRuleType() not in ruleTypes.ACTION_TYPES:
data.pop("gestures", None)
data.get("properties", {}).pop("autoAction", None)
elif not data.get("gestures"):
Expand Down
44 changes: 37 additions & 7 deletions addon/globalPlugins/webAccess/gui/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""Web Access GUI."""


__version__ = "2024.08.25"
__version__ = "2024.08.26"
__authors__ = (
"Julien Cochuyt <[email protected]>",
"André-Abush Clause <[email protected]>",
Expand All @@ -33,6 +33,7 @@
import wx

import addonHandler
import config
import gui

from ... import webAccess
Expand Down Expand Up @@ -80,7 +81,20 @@ def __init__(self, context):
_("&New web module..."))
self.Bind(wx.EVT_MENU, self.onWebModuleCreate, item)

if webModule:
stack = context.get("webModuleStackAtCaret", []).copy()
if stack:
subMenu = wx.Menu()
while stack:
mod = stack.pop(0)
handler = lambda evt, webModule=mod: self.onWebModuleEdit(evt, webModule=webModule)
item = subMenu.Append(wx.ID_ANY, mod.name)
subMenu.Bind(wx.EVT_MENU, handler, item)
self.AppendSubMenu(
subMenu,
# Translators: Web Access menu item label.
_("Edit &web module")
)
elif webModule:
item = self.Append(
wx.ID_ANY,
# Translators: Web Access menu item label.
Expand All @@ -97,6 +111,16 @@ def __init__(self, context):

self.AppendSeparator()

if config.conf["webAccess"]["devMode"]:
item = self.Append(
wx.ID_ANY,
# Translators: Web Access menu item label.
_("&Element description...")
)
self.Bind(wx.EVT_MENU, self.onElementDescription, item)

self.AppendSeparator()

item = self.AppendCheckItem(
wx.ID_ANY,
# Translators: Web Access menu item label.
Expand All @@ -110,6 +134,11 @@ def show(self):
gui.mainFrame.PopupMenu(self)
gui.mainFrame.postPopup()

@guarded
def onElementDescription(self, evt):
from .elementDescription import showElementDescriptionDialog
showElementDescriptionDialog()

@guarded
def onRuleCreate(self, evt):
self.context["new"] = True
Expand All @@ -122,13 +151,14 @@ def onRulesManager(self, evt):
show(self.context, gui.mainFrame)

@guarded
def onWebModuleCreate(self, evt):
self.context["new"] = True
from .webModuleEditor import show
show(self.context, gui.mainFrame)
def onSubModuleEdit(self, evt, webModule):
from logHandler import log
log.info(f"onSubModuleEdit: {dir(evt)}")

@guarded
def onWebModuleEdit(self, evt):
def onWebModuleEdit(self, evt, webModule=None):
if webModule is not None:
self.context["webModule"] = webModule
from .webModuleEditor import show
show(self.context)

Expand Down
23 changes: 6 additions & 17 deletions addon/globalPlugins/webAccess/gui/rule/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def onRuleType_change(self):
prm = self.categoryParams
# FIXME: Having a mapping stored in an attribute initialized with an unused sequence is quite misleading
categoryClasses = tuple(nodeInfo.categoryClass for nodeInfo in self.Parent.Parent.categoryClasses)
for index in (categoryClasses.index(cls) for cls in (ActionsPanel, PropertiesPanel)):
for index in (categoryClasses.index(cls) for cls in (GeneralPanel, ActionsPanel, PropertiesPanel)):
category = prm.tree.getXChild(prm.tree.GetRootItem(), index)
self.refreshParent(category)

Expand Down Expand Up @@ -227,22 +227,11 @@ def makeSettings(self, settingsSizer):
def initData(self, context: Mapping[str, Any]) -> None:
super().initData(context)
data = self.getData()
if 'type' in data:
self.ruleType.SetSelection(list(ruleTypes.ruleTypeLabels.keys()).index(data['type']))
else:
self.ruleType.SetSelection(0)

self.ruleType.SetSelection(tuple(ruleTypes.ruleTypeLabels.keys()).index(data["type"]))
self.ruleName.Value = data.get("name", "")
self.commentText.Value = data.get("comment", "")
self.refreshSummary()

@staticmethod
def initRuleTypeChoice(data, ruleTypeChoice):
for index, key in enumerate(ruleTypes.ruleTypeLabels.keys()):
if key == data["type"]:
ruleTypeChoice.Selection = index
break

def updateData(self):
data = self.getData()
# The rule type should already be stored as of onRuleType_choice
Expand Down Expand Up @@ -863,16 +852,16 @@ def getGeneralChildren(self):
categoryParams=prm
)
for editorType, prm in (
(EditorType.TEXT, cls.CategoryParams(
fieldDisplayName=SHARED_LABELS["name"],
fieldName="name",
)),
(EditorType.CHOICE, cls.CategoryParams(
editorChoices=ruleTypes.ruleTypeLabels,
fieldDisplayName=SHARED_LABELS["type"],
fieldName="type",
onEditor_change=cls.onRuleType_change,
)),
(EditorType.TEXT, cls.CategoryParams(
fieldDisplayName=SHARED_LABELS["name"],
fieldName="name",
)),
)
)

Expand Down
7 changes: 5 additions & 2 deletions addon/globalPlugins/webAccess/gui/webModulesManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,16 @@ def refreshModulesList(self, selectIndex: int = None, selectItem: "WebModule" =
ctrl = self.modulesList
ctrl.DeleteAllItems()
contextModule = self.context.get("webModule")
contextModules = {
(module.name, module.layers[0].storeRef): module
for module in list(reversed(contextModule.ruleManager.subModules.all())) + [contextModule]
}
modules = self.modules = []
from .. import webModuleHandler
for index, module in enumerate(webModuleHandler.getWebModules()):
if selectIndex is None and module.equals(selectItem):
selectIndex = index
if module.equals(contextModule):
module = contextModule
module = contextModules.get((module.name, module.layers[0].storeRef), module)
trigger = (" %s " % _("and")).join(
([
"url=%s" % url
Expand Down
25 changes: 13 additions & 12 deletions addon/globalPlugins/webAccess/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,15 @@ def webModule(self):
except Exception:
log.exception()
return webModule


@property
def webModuleAtCaret(self):
rootModule = self.webModule
if not rootModule:
return None
info = self.treeInterceptor.makeTextInfo(textInfos.POSITION_CARET)
return self.ruleManager.subModules.atPosition(info._startOffset) or rootModule

@property
def zone(self):
ruleManager = self.ruleManager
Expand Down Expand Up @@ -931,19 +939,12 @@ class Break(Exception):
return super().getAlternativeScript(gesture, script)

def getScript(self, gesture):
webModule = self.webAccess.webModule
webModule = self.webAccess.webModuleAtCaret
if webModule:
func = webModule.getScript(gesture)
if func:
return ScriptWrapper(
func, ignoreTreeInterceptorPassThrough=True
)
mgr = self.webAccess.ruleManager
if mgr:
func = mgr.getScript(gesture)
if func:
script = webModule.getScript(gesture)
if script:
return ScriptWrapper(
func, ignoreTreeInterceptorPassThrough=True
script, ignoreTreeInterceptorPassThrough=True
)
return super().getScript(gesture)

Expand Down
Loading

0 comments on commit f6b68eb

Please sign in to comment.