SOLVED How to create Short Key popover?



  • Hey Guys,
    (I hope it is not some big RF secret)
    I was wandering how to make something this (list + the popover with given keystrokes)?:
    Screenshot 2019-07-18 at 13.15.48.png

    I wanted be able to interpret key strokes with the fancy modifying-key-icons.



  • oh my god, I'm really blind o_O


  • admin

    be careful with your naming :)

    from lib.UI.fileBrowser import RFShortKeyCell, shortKeyToString
    from vanilla import *
    from AppKit import *
    
    class ListDemo(object):
    
        def __init__(self):
            columnDescriptions = [
                    dict(title='name'),
                    dict(title='shortKey', cell=RFShortKeyCell(self.shortKeyCallback, ignoreErrors=False)),
                ]
            modifiers = NSCommandKeyMask | NSShiftKeyMask
            self.w = Window((100, 100))
            self.w.myList = List((0, 0, -0, -0),
                         [{"name": "A",'shortKey': [modifiers, 'a']}, {"name": "B",'shortKey': [modifiers, 'a']}],
                         columnDescriptions=columnDescriptions,
                         )
            self.w.open()
    
        def shortKeyCallback(self, sender):
            print(sender)
    
    ListDemo()
    


  • hmm, now I'm getting this error in the log file (RF crashes):

    Traceback (most recent call last):
    File "lib/UI/fileBrowser.pyc", line 429, in drawWithFrame_inView_
    File "objc/_convenience_mapping.pyc", line 18, in __getitem__objectForKey_
    File "objc/_convenience.pyc", line 101, in container_unwrap
    KeyError: 'shortKey'
    

    Here is my code:

    from lib.UI.fileBrowser import RFShortKeyCell, shortKeyToString
    from vanilla import *
    from AppKit import *
    
    class ListDemo(object):
    
        def __init__(self):
            columnDescriptions = [
                    dict(title='name'),
                    dict(title='key', cell=RFShortKeyCell(self.shortKeyCallback, ignoreErrors=False)),
                ]
            modifiers = NSCommandKeyMask | NSShiftKeyMask
            self.w = Window((100, 100))
            self.w.myList = List((0, 0, -0, -0),
                         [{"name": "A",'key': [modifiers, 'a']}, {"name": "B",'shortKey': [modifiers, 'a']}],
                         columnDescriptions=columnDescriptions,
                         )
            self.w.open()
    
        def shortKeyCallback(self, sender):
            print(sender)
    
    ListDemo()
    


  • cool, thanks!


  • admin

    oh yeah, must be a tuple:

    (modifiers, character)
    

    where modifiers is:

    modifiers = AppKit.NSCommandKeyMask | AppKit.NSShiftKeyMask
    character = "m"
    

    this will create a shortcut for cmd + shift + m



  • Another question: how to implement entry for this cell? I'm getting shortKeyToString errors every time I'm testing different values.

    from lib.UI.fileBrowser import RFShortKeyCell
    from vanilla import *
    
    class ListDemo(object):
    
        def __init__(self):
            columnDescriptions = [
                    dict(title='name'),
                    dict(title='key', cell=RFShortKeyCell(self.shortKeyCallback, ignoreErrors=False)),
                ]
            shortkey1 = None ### ???
            shortkey2 = None ### ???
            self.w = Window((100, 100))
            self.w.myList = List((0, 0, -0, -0),
                         [{"name": "A",'key': shortkey1}, {"name": "B",'key': shortkey2}],
                         columnDescriptions=columnDescriptions,
                         )
            self.w.open()
    
    
        def shortKeyCallback(self, sender):
            print(sender)
    
    ListDemo()
    

  • admin

    its a vanilla List cell used in the column descriptions

    from lib.UI.fileBrowser import RFShortKeyCell
    
    cell = RFShortKeyCell(callback, ignoreErrors=True)
    

    ignoreErrors will show if its not possible to make the key or when there is a duplicated key

    good luck with the secrets!