Exemple #1
0
    def __init__(self, helpList, callback):
        List.__init__(self)
        self.callback = callback
        self.rcKeyIndex = None
        self.buttonMap = {}
        self.longSeen = False
        formatFlags = 0

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

        headings, sortCmp, sortKey = {
            "headings+alphabetic": (True, None, self._sortKeyAlpha),
            "flat+alphabetic": (False, None, self._sortKeyAlpha),
            "flat+remotepos": (False, self._sortCmpPos, None),
            "flat+remotegroups": (False, self._sortCmpInd, None)
        }.get(config.usage.helpSortOrder.value, (False, None, None))
        if remoteControl is None:
            if sortCmp in (self._sortCmpPos, self._sortCmpInd):
                sortCmp = None
        else:
            if sortCmp == self._sortCmpInd:
                self.rcKeyIndex = dict((x[1], x[0]) for x in enumerate(
                    remoteControl.getRemoteControlKeyList()))
        buttonsProcessed = set()
        helpSeen = defaultdict(list)
        sortedHelpList = sorted(helpList, key=lambda hle: hle[0].prio)
        actionMapHelp = defaultdict(list)
        for (actionmap, context, actions) in sortedHelpList:
            # print("[HelpMenu] HelpMenuList DEBUG: actionmap='%s', context='%s', actions='%s'." % (str(actionmap), context, str(actions)))
            if not actionmap.enabled:
                # print("[HelpMenu] Action map disabled.")
                continue
            amId = actMapId()
            if headings and actionmap.description and not (formatFlags
                                                           & self.HEADINGS):
                # print("[HelpMenu] HelpMenuList DEBUG: Headings found.")
                formatFlags |= self.HEADINGS
            for (action, help) in actions:  # DEBUG: Should help be response?
                helpTags = [
                ]  # if mapFlag else [pgettext("Abbreviation of 'Disabled'", "Disabled")]
                if callable(help):
                    help = help()
                    helpTags.append(
                        pgettext("Abbreviation of 'Configurable'",
                                 "Configurable"))
                if help is None:
                    # print("[HelpMenu] HelpMenuList DEBUG: No help text found.")
                    # help = _("No help text available")
                    continue
                buttons = queryKeyBinding(context, action)
                # print("[HelpMenu] HelpMenuList DEBUG: queryKeyBinding buttons=%s." % str(buttons))
                if not buttons:  # Do not display entries which are not accessible from keys.
                    # print("[HelpMenu] HelpMenuList DEBUG: No buttons allocated.")
                    # helpTags.append(pgettext("Abbreviation of 'Unassigned'", "Unassigned"))
                    continue
                buttonLabels = []
                for keyId, flags in buttons:
                    if remoteControl.getRemoteControlKeyPos(keyId):
                        buttonLabels.append(
                            (keyId, "LONG") if flags & 8 else (keyId, )
                        )  # For long keypresses, make the second tuple item "LONG".
                if not buttonLabels:  # Only show entries with keys that are available on the used rc.
                    # print("[HelpMenu] HelpMenuList DEBUG: Button not available on current remote control.")
                    # helpTags.append(pgettext("Abbreviation of 'No Button'", "No Button"))
                    continue
                isExtended = isinstance(help, (list, tuple))
                if isExtended and not (formatFlags & self.EXTENDED):
                    # print("[HelpMenu] HelpMenuList DEBUG: Extended help entry found.")
                    formatFlags |= self.EXTENDED
                if helpTags:
                    helpStr = help[0] if isExtended else help
                    tagsStr = pgettext("Text list separator",
                                       ", ").join(helpTags)
                    helpStr = _("%s  (%s)") % (helpStr, tagsStr)
                    help = [helpStr, help[1]] if isExtended else helpStr
                entry = [(actionmap, context, action, buttonLabels, help),
                         help]
                if self._filterHelpList(entry, helpSeen):
                    actionMapHelp[actMapId()].append(entry)
        helpMenuList = []
        extendedPadding = (None, ) if formatFlags & self.EXTENDED else ()
        for (actionmap, context, actions) in helpList:
            amId = actMapId()
            if headings and amId in actionMapHelp and getattr(
                    actionmap, "description", None):
                if sortCmp:
                    actionMapHelp[amId].sort(key=cmp_to_key(sortCmp))
                elif sortKey:
                    actionMapHelp[amId].sort(key=sortKey)
                self.addListBoxContext(actionMapHelp[amId], formatFlags)
                helpMenuList.append((None, actionmap.description, None) +
                                    extendedPadding)
                helpMenuList.extend(actionMapHelp[amId])
                del actionMapHelp[amId]
        if actionMapHelp:
            if formatFlags & self.HEADINGS:  # Add a header if other actionmaps have descriptions.
                helpMenuList.append((None, _("Other Actions"), None) +
                                    extendedPadding)
            otherHelp = []
            for (actionmap, context, actions) in helpList:
                amId = actMapId()
                if amId in actionMapHelp:
                    otherHelp.extend(actionMapHelp[amId])
                    del actionMapHelp[amId]
            if sortCmp:
                otherHelp.sort(key=cmp_to_key(sortCmp))
            elif sortKey:
                otherHelp.sort(key=sortKey)
            self.addListBoxContext(otherHelp, formatFlags)
            helpMenuList.extend(otherHelp)
        ignoredKeyIds = (KEYIDS.get("KEY_OK"), KEYIDS.get("KEY_EXIT"))
        for index, entry in enumerate(helpMenuList):
            if entry[0] and entry[0][3]:  # This should not be required.
                for button in entry[0][3]:
                    if button[0] not in (
                            ignoredKeyIds
                    ):  # Ignore "break" events from OK and EXIT on return from help popup.
                        self.buttonMap[button] = index
        self.style = (
            "default",
            "default+headings",
            "extended",
            "extended+headings",
        )[formatFlags]
        # [(actionmap, context, [(action, help), (action, help), ...]), ...]
        # [((ActionMap, Context, Action, [(Button, Device/Long), ...], HelpText), HelpText), ...]
        self.list = helpMenuList
