def __init__(self, parent, contexts, actions=None, prio=0, description=None): def exists(record): for context in parent.helpList: if record in context[2]: print("[ActionMap] removed duplicity: %s %s" % (context[1], record)) return True return False if not hasattr(contexts, '__iter__'): contexts = [contexts] actions = actions or {} self.description = description adict = {} for context in contexts: alist = [] for (action, funchelp) in iter(actions.items()): # Check if this is a tuple. if isinstance(funchelp, tuple): if queryKeyBinding(context, action): if not exists((action, funchelp[1])): alist.append((action, funchelp[1])) adict[action] = funchelp[0] else: if queryKeyBinding(context, action): if not exists((action, None)): alist.append((action, None)) adict[action] = funchelp parent.helpList.append((self, context, alist)) ActionMap.__init__(self, contexts, adict, prio)
def __init__(self, parent, contexts, actions=None, prio=0, description=None): if not hasattr(contexts, '__iter__'): contexts = [contexts] actions = actions or {} self.description = description adict = {} for context in contexts: alist = [] for (action, funchelp) in actions.iteritems(): # Check if this is a tuple. if isinstance(funchelp, tuple): if queryKeyBinding(context, action): alist.append((action, funchelp[1])) adict[action] = funchelp[0] else: if queryKeyBinding(context, action): alist.append((action, None)) adict[action] = funchelp parent.helpList.append((self, context, alist)) ActionMap.__init__(self, contexts, adict, prio)
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: 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 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 "extendedHelpEntry found" x, y, w, h = skin.parameters.get("HelpMenuListExtHlp0", (0, 0, 400, 26)) x1, y1, w1, h1 = skin.parameters.get( "HelpMenuListExtHlp1", (0, 28, 400, 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 = skin.parameters.get("HelpMenuListHlp", (0, 0, 400, 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 = skin.fonts.get("HelpMenuListExt0", ("Regular", 24, 50)) self.l.setFont(0, gFont(font[0], font[1])) self.l.setItemHeight(font[2]) font = skin.fonts.get("HelpMenuListExt1", ("Regular", 18)) self.l.setFont(1, gFont(font[0], font[1])) else: font = skin.fonts.get("HelpMenuList", ("Regular", 24, 38)) self.l.setFont(0, gFont(font[0], font[1])) self.l.setItemHeight(font[2])
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 "extendedHelpEntry found" entry.extend(((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 600, 26, 0, 0, help[0]), (eListboxPythonMultiContent.TYPE_TEXT, 0, 28, 600, 20, 1, 0, help[1]))) else: entry.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 600, 28, 0, 0, help)) l.append(entry) self.l.setList(l) if self.extendedHelp is True: self.l.setFont(0, gFont("Regular", 24)) self.l.setFont(1, gFont("Regular", 18)) self.l.setItemHeight(50) else: self.l.setFont(0, gFont("Regular", 24)) self.l.setItemHeight(38)
def __init__(self, helplist, callback): GUIComponent.__init__(self) self.onSelChanged = [] self.l = eListboxPythonMultiContent() self.callback = callback self.extendedHelp = False l = [] sizes = componentSizes[componentSizes.HELP_MENU_LIST] textX = sizes.get("textX", 5) textY = sizes.get("textY", 35) textWidth = sizes.get("textWidth", 1000) textHeight = sizes.get("textHeight", 35) for (actionmap, context, actions) in helplist: if not actionmap.enabled: continue for (action, help) in actions: 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 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 "extendedHelpEntry found" entry.extend( ((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, textWidth, textHeight, 0, RT_VALIGN_CENTER, help[0]), (eListboxPythonMultiContent.TYPE_TEXT, 0, textY, textWidth, textHeight, 1, RT_VALIGN_CENTER, help[1]))) else: entry.append( (eListboxPythonMultiContent.TYPE_TEXT, textX, 0, textWidth, textHeight, 0, RT_VALIGN_CENTER, help)) l.append(entry) self.l.setList(l) tlf = TemplatedListFonts() self.l.setFont(0, gFont(tlf.face(tlf.BIG), tlf.size(tlf.BIG))) self.l.setFont(1, gFont(tlf.face(tlf.MEDIUM), tlf.size(tlf.MEDIUM))) self.l.setItemHeight(sizes.get(componentSizes.ITEM_HEIGHT, 30))
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) 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 if name is None: continue if flags & 8: name = (name[0], 'long') entry = [(actionmap, context, action, name)] if isinstance(help, list): self.extendedHelp = True print 'extendedHelpEntry found' x, y, w, h = skin.parameters.get('HelpMenuListExtHlp0', (0, 0, 600, 26)) x1, y1, w1, h1 = skin.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 = skin.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 = skin.fonts.get('HelpMenuListExt0', ('Regular', 24, 50)) self.l.setFont(0, gFont(font[0], font[1])) self.l.setItemHeight(font[2]) font = skin.fonts.get('HelpMenuListExt1', ('Regular', 18)) self.l.setFont(1, gFont(font[0], font[1])) else: font = skin.fonts.get('HelpMenuList', ('Regular', 24, 38)) self.l.setFont(0, gFont(font[0], font[1])) self.l.setItemHeight(font[2])
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 "extendedHelpEntry found" entry.extend(( (eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 600, 26, 0, 0, help[0]), (eListboxPythonMultiContent.TYPE_TEXT, 0, 28, 600, 20, 1, 0, help[1]) )) else: entry.append( (eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 600, 28, 0, 0, help) ) l.append(entry) self.l.setList(l) if self.extendedHelp is True: self.l.setFont(0, gFont("Regular", 24)) self.l.setFont(1, gFont("Regular", 18)) self.l.setItemHeight(50) else: self.l.setFont(0, gFont("Regular", 24)) self.l.setItemHeight(38)
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: 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 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 "extendedHelpEntry found" x,y,w,h = skin.parameters.get("HelpMenuListExtHlp0", (0,0,400,26)) x1,y1,w1,h1 = skin.parameters.get("HelpMenuListExtHlp1", (0,28,400,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 = skin.parameters.get("HelpMenuListHlp", (10,4,750,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, size = skin.parameters.get("HelpMenuListExtendedFont0", ('Regular', 24)) self.l.setFont(0, gFont(font, size)) font, size = skin.parameters.get("HelpMenuListExtendedFont1", ('Regular', 18)) self.l.setFont(1, gFont(font, size)) self.l.setItemHeight(int(skin.parameters.get("HelpMenuListExtendedItemHeight", (50,))[0])) else: font, size = skin.parameters.get("HelpMenuListFont0", ('Regular', 24)) self.l.setFont(0, gFont(font, size)) self.l.setItemHeight(int(skin.parameters.get("HelpMenuListItemHeight", (38,))[0]))
def __init__(self, parent, contexts, actions={}, prio=0, description=None): if not hasattr(contexts, '__iter__'): contexts = [contexts] self.description = description adict = {} for context in contexts: alist = [] for (action, funchelp) in actions.iteritems(): # Check if this is a tuple. if isinstance(funchelp, tuple): if queryKeyBinding(context, action): alist.append((action, funchelp[1])) adict[action] = funchelp[0] else: if queryKeyBinding(context, action): alist.append((action, None)) adict[action] = funchelp parent.helpList.append((self, context, alist)) ActionMap.__init__(self, contexts, adict, prio)
def __init__(self, helplist, callback): GUIComponent.__init__(self) self.onSelChanged = [ ] self.l = eListboxPythonMultiContent() self.callback = callback self.extendedHelp = False l = [ ] sizes = componentSizes[componentSizes.HELP_MENU_LIST] textX = sizes.get("textX", 5) textY = sizes.get("textY", 35) textWidth = sizes.get("textWidth", 1000) textHeight = sizes.get("textHeight", 35) for (actionmap, context, actions) in helplist: if not actionmap.enabled: continue for (action, help) in actions: 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 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 "extendedHelpEntry found" entry.extend(( (eListboxPythonMultiContent.TYPE_TEXT, 0, 0, textWidth, textHeight, 0, RT_VALIGN_CENTER, help[0]), (eListboxPythonMultiContent.TYPE_TEXT, 0, textY, textWidth, textHeight, 1, RT_VALIGN_CENTER, help[1]) )) else: entry.append( (eListboxPythonMultiContent.TYPE_TEXT, textX, 0, textWidth, textHeight, 0, RT_VALIGN_CENTER, help) ) l.append(entry) self.l.setList(l) tlf = TemplatedListFonts() self.l.setFont(0, gFont(tlf.face(tlf.BIG), tlf.size(tlf.BIG))) self.l.setFont(1, gFont(tlf.face(tlf.MEDIUM), tlf.size(tlf.MEDIUM))) self.l.setItemHeight(sizes.get(componentSizes.ITEM_HEIGHT, 30))
def __init__(self, contexts=None, actions=None, prio=0): self.contexts = contexts or [] self.actions = actions or {} self.prio = prio self.p = eActionMap.getInstance() self.bound = False self.exec_active = False self.enabled = True unknown = list(self.actions.keys()) for action in unknown[:]: for context in self.contexts: if queryKeyBinding(context, action): unknown.remove(action) break
def __init__(self, contexts=None, actions=None, prio=0): self.contexts = contexts or [] self.actions = actions or {} self.prio = prio self.p = eActionMap.getInstance() self.bound = False self.exec_active = False self.enabled = True unknown = self.actions.keys() for action in unknown[:]: for context in self.contexts: if queryKeyBinding(context, action): unknown.remove(action) break if unknown: print("[ActionMap] Keymap(s) '%s' -> Undefined action(s) '%s'." % (", ".join(contexts), ", ".join(unknown)))
def __init__(self, contexts=None, actions=None, prio=0): if actions is None: actions = {} if contexts is None: contexts = [] self.actions = actions self.contexts = contexts self.prio = prio self.p = eActionMap.getInstance() self.bound = False self.exec_active = False self.enabled = True unknown = actions.keys() for action in unknown[:]: for ctx in contexts: if queryKeyBinding(ctx, action): unknown.remove(action) break if unknown: print "[ActionMap] action(s) '%s' not in context(s) '%s'" % ( ", ".join(unknown), ", ".join(contexts))
def __init__(self, helplist, callback): GUIComponent.__init__(self) self.onSelChanged = [ ] self.l = eListboxPythonMultiContent() self.callback = callback self.extendedHelp = False l = [ ] sortlist = [] for (actionmap, context, actions) in helplist: for (action, help) in actions: if hasattr(help, '__call__'): help = help() if not help: continue sortlist.append((actionmap, context, action, help)) # Sort by description text (main and extended), then by action (this puts numeric actions in ascending order). sortlist.sort(key=lambda helpItem: (map(str.lower, helpItem[3] if isinstance(helpItem[3], (tuple, list)) else [helpItem[3]]), helpItem[2])) for (actionmap, context, action, help) in sortlist: 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 "extendedHelpEntry found" x, y, w, h = skin.parameters.get("HelpMenuListExtHlp0",(skin.applySkinFactor(5), 0, skin.applySkinFactor(595), skin.applySkinFactor(28))) x1, y1, w1, h1 = skin.parameters.get("HelpMenuListExtHlp1",(skin.applySkinFactor(5), skin.applySkinFactor(34), skin.applySkinFactor(595), skin.applySkinFactor(22))) 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 = skin.parameters.get("HelpMenuListHlp",(skin.applySkinFactor(5), 0, skin.applySkinFactor(595), skin.applySkinFactor(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 = skin.fonts.get("HelpMenuListExt0", ("Regular", skin.applySkinFactor(24), skin.applySkinFactor(56))) self.l.setFont(0, gFont(font[0], font[1])) self.l.setItemHeight(font[2]) font = skin.fonts.get("HelpMenuListExt1", ("Regular", skin.applySkinFactor(18))) self.l.setFont(1, gFont(font[0], font[1])) else: font = skin.fonts.get("HelpMenuList", ("Regular", skin.applySkinFactor(24), skin.applySkinFactor(28))) self.l.setFont(0, gFont(font[0], font[1])) self.l.setItemHeight(font[2])
def __init__(self, helplist, callback, rcPos=None): List.__init__(self) self.callback = callback formatFlags = 0 self.rcPos = rcPos self.rcKeyIndex = None self.buttonMap = {} self.longSeen = False 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.help_sortorder.value, (False, None, None)) if rcPos 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(rcPos.getRcKeyList())) buttonsProcessed = set() helpSeen = defaultdict(list) sortedHelplist = sorted(helplist, key=lambda hle: hle[0].prio) actionMapHelp = defaultdict(list) for (actionmap, context, actions) in sortedHelplist: if not actionmap.enabled: continue amId = actMapId() if headings and actionmap.description and not (formatFlags & self.HEADINGS): print "[HelpMenuList] headings found" formatFlags |= self.HEADINGS for (action, help) in actions: helpTags = [] if callable(help): help = help() helpTags.append( pgettext('Abbreviation of "Configurable"', 'C')) if help is None: continue buttons = queryKeyBinding(context, action) if not buttons: # Do not display entries which are not accessible from keys. continue buttonNames = [] for n in buttons: name = getKeyDescription(n[0]) if name is not None: if len(name) > 0 and not rcPos.getRcKeyPos( name[0] ): # Ignore buttons that don't have a button location. continue if (len(name) < 2 or name[1] not in ("fp", "kbd")): if n[1] & 8: # For long keypresses, make the second tuple item "long". name = (name[0], "long") if name not in buttonsProcessed: buttonNames.append(name) buttonsProcessed.add(name) if not buttonNames: # Only show entries with keys that are available on the used rc. continue isExtended = isinstance(help, (tuple, list)) if isExtended and not (formatFlags & self.EXTENDED): print "[HelpMenuList] extendedHelp 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, buttonNames, help), help] if self._filterHelpList(entry, helpSeen): actionMapHelp[actMapId()].append(entry) lst = [] 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 or sortKey: actionMapHelp[amId].sort(cmp=sortCmp, key=sortKey) self.addListBoxContext(actionMapHelp[amId], formatFlags) lst.append((None, actionmap.description, None) + extendedPadding) lst.extend(actionMapHelp[amId]) del actionMapHelp[amId] if actionMapHelp: if formatFlags & self.HEADINGS: # Add a header if other actionmaps have descriptions. lst.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 sortCmp or sortKey: otherHelp.sort(cmp=sortCmp, key=sortKey) self.addListBoxContext(otherHelp, formatFlags) lst.extend(otherHelp) for i, ent in enumerate(lst): if ent[0] is not None: for b in ent[0][ 3]: # Ignore "break" events from OK and EXIT on return from help popup. if b[0] not in ('OK', 'EXIT'): self.buttonMap[b] = i self.style = ( "default", "default+headings", "extended", "extended+headings", )[formatFlags] self.list = lst
def __init__(self, helplist, callback, rcPos=None): List.__init__(self) self.onSelChanged = [] self.callback = callback self.extendedHelp = False self.rcPos = rcPos self.rcKeyIndex = None self.buttonMap = {} self.longSeen = False self.onSelectionChanged.append(self.selChanged) 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.help_sortorder.value, (False, None, None)) if rcPos 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(rcPos.getRcKeyList())) indent = 0 if headings: for (actionmap, context, actions) in helplist: if actionmap.enabled and getattr(actionmap, "description", None): indent = 1 break buttonsProcessed = set() helpSeen = defaultdict(list) sortedHelplist = sorted(helplist, key=lambda hle: hle[0].prio) actionMapHelp = defaultdict(list) for (actionmap, context, actions) in sortedHelplist: if not actionmap.enabled: continue amId = actMapId() from Screens.ButtonSetup import helpableButtonSetupActionMap isHelpableButtonSetupActionMap = isinstance(actionmap, helpableButtonSetupActionMap) for (action, help) in actions: helpTags = [] if callable(help): help = help() # ButtonSetupButtonActions help looks as though # the button is configurable, but it isn't really if not isHelpableButtonSetupActionMap: helpTags.append('C') if help is None: continue # Ignore inactive ButtonSetupButtonActions if isHelpableButtonSetupActionMap and not help: continue buttons = queryKeyBinding(context, action) # do not display entries which are not accessible from keys if not buttons: continue name = None flags = 0 buttonNames = [] for n in buttons: (name, flags) = (getKeyDescription(n[0]), n[1]) if name is not None: if not self.rcPos.getRcKeyPos(name[0]): continue if (len(name) < 2 or name[1] not in("fp", "kbd")): if flags & 8: # for long keypresses, make the second tuple item "long". name = (name[0], "long") nlong = (n[0], flags & 8) if nlong not in buttonsProcessed: buttonNames.append(name) buttonsProcessed.add(nlong) # only show non-empty entries with keys that are available on the used rc if not (buttonNames and help): continue if isinstance(help, (tuple, list)): self.extendedHelp = True if helpTags: helpTagStr = " (" + ", ".join(helpTags) + ")" if isinstance(help, (tuple, list)): help[0] += helpTagStr else: help += helpTagStr entry = [(actionmap, context, action, buttonNames), help] if self._filterHelpList(entry, helpSeen): actionMapHelp[amId].append(entry) l = [] extendedPadding = ('', '') if self.extendedHelp else () for (actionmap, context, actions) in helplist: amId = actMapId() if headings and amId in actionMapHelp and getattr(actionmap, "description", None): if sortCmp or sortKey: actionMapHelp[amId].sort(cmp=sortCmp, key=sortKey) self.addListBoxContext(actionMapHelp[amId], indent) l.append((None, actionmap.description, '') + extendedPadding) l.extend(actionMapHelp[amId]) del actionMapHelp[amId] if actionMapHelp: if indent: l.append((None, _("Other functions"), '') + extendedPadding) otherHelp = [] for (actionmap, context, actions) in helplist: amId = actMapId() if amId in actionMapHelp: otherHelp.extend(actionMapHelp[amId]) del actionMapHelp[amId] if sortCmp or sortKey: otherHelp.sort(cmp=sortCmp, key=sortKey) self.addListBoxContext(otherHelp, indent) l.extend(otherHelp) for i, ent in enumerate(l): if ent[0] is not None: for b in ent[0][3]: # Ignore "break" events from # OK and EXIT on return from # help popup if b[0] not in ('OK', 'EXIT'): self.buttonMap[b] = i if self.extendedHelp: self.style = "extended" self.list = l
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) 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 if name is None: continue if flags & 8: name = (name[0], 'long') entry = [(actionmap, context, action, name)] if isinstance(help, list): self.extendedHelp = True print 'extendedHelpEntry found' x, y, w, h = skin.parameters.get('HelpMenuListExtHlp0', (0, 0, 600, 26)) x1, y1, w1, h1 = skin.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 = skin.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 = skin.fonts.get('HelpMenuListExt0', ('Regular', 24, 50)) self.l.setFont(0, gFont(font[0], font[1])) self.l.setItemHeight(font[2]) font = skin.fonts.get('HelpMenuListExt1', ('Regular', 18)) self.l.setFont(1, gFont(font[0], font[1])) else: font = skin.fonts.get('HelpMenuList', ('Regular', 24, 38)) self.l.setFont(0, gFont(font[0], font[1])) self.l.setItemHeight(font[2]) return
def __init__(self, helplist, callback, rcPos=None): screenwidth = getDesktop(0).size().width() GUIComponent.__init__(self) self.onSelChanged = [] self.l = eListboxPythonMultiContent() self.callback = callback self.extendedHelp = False self.rcPos = rcPos self.rcKeyIndex = None self.buttonMap = {} self.longSeen = False 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.help_sortorder.value, (False, None, None)) if rcPos 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(rcPos.getRcKeyList())) width = 640 indent = 0 if headings: for (actionmap, context, actions) in helplist: if actionmap.enabled and getattr(actionmap, "description", None): indent = 20 break buttonsProcessed = set() helpSeen = defaultdict(list) sortedHelplist = sorted(helplist, key=lambda hle: hle[0].prio) actionMapHelp = defaultdict(list) for (actionmap, context, actions) in sortedHelplist: if not actionmap.enabled: continue amId = actMapId() from Screens.ButtonSetup import helpableButtonSetupActionMap isHelpableButtonSetupActionMap = isinstance(actionmap, helpableButtonSetupActionMap) for (action, help) in actions: helpTags = [] if callable(help): help = help() # ButtonSetupButtonActions help looks as though # the button is configurable, but it isn't really if not isHelpableButtonSetupActionMap: helpTags.append('C') if help is None: continue # Ignore inactive ButtonSetupButtonActions if isHelpableButtonSetupActionMap and not help: continue buttons = queryKeyBinding(context, action) # do not display entries which are not accessible from keys if not buttons: continue name = None flags = 0 buttonNames = [] for n in buttons: (name, flags) = (getKeyDescription(n[0]), n[1]) if name is not None and (len(name) < 2 or name[1] not in("fp", "kbd")): if flags & 8: # for long keypresses, make the second tuple item "long". name = (name[0], "long") nlong = (n[0], flags & 8) if nlong not in buttonsProcessed: buttonNames.append(name) buttonsProcessed.add(nlong) # only show non-empty entries with keys that are available on the used rc if not (buttonNames and help): continue if helpTags: helpTagStr = " (" + ", ".join(helpTags) + ")" if isinstance(help, list): help[0] += helpTagStr else: help += helpTagStr entry = [(actionmap, context, action, buttonNames), help] if self._filterHelpList(entry, helpSeen): actionMapHelp[amId].append(entry) l = [] for (actionmap, context, actions) in helplist: amId = actMapId() if headings and amId in actionMapHelp and getattr(actionmap, "description", None): if sortCmp or sortKey: actionMapHelp[amId].sort(cmp=sortCmp, key=sortKey) self.addListBoxContext(actionMapHelp[amId], width, indent) l.append([None, MultiContentEntryText(pos=(0, 0), size=(width, 26), text=actionmap.description)]) l.extend(actionMapHelp[amId]) del actionMapHelp[amId] if actionMapHelp: if indent: l.append([None, MultiContentEntryText(pos=(0, 0), size=(width, 26), text=_("Other functions"))]) otherHelp = [] for (actionmap, context, actions) in helplist: amId = actMapId() if amId in actionMapHelp: otherHelp.extend(actionMapHelp[amId]) del actionMapHelp[amId] if sortCmp or sortKey: otherHelp.sort(cmp=sortCmp, key=sortKey) self.addListBoxContext(otherHelp, width, indent) l.extend(otherHelp) for i, ent in enumerate(l): if ent[0] is not None: for b in ent[0][3]: self.buttonMap[b] = i self.l.setList(l) if self.extendedHelp: self.l.setFont(0, gFont("Regular", 24)) self.l.setFont(1, gFont("Regular", 18)) self.l.setFont(2, gFont("Regular", 30)) self.l.setFont(3, gFont("Regular", 26)) self.l.setItemHeight(50) else: self.l.setFont(0, gFont("Regular", 24)) self.l.setFont(1, gFont("Regular", 30)) self.l.setItemHeight(38)
def __init__(self, helplist, callback, rcPos=None): GUIComponent.__init__(self) self.onSelChanged = [] self.l = eListboxPythonMultiContent() self.callback = callback self.extendedHelp = False self.rcPos = rcPos self.rcKeyIndex = None 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.help_sortorder.value, (False, None, None)) if rcPos 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(rcPos.getRcKeyList())) width = 640 indent = 0 for (actionmap, context, actions) in helplist: if headings and actionmap.enabled and getattr(actionmap, "description", None): indent = 20 break buttonsProcessed = set() helpSeen = defaultdict(list) sortedHelplist = sorted(helplist, key=lambda hle: hle[0].prio) actionMapHelp = defaultdict(list) for (actionmap, context, actions) in sortedHelplist: if not actionmap.enabled: continue for (action, help) in actions: if hasattr(help, '__call__'): help = help() buttons = queryKeyBinding(context, action) # do not display entries which are not accessible from keys if not buttons: continue name = None flags = 0 buttonNames = [] for n in buttons: (name, flags) = (getKeyDescription(n[0]), n[1]) if name is not None and (len(name) < 2 or name[1] not in("fp", "kbd")): if flags & 8: # for long keypresses, make the second tuple item "long". name = (name[0], "long") nlong = (n[0], flags & 8) if nlong not in buttonsProcessed: buttonNames.append(name) buttonsProcessed.add(nlong) # only show entries with keys that are available on the used rc if not buttonNames: continue entry = [(actionmap, context, action, buttonNames), help] if self._filterHelpList(entry, helpSeen): actionMapHelp[context].append(entry) l = [] for (actionmap, context, actions) in helplist: if headings and context in actionMapHelp and getattr(actionmap, "description", None): if sortCmp or sortKey: actionMapHelp[context].sort(cmp=sortCmp, key=sortKey) self.addListBoxContext(actionMapHelp[context], width, indent) l.append([None, MultiContentEntryText(pos=(0, 0), size=(width, 26), text=actionmap.description)]) l.extend(actionMapHelp[context]) del actionMapHelp[context] if actionMapHelp: if indent: l.append([None, MultiContentEntryText(pos=(0, 0), size=(width, 26), text=_("Other functions"))]) otherHelp = [] for (actionmap, context, actions) in helplist: if context in actionMapHelp: otherHelp.extend(actionMapHelp[context]) del actionMapHelp[context] if sortCmp or sortKey: otherHelp.sort(cmp=sortCmp, key=sortKey) self.addListBoxContext(otherHelp, width, indent) l.extend(otherHelp) self.l.setList(l) if self.extendedHelp: self.l.setFont(0, gFont("Regular", 24)) self.l.setFont(1, gFont("Regular", 18)) self.l.setItemHeight(50) else: self.l.setFont(0, gFont("Regular", 24)) self.l.setItemHeight(38)