def create_cgpath(frame): newPath = CGPathCreateMutable() CGPathMoveToPoint(newPath, None, 0, 0) CGPathAddLineToPoint(newPath, None, frame.size.width, 0) CGPathAddLineToPoint(newPath, None, 0, frame.size.height) CGPathCloseSubpath(newPath) return newPath
def shake(self, the_window): '''Uses CoreAnimation to "shake" the alert window''' # adapted from here: # http://stackoverflow.com/questions/10517386/how-to-give-nswindow-a-shake-effect-as-saying-no-as-in-login-failure-window/23491643#23491643 numberOfShakes = 3 durationOfShake = 0.5 vigourOfShake = 0.05 frame = the_window.frame() shakeAnimation = CAKeyframeAnimation.animation() shakePath = CGPathCreateMutable() CGPathMoveToPoint(shakePath, None, NSMinX(frame), NSMinY(frame)) for index in range(numberOfShakes): CGPathAddLineToPoint( shakePath, None, NSMinX(frame) - frame.size.width * vigourOfShake, NSMinY(frame)) CGPathAddLineToPoint( shakePath, None, NSMinX(frame) + frame.size.width * vigourOfShake, NSMinY(frame)) CGPathCloseSubpath(shakePath) shakeAnimation.setPath_(shakePath) shakeAnimation.setDuration_(durationOfShake) the_window.setAnimations_({'frameOrigin': shakeAnimation}) the_window.animator().setFrameOrigin_(frame.origin)
def textBoxBaseLines(self, txt, box): x, y, w, h = box attrString = txt.getNSObject() setter = CTFramesetterCreateWithAttributedString(attrString) path = CGPathCreateMutable() CGPathAddRect(path, None, CGRectMake(*box)) box = CTFramesetterCreateFrame(setter, (0, 0), path, None) ctLines = CTFrameGetLines(box) origins = CTFrameGetLineOrigins(box, (0, len(ctLines)), None) return [(x + o.x, y + o.y) for o in origins]
def move(self, pos_tpl, duration=None, **kwargs): """ Move the input's position by move_x and move_y units This change is permanent/saved. If you want non-saved move use the translate* animations """ curr_x = self.animationLayer.position().x curr_y = self.animationLayer.position().y def vmk(val): new_coord = self.real_coordinate_from_fract(val[0], val[1]) return NSPoint(curr_x + new_coord.x, curr_y + new_coord.y) anim_vals = self.make_animation_values(NSPoint(curr_x, curr_y), pos_tpl, vmk) path = CGPathCreateMutable() CGPathAddLines(path, None, anim_vals, len(anim_vals)) ret = self.moveTo(anim_vals, duration, **kwargs) CGPathCloseSubpath(path) #CGPathRelease(path) return ret
def getTextLines(self, w, h=None, align=LEFT): """Answers the dictionary of TextLine instances. Key is y position of the line. >>> from pagebot.toolbox.units import mm, uRound >>> from drawbotcontext import DrawBotContext >>> context = DrawBotContext() >>> style = dict(font='Verdana', fontSize=pt(12)) >>> bs = context.newString('Example Text ' * 10, style=style) >>> lines = bs.getTextLines(w=200) >>> len(lines) 5 >>> line = lines[0] >>> line.maximumLineHeight 1.4em >>> """ assert w if not h: h = XXXL wpt, hpt = upt(w, h) textLines = [] attrString = self.s.getNSObject() setter = CTFramesetterCreateWithAttributedString(attrString) path = CGPathCreateMutable() CGPathAddRect(path, None, CGRectMake(0, 0, wpt, hpt)) ctBox = CTFramesetterCreateFrame(setter, (0, 0), path, None) ctLines = CTFrameGetLines(ctBox) origins = CTFrameGetLineOrigins(ctBox, (0, len(ctLines)), None) for lIndex, ctLine in enumerate(ctLines): origin = origins[lIndex] textLine = TextLine(ctLine, pt(origin.x), pt(origin.y), lIndex) textLines.append(textLine) return textLines
def create_cgpath(frame): newpath = CGPathCreateMutable() CGPathAddArc(newpath, None, 0,0, math.sqrt(frame.size.width**2 + frame.size.height**2)/2, math.radians(90), 0, True) CGPathAddLineToPoint(newpath, None, 0,0) return newpath
context.newDrawing() context.newPage(W, H) x = 0 y = 0 context.text('(%s, %s)' % (x, y), (x, y)) x = W / 2 y = H - hbox context.text('(%s, %s)' % (x, y), (x, y)) b = blurb.getBlurb('stylewars_documentary')[:200] font = findFont('Bungee-Regular') style = dict(font=font, fontSize=pt(18), textFill=color(0.5, 1, 0)) bs = context.newString(b, style=style) lines = bs.getTextLines(w=wbox, h=hbox) attrString = bs.s.getNSObject() setter = CTFramesetterCreateWithAttributedString(attrString) path = CGPathCreateMutable() CGPathAddRect(path, None, CGRectMake(0, 0, wbox, hbox)) ctBox = CTFramesetterCreateFrame(setter, (0, 0), path, None) ctLines = CTFrameGetLines(ctBox) origins = CTFrameGetLineOrigins(ctBox, (0, len(ctLines)), None) context.fill(None) context.stroke(f) context.rect(PADDING, H, wbox, -hbox) context.fill(f) for p in origins: context.circle(PADDING + p.x + 2, (p.y + 2), 4) print(p.y) y = H - LINE
def create_cgpath(frame): newpath = CGPathCreateMutable() CGPathAddEllipseInRect(newpath, None, frame) return newpath