Skip to content

Commit

Permalink
Add an instant method to change the order and layout of the Helpscreen
Browse files Browse the repository at this point in the history
With short help you get some help instructions and with long help you
can now toggle between the different order/layout modes the help screen
offers without going deep into the menus
  • Loading branch information
Littlesat committed Jan 5, 2025
1 parent 6bf1eee commit 09ca5b4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
2 changes: 2 additions & 0 deletions data/keymap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@

<map context="HelpActions">
<key id="KEY_HELP" mapto="displayHelp" flags="b" />
<key id="KEY_HELP" mapto="toggleConfig" flags="l" />
<!-- Keyboard specific buttons -->
<key id="KEY_F1" mapto="displayHelp" flags="b" />
<key id="KEY_F1" mapto="toggleConfig" flags="l" />
</map>

<map context="NavigationActions">
Expand Down
22 changes: 13 additions & 9 deletions lib/python/Components/HelpMenuList.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,19 @@ class HelpMenuList(List):
def __init__(self, helplist, callback, rcPos=None):
List.__init__(self)
self.callback = callback
formatFlags = 0
self.rcPos = rcPos
self.helplist=helplist
self.createHelpList()

def createHelpList(self):
def getActionmapGroupKey(actionmap, context):
return getattr(actionmap, "description", None) or context

self.rcKeyIndex = None
self.buttonMap = {}
self.longSeen = False
self.skipKeys = getFpAndKbdKeys()

def getActionmapGroupKey(actionmap, context):
return getattr(actionmap, "description", None) or context
formatFlags = 0

headings, sortKey = {
"headings+alphabetic": (True, self._sortKeyAlpha),
Expand All @@ -66,16 +70,16 @@ def getActionmapGroupKey(actionmap, context):
"flat+remotegroups": (False, self._sortInd)
}.get(config.usage.help_sortorder.value, (False, None))

if rcPos is None:
if self.rcPos is None:
if sortKey in (self._sortPos, self._sortInd):
sortKey = None
else:
if sortKey == self._sortInd:
self.rcKeyIndex = dict((x[1], x[0]) for x in enumerate(rcPos.getRcKeyList()))
self.rcKeyIndex = dict((x[1], x[0]) for x in enumerate(self.rcPos.getRcKeyList()))

buttonsProcessed = set()
helpSeen = defaultdict(list)
sortedHelplist = sorted(helplist, key=lambda hle: hle[0].prio)
sortedHelplist = sorted(self.helplist, key=lambda hle: hle[0].prio)
actionMapHelp = defaultdict(list)

for (actionmap, context, actions) in sortedHelplist:
Expand Down Expand Up @@ -137,7 +141,7 @@ def getActionmapGroupKey(actionmap, context):
self.list = []
extendedPadding = (None, ) if formatFlags & self.EXTENDED else ()
if headings:
for (actionmap, context, actions) in sorted(helplist, key=self._sortHeadingsAlpha):
for (actionmap, context, actions) in sorted(self.helplist, key=self._sortHeadingsAlpha):
actionmapGroupKey = getActionmapGroupKey(actionmap, context)
if actionmapGroupKey in actionMapHelp:
if sortKey:
Expand All @@ -147,7 +151,7 @@ def getActionmapGroupKey(actionmap, context):
self.list.extend(actionMapHelp[actionmapGroupKey])
del actionMapHelp[actionmapGroupKey]
else:
for (actionmap, context, actions) in helplist:
for (actionmap, context, actions) in self.helplist:
actionmapGroupKey = getActionmapGroupKey(actionmap, context)
if actionmapGroupKey in actionMapHelp:
self.list.extend(actionMapHelp[actionmapGroupKey])
Expand Down
13 changes: 10 additions & 3 deletions lib/python/Screens/HelpMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from Screens.TextBox import TextBox
from Tools.KeyBindings import keyBindings
from Tools.BoundFunction import boundFunction
from Components.config import config
from Components.Label import Label
from Components.ActionMap import ActionMap
from Components.HelpMenuList import HelpMenuList
Expand All @@ -19,12 +20,11 @@ def helpText(self):
_("Other buttons will jump to the help for that button, if there is help."),
_("If an action is user-configurable, its help entry will be flagged (C)"),
_("A highlight on the remote control image shows which button the help refers to. If more than one button performs the indicated function, more than one highlight will be shown. Text below the list indicates whether the function is for a long press of the button(s)."),
_("The order and grouping of the help information list can be controlled using MENU>Setup>User Interface>Settings>Sort order for help screen.")])
_("The order and grouping of the help information list can be controlled using MENU>Setup>User Interface>Settings>Sort order for help screen or pressing long help")])

def __init__(self, session, list):
Screen.__init__(self, session)
self.setup_title = _("Help")
Screen.setTitle(self, self.setup_title)
Screen.setTitle(self, _("Help"))
Rc.__init__(self)
self["list"] = HelpMenuList(list, self.close, rcPos=self.getRcPositions())
self["longshift_key0"] = Label("")
Expand Down Expand Up @@ -68,6 +68,7 @@ def __init__(self, session, list):

self["helpActions"] = ActionMap(["HelpActions"], {
"displayHelp": self.showHelp,
"toggleConfig": self.toggleConfig,
})

self.onLayoutFinish.append(self.doOnLayoutFinish)
Expand Down Expand Up @@ -141,6 +142,12 @@ def interceptButton(self, key, flag):
def showHelp(self):
self.session.open(TextBox, self.helpText(), _("Help Screen"))

def toggleConfig(self):
config.usage.help_sortorder.selectNext()
config.usage.help_sortorder.save()
Screen.setTitle(self, "%s - %s" % (_("Help"), config.usage.help_sortorder.getText()))
self["list"].createHelpList()


class HelpableScreen:
def __init__(self):
Expand Down

0 comments on commit 09ca5b4

Please sign in to comment.