Skip to content

Instantly share code, notes, and snippets.

@typemytype
typemytype / implementation.py
Created September 4, 2017 13:19
implementation proposal
import weakref
class ImplementationError(Exception):
pass
def _implementation_get(cls):
def wrapped(superObject):
attr = "__implementationObject_%s" % cls.owner
@typemytype
typemytype / takeScreenshotAndSaveIt.py.py
Last active June 15, 2017 20:41
take screenshot and save it
import Quartz
import AppKit
from mojo.UI import CurrentSpaceCenterWindow
# a path where to save the screenshot
path = u"~/Documents/test.png"
# get the space center window
sp = CurrentSpaceCenterWindow()
@typemytype
typemytype / adForPainting.py
Last active June 3, 2017 00:46
ad for painting in drawBot
amount = 10
s = 20
dotInset = 4
im = ImageObject()
path = BezierPath()
path.moveTo((0, 0))
path.lineTo((0, s))
path.lineTo((s, s))
class Implementation(object):
def __init__(self, tag):
self._tag = tag
self._instance = None
def __getattr__(self, attr):
attr = "_%s_%s" % (self._tag, attr)
return getattr(self._instance, attr)
class Implementation(object):
"""
Implementation object collection all methods for a given implementation
"""
def __init__(self):
self.funcMap = {}
self._currentInstance = None
# custom directives
from docutils import nodes
from docutils.statemachine import ViewList
from sphinx import addnodes
from sphinx.util import rst
from docutils.parsers.rst import directives
from sphinx.ext.autosummary import Autosummary, import_by_name, get_import_prefixes_from_env, autosummary_table
class MetaMock(type):
def __getattr__(self, name):
return self
class Mock(object):
__metaclass__ = MetaMock
@typemytype
typemytype / setFileExtensionDefaultApp.py
Last active January 16, 2017 11:54
set the default app by file extension in python
import LaunchServices
import AppKit
fileExtension = "thisShouldBeACoolFile" # file extension
UTI = LaunchServices.UTTypeCreatePreferredIdentifierForTag(LaunchServices.kUTTagClassFilenameExtension, fileExtension, None)
r = LaunchServices.LSSetDefaultRoleHandlerForContentType(UTI, LaunchServices.kLSRolesAll, AppKit.NSBundle.mainBundle().bundleIdentifier())
if r != 0:
print "oeps"
from ufoLib.pointPen import AbstractPointPen
from defcon.pens.transformPointPen import TransformPointPen
from defcon.objects.component import _defaultTransformation
class DecomposePointPen(object):
def __init__(self, glyphSet, outPointPen):
self._glyphSet = glyphSet
self._outPointPen = outPointPen
@typemytype
typemytype / exportToAFM.py
Created May 24, 2016 16:13
export kerning to afm
from fontTools.afmLib import AFM
from ufo2fdk.fontInfoData import getFontBounds
from ufo2fdk.fontInfoData import getAttrWithFallback
from robofab.interface.all.dialogs import PutFile
def buildFlatKerningWithGroupsAndKerning(groups, kerning):
flat = {}
keys = sorted(kerning.keys())