Skip to content

Instantly share code, notes, and snippets.

@okay-type
Created April 20, 2020 14:39
Show Gist options
  • Save okay-type/38d270d047abcdadd46072fcff2d28b4 to your computer and use it in GitHub Desktop.
Save okay-type/38d270d047abcdadd46072fcff2d28b4 to your computer and use it in GitHub Desktop.
Refireable Tiny Script Window
# menuTitle : Tiny Script Window
from vanilla import Window
from lib.scripting.scriptingWindow import PyTextEditor, OutPutEditor
from mojo.events import addObserver, removeObserver
class tinyScriptWin(object):
def __init__(self):
self.w = Window((640, 480), minSize=(200, 200))
self.w.editor = PyTextEditor((0, 0, 0, -200), "print('test')")
self.w.output = OutPutEditor((0, -200, -0, -0), readOnly=True)
self.w.editor.setOutputView_(self.w.output)
self.w.bind("close", self.windowClose)
self.w.open()
addObserver(self, 'trigger', 'tinyScriptWindow')
def windowClose(self, sender):
removeObserver(self, 'tinyScriptWindow')
def trigger(self, notification):
if notification['trigger'] == 'fire':
self.w.editor.run()
tinyScriptWin()
# menuTitle : Tiny Script Fire
# shortCut : command+p
from mojo.events import postEvent
postEvent('tinyScriptWindow', trigger='fire')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment