Skip to content

Instantly share code, notes, and snippets.

@typemytype
typemytype / sheetDemo.py
Created March 8, 2013 08:50
extend vanilla sheet demo
from vanilla import *
class SheetDemo(object):
def __init__(self, parentWindow):
self.w = Sheet((200, 100), parentWindow)
self.w.myButton = Button((10, 10, -10, 20), "My Button")
self.w.myTextBox = TextBox((10, 40, -10, 17), "My Text Box")
self.w.closeButton = Button((10, -30, 80, 22), "Close", self.closeCallback)
self.w.open()
@typemytype
typemytype / vanillaPopover.py
Last active February 17, 2016 07:27
A vanilla Popover proposal
from AppKit import *
from vanilla.vanillaBase import _setAttr, _delAttr, VanillaBaseObject
_edgeMap = {
"left" : NSMinXEdge,
"right" : NSMaxXEdge,
"top" : NSMinYEdge,
"bottom" : NSMaxYEdge
}
@typemytype
typemytype / swapper.py
Created March 3, 2014 16:20
swap bottom/top part of all glyphs in a font :)
g = CurrentGlyph()
f = CurrentFont()
for g in f:
box = g.box
if box is None:
from fontTools.pens.basePen import BasePen
class MyPen(BasePen):
def _moveTo(self, pt):
print "move to", pt
def _lineTo(self, pt):
print "line to", pt
@typemytype
typemytype / reconvertSplinePointPen.py
Created April 6, 2014 20:50
ReconvertSplinePointPen
from robofab.pens.pointPen import AbstractPointPen, PrintingPointPen
from robofab.pens.adapterPens import SegmentToPointPen
from lib.tools.bezierTools import intersectRayRay
class ReconvertSplinePointPen(AbstractPointPen):
def __init__(self, outPointPen):
self.outPointPen = outPointPen
def beginPath(self):
@typemytype
typemytype / spaceCenterButtonAdder.py
Created May 3, 2014 07:45
Add buttons to a Space Center
from mojo.UI import CurrentSpaceCenter
from vanilla import *
class AddButtonToSpaceCenter:
def __init__(self):
sp = CurrentSpaceCenter()
l, t, w, h = sp.top.glyphLinePreInput.getPosSize()
sp.top.glyphLinePreInput.setPosSize((l + 50, t, w, h))
@typemytype
typemytype / getCreationModDate.py
Created June 25, 2014 12:02
get file creation and mod date
path = u"path/to/file"
from AppKit import *
fm = NSFileManager.defaultManager()
attr, error = fm.attributesOfItemAtPath_error_(path, None)
print attr[NSFileCreationDate]
print attr[NSFileModificationDate]
from fontTools.pens.basePen import BasePen
def pointOnCurve(p1, c1, c2, p2, value):
dx = p1[0]
cx = (c1[0] - dx) * 3.0
bx = (c2[0] - c1[0]) * 3.0 - cx
ax = p2[0] - dx - cx - bx
dy = p1[1]
cy = (c1[1] - dy) * 3.0
@typemytype
typemytype / autoConstraintsProposal.py
Created November 3, 2014 20:21
auto layout contraints proposal
import vanilla
from AppKit import *
"""
for the demo some vanilla objects are subclassed
- the main change would be in the VanillaBaseObject
- a window, sheet, group, popover (all elements that can set vanillaObjects) could have a addConstraints attribute
- map the attribute name and the view automatically whenever the posSize is "auto"
- the constraint cannot be a replacement of the posSize cause it the constraint Visual Format Language is a discription of a complete UI.
@typemytype
typemytype / previewer.py
Created November 6, 2014 08:16
drawBot in RoboFont
from drawBot import *
from drawBot.ui.drawView import DrawView
from vanilla import *
class Previewer(object):
def __init__(self):
# setup the window
self.w = Window((400, 400), "Previewer", minSize=(200, 200))