<?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[Keep reference to an arbitrary vanilla window for later use]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I'm trying to find a window by assigning a <code>__name__</code> attribute to it. This used to work in RF1. Could you please direct me on how to get the window using the below example in RF3?</p>
<pre><code class="language-python">from mojo.roboFont import OpenWindow
from vanilla import *

WIN_KEY = 'test'

class WindowDemo(object):
    __name__ = WIN_KEY
    def __init__(self):
        self.w = Window((200, 70), "Window Demo")
        self.w.open()

def GetWindow(key):
	from AppKit import NSApp
	for w in NSApp().orderedWindows():
		delegate = w.delegate()
		if delegate:
			if not hasattr(delegate, "vanillaWrapper"):
				continue
			vanillaWrapper = delegate.vanillaWrapper()
			if hasattr(vanillaWrapper, "__name__") and vanillaWrapper.__name__ == key:
				return vanillaWrapper.w

OpenWindow(WindowDemo)
print(GetWindow(WIN_KEY))
</code></pre>
]]></description><link>https://forum.robofont.com/topic/745/keep-reference-to-an-arbitrary-vanilla-window-for-later-use</link><generator>RSS for Node</generator><lastBuildDate>Tue, 11 Aug 2026 11:19:48 GMT</lastBuildDate><atom:link href="https://forum.robofont.com/topic/745.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 19 Nov 2019 15:37:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Keep reference to an arbitrary vanilla window for later use on Tue, 19 Nov 2019 17:37:55 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I'm trying to find a window by assigning a <code>__name__</code> attribute to it. This used to work in RF1. Could you please direct me on how to get the window using the below example in RF3?</p>
<pre><code class="language-python">from mojo.roboFont import OpenWindow
from vanilla import *

WIN_KEY = 'test'

class WindowDemo(object):
    __name__ = WIN_KEY
    def __init__(self):
        self.w = Window((200, 70), "Window Demo")
        self.w.open()

def GetWindow(key):
	from AppKit import NSApp
	for w in NSApp().orderedWindows():
		delegate = w.delegate()
		if delegate:
			if not hasattr(delegate, "vanillaWrapper"):
				continue
			vanillaWrapper = delegate.vanillaWrapper()
			if hasattr(vanillaWrapper, "__name__") and vanillaWrapper.__name__ == key:
				return vanillaWrapper.w

OpenWindow(WindowDemo)
print(GetWindow(WIN_KEY))
</code></pre>
]]></description><link>https://forum.robofont.com/post/2799</link><guid isPermaLink="true">https://forum.robofont.com/post/2799</guid><dc:creator><![CDATA[bahman]]></dc:creator><pubDate>Tue, 19 Nov 2019 17:37:55 GMT</pubDate></item><item><title><![CDATA[Reply to Keep reference to an arbitrary vanilla window for later use on Tue, 19 Nov 2019 17:42:39 GMT]]></title><description><![CDATA[<p dir="auto">hello <a class="plugin-mentions-user plugin-mentions-a" href="https://forum.robofont.com/uid/80">@bahman</a>,</p>
<p dir="auto">you have to set the <code>vanillaWrapper</code> yourself while creating the window controller, and connect it with a <a href="http://docs.python.org/3/library/weakref.html" rel="nofollow">weakref</a>:</p>
<pre><code class="language-python">self.w.vanillaWrapper = weakref.ref(self)
</code></pre>
<p dir="auto">thanks <a class="plugin-mentions-user plugin-mentions-a" href="https://forum.robofont.com/uid/1">@frederik</a> for answering it :)</p>
<p dir="auto">cheers!</p>
]]></description><link>https://forum.robofont.com/post/2801</link><guid isPermaLink="true">https://forum.robofont.com/post/2801</guid><dc:creator><![CDATA[gferreira]]></dc:creator><pubDate>Tue, 19 Nov 2019 17:42:39 GMT</pubDate></item><item><title><![CDATA[Reply to Keep reference to an arbitrary vanilla window for later use on Tue, 19 Nov 2019 18:47:19 GMT]]></title><description><![CDATA[<p dir="auto">Great question, I've been wanting to figure how to do this for a while. I made a pair of scripts to test how it would work to get input from one window into another. It works, but things break if I remove the Button from the Set window.</p>
<pre><code>from vanilla import Window, EditText, Button
import weakref

WIN_KEY = 'VanillaObjectWindow'

class setVanillaObject(object):

    __name__ = WIN_KEY  
    def __init__(self):
        self.windowname = 'Set'
        self.w = Window((333, 80), self.windowname)
        self.w.vanillaWrapper = weakref.ref(self)
        self.w.zzzzzzzz = EditText((12, 10, -12, 22), 'Placeholder Placeholder Placeholder')
        self.w.b = Button((12, 34, -12, 22), 'Button', callback=self.do) # doesn't work without this ??
        self.w.open()

    def do(self, sender):
        print(self.w)

setVanillaObject()
</code></pre>
<pre><code>from vanilla import Window, Button, EditText
from AppKit import NSApp

WIN_KEY = 'VanillaObjectWindow'

class getVanillaObject(object):

    def __init__(self):
        self.windowname = 'Get'
        self.w = Window((333, 70), self.windowname)
        self.w.t = EditText((12, 10, -12, 22), '...')
        self.w.b =   Button((12, 34, -12, 22), 'Get Placeholder from Set', callback=self.do)
        self.w.open()

    def do(self, sender):
        w = GetWindow(WIN_KEY)
        x = w.zzzzzzzz.get()
        self.w.t.set(x)

def GetWindow(key):
    from AppKit import NSApp
    for w in NSApp().orderedWindows():
        delegate = w.delegate()
        if delegate:
            if not hasattr(delegate, "vanillaWrapper"):
                continue
            vanillaWrapper = delegate.vanillaWrapper()
            if hasattr(vanillaWrapper, "__name__") and vanillaWrapper.__name__ == key:
                return vanillaWrapper.w

getVanillaObject()
</code></pre>
]]></description><link>https://forum.robofont.com/post/2803</link><guid isPermaLink="true">https://forum.robofont.com/post/2803</guid><dc:creator><![CDATA[okaytype]]></dc:creator><pubDate>Tue, 19 Nov 2019 18:47:19 GMT</pubDate></item><item><title><![CDATA[Reply to Keep reference to an arbitrary vanilla window for later use on Tue, 19 Nov 2019 20:54:56 GMT]]></title><description><![CDATA[<p dir="auto">wait ... a ... second! this is bad coding :)</p>
<p dir="auto">if two views needs to know something from each other much better to send a notification and retrieve data from there.</p>
]]></description><link>https://forum.robofont.com/post/2804</link><guid isPermaLink="true">https://forum.robofont.com/post/2804</guid><dc:creator><![CDATA[frederik]]></dc:creator><pubDate>Tue, 19 Nov 2019 20:54:56 GMT</pubDate></item><item><title><![CDATA[Reply to Keep reference to an arbitrary vanilla window for later use on Tue, 19 Nov 2019 21:05:19 GMT]]></title><description><![CDATA[<p dir="auto">Well that doesn't surprise me since I have no idea what I'm doing. I'll read up on notifications. It would be helpful to know why this is bad though.</p>
]]></description><link>https://forum.robofont.com/post/2805</link><guid isPermaLink="true">https://forum.robofont.com/post/2805</guid><dc:creator><![CDATA[okaytype]]></dc:creator><pubDate>Tue, 19 Nov 2019 21:05:19 GMT</pubDate></item></channel></rss>