Skip to content

Commit

Permalink
Cleanup and fix small issues in HelpMenuList
Browse files Browse the repository at this point in the history
As I use the context as key groups when no description is defined we do
not have 'Other Functions". We always gave a group via the context in
the keymaps. Als rename some functions and variables trying to make the
code a bit more readable.
  • Loading branch information
Littlesat committed Dec 22, 2024
1 parent 5627342 commit 598345f
Showing 1 changed file with 14 additions and 39 deletions.
53 changes: 14 additions & 39 deletions lib/python/Components/HelpMenuList.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def __init__(self, helplist, callback, rcPos=None):
self.longSeen = False
self.skipKeys = getFpAndKbdKeys()

def actMapId():
return getattr(actionmap, "description", None) or id(actionmap)
def getActionmapGroupKey(actionmap, context):
return getattr(actionmap, "description", None) or context

headings, sortKey = {
"headings+alphabetic": (True, self._sortKeyAlpha),
Expand Down Expand Up @@ -132,45 +132,22 @@ def actMapId():

entry = [(actionmap, context, action, buttonLabels), help]
if self._filterHelpList(entry, helpSeen):
actionMapHelp[actMapId()].append(entry)
actionMapHelp[getActionmapGroupKey(actionmap, context)].append(entry)

l = []
self.list = []
extendedPadding = (None, ) if formatFlags & self.EXTENDED else ()
groups = []
for (actionmap, context, actions) in sorted(helplist, key=self._sortHeadingsAlpha):
amId = actMapId()
if headings and amId in actionMapHelp:
actionmapGroupKey = getActionmapGroupKey(actionmap, context)
print(actionmapGroupKey)
if headings and actionmapGroupKey in actionMapHelp:
if sortKey:
actionMapHelp[amId].sort(key=sortKey)
self.addListBoxContext(actionMapHelp[amId], formatFlags)

if getattr(actionmap, "description", None):
l.append((None, actionmap.description, None) + extendedPadding)
else:
if context not in groups:
groups.append(context)
l.append((None, _(re.sub(r"(\w)([A-Z])([a-z])", r"\1 \2\3", context)), None) + extendedPadding)
l.extend(actionMapHelp[amId])
del actionMapHelp[amId]

if actionMapHelp:
# Add a header if other actionmaps have descriptions
if formatFlags & self.HEADINGS:
l.append((None, _("Other functions"), None) + extendedPadding)

otherHelp = []
for (actionmap, context, actions) in helplist:
amId = actMapId()
if amId in actionMapHelp:
otherHelp.extend(actionMapHelp[amId])
del actionMapHelp[amId]

if sortKey:
otherHelp.sort(key=sortKey)
self.addListBoxContext(otherHelp, formatFlags)
l.extend(otherHelp)

for i, ent in enumerate(l):
actionMapHelp[actionmapGroupKey].sort(key=sortKey)
self.addListBoxContext(actionMapHelp[actionmapGroupKey], formatFlags)
self.list.append((None, actionmap.description if getattr(actionmap, "description", None) else _(re.sub(r"(\w)([A-Z])([a-z])", r"\1 \2\3", context)), None) + extendedPadding)
self.list.extend(actionMapHelp[actionmapGroupKey])
del actionMapHelp[actionmapGroupKey]

for i, ent in enumerate(self.list):
if ent[0] is not None:
# Ignore "break" events from
# OK and EXIT on return from
Expand All @@ -186,8 +163,6 @@ def actMapId():
"extended+headings",
)[formatFlags]

self.list = l

def _mergeButLists(self, bl1, bl2):
bl1.extend([b for b in bl2 if b not in bl1])

Expand Down

0 comments on commit 598345f

Please sign in to comment.