<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[selection observer]]></title><description><![CDATA[<p dir="auto">Is there a way to observe for changes in selection of points and components?<br />
Tools have a selection object, but how to access it outside a tool?</p>
]]></description><link>https://forum.robofont.com/topic/513/selection-observer</link><generator>RSS for Node</generator><lastBuildDate>Sat, 09 May 2026 14:22:14 GMT</lastBuildDate><atom:link href="https://forum.robofont.com/topic/513.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 27 Sep 2018 18:02:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to selection observer on Fri, 28 Sep 2018 09:53:50 GMT]]></title><description><![CDATA[<p dir="auto">Is there a way to observe for changes in selection of points and components?<br />
Tools have a selection object, but how to access it outside a tool?</p>
]]></description><link>https://forum.robofont.com/post/1721</link><guid isPermaLink="true">https://forum.robofont.com/post/1721</guid><dc:creator><![CDATA[timotimo]]></dc:creator><pubDate>Fri, 28 Sep 2018 09:53:50 GMT</pubDate></item><item><title><![CDATA[Reply to selection observer on Fri, 28 Sep 2018 10:16:09 GMT]]></title><description><![CDATA[<p dir="auto">there is a way to observe selection changes:</p>
<pre><code class="language-python">
class DummyController(object):
    
    def __init__(self):
        self.glyph = CurrentGlyph()
        self.glyph.addObserver(self, "myCallback", "Glyph.SelectionChanged")
        print("done")
    
    def myCallback(self, notification):
        print("Selection Changed")
        
    
DummyController()
</code></pre>
<p dir="auto">don’t forget the <code>removeObserver</code> when you are done...</p>
]]></description><link>https://forum.robofont.com/post/1722</link><guid isPermaLink="true">https://forum.robofont.com/post/1722</guid><dc:creator><![CDATA[frederik]]></dc:creator><pubDate>Fri, 28 Sep 2018 10:16:09 GMT</pubDate></item><item><title><![CDATA[Reply to selection observer on Fri, 28 Sep 2018 11:11:07 GMT]]></title><description><![CDATA[<p dir="auto">But then I have to handle all the glyph changes somehow, like this:</p>
<pre><code>from mojo.events import addObserver, removeObserver, postEvent


class DummyController(object):
    
    def __init__(self):
        self.glyph = CurrentGlyph()
        addObserver(self, "currentGlyphChanged", "currentGlyphChanged")
        self.addSelectionObserver()
    
    def currentGlyphChanged(self, notification):
        self.removeSelectionObserver()
        self.glyph = notification["glyph"]
        self.addSelectionObserver()
        postEvent("selectionChanged")
    
    def glyphSelectionChanged(self, notification):
        postEvent("selectionChanged")
    
    def addSelectionObserver(self):
        if self.glyph is not None:
            self.glyph.addObserver(self, "glyphSelectionChanged", "Glyph.SelectionChanged")
    
    def removeSelectionObserver(self):
        if self.glyph is not None:
            self.glyph.removeObserver(self, "Glyph.SelectionChanged")

    
class DummyObserver():
    
    def __init__(self):
        addObserver(self, "selectionChanged", "selectionChanged")
    
    def selectionChanged(self, notification):
        self.glyph = notification["glyph"]
        if self.glyph is not None:
            print(self.glyph.selectedPoints, self.glyph.selectedComponents)


DummyController()
DummyObserver()
</code></pre>
<p dir="auto">I was thinking there might be something like this already built in.</p>
]]></description><link>https://forum.robofont.com/post/1723</link><guid isPermaLink="true">https://forum.robofont.com/post/1723</guid><dc:creator><![CDATA[timotimo]]></dc:creator><pubDate>Fri, 28 Sep 2018 11:11:07 GMT</pubDate></item></channel></rss>