def __init__(self): bgColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(255, 255, 255, 255) buttonColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(0, 0, 0, 255) self.w = Window((1000, 400), 'Interpolation Matrix', minSize=(470, 300)) self.w.getNSWindow().setBackgroundColor_(bgColor) self.w.glyphTitle = Box((10, 10, 200, 30)) self.w.glyphName = TextBox((20, 15, 190, 20), 'No current glyph') # self.w.fontList = PopUpButton() self.axesGrid = {'horizontal': 3, 'vertical': 1} self.masters = [] self.instanceSpots = [] self.mutator = None self.currentGlyph = None self.buildMatrix((self.axesGrid['horizontal'], self.axesGrid['vertical'])) self.w.addColumn = SquareButton((-80, 10, 30, 30), u'+', callback=self.addColumn) self.w.removeColumn = SquareButton((-115, 10, 30, 30), u'-', callback=self.removeColumn) self.w.addLine = SquareButton((-40, -40, 30, 30), u'+', callback=self.addLine) self.w.removeLine = SquareButton((-40, -70, 30, 30), u'-', callback=self.removeLine) for button in [self.w.addColumn, self.w.removeColumn, self.w.addLine, self.w.removeLine]: button.getNSButton().setBezelStyle_(10) self.w.clearMatrix = Button((220, 15, 70, 20), 'Clear', callback=self.clearMatrix) self.w.generate = Button((300, 15, 100, 20), 'Generate', callback=self.instanceGeneration) # self.w.saveMatrix = Button((300, 15, 70, 20), 'Save', callback=self.saveMatrix) # self.w.loadMatrix = Button((380, 15, 70, 20), 'Load', callback=self.loadMatrix) addObserver(self, 'updateMatrix', 'currentGlyphChanged') addObserver(self, 'updateMatrix', 'fontDidClose') addObserver(self, 'updateMatrix', 'mouseUp') addObserver(self, 'updateMatrix', 'keyUp') self.w.bind('close', self.windowClose) self.w.bind('resize', self.windowResize) self.w.open()
def __init__(self): bgColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(255, 255, 255, 255) buttonColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(0, 0, 0, 255) self.w = Window((1000, 400), 'Interpolation Matrix', minSize=(470, 300)) self.w.getNSWindow().setBackgroundColor_(bgColor) self.w.glyphTitle = Box((10, 10, 200, 30)) self.w.glyphTitle.name = EditText((5, 0, -5, 20), 'No current glyph', self.changeGlyph, continuous=False) glyphEdit = self.w.glyphTitle.name.getNSTextField() glyphEdit.setBordered_(False) glyphEdit.setBackgroundColor_(Transparent) glyphEdit.setFocusRingType_(NSFocusRingTypeNone) self.axesGrid = {'horizontal': 3, 'vertical': 1} self.masters = [] self.instanceSpots = [] self.mutator = None self.currentGlyph = None self.errorGlyph = errorGlyph() self.buildMatrix((self.axesGrid['horizontal'], self.axesGrid['vertical'])) self.w.addColumn = SquareButton((-80, 10, 30, 30), u'+', callback=self.addColumn) self.w.removeColumn = SquareButton((-115, 10, 30, 30), u'-', callback=self.removeColumn) self.w.addLine = SquareButton((-40, -40, 30, 30), u'+', callback=self.addLine) self.w.removeLine = SquareButton((-40, -70, 30, 30), u'-', callback=self.removeLine) for button in [self.w.addColumn, self.w.removeColumn, self.w.addLine, self.w.removeLine]: button.getNSButton().setBezelStyle_(10) self.w.clearMatrix = Button((220, 15, 70, 20), 'Clear', callback=self.clearMatrix) self.w.generate = Button((300, 15, 100, 20), 'Generate', callback=self.instanceGeneration) # self.w.saveMatrix = Button((300, 15, 70, 20), 'Save', callback=self.saveMatrix) # self.w.loadMatrix = Button((380, 15, 70, 20), 'Load', callback=self.loadMatrix) addObserver(self, 'updateMatrix', 'currentGlyphChanged') addObserver(self, 'updateMatrix', 'fontDidClose') addObserver(self, 'updateMatrix', 'mouseUp') addObserver(self, 'updateMatrix', 'keyUp') self.w.bind('close', self.windowClose) self.w.bind('resize', self.windowResize) self.w.open()
def __init__(self, drawGrid=False): self.w = Window((600, 500), "", minSize=(300, 250)) grp = Group((0, 0, 0, 0)) grp.button = Button((10, 10, -10, 20), "Toggle", self.buttonCallback) self.view1 = TestSplitSubview((0, 0, 0, 0), NSColor.redColor()) paneDescriptions2 = [ dict(view=self.view1, canCollapse=True, size=50, identifier="pane1"), dict(view=grp, identifier="pane2"), dict(view=TestSplitSubview((0, 0, 0, 0), NSColor.greenColor()), minSize=50, identifier="pane3"), dict(view=TestSplitSubview((0, 0, 0, 0), NSColor.yellowColor()), identifier="pane4"), ] self.nestedSplit = SplitView((0, 0, 0, 0), paneDescriptions2, isVertical=True) paneDescriptions1 = [ dict(view=self.nestedSplit, identifier="pane5"), dict( view=TestSplitSubview((0, 0, 0, 0), NSColor.magentaColor()), minSize=100, size=100, canCollapse=True, identifier="pane6", ), ] self.w.splitView = SplitView((10, 10, -10, -10), paneDescriptions1, isVertical=False) if drawGrid: self.drawGrid() self.w.open()
def _drawUnspecified(self, position, kind, size, vector=(-1, 1)): if vector is None: vector = (-1, 1) angle = atan2(vector[1], vector[0]) circle_size = size * 1.3 x, y = position NSColor.colorWithCalibratedRed_green_blue_alpha_(0.9, 0.1, 0.0, 0.85).set() t = NSAffineTransform.transform() t.translateXBy_yBy_(x, y) t.rotateByRadians_(angle) myPath = NSBezierPath.alloc().init() myPath.setLineWidth_(0) myPath.appendBezierPathWithOvalInRect_( NSMakeRect(x - 0.5 * circle_size, y - 0.5 * circle_size, circle_size, circle_size)) myPath.stroke() if self.show_labels or distance_between_points(self.mouse_position, position) < size: self._drawTextLabel( transform=t, text=kind, size=size, angle=angle, )
def setPixel(self, event, dragging=False): if self.data is None: return False try: editView = self.editViewController().graphicView() except: return False layer = editView.activeLayer() try: master = layer.parent.parent.masters[layer.layerId] except KeyError: return False if master is None: return False # Get location of click in font coordinates Loc = editView.getActiveLocation_(event) loc_pixel = ((Loc.x - self.rect.origin.x) / self.pixel_size, (Loc.y - self.rect.origin.y) / self.pixel_size / self.pixel_ratio) if self.prev_location != loc_pixel: x, y = loc_pixel current = NSGraphicsContext.currentContext() context = NSGraphicsContext.graphicsContextWithBitmapImageRep_( self.data) if context is None: self.prev_location = loc_pixel print("Could not get context in setPixel") return False NSGraphicsContext.saveGraphicsState() NSGraphicsContext.setCurrentContext_(context) if self.erase: NSColor.whiteColor().set() else: NSColor.blackColor().set() effective_size = self.pen_size / self.pixel_size if dragging and self.prev_location is not None: px, py = self.prev_location path = NSBezierPath.alloc().init() path.setLineCapStyle_(NSRoundLineCapStyle) path.setLineWidth_(effective_size) # path.strokeLineFromPoint_toPoint_(x, y, x + self.pen_size, y + self.pen_size) path.moveToPoint_((px, py)) path.lineToPoint_((x, y)) path.stroke() self.needs_save = True else: half = effective_size / 2 rect = NSMakeRect(x - half, y - half, effective_size, effective_size) path = NSBezierPath.bezierPathWithOvalInRect_(rect) path.fill() self.needs_save = True # For rectangular pens: # NSBezierPath.fillRect_(rect) NSGraphicsContext.setCurrentContext_(current) NSGraphicsContext.restoreGraphicsState() self.prev_location = loc_pixel return True
def drawWithFrame_inView_(self, frame, view): row = view.selectedRow() columnCount = len(view.tableColumns()) frames = [ view.frameOfCellAtColumn_row_(i, row) for i in range(columnCount) ] selected = frame in frames (x, y), (w, h) = frame y += 1 h -= 2 if selected: pillTextAttributes[NSForegroundColorAttributeName] = self._color foregroundColor = NSColor.whiteColor() else: pillTextAttributes[ NSForegroundColorAttributeName] = NSColor.whiteColor() foregroundColor = self._color text = self.title() text = NSAttributedString.alloc().initWithString_attributes_( text, pillTextAttributes) textRect = text.boundingRectWithSize_options_((w, h), 0) (textX, textY), (textW, textH) = textRect foregroundColor.set() path = NSBezierPath.bezierPath() radius = h / 2.0 path.appendBezierPathWithOvalInRect_(((x, y), (h, h))) path.appendBezierPathWithOvalInRect_(((x + textW - 1, y), (h, h))) path.appendBezierPathWithRect_(((x + radius, y), (textW - 1, h))) path.fill() text.drawInRect_(((x + radius, y), (textW, textH)))
def __init__(self,): self.w = FloatingWindow((self._width, self._height), self._title, closable=False) self._all_fonts = AllFonts() for f in self._all_fonts: self._all_fonts_names.append(get_full_name(f)) # source font self.w._source_label = TextBox((self._padding, self._padding_top, -self._padding, 17), "source font:") self.w._source_value = PopUpButton((self._padding, 35, -self._padding, 20), self._all_fonts_names) # mark source self.w.mark_source_checkbox = CheckBox((self._padding, 65, -self._padding, 20), "mark glyphs", value=True) self.w.mark_source_color = ColorWell( (120, 65, -13, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_(*self._mark_color_source) ) # dest font self.w._dest_label = TextBox((self._padding, 100, -self._padding, 17), "target font:") self.w._dest_value = PopUpButton((self._padding, 125, -self._padding, 20), self._all_fonts_names) # mark dest self.w.mark_dest_checkbox = CheckBox((self._padding, 155, -self._padding, 20), "mark glyphs", value=True) self.w.mark_dest_color = ColorWell( (120, 155, -13, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_(*self._mark_color_dest) ) self.w.line = HorizontalLine((self._padding, 200, -self._padding, 1)) # center self.w.center_checkbox = CheckBox((self._padding, 215, -self._padding, 20), "center glyphs", value=False) self.w.line2 = HorizontalLine((self._padding, 250, -self._padding, 1)) # buttons self.w.button_apply = Button( (self._padding, -50, self._width / 2 - 15, 0), "apply", callback=self.apply_callback ) self.w.button_close = Button( (self._width / 2 + 5, -50, -self._padding, 0), "close", callback=self.close_callback ) # open window self.w.open()
def drawHashMarksAndLabelsInRect_(self, rect): bounds = self.bounds() view = self.clientView() rulerBackgroundColor = self.rulerBackgroundColor() if rulerBackgroundColor is not None: rulerBackgroundColor.set() NSRectFill(bounds) if not isinstance(view, NSTextView): return layoutManager = view.layoutManager() container = view.textContainer() text = view.string() nullRange = NSMakeRange(NSNotFound, 0) yinset = view.textContainerInset().height visibleRect = self.scrollView().contentView().bounds() textAttributes = self.textAttributes() lines = self.lineIndices() glyphRange = layoutManager.glyphRangeForBoundingRect_inTextContainer_(visibleRect, container) _range = layoutManager.characterRangeForGlyphRange_actualGlyphRange_(glyphRange, None)[0] _range.length += 1 count = len(lines) index = 0 lineNumber = self.lineNumberForCharacterIndex_inText_(_range.location, text) for line in range(lineNumber, count): index = lines[line] if NSLocationInRange(index, _range): rects, rectCount = layoutManager.rectArrayForCharacterRange_withinSelectedCharacterRange_inTextContainer_rectCount_( NSMakeRange(index, 0), nullRange, container, None ) if rectCount > 0: ypos = yinset + NSMinY(rects[0]) - NSMinY(visibleRect) labelText = NSString.stringWithString_("%s" % (line + 1)) stringSize = labelText.sizeWithAttributes_(textAttributes) x = NSWidth(bounds) - stringSize.width - self.RULER_MARGIN y = ypos + (NSHeight(rects[0]) - stringSize.height) / 2.0 w = NSWidth(bounds) - self.RULER_MARGIN * 2.0 h = NSHeight(rects[0]) labelText.drawInRect_withAttributes_(NSMakeRect(x, y, w, h), textAttributes) if index > NSMaxRange(_range): break path = NSBezierPath.bezierPath() path.moveToPoint_((bounds.origin.x + bounds.size.width, bounds.origin.y)) path.lineToPoint_((bounds.origin.x + bounds.size.width, bounds.origin.y + bounds.size.height)) NSColor.grayColor().set() path.stroke()
def drawWithFrame_inView_(self, frame, view): row = view.selectedRow() columnCount = len(view.tableColumns()) frames = [view.frameOfCellAtColumn_row_(i, row) for i in xrange(columnCount)] selected = frame in frames (x, y), (w, h) = frame y += 1 h -= 2 if selected: pillTextAttributes[NSForegroundColorAttributeName] = self._color foregroundColor = NSColor.whiteColor() else: pillTextAttributes[NSForegroundColorAttributeName] = NSColor.whiteColor() foregroundColor = self._color text = self.title() text = NSAttributedString.alloc().initWithString_attributes_(text, pillTextAttributes) textRect = text.boundingRectWithSize_options_((w, h), 0) (textX, textY), (textW, textH) = textRect foregroundColor.set() path = NSBezierPath.bezierPath() radius = h / 2.0 path.appendBezierPathWithOvalInRect_(((x, y), (h, h))) path.appendBezierPathWithOvalInRect_(((x + textW - 1, y), (h, h))) path.appendBezierPathWithRect_(((x + radius, y), (textW - 1, h))) path.fill() text.drawInRect_(((x + radius, y), (textW, textH)))
def background(self, layer): try: NSColor.colorWithDeviceRed_green_blue_alpha_(0.2, 0.2, 0.2, 0.5).set() for a in layer.anchors: if a not in layer.selection: continue for (l2, otherAnchor) in self.matchingGlyphsAndAnchorsForAnchor( layer, a): if l2.parent.name in self.skipMark: continue anchorAnchorPos = NSPoint( a.position.x - otherAnchor.position.x, a.position.y - otherAnchor.position.y, ) bez = NSBezierPath.bezierPath() bez.appendBezierPath_(l2.bezierPath) t = NSAffineTransform.transform() t.translateXBy_yBy_(anchorAnchorPos.x, anchorAnchorPos.y) bez.transformUsingAffineTransform_(t) bez.fill() except: print("Oops!", sys.exc_info()[0], "occured.") traceback.print_exc(file=sys.stdout)
def isWindowOnDockingSide(self, dockingWindow): ''' checks whenever dragged docking window is above any dock bar ''' winX, winY, winW, winH = dockingWindow.getPosSize() titleBarHeight = self._calculateParentWindowTitlebarHeight() x, y = (winX + winW / 2, winY - titleBarHeight / 2) px, py, pw, ph = self.getParentWindowPosSize() titleBarMiddlePoint = NSPoint(pw - (px - x) - pw, (py - y) + ph) isDockingWindowAbove = False dockingPosition = None for position in self.dockingRectPosSizes.keys(): dockingSideObj = getattr(self, f'{position}_dockbar', None) if dockingSideObj is not None: view = dockingSideObj.getNSView().hitTest_(titleBarMiddlePoint) if view is not None: dockingSideObj.getNSView().layer().setBackgroundColor_( NSColor.orangeColor().CGColor()) dockingPosition = position isDockingWindowAbove = True else: dockingSideObj.getNSView().layer().setBackgroundColor_( NSColor.clearColor().CGColor()) if isDockingWindowAbove: dockingWindow.getNSWindow().setAlphaValue_(.4) else: dockingWindow.getNSWindow().setAlphaValue_(1) return dockingPosition, self
def start(self): self.leftInput = "n" super(ptHUDleftContext, self).start() addObserver(self, "drawNeighbors", "drawBackground") addObserver(self, "drawPreviewNeighBors", "drawPreview") addObserver(self, "currentFontChanged", "fontBecameCurrent") foregroundColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 0.0, 0.0, 0.0, 0.7) backgroundColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 0.0, 0.0, 0.0, 0.05) self.view.unicodeLeftEditText = vanilla.EditText( (0, 0, 40, 19), "n", callback=self.editLeftCallback, continuous=False, sizeStyle="small") controls = [ (self.view.unicodeLeftEditText, NSCenterTextAlignment), ] for control, alignment in controls: textField = control.getNSTextField() textField.setBordered_(False) textField.setTextColor_(foregroundColor) textField.setBackgroundColor_(backgroundColor) textField.setFocusRingType_(NSFocusRingTypeNone) textField.setAlignment_(alignment)
def __init__(self): f = CurrentFont() if f is None: return if f.path is None: print("Save this font first!") return self.designSpaceModel = f.lib.get(self.designSpaceModelLibKey, "twobytwo") #print "self.designSpaceModel", self.designSpaceModel if self.designSpaceModel == "twobytwo": self.masterNames = [ 'narrow-thin', 'wide-thin', 'narrow-bold', 'wide-bold' ] elif self.designSpaceModel == "twobyone": self.masterNames = ['narrow-thin', 'wide-thin'] rgbBlack = NSColor.colorWithDeviceRed_green_blue_alpha_(0, 0, 0, 1) rgbWhite = NSColor.colorWithDeviceRed_green_blue_alpha_( 255, 255, 255, 1) self.shapeColor = rgbWhite self.backgroundColor = rgbBlack self.extrapolateMinValue = 0 self.extrapolateMaxValue = 1 self.w = vanilla.Window((500, 600), "Responsive Lettering", minSize=(300, 200)) self.w.preview = HTMLView((0, 0, -0, -140)) self.w.exportButton = vanilla.Button((-150, -30, -10, 20), "Export SVG", callback=self.cbExport) columnDescriptions = [ dict(title="Glyphname", key="name", width=125), dict(title="Width", key="width", width=50), dict(title="Height", key="height", width=50), dict(title="Bounds?", key="bounds", width=75), dict(title="Contours", key="contours", width=50), dict(title="Points", key="points", width=50), ] self.w.l = vanilla.List((0, -140, -0, -40), self.wrapGlyphs(), columnDescriptions=columnDescriptions, doubleClickCallback=self.callbackListClick) self.w.t = vanilla.TextBox((70, -27, -160, 20), "FontName", sizeStyle="small") self.w.backgroundColorWell = vanilla.ColorWell( (10, -30, 20, 20), callback=self.backgroundColorWellCallback, color=rgbBlack) self.w.shapeColorWell = vanilla.ColorWell( (35, -30, 20, 20), callback=self.shapeColorWellCallback, color=rgbWhite) self.w.bind("became main", self.windowBecameMainCallback) self.setColorsFromLib() self.update() self.w.open() self.cbMakePreview(None)
def drawGlyphFillAndStroke(glyph, scale, rect, drawFill=True, drawStroke=True, contourFillColor=None, contourStrokeColor=None, componentFillColor=None, backgroundColor=None, contourStrokeWidth=1.0): # get the layer color layer = glyph.layer layerColor = None if layer is not None and layer.color is not None: layerColor = colorToNSColor(layer.color) # get the paths contourPath = glyph.getRepresentation( "defconAppKit.NoComponentsNSBezierPath") componentPath = glyph.getRepresentation( "defconAppKit.OnlyComponentsNSBezierPath") # fill if drawFill: # work out the colors if contourFillColor is None and layerColor is not None: contourFillColor = layerColor elif contourFillColor is None and layerColor is None: contourFillColor = getDefaultColor("glyphContourFill") if componentFillColor is None and layerColor is not None: componentFillColor = layerColor elif componentFillColor is None and layerColor is None: componentFillColor = getDefaultColor("glyphComponentFill") # make the fill less opaque if stroking if drawStroke: contourFillColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( contourFillColor.redComponent(), contourFillColor.greenComponent(), contourFillColor.blueComponent(), contourFillColor.alphaComponent() * 0.6) componentFillColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( componentFillColor.redComponent(), componentFillColor.greenComponent(), componentFillColor.blueComponent(), componentFillColor.alphaComponent() * 0.6) # components componentFillColor.set() componentPath.fill() # contours contourFillColor.set() contourPath.fill() # stroke if drawStroke: # work out the color if contourStrokeColor is None and layerColor is not None: contourStrokeColor = layerColor elif contourStrokeColor is None and layerColor is None: contourStrokeColor = getDefaultColor("glyphContourStroke") # contours contourPath.setLineWidth_(contourStrokeWidth * scale) contourStrokeColor.set() contourPath.stroke()
def drawFriends(self, layer): try: friends = self.currentWindow.glyphList.get() except: friends = None c = 0 if friends: for friend in friends: if friend.get("Visibility", 0): g = friend["layer"] if g.completeBezierPath is not None: bP = g.completeBezierPath.copy() t = NSAffineTransform.transform() if self.alignment == 1: translateX = layer.width / 2.0 - g.width / 2.0 + friend[ "Position"] elif self.alignment == 2: translateX = layer.width - g.width + friend[ "Position"] else: translateX = int(friend["Position"]) t.translateXBy_yBy_(translateX, 0.0) tM = t.transformStruct() bP.applyTransform_(tM) NSColor.colorWithDeviceRed_green_blue_alpha_( 1.0, 0.73, c, 0.35).set() bP.fill() c = (c + 0.27) % 1.0
def draw_color(layer, info): r, g, b, a = 231 / 255.0, 227 / 255.0, 51 / 147.0, 50 / 100.0 try: NSColor.colorWithCalibratedRed_green_blue_alpha_(r, g, b, a).set() layer.background.bezierPath.fill() except: import traceback print traceback.format_exc()
def drawRect_(self, rect): NSColor.whiteColor().set() NSRectFill(self.bounds()) origin = (self.center[0]-self.radius, self.center[1]-self.radius) size = (2 * self.radius, 2 * self.radius) dotRect = (origin, size) self.color.set() NSBezierPath.bezierPathWithOvalInRect_(dotRect).fill()
def drawRect_(self, rect): from AppKit import NSRectFill, NSBezierPath, NSColor self.color.set() NSRectFill(self.bounds()) NSColor.blackColor().set() p = NSBezierPath.bezierPathWithRect_(self.bounds()) p.setLineWidth_(10) p.stroke()
def drawRect_(self, rect): NSColor.whiteColor().set() NSRectFill(self.bounds()) origin = (self.center[0] - self.radius, self.center[1] - self.radius) size = (2 * self.radius, 2 * self.radius) dotRect = (origin, size) self.color.set() NSBezierPath.bezierPathWithOvalInRect_(dotRect).fill()
def drawRect_(self, rect): printB("drawRect", rect ) """.""" NSColor.whiteColor().set() NSBezierPath.fillRect_(rect) self.itemColor().set() NSBezierPath.fillRect_(self.calculatedItemBounds())
def drawRect_(self, rect): super(PictureView, self).drawRect_(rect) pos = self.dropboxViewFinalPosition.origin size = self.dropboxViewFinalPosition.size a = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(NSRect((pos[0] - 3, pos[1] - 3), (size[0] + 6, size[1] + 6)), 5.0, 5.0) a.setLineWidth_(2) NSColor.whiteColor().set() a.fill()
def draw_color(self, layer, info): r, g, b, a = 231 / 255.0, 227 / 255.0, 51 / 147.0, 50 / 100.0 try: NSColor.colorWithCalibratedRed_green_blue_alpha_(r, g, b, a).set() layer.background.bezierPath.fill() except: import traceback print traceback.format_exc()
def draw_ground(layer, info): # Due to internal Glyphs.app structure, we need to catch and print exceptions # of these callback functions with try/except like so: try: NSColor.colorWithCalibratedRed_green_blue_alpha_(r, g, b, a).set() layer.background.bezierPath.fill() # check how to draw on foreground except: import traceback print traceback.format_exc()
def linearGradient(startPoint=None, endPoint=None, colors=None, locations=None): global currentGradient global currentFillColor if colors is None: colors = [NSColor.greenColor(), NSColor.redColor()] if locations is None: locations = [i / float(len(colors)-1) for i in range(len(colors))] currentGradient = ("linear", startPoint, endPoint, colors, locations) currentFillColor = None
def stroke(r=None, g=None, b=None, a=1): # Set the stroke color as RGB value. global currentStrokeColor if r is None: currentStrokeColor = None elif g is None: currentStrokeColor = NSColor.colorWithDeviceWhite_alpha_(r, a) else: currentStrokeColor = NSColor.colorWithDeviceRed_green_blue_alpha_(r, g, b, a)
def drawRect_(self, rect): if not self.border: return super(ThumbnailBoxView, self).drawRect_(rect) with save_graphics_state(): self._shadow.set() NSColor.whiteColor().set() NSBezierPath.bezierPathWithRect_(NSInsetRect(rect, self.BORDER_INSET, self.BORDER_INSET)).fill() size = self.image().size() self.image().drawInRect_fromRect_operation_fraction_(NSInsetRect(rect, self.IMAGE_INSET, self.IMAGE_INSET), NSMakeRect(*rect_to_centered_square(size.width, size.height)), NSCompositeSourceOver, 1.0)
def drawRect_(self, rect): NSColor.whiteColor().set() NSBezierPath.fillRect_(rect) if Glyphs.font is None: return if not Glyphs.font.selectedLayers: return glyphToRotate = None try: glyphToRotate = Glyphs.font.selectedLayers[0] except: print(traceback.format_exc()) if glyphToRotate is None: return try: previewPath = glyphToRotate.completeBezierPath rotationFactor = self.wrapper._rotationFactor Width = NSWidth(self.frame()) Height = NSHeight(self.frame()) scaleFactor = 0.666666 / (glyphToRotate.parent.parent.upm / min(Width, Height)) ## scaling and zeroing the glyph #------------------------ transform = NSAffineTransform.transform() transform.scaleBy_(scaleFactor) bounds = glyphToRotate.bounds transform.translateXBy_yBy_(-NSMidX(bounds), -NSMidY(bounds)) previewPath.transformUsingAffineTransform_(transform) ## rotation #------------------------ transform = NSAffineTransform.transform() transform.rotateByDegrees_(rotationFactor) previewPath.transformUsingAffineTransform_(transform) ## positioning to the middle of the viewport #------------------------ transform = NSAffineTransform.transform() transform.translateXBy_yBy_(Width / 2, Height / 2 - 8) previewPath.transformUsingAffineTransform_(transform) ## fill path #------------------------ NSColor.blackColor().set() previewPath.fill() except: print(traceback.format_exc())
def DrawGlyph(f, glyph, PSCommands, xoffset, yoffset, ratio, fillcolour, strokecolour, strokewidth, dashed): if not PSCommands: layer = glyph.layers[0] p = layer.drawBezierPath transform = NSAffineTransform.new() transform.translateXBy_yBy_(xoffset * mm, yoffset * mm) transform.scaleBy_(ratio) p.transformUsingAffineTransform_(transform) else: p = NSBezierPath.bezierPath() for command in PSCommands: if command[0] == 'moveTo': try: p.close() except: pass x = xoffset * mm + command[1][0] * ratio y = yoffset * mm + command[1][1] * ratio p.moveToPoint_((x, y)) #print "('moveTo', (%s, %s))," % (command[1][0], command[1][1]) if command[0] == 'lineTo': x = xoffset * mm + command[1][0] * ratio y = yoffset * mm + command[1][1] * ratio p.lineToPoint_((x, y)) #print "('lineTo', (%s, %s))," % (command[1][0], command[1][1]) if command[0] == 'curveTo': points = [] for point in command[1:]: points.append((xoffset * mm + point[0] * ratio, yoffset * mm + point[1] * ratio)) p.curveToPoint_controlPoint1_controlPoint2_( points[0], points[1], points[2]) p.closePath() if fillcolour: NSColor.colorWithDeviceCyan_magenta_yellow_black_alpha_( fillcolour[0], fillcolour[1], fillcolour[2], fillcolour[3], 1).set() p.fill() if strokecolour: NSColor.colorWithDeviceCyan_magenta_yellow_black_alpha_( strokecolour[0], strokecolour[1], strokecolour[2], strokecolour[3], 1).set() if dashed: p.setLineDash_count_phase_(dashed, 2, 0.0) p.setLineWidth_(strokewidth) p.stroke()
def draw_color(layer, info): r, g, b, a = 231 / 255.0, 227 / 255.0, 51 / 147.0, 50 / 100.0 try: NSColor.colorWithCalibratedRed_green_blue_alpha_(r, g, b, a).set() for gname in up_diacritics: l = font.glyphs[d_name].layers['diacritics'] l.bezierPath.fill() except: import traceback print traceback.format_exc()
def stroke(r=None, g=None, b=None, a=1): # Set the stroke color as RGB value. global currentStrokeColor if r is None: currentStrokeColor = None elif g is None: currentStrokeColor = NSColor.colorWithDeviceWhite_alpha_(r, a) else: currentStrokeColor = NSColor.colorWithDeviceRed_green_blue_alpha_( r, g, b, a)
def check_signature_matcher(self, obj): regex = obj.stringValue() feedback = self.customSignatureMatcherFeedback try: re.compile(regex) feedback.setColor_(NSColor.greenColor()) feedback.setToolTip_("") except re.error, e: feedback.setColor_(NSColor.redColor()) feedback.setToolTip_(str(e))
def background(self, layer): # Fills background path of current glyph with non-photo blue NSColor.colorWithRed_green_blue_alpha_(.643, .867, .929, .3).set() if layer.background.bezierPath: layer.background.bezierPath.fill() # Fills background path of current component glyph with vermillion NSColor.colorWithRed_green_blue_alpha_(.89, .259, .204, .3).set() for backgroundComponent in layer.background.components: backgroundComponent.bezierPath.fill()
def flatButt(self, this, match=False): this = this.getNSButton() this.setBezelStyle_(buttstyle) this.setBordered_(False) this.setWantsLayer_(True) this.setBackgroundColor_(NSColor.whiteColor()) if match == True: this.setBackgroundColor_( NSColor.colorWithCalibratedRed_green_blue_alpha_( .9, 1, .85, 1))
def showWindow_(self, sender): try: edY = 22 clX = 22 spX = 8 spY = 8 btnY = 17 self.windowWidth = 300 self.windowHeight = 240 self.currentDocument = Glyphs.currentDocument self.thisfont = Glyphs.font # self.thisfont = GlyphsApp.currentFont() self.w = FloatingWindow( (self.windowWidth, self.windowWidth), self.name, autosaveName="com.Tosche.Waterfall.mainwindow", minSize=(self.windowWidth, self.windowWidth + 20)) self.w.bind("close", self.windowClosed_) insList = [i.name for i in Glyphs.font.instances] insList.insert(0, 'Current Master') self.w.edit = EditText( (spX, spY, (-spX * 3 - clX * 2) - 80, edY), text="The quick brown jumps over the lazy dog.", callback=self.textChanged_) self.w.edit.getNSTextField().setNeedsLayout_(True) defaultWhite = NSColor.colorWithCalibratedRed_green_blue_alpha_( 1, 1, 1, 1) defaultBlack = NSColor.colorWithCalibratedRed_green_blue_alpha_( 0, 0, 0, 1) self.w.foreColour = ColorWell((-spX * 2 - clX * 2, spY, clX, edY), color=defaultBlack, callback=self.uiChange_) self.w.backColour = ColorWell((-spX - clX, spY, clX, edY), color=defaultWhite, callback=self.uiChange_) self.w.refresh = Button((-spX - 138, spY, 80, edY), "Refresh", callback=self.textChanged_) self.w.instancePopup = PopUpButton((spX, spY * 2 + edY, -spX, edY), insList, callback=self.changeInstance_) self.w.preview = TheView((0, spX * 3 + edY * 2, -0, -0)) self.w.preview.instances = {} self.loadPrefs() self.w.open() self.uiChange_(None) self.changeInstance_(self.w.instancePopup) self.textChanged_(self.w.edit) Glyphs.addCallback( self.changeInstance_, UPDATEINTERFACE ) # will be called on every change to the interface Glyphs.addCallback(self.changeDocument_, DOCUMENTACTIVATED) except: print(traceback.format_exc())
def drawline(x1, y1, x2, y2, colour, strokewidth, dashed): NSColor.colorWithDeviceCyan_magenta_yellow_black_alpha_(colour[0], colour[1], colour[2], colour[3], 1).set() Path = NSBezierPath.bezierPath() Path.moveToPoint_((x1, y1)) Path.lineToPoint_((x2, y2)) Path.setLineWidth_(strokewidth) if dashed: Path.setLineDash_count_phase_(dashed, 2, 0.0) Path.stroke()
def __init__(self, ): self.w = FloatingWindow((self._width, self._height), self._title, closable=False) self._all_fonts = AllFonts() for f in self._all_fonts: self._all_fonts_names.append(get_full_name(f)) # source font self.w._source_label = TextBox( (self._padding, self._padding_top, -self._padding, 17), "source font:") self.w._source_value = PopUpButton( (self._padding, 35, -self._padding, 20), self._all_fonts_names) # mark source self.w.mark_source_checkbox = CheckBox( (self._padding, 65, -self._padding, 20), "mark glyphs", value=True) self.w.mark_source_color = ColorWell( (120, 65, -13, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( *self._mark_color_source)) # dest font self.w._dest_label = TextBox((self._padding, 100, -self._padding, 17), "target font:") self.w._dest_value = PopUpButton( (self._padding, 125, -self._padding, 20), self._all_fonts_names) # mark dest self.w.mark_dest_checkbox = CheckBox( (self._padding, 155, -self._padding, 20), "mark glyphs", value=True) self.w.mark_dest_color = ColorWell( (120, 155, -13, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( *self._mark_color_dest)) self.w.line = HorizontalLine((self._padding, 200, -self._padding, 1)) # left / right self.w.left_checkbox = CheckBox( (self._padding, 215, -self._padding, 20), "copy left", value=True) self.w.right_checkbox = CheckBox( (self._width / 2, 215, -self._padding, 20), "copy right", value=True) self.w.line2 = HorizontalLine((self._padding, 250, -self._padding, 1)) # buttons self.w.button_apply = Button( (self._padding, -50, self._width / 2 - 15, 0), "apply", callback=self.apply_callback) self.w.button_close = Button( (self._width / 2 + 5, -50, -self._padding, 0), "close", callback=self.close_callback) # open window self.w.open()
def drawCoveringBadge(self, x, y, width, height, radius): try: myPath = NSBezierPath.alloc().init() NSColor.colorWithCalibratedRed_green_blue_alpha_(*COLOR).set() myRect = NSRect((x, y), (width, height)) thisPath = NSBezierPath.bezierPathWithRoundedRect_cornerRadius_( myRect, radius) myPath.appendBezierPath_(thisPath) myPath.fill() except: print traceback.format_exc()
def drawLine(self, x1, y1, x2, y2, strokeWidth=1): try: myPath = NSBezierPath.bezierPath() myPath.moveToPoint_( (x1, y1) ) myPath.lineToPoint_( (x2, y2) ) myPath.setLineWidth_( strokeWidth/self.getScale() ) selectionColor = 0, 0, 0.5, 0.2 NSColor.colorWithCalibratedRed_green_blue_alpha_( *selectionColor ).set() myPath.stroke() except: print(traceback.format_exc())
def drawGlyphFillAndStroke(glyph, scale, rect, drawFill=True, drawStroke=True, contourFillColor=None, contourStrokeColor=None, componentFillColor=None, backgroundColor=None, contourStrokeWidth=1.0): # get the layer color layer = glyph.layer layerColor = None if layer is not None and layer.color is not None: layerColor = colorToNSColor(layer.color) # get the paths contourPath = glyph.getRepresentation("defconAppKit.NoComponentsNSBezierPath") componentPath = glyph.getRepresentation("defconAppKit.OnlyComponentsNSBezierPath") # fill if drawFill: # work out the colors if contourFillColor is None and layerColor is not None: contourFillColor = layerColor elif contourFillColor is None and layerColor is None: contourFillColor = getDefaultColor("glyphContourFill") if componentFillColor is None and layerColor is not None: componentFillColor = layerColor elif componentFillColor is None and layerColor is None: componentFillColor = getDefaultColor("glyphComponentFill") # make the fill less opaque if stroking if drawStroke: contourFillColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( contourFillColor.redComponent(), contourFillColor.greenComponent(), contourFillColor.blueComponent(), contourFillColor.alphaComponent() * 0.6 ) componentFillColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( componentFillColor.redComponent(), componentFillColor.greenComponent(), componentFillColor.blueComponent(), componentFillColor.alphaComponent() * 0.6 ) # components componentFillColor.set() componentPath.fill() # contours contourFillColor.set() contourPath.fill() # stroke if drawStroke: # work out the color if contourStrokeColor is None and layerColor is not None: contourStrokeColor = layerColor elif contourStrokeColor is None and layerColor is None: contourStrokeColor = getDefaultColor("glyphContourStroke") # contours contourPath.setLineWidth_(contourStrokeWidth * scale) contourStrokeColor.set() contourPath.stroke()
def drawline(x1, y1, x2, y2, colour, strokewidth, dashed): NSColor.colorWithDeviceCyan_magenta_yellow_black_alpha_( colour[0], colour[1], colour[2], colour[3], 1).set() Path = NSBezierPath.bezierPath() Path.moveToPoint_((x1, y1)) Path.lineToPoint_((x2, y2)) Path.setLineWidth_(strokewidth) if dashed: Path.setLineDash_count_phase_(dashed, 2, 0.0) Path.stroke()
def drawrect(x1, y1, x2, y2, fillcolour, strokecolour, strokewidth, dashed, rounded): Rect = NSMakeRect(x1, y1, x2 - x1, y2 - y1) Path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(Rect, rounded, rounded) if fillcolour: NSColor.colorWithDeviceCyan_magenta_yellow_black_alpha_(fillcolour[0], fillcolour[1], fillcolour[2], fillcolour[3], 1).set() Path.fill() if strokecolour: Path.setLineWidth_(strokewidth) if dashed: Path.setLineDash_count_phase_(dashed, 2, 0.0) NSColor.colorWithDeviceCyan_magenta_yellow_black_alpha_(strokecolour[0], strokecolour[1], strokecolour[2], strokecolour[3], 1).set() Path.stroke()
def fill(r=None, g=None, b=None, a=1): # Set the fill color as RGB value. global currentFillColor global currentGradient if r is None: currentFillColor = None elif g is None: currentFillColor = NSColor.colorWithDeviceWhite_alpha_(r, a) currentGradient = None else: currentFillColor = NSColor.colorWithDeviceRed_green_blue_alpha_(r, g, b, a) currentGradient = None
def linearGradient(startPoint=None, endPoint=None, colors=None, locations=None): global currentGradient global currentFillColor if colors is None: colors = [NSColor.greenColor(), NSColor.redColor()] if locations is None: locations = [i / float(len(colors) - 1) for i in range(len(colors))] currentGradient = ("linear", startPoint, endPoint, colors, locations) currentFillColor = None
def applicationDidFinishLaunching_(self, aNotification): d = {'StderrColor': NSArchiver.archivedDataWithRootObject_(NSColor.redColor()), 'StdoutColor': NSArchiver.archivedDataWithRootObject_(NSColor.blueColor()), 'CodeColor': NSArchiver.archivedDataWithRootObject_(NSColor.blackColor()), } defaults = NSUserDefaults.standardUserDefaults() defaults.registerDefaults_(d) self.textView.setFont_(self.font()) self._stderrColor = NSUnarchiver.unarchiveObjectWithData_(defaults['StderrColor']) self._stdoutColor = NSUnarchiver.unarchiveObjectWithData_(defaults['StdoutColor']) self._codeColor = NSUnarchiver.unarchiveObjectWithData_(defaults['CodeColor']) self._executeWithRedirectedIO_args_kwds_(self._interp, (), {})
def setDarkMode(w, darkMode): if darkMode: appearance = NSAppearance.appearanceNamed_('NSAppearanceNameVibrantDark') if hasattr(w, "accordionView"): w.accordionView.setBackgroundColor(NSColor.colorWithCalibratedRed_green_blue_alpha_(.08, .08, .08, 1)) else: appearance = NSAppearance.appearanceNamed_('NSAppearanceNameAqua') if hasattr(w, "accordionView"): w.accordionView.setBackgroundColor(NSColor.colorWithCalibratedRed_green_blue_alpha_(1, 1, 1, 1)) w.getNSWindow().setAppearance_(appearance) if CurrentGlyphWindow(): CurrentGlyphWindow().window().getNSWindow().setAppearance_(appearance)
def __init__(self, posSize, pointSize=100, rightToLeft=False, applyKerning=False, glyphColor=None, backgroundColor=None, alternateHighlightColor=None, autohideScrollers=True, showPointSizePlacard=False): if glyphColor is None: glyphColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 0, 0, 0, 1) if backgroundColor is None: backgroundColor = NSColor.whiteColor() if alternateHighlightColor is None: alternateHighlightColor = defaultAlternateHighlightColor self._applyKerning = applyKerning self._glyphLineView = self.glyphLineViewClass.alloc().init() self._glyphLineView.setPointSize_(pointSize) self._glyphLineView.setRightToLeft_(rightToLeft) self._glyphLineView.setGlyphColor_(glyphColor) self._glyphLineView.setBackgroundColor_(backgroundColor) self._glyphLineView.setAlternateHighlightColor_( alternateHighlightColor) self._glyphLineView.vanillaWrapper = weakref.ref(self) # don't autohide if the placard is to be visible. # bad things will happen if this is not the case. if showPointSizePlacard: autohideScrollers = False # setup the scroll view super(GlyphLineView, self).__init__(posSize, self._glyphLineView, autohidesScrollers=autohideScrollers, backgroundColor=backgroundColor) # placard if showPointSizePlacard: self._pointSizes = ["Auto"] + [str(i) for i in pointSizes] placardW = 55 placardH = 16 self._placard = vanilla.Group((0, 0, placardW, placardH)) self._placard.button = PlacardPopUpButton( (0, 0, placardW, placardH), self._pointSizes, callback=self._placardSelection, sizeStyle="mini") self.setPlacard(self._placard) pointSize = str(pointSize) if pointSize in self._pointSizes: index = self._pointSizes.index(pointSize) self._placard.button.set(index)
def drawGlyphIntoBackground(layer, info): # Due to internal Glyphs.app structure, we need to catch and print exceptions # of these callback functions with try/except like so: try: # Your drawing code here NSColor.yellowColor().set() layer.background.bezierPath.fill() # Error. Print exception. except: import traceback print traceback.format_exc()
def drawRect_(self, rect): frame = self.frame() NSColor.whiteColor().set() NSRectFill(frame) try: if self._glyph is not None: if self._glyph.__class__.__name__ in ("NSKVONotifying_GSLayer", "GSLayer"): layer = self._glyph elif isinstance(self._glyph, RGlyph): layer = self._glyph._layer if layer: layer.drawInFrame_(frame) except: print traceback.format_exc()
def DrawGlyph(f, glyph, PSCommands, xoffset, yoffset, ratio, fillcolour, strokecolour, strokewidth, dashed): if not PSCommands: layer = glyph.layers[0] p = layer.drawBezierPath transform = NSAffineTransform.new() transform.translateXBy_yBy_(xoffset*mm, yoffset*mm) transform.scaleBy_(ratio) p.transformUsingAffineTransform_(transform) else: p = NSBezierPath.bezierPath() for command in PSCommands: if command[0] == 'moveTo': try: p.close() except: pass x = xoffset*mm + command[1][0] * ratio y = yoffset*mm + command[1][1] * ratio p.moveToPoint_((x, y)) #print "('moveTo', (%s, %s))," % (command[1][0], command[1][1]) if command[0] == 'lineTo': x = xoffset*mm + command[1][0] * ratio y = yoffset*mm + command[1][1] * ratio p.lineToPoint_((x, y)) #print "('lineTo', (%s, %s))," % (command[1][0], command[1][1]) if command[0] == 'curveTo': points = [] for point in command[1:]: points.append( (xoffset*mm + point[0] * ratio, yoffset*mm + point[1] * ratio) ) p.curveToPoint_controlPoint1_controlPoint2_(points[0], points[1], points[2]) p.closePath() if fillcolour: NSColor.colorWithDeviceCyan_magenta_yellow_black_alpha_(fillcolour[0], fillcolour[1], fillcolour[2], fillcolour[3], 1).set() p.fill() if strokecolour: NSColor.colorWithDeviceCyan_magenta_yellow_black_alpha_(strokecolour[0], strokecolour[1], strokecolour[2], strokecolour[3], 1).set() if dashed: p.setLineDash_count_phase_(dashed, 2, 0.0) p.setLineWidth_(strokewidth) p.stroke()
def DrawTableLines(list, colour, thickness): global myDialog for i, point in enumerate(list): try: drawline(list[i][1]*mm, list[i][2]*mm, list[i+1][1]*mm, list[i+1][2]*mm, colour, thickness, None) except: pass NSColor.colorWithDeviceCyan_magenta_yellow_black_alpha_(colour[0], colour[1], colour[2], colour[3], 1).set() Rect = NSMakeRect(point[1]*mm-(thickness), point[2]*mm-(thickness), thickness*2, thickness*2) NSBezierPath.bezierPathWithOvalInRect_(Rect).fill() if Glyphs.boolDefaults["com_yanone_Autopsy_drawpointsvalues"]: DrawText(pdffont['Regular'], pointsvaluefontsize, glyphcolour, point[1]*mm + (thickness/6+1)*mm, point[2]*mm - (thickness/6+2.5)*mm, str(int(round(point[0]))))
def __init__(self, posSize, layer = None, backgroundColor = None): self._setupView(self.nsViewClass, posSize) self.layer = layer if backgroundColor != None: self.backgroundColor = backgroundColor else: self.backgroundColor = NSColor.whiteColor()
def __init__(self): self.w = FloatingWindow((self._width, self._height), self._title, closable=False) # left self.w.left_label = TextBox((self._padding, self._padding, -self._padding, 17), "left") self.w.left_mode = PopUpButton( (60, self._padding, self._column_1, 20), self._modes, callback=self.left_mode_callback ) self.w.left_value = EditText((195, self._padding, -self._padding, 20), placeholder="set value") self.w.left_value.enable(False) # right self.w.right_label = TextBox((self._padding, 40, -self._padding, 17), "right") self.w.right_mode = PopUpButton((60, 40, self._column_1, 20), self._modes, callback=self.right_mode_callback) self.w.right_value = EditText((195, 40, -self._padding, 20), placeholder="set value") self.w.right_value.enable(False) # colors self.w.mark_checkbox = CheckBox((self._padding, 75, -170, 20), "mark glyphs", value=True) self.w.mark_color = ColorWell( (120, 75, -self._padding, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_(*self._mark_color) ) # buttons self.w.button_apply = Button( (self._padding, -35, (self._width / 2) - self._padding, 20), "apply", callback=self.apply_callback ) self.w.button_close = Button( ((self._width / 2) + self._padding, -35, -self._padding, 20), "close", callback=self.close_callback ) # open window self.w.setDefaultButton(self.w.button_apply) self.w.button_close.bind(".", ["command"]) self.w.button_close.bind(unichr(27), []) self.w.open()
def __init__(self): self.doMarkGlyphs = 0 self.doOverwrite = 1 self.sourceFontList = AllFonts() self.destinationFontList = AllFonts() self.source_font = self.sourceFontList[0] self.destination_fonts = None self.glyphs = None self.mark = NSColor.redColor() ## create a window self.w = Window((700, 500), "Copy Glyphs", minSize=(700, 500)) self.w.sourceTitle = TextBox((15, 20, 200, 20), "Source Font:") self.w.sourceFont = PopUpButton((15, 42, -410, 20), [f.info.familyName + ' ' + f.info.styleName for f in self.sourceFontList], callback=self.sourceCallback) self.w.glyphs = GlyphCollectionView((16, 70, -410, -65), initialMode="list", enableDelete=False, allowDrag=False, selectionCallback=self.glyphCallback) self._sortGlyphs(self.source_font) self.w.desTitle = TextBox((-400, 20, 200, 20), "Destination Fonts:") self.w.destinationFonts = FontList((-400, 42, -15, -115), self.destinationFontList, selectionCallback=self.desCallback) self.w.overwrite = CheckBox((-395, -105, 130, 22), "Overwrite glyphs", callback=self.overwriteCallback, value=self.doOverwrite) self.w.markGlyphs = CheckBox((-395, -84, 100, 22), "Mark Glyphs", callback=self.markCallback, value=self.doMarkGlyphs) self.w.copyButton = Button((-115, -40, 100, 20), 'Copy Glyphs', callback=self.copyCallback) self.w.line = HorizontalLine((10, -50, -10, 1)) self._updateDest() ## open the window self.w.open()
def _getColor(self, key, fallback): if key not in self._values: color = getExtensionDefaultColor(key) if color is None: color = NSColor.colorWithCalibratedRed_green_blue_alpha_(*fallback) self._values[key] = color return self._values[key]
def openSplash(): global splash splash = NSWindow.alloc() rect = NSMakeRect(0,0,240,420) styleMask = 0 splash.initWithContentRect_styleMask_backing_defer_(rect, styleMask, NSBackingStoreBuffered, False) # http://stackoverflow.com/questions/19437580/splash-screen-in-osx-cocoa-app splashImage = NSImageView.alloc().initWithFrame_(rect) splashImage.setImageScaling_(NSScaleToFit) splashImage.setImage_(NSImage.imageNamed_('ottosplash.png')) #[customView addSubview:splashImage]; #splash.setContentView_(webview) splash.setContentView_(splashImage) splash.setHasShadow_(True) splash.setOpaque_(False) splash.setBackgroundColor_(NSColor.clearColor()) # xPos = NSWidth([[splashWindow screen] frame])/2 - NSWidth([splashWindow frame])/2; #CGFloat yPos = NSHeight([[splashWindow screen] frame])/2 - NSHeight([splashWindow frame])/2; #[splashWindow setFrame:NSMakeRect(xPos, yPos, NSWidth([splashWindow frame]), NSHeight([splashWindow frame])) display:YES]; splash.center() splash.orderFrontRegardless()