inspectorWindowWillShowDescriptions?



  • Re: Ability to customize existing Inspector

    I am working on a tool that lives in the inspector window, I think that it's important to note that the tool is dependent on a font and not an individual glyph that inspectorWindowWillShowDescriptions can provide. Anyways, I am running into an issue when a font is open before the inspector window, where the values are not being set despite the function running. I have it set up so the tool's EditText.enable is set to false by default just in case there is no font open when the window is originally opened. I hope this makes sense:) Any help is greatly appreciated!!



  • I'm not sure if I fully understand the issue you're running into, but in Sidebear, the EditText fields react to other observers like glyphChanged and can probably react to the likes of fontWillOpen?



  • Sorry, I knew that made no sense!

    So, my tool displays some custom lib keys, currently, there is no issue with it noticing a new font (this is actually working great). The problem is only when the font is open prior to the inspector window. Even if you close the inspector and re-open, the data isn't being displayed anymore. I tried to use inspectorWindowWillShowDescriptions to trigger the tool to reset the values but no luck. 🤦‍♂️



  • When building Sidebear, I had an issue where I couldn't generate two independent panels at once (with two fonts open). Either the panel would be empty on a new font, or a one panel would be showing information from the glyph in the other font.

    The issue I was running into was a structural problem, and Just van Rossum pointed that out. He put the insertion of the inspector panel into its own independent class. You can see that at the bottom of the code. TBH I still don't quite understand fundamentally why it works now; I would describe it as making each panel object independently of one another, rather than trying to start the same one up again and again.

    ...

    Now, that may not be applicable to your situation, but thought I'd rant about that. One piece that I learned in the process that may clarify things for you: if you're in Single Window Mode, inspectorWindowWillShowDescriptions only runs the first time, I believe when the font itself is opened. If you hide/reveal the inspector, it's doing just that—hiding and revealing—the observer won't be tipped off.

    If you're not in Single Window Mode, and you have the necessary updates under inspectorWindowWillShowDescriptions’s callbacks, then I'm not sure I can help, but happy to look at the code in a less abstract sense.


  • admin

    hello @connor,

    I’ve tried to reproduce the situation you describe in the script below.

    The problem is only when the font is open prior to the inspector window.

    if I understand it correctly, the problem happens because there is no font event triggered after the panel is added. this can be solved by updating the font when the panel is created (see comment).

    from vanilla import Group, TextBox
    from mojo.UI import AccordionView
    from mojo.events import addObserver
    
    class MyCustomPanel:
    
        height = 120
    
        def __init__(self):
            self.w = Group((0, 0, -0, -0))
            self.w.currentFontLabel = TextBox((10, 10, 50, 22), 'font:')
            self.w.currentFont = TextBox((60, 10, -10, 22), '')
            self.w.currentGlyphLabel = TextBox((10, 40, 50, 22), 'glyph:')
            self.w.currentGlyph = TextBox((60, 40, -10, 22), '')
            addObserver(self, "updateFont", "fontBecameCurrent")
            addObserver(self, "updateFont", "fontDidOpen")
            addObserver(self, "updateFont", "fontDidClose")
            addObserver(self, "updateGlyph", "currentGlyphChanged")
            ### update with already open font
            self.updateFont(None)
            self.updateGlyph(None)
    
        def updateFont(self, notification):
            f = CurrentFont()
            fontName = f'{f.info.familyName} {f.info.styleName}' if f else '[none]'
            self.w.currentFont.set(fontName)
    
        def updateGlyph(self, notification):
            g = CurrentGlyph()
            glyphName = g.name if g is not None else '[none]'
            self.w.currentGlyph.set(glyphName)
    
    class PanelInsert:
    
        def __init__(self):
            addObserver(self, "insertPanel", "inspectorWindowWillShowDescriptions")
    
        def insertPanel(self, notification):
            print('adding custom panel')
            title = "My Panel"
            myPanel = MyCustomPanel()
            item = dict(label=title, view=myPanel.w, size=myPanel.height, collapsed=False, canResize=False)
            if notification["descriptions"][1]['label'] == title:
                del notification["descriptions"][1]
            notification["descriptions"].insert(1, item)
    
    PanelInsert()
    

    I hope this makes sense! cheers



  • Oh my, I really did overthink the issue — reorganizing my functions just a little and adding the
    self.updateFont(None) solved it!!
    Thanks for the help, Gustavo!


Log in to reply