SOLVED help claims that guideline.selected exists but does not



  • I know that this is probably not a way how to get active guideline, but the help says it is.

    g = CurrentGlyph()
    for guideline in g.guidelines:
        help(guideline)
        #print(guideline.selected)
        break
    
     |  Data descriptors inherited from fontParts.base.base.SelectionMixin:
     |  
     |  selected
     |      The object's selection state.
     |      
     |          >>> obj.selected
     |          False
     |          >>> obj.selected = True
    


  • hello @jansindl3r,

    the current guideline is only available from an interactive tool.

    here’s an example: (shift-click guide to flip direction)

    from mojo.events import EditingTool, installTool
    
    class FlipGuideTool(EditingTool):
        
        def getToolbarTip(self):
            return "flip guide"
    
        def mouseDown(self, point, clickCount):
            g = CurrentGlyph()
            guides = CurrentGuidelines()
            if guides and self.shiftDown:
                guides[0].angle += 90
    
    installTool(FlipGuideTool())
    

    cheers!



  • Maybe it is not clear to me, but should be the active guideline in the sender argument of function testje? I want to right click the guideline and flip it horizontally or vertically.

    from mojo.events import addObserver, clearObservers
    # clearObservers()
    class Test(object):
        
        def __init__(self):
            
            addObserver(self, "guideAdditionContextualMenuItems", "guideAdditionContextualMenuItems")
            
        def guideAdditionContextualMenuItems(self, notification):
            myMenuItems = [
                ("testje", self.testje), 
                ]
            notification["additionContextualMenuItems"].extend(myMenuItems)
        
        def testje(self, sender):
            print(dir(sender))
    
    Test()
    

  • admin

    you can add a item in the guideline contextual menu by subscribing to the notification: guideAdditionContextualMenuItems and append a tuple of (menu titles, callback) to additionContextualMenuItems key in the notification object.

    see https://robofont.com/documentation/building-tools/api/custom-observers/#RoboFont observers.guideAdditionContextualMenuItems



  • how do you get the activated guideline, then? If I right click and want to have contextual action for this specific guideline? right clicked == dragged?


  • admin

    in RF a guide is only selected during a drag... so in all other cases they are not selected!



  • hi @jansindl3r,

    guidelines currently don’t implement the selected attribute in RF.

    not sure if there’s a reason behind it… seems like it could be useful? @frederik

    thanks!