Exemple #2
0
    def __init__(self, helplist, callback):
        GUIComponent.__init__(self)
        self.onSelChanged = []
        self.l = eListboxPythonMultiContent()
        self.callback = callback
        self.extendedHelp = False

        l = []
        for (actionmap, context, actions) in helplist:
            for (action, help) in actions:
                if hasattr(help, '__call__'):
                    help = help()
                if not help:
                    continue
                buttons = queryKeyBinding(context, action)

                # do not display entries which are not accessible from keys
                if not len(buttons):
                    continue

                name = None
                flags = 0

                for n in buttons:
                    (name, flags) = (getKeyDescription(n[0]), n[1])
                    if name is not None:
                        break

                # only show entries with keys that are available on the used rc
                if name is None:
                    continue

                if flags & 8:  # for long keypresses, prepend l_ into the key name.
                    name = (name[0], "long")

                entry = [(actionmap, context, action, name)]

                if isinstance(help, list):
                    self.extendedHelp = True
                    print("[HelpMenuList] extendedHelpEntry found")
                    x, y, w, h = parameters.get("HelpMenuListExtHlp0",
                                                (0, 0, 600, 26))
                    x1, y1, w1, h1 = parameters.get("HelpMenuListExtHlp1",
                                                    (0, 28, 600, 20))
                    entry.extend(
                        ((eListboxPythonMultiContent.TYPE_TEXT, x, y, w, h, 0,
                          0, help[0]), (eListboxPythonMultiContent.TYPE_TEXT,
                                        x1, y1, w1, h1, 1, 0, help[1])))
                else:
                    x, y, w, h = parameters.get("HelpMenuListHlp",
                                                (0, 0, 600, 28))
                    entry.append((eListboxPythonMultiContent.TYPE_TEXT, x, y,
                                  w, h, 0, 0, help))

                l.append(entry)

        self.l.setList(l)
        if self.extendedHelp is True:
            font = fonts.get("HelpMenuListExt0", ("Regular", 24, 50))
            self.l.setFont(0, gFont(font[0], font[1]))
            self.l.setItemHeight(font[2])
            font = fonts.get("HelpMenuListExt1", ("Regular", 18))
            self.l.setFont(1, gFont(font[0], font[1]))
        else:
            font = fonts.get("HelpMenuList", ("Regular", 24, 38))
            self.l.setFont(0, gFont(font[0], font[1]))
            self.l.setItemHeight(font[2])