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 __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 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 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 _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 __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 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 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 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_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 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 __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 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 __init__(self, posSize, text, callback=None): # there must be a callback as it triggers the creation of the delegate if callback is None: callback = self._fallbackCallback super(FeatureTextEditor, self).__init__(posSize, "", callback=callback) self._nsObject.setHasHorizontalScroller_(True) font = NSFont.fontWithName_size_("Monaco", 10) self._textView.setFont_(font) self._textView.setUsesFindPanel_(True) ## line numbers #ruler = DefconAppKitLineNumberView.alloc().init() #ruler.setClientView_(self._textView) #self._nsObject.setVerticalRulerView_(ruler) #self._nsObject.setHasHorizontalRuler_(False) #self._nsObject.setHasVerticalRuler_(True) #self._nsObject.setRulersVisible_(True) #notificationCenter = NSNotificationCenter.defaultCenter() #notificationCenter.addObserver_selector_name_object_( # ruler, "clientViewSelectionChanged:", NSTextViewDidChangeSelectionNotification, self._textView #) # colors self._mainColor = NSColor.blackColor() self._commentColor = NSColor.colorWithCalibratedWhite_alpha_(.6, 1) self._keywordColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( .8, 0, 0, 1) self._tokenColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( .8, .4, 0, 1) self._classNameColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 0, 0, .8, 1) self._includeColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( .8, 0, .8, 1) self._stringColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 0, .6, 0, 1) # build the placard placardW = 65 placardH = 16 self._placardJumps = [] self._placard = vanilla.Group((0, 0, placardW, placardH)) self._placard.featureJumpButton = PlacardPopUpButton( (0, 0, placardW, placardH), [], callback=self._placardFeatureSelectionCallback, sizeStyle="mini") self._nsObject.setPlacard_(self._placard.getNSView()) # registed for syntax coloring notifications self._programmaticallySettingText = False delegate = self._textViewDelegate delegate.vanillaWrapper = weakref.ref(self) notificationCenter = NSNotificationCenter.defaultCenter() notificationCenter.addObserver_selector_name_object_( self._textViewDelegate, "textStorageDidProcessEditing:", NSTextStorageDidProcessEditingNotification, self._textView.textStorage()) # set the text self.set(text)
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 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): self = super(DefconAppKitGlyphLineNSView, self).init() self._showLayers = False self._layerDrawingAttributes = {} self._fallbackDrawingAttributes = dict( showGlyphFill=True, showGlyphStroke=False, showGlyphOnCurvePoints=False, showGlyphStartPoints=False, showGlyphOffCurvePoints=False, showGlyphPointCoordinates=False, showGlyphAnchors=False, showGlyphImage=False, showGlyphMargins=False, showFontVerticalMetrics=False, showFontPostscriptBlues=False, showFontPostscriptFamilyBlues=False) self._glyphRecords = [] self._alternateRects = {} self._currentZeroZeroPoint = NSPoint(0, 0) self._rightToLeft = False self._pointSize = 150 self._impliedPointSize = 150 self._scale = 1.0 self._inverseScale = 0.1 self._upm = 1000 self._descender = -250 self._bufferLeft = self._bufferRight = self._bufferBottom = self._bufferTop = 15 self._cutoffDisplayPointSizes = dict(showFontVerticalMetrics=150, showGlyphStartPoints=175, showGlyphOnCurvePoints=175, showGlyphOffCurvePoints=175, showGlyphPointCoordinates=250, showGlyphAnchors=50) self._fitToFrame = None self._backgroundColor = NSColor.whiteColor() self._glyphColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 0, 0, 0, 1) self._strokeColor = None self._pointColor = None self._alternateHighlightColor = defaultAlternateHighlightColor self._notdefBackgroundColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 1, 0, 0, .25) return self
def _drawTextLabel(self, transform, text, size, vector, percent=1.0): if text is None: return if vector is None: vector = (-1, 1) angle = atan2(vector[0], -vector[1]) text_size = 0.5 * size # para_style = NSMutableParagraphStyle.alloc().init() # para_style.setAlignment_(NSCenterTextAlignment) attrs = { NSFontAttributeName: NSFont.systemFontOfSize_(text_size), NSForegroundColorAttributeName: NSColor.colorWithCalibratedRed_green_blue_alpha_( text_color[0], text_color[1], text_color[2], text_color[3] * percent, ), # NSParagraphStyleAttributeName: para_style, } myString = NSString.string().stringByAppendingString_(text) bbox = myString.sizeWithAttributes_(attrs) bw = bbox.width bh = bbox.height text_pt = NSPoint() text_pt.y = 0 if -0.5 * pi < angle <= 0.5 * pi: text_pt.x = -1.3 * size - bw / 2 * cos(angle) - bh / 2 * sin(angle) else: text_pt.x = -1.3 * size + bw / 2 * cos(angle) + bh / 2 * sin(angle) text_pt = transform.transformPoint_(text_pt) rr = NSRect(origin=(text_pt.x - bw / 2, text_pt.y - bh / 2), size=(bw, bh)) if DEBUG: NSColor.colorWithCalibratedRed_green_blue_alpha_(0, 0, 0, 0.15).set() myRect = NSBezierPath.bezierPathWithRect_(rr) myRect.setLineWidth_(0.05 * size) myRect.stroke() myString.drawInRect_withAttributes_(rr, attrs)
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 makeColor(hexValue, a=1): if not hexValue: return None if hexValue[0] == '#': hexValue = hexValue[1:] r, g, b = struct.unpack('BBB',hexValue.decode('hex')) return NSColor.colorWithCalibratedRed_green_blue_alpha_(r/255, g/255, b/255, a)
def __init__(self): self.draw = False self.swap = True self.radius = getExtensionDefault( "%s.%s" % (WurstSchreiberDefaultKey, "radius"), 60) color = NSColor.colorWithCalibratedRed_green_blue_alpha_(1, 0, 0, .5) colorValue = getExtensionDefaultColor( "%s.%s" % (WurstSchreiberDefaultKey, "color"), color) self.w = FloatingWindow((150, 170), "WurstSchreiber") x = 15 y = 15 self.w.preview = CheckBox( (x, y, -x, 20), "Preview", callback=self.previewChanged, value=True) y+=30 self.w.slider = SliderGroup( (x, y, -x, 22), 0, 100, self.radius, callback=self.sliderChanged) y+=35 self.w.color = ColorWell( (x, y, -x, 40), callback=self.colorChanged, color=colorValue) y+=55 self.w.button = Button( (x, y, -x, 20), "Trace!", callback=self.traceButton) addObserver(self, "drawWurst", "drawBackground") self.w.bind("close", self.closing) self.w.open()
def drawPreviewRef(self, info): save() fillColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(0.0, 0.0, 0.0, 0.05) fillColor.set() self. _drawGlyph(info["glyph"], scale=1, stroke=False) UpdateCurrentGlyphView() restore()
def drawRef(self, info): save() fillColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(0.0, 0.0, 0.0, 1.0) fillColor.set() self. _drawGlyph(info["glyph"], scale=info["scale"]) UpdateCurrentGlyphView() restore()
def __init__(self): self.w = FloatingWindow( (self._width, self._height), self._title, closable=False) # left self.w.width_label = TextBox( (self._padding, self._padding, -self._padding, 20), "width") self.w.width_value = EditText( (80, self._padding, -15, 20), placeholder = 'set value', text = self._default_width) # center self.w.center_checkbox = CheckBox( (self._padding, 40, -self._padding, 20), "center", value = False) self.w.mark_checkbox = CheckBox( (80, 40, -self._padding, 20), "mark", value = True) self.w.mark_color = ColorWell( (140, 40, -15, 20), color = NSColor.colorWithCalibratedRed_green_blue_alpha_(*self._mark_color)) # buttons self.w.button_close = Button( (self._padding, -30, (self._width / 2) - 15, 20), "close", callback = self.close_callback) self.w.button_apply = Button( ((self._width / 2) + 5, -30, -self._padding, 20), "apply", callback = self.apply_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 _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 drawNodeDistanceText(self, layer): if layer is None: return toolEventHandler = self.controller.view().window().windowController( ).toolEventHandler() toolIsTextTool = toolEventHandler.className() == "GlyphsToolText" toolIsToolHand = toolEventHandler.className() == "GlyphsToolHand" currentController = self.controller.view().window().windowController() if currentController: if not toolIsTextTool and not toolIsToolHand: try: # scale = self.getScale() for eachComponent in layer.components: # string = NSString.stringWithString_(u"%s" % eachComponent.componentName) # attributes = NSString.drawTextAttributes_(NSColor.colorWithCalibratedRed_green_blue_alpha_( *COLOR )) # textSize = string.sizeWithAttributes_(attributes) cpX = eachComponent.bounds.origin.x + eachComponent.bounds.size.width / 2 + 10 cpY = eachComponent.bounds.origin.y + eachComponent.bounds.size.height / 2 - 10 cpX = cpX #* scale cpY = cpY #* scale string = eachComponent.componentName self.drawText( layer, string, (cpX, cpY), 10, NSColor.colorWithCalibratedRed_green_blue_alpha_( *COLOR)) except: print traceback.format_exc() pass
def __init__(self): self.w = FloatingWindow((self._width, self._height), self._title, closable=False) # left self.w.width_label = TextBox( (self._padding, self._padding, -self._padding, 20), "width") self.w.width_value = EditText((80, self._padding, -15, 20), placeholder='set value', text=self._default_width) # center self.w.center_checkbox = CheckBox( (self._padding, 40, -self._padding, 20), "center", value=False) self.w.mark_checkbox = CheckBox((80, 40, -self._padding, 20), "mark", value=True) self.w.mark_color = ColorWell( (140, 40, -15, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_( *self._mark_color)) # buttons self.w.button_close = Button( (self._padding, -30, (self._width / 2) - 15, 20), "close", callback=self.close_callback) self.w.button_apply = Button( ((self._width / 2) + 5, -30, -self._padding, 20), "apply", callback=self.apply_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, red, green, blue, alpha=1.0, image=False, im=''): self.image = image if image: # self._ns_color = NSColor.colorWithPatternImage_(im._ns_image) self._ns_color = im._ns_image else: self._ns_color = NSColor.colorWithCalibratedRed_green_blue_alpha_( red, green, blue, alpha)
def loadPrefs(self): try: editText = Glyphs.defaults["com.Tosche.Waterfall.edit"] if editText: self.w.edit.set(editText) R_f, G_f, B_f, A_f = Glyphs.defaults[ "com.Tosche.Waterfall.foreColour"] self.w.foreColour.set( NSColor.colorWithCalibratedRed_green_blue_alpha_( float(R_f), float(G_f), float(B_f), float(A_f))) R_b, G_b, B_b, A_b = Glyphs.defaults[ "com.Tosche.Waterfall.backColour"] self.w.backColour.set( NSColor.colorWithCalibratedRed_green_blue_alpha_( float(R_b), float(G_b), float(B_b), float(A_b))) except StandardError: print(traceback.format_exc())
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 makeColor(hexValue, a=1): if not hexValue: return None if hexValue[0] == '#': hexValue = hexValue[1:] r, g, b = struct.unpack('BBB', hexValue.decode('hex')) return NSColor.colorWithCalibratedRed_green_blue_alpha_( r / 255, g / 255, b / 255, a)
def _drawArrow(self, position, kind, size, vector=(-1, 1), level="e"): if vector is None: vector = (-1, 1) angle = atan2(vector[0], -vector[1]) size *= 2 x, y = position head_ratio = 0.7 w = size * 0.5 tail_width = 0.3 chin = 0.5 * (w - w * tail_width) # part under the head if level == "e": arrow_color = error_color else: arrow_color = warning_color NSColor.colorWithCalibratedRed_green_blue_alpha_(*arrow_color).set() t = NSAffineTransform.transform() t.translateXBy_yBy_(x, y) t.rotateByRadians_(angle) myPath = NSBezierPath.alloc().init() myPath.moveToPoint_((0, 0)) myPath.relativeLineToPoint_((-size * head_ratio, w * 0.5)) myPath.relativeLineToPoint_((0, -chin)) myPath.relativeLineToPoint_((-size * (1 - head_ratio), 0)) myPath.relativeLineToPoint_((0, -w * tail_width)) myPath.relativeLineToPoint_((size * (1 - head_ratio), 0)) myPath.relativeLineToPoint_((0, -chin)) myPath.closePath() myPath.transformUsingAffineTransform_(t) myPath.fill() percent = 1 if not self.show_labels: percent = ( -distance_between_points(self.mouse_position, position) / size * 2 + 2) if self.show_labels or percent > 0.2: self._drawTextLabel( transform=t, text=kind, size=size, vector=vector, percent=percent, )
def _loadDefaults(self): self._positions = {} positions = extensions.getExtensionDefault(defaultStub + "positions") for position, name in positions.items(): position = tuple(position.split(" ")) self._positions[position] = name self._margin = extensions.getExtensionDefault(defaultStub + "margin") self._inactiveOpacity = extensions.getExtensionDefault( defaultStub + "inactiveOpacity") r, g, b, a = extensions.getExtensionDefault(defaultStub + "foregroundColor") self._foregroundColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( r, g, b, a) r, g, b, a = extensions.getExtensionDefault(defaultStub + "backgroundColor") self._backgroundColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( r, g, b, a)
def __init__(self, red, green, blue, alpha = 1.0, image = False, im = ''): self.image = image if image: # self._ns_color = NSColor.colorWithPatternImage_(im._ns_image) self._ns_color = im._ns_image else: self._ns_color = NSColor.colorWithCalibratedRed_green_blue_alpha_( red, green, blue, alpha)
def drawNeighbors(self, info): save() fillColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 0.0, 0.0, 0.0, 0.05) fillColor.set() self._drawLeftNeighborsGlyphs(info["glyph"], scale=info["scale"]) UpdateCurrentGlyphView() restore()
def __init__(self): self.w = Window((150, 50), "set color") self.w.colorWell = ColorWell( (10, 10, -10, -10), callback=self.colorWellEdit, color=NSColor.colorWithCalibratedRed_green_blue_alpha_( 0, 0.2, 1, .25)) self.w.open()
def __init__(self, posSize, text, callback=None): # there must be a callback as it triggers the creation of the delegate if callback is None: callback = self._fallbackCallback super(FeatureTextEditor, self).__init__(posSize, "", callback=callback) self._nsObject.setHasHorizontalScroller_(True) font = NSFont.fontWithName_size_("Monaco", 10) self._textView.setFont_(font) self._textView.setUsesFindPanel_(True) ## line numbers #ruler = DefconAppKitLineNumberView.alloc().init() #ruler.setClientView_(self._textView) #self._nsObject.setVerticalRulerView_(ruler) #self._nsObject.setHasHorizontalRuler_(False) #self._nsObject.setHasVerticalRuler_(True) #self._nsObject.setRulersVisible_(True) #notificationCenter = NSNotificationCenter.defaultCenter() #notificationCenter.addObserver_selector_name_object_( # ruler, "clientViewSelectionChanged:", NSTextViewDidChangeSelectionNotification, self._textView #) # colors self._mainColor = NSColor.blackColor() self._commentColor = NSColor.colorWithCalibratedWhite_alpha_(.6, 1) self._keywordColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(.8, 0, 0, 1) self._tokenColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(.8, .4, 0, 1) self._classNameColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(0, 0, .8, 1) self._includeColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(.8, 0, .8, 1) self._stringColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(0, .6, 0, 1) # build the placard placardW = 65 placardH = 16 self._placardJumps = [] self._placard = vanilla.Group((0, 0, placardW, placardH)) self._placard.featureJumpButton = PlacardPopUpButton((0, 0, placardW, placardH), [], callback=self._placardFeatureSelectionCallback, sizeStyle="mini") self._nsObject.setPlacard_(self._placard.getNSView()) # registed for syntax coloring notifications self._programmaticallySettingText = False delegate = self._textViewDelegate delegate.vanillaWrapper = weakref.ref(self) notificationCenter = NSNotificationCenter.defaultCenter() notificationCenter.addObserver_selector_name_object_( self._textViewDelegate, "textStorageDidProcessEditing", NSTextStorageDidProcessEditingNotification, self._textView.textStorage()) # set the text self.set(text)
def drawPath(self, path=[]): """ Draw the points from path to a NSBezierPath. """ subpath = NSBezierPath.alloc().init() subpath.moveToPoint_(path[0][0]) for p in path[1:]: if len(p) == 3: # curve A, B, C = p subpath.curveToPoint_controlPoint1_controlPoint2_(C, A, B) else: subpath.lineToPoint_(p[0]) subpath.closePath() NSColor.colorWithCalibratedRed_green_blue_alpha_(0, 0, 1, self.alpha).set() subpath.stroke()
def drawSolidPreview(self, info): outline = self.getRotatedGlyph() pen = CocoaPen(None) outline.draw(pen) defaultPreviewColor = getDefault('glyphViewPreviewFillColor') fillColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( *defaultPreviewColor) fillColor.set() pen.path.fill()
def _drawTextLabel(self, transform, text, size, vector): if vector is None: vector = (-1, 1) angle = atan2(vector[0], -vector[1]) text_size = 0.5 * size #para_style = NSMutableParagraphStyle.alloc().init() #para_style.setAlignment_(NSCenterTextAlignment) attrs = { NSFontAttributeName: NSFont.systemFontOfSize_(text_size), NSForegroundColorAttributeName: NSColor.colorWithCalibratedRed_green_blue_alpha_( 0.4, 0.4, 0.6, 0.7 ), #NSParagraphStyleAttributeName: para_style, } myString = NSString.string().stringByAppendingString_(text) bbox = myString.sizeWithAttributes_(attrs) bw = bbox.width bh = bbox.height text_pt = NSPoint() text_pt.y = 0 if -0.5 * pi < angle <= 0.5 * pi: text_pt.x = -1.3 * size - bw / 2 * cos(angle) - bh / 2 * sin(angle) else: text_pt.x = -1.3 * size + bw / 2 * cos(angle) + bh / 2 * sin(angle) text_pt = transform.transformPoint_(text_pt) rr = NSRect( origin = (text_pt.x - bw / 2, text_pt.y - bh / 2), size = (bw, bh) ) if DEBUG: NSColor.colorWithCalibratedRed_green_blue_alpha_( 0, 0, 0, 0.15 ).set() myRect = NSBezierPath.bezierPathWithRect_(rr) myRect.setLineWidth_(0.05 * size) myRect.stroke() myString.drawInRect_withAttributes_( rr, attrs )
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 drawCellHeaderText(self, rect): paragraph = NSMutableParagraphStyle.alloc().init() paragraph.setAlignment_(NSCenterTextAlignment) paragraph.setLineBreakMode_(NSLineBreakByTruncatingMiddle) attributes = { NSFontAttributeName: NSFont.systemFontOfSize_(10.0), NSForegroundColorAttributeName: NSColor.colorWithCalibratedRed_green_blue_alpha_(.22, .22, .27, 1.0), NSParagraphStyleAttributeName: paragraph, } text = NSAttributedString.alloc().initWithString_attributes_(self.glyph.name, attributes) text.drawInRect_(rect)
def __init__(self): bgColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(255, 255, 255, 255) self.w = Window((1200, 900), minSize=(900, 600)) self.w.getNSWindow().setBackgroundColor_(bgColor) self.w.fontList = SingleFontList(self, AllFonts(), (0, 0, 300, 250)) self.w.matrixModel = Group((15, 265, 270, 270)) self.w.matrixView = Group((300, 0, 0, -0)) self.master_matrix = [] self.instance_matrix = [] self.ipf = .5 self.xpf = 1 x, y, wi, he = self.w.getPosSize() wi = (wi-300)/3 he /= 3 for i, k in enumerate(['a','b','c']): self.master_matrix.append([]) self.instance_matrix.append([]) for j, l in enumerate(['a','b','c']): setattr(self.w.matrixView, 'back'+k+l, Box((wi*i, he*j, wi, he))) setattr(self.w.matrixView, k+l, GlyphPreview((wi*i, he*j, wi, he))) setattr(self.w.matrixModel, 'back'+k+l, Box((90*i, 90*j, 90, 90))) setattr(self.w.matrixModel, k+l, SquareButton((5+(90*i), 5+(90*j), 80, 80), '', callback=self.pickSpot, sizeStyle='mini')) setattr(self.w.matrixModel, 'reset'+k+l, SquareButton((1+(90*i), 1+(90*j), 20, 20), 'x', callback=self.clearSpot, sizeStyle='mini')) spotButton = getattr(self.w.matrixModel, k+l) resetpot = getattr(self.w.matrixModel, 'reset'+k+l) resetpot.key = spotButton.key = (i,j,k,l) spotButton.getNSButton().setBordered_(False) resetpot.getNSButton().setBezelStyle_(7) self.master_matrix[i].append([k+l, None]) self.instance_matrix[i].append([k+l, None]) self.w.interpolation = Group((10, 565, 280, 50)) self.w.interpolation.start = TextBox((7, 2, 20, 12), '0', sizeStyle='mini') self.w.interpolation.end = TextBox((-20, 2, 20, 12), '1', sizeStyle='mini') self.w.interpolation.title = TextBox((20, 0, -20, 17), 'Interpolation factor', sizeStyle='small', alignment='center') self.w.interpolation.slider = Slider((5, 27, -5, 15), minValue=0, maxValue=1, value=self.ipf, callback=self.sliderInput, tickMarkCount=5) self.w.interpolation.slider.name = 'ipf' self.w.extrapolation = Group((10, 632, 280, 50)) self.w.extrapolation.start = TextBox((7, 2, 20, 12), '1', sizeStyle='mini') self.w.extrapolation.end = TextBox((-20, 2, 20, 12), '3', sizeStyle='mini') self.w.extrapolation.title = TextBox((20, 0, -20, 17), 'Extrapolation factor', sizeStyle='small', alignment='center') self.w.extrapolation.slider = Slider((5, 27, -5, 15), minValue=0, maxValue=2, value=self.xpf, callback=self.sliderInput, tickMarkCount=5) self.w.extrapolation.slider.name = 'xpf' self.spotFocus = getattr(self.w.matrixModel, 'bb') self.w.updateMatrixButton = Button((10, 727, 280, 20), 'Update', callback=self.updateMasters) self.w.resetMatrixButton = Button((10, 755, 280, 20), 'Reset', callback=self.resetMatrix) self.newFont = [] addObserver(self, 'updateMasters', 'currentGlyphChanged') addObserver(self, 'updateMasters', 'draw') addObserver(self, 'updateFontList', 'fontDidOpen') addObserver(self, 'updateFontList', 'fontDidClose') self.w.bind('close', self.windowClose) self.w.bind('resize', self.windowResize) self.w.open()
def init(self): self = super(DefconAppKitGlyphLineNSView, self).init() self._showLayers = False self._layerDrawingAttributes = {} self._fallbackDrawingAttributes = dict( showGlyphFill=True, showGlyphStroke=False, showGlyphOnCurvePoints=False, showGlyphStartPoints=False, showGlyphOffCurvePoints=False, showGlyphPointCoordinates=False, showGlyphAnchors=False, showGlyphImage=False, showGlyphMargins=False, showFontVerticalMetrics=False, showFontPostscriptBlues=False, showFontPostscriptFamilyBlues=False ) self._glyphRecords = [] self._alternateRects = {} self._currentZeroZeroPoint = NSPoint(0, 0) self._rightToLeft = False self._pointSize = 150 self._impliedPointSize = 150 self._scale = 1.0 self._inverseScale = 0.1 self._upm = 1000 self._descender = -250 self._bufferLeft = self._bufferRight = self._bufferBottom = self._bufferTop = 15 self._fitToFrame = None self._backgroundColor = NSColor.whiteColor() self._glyphColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(0, 0, 0, 1) self._alternateHighlightColor = defaultAlternateHighlightColor self._notdefBackgroundColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(1, 0, 0, .25) return self
def initWithFrame_imageDir_(self, frame, imageDir): self = super(IntroView, self).initWithFrame_(frame) if not self: return None dropboxImage = NSImage.alloc().initWithContentsOfFile_(os.path.join(imageDir, u'box_stroked_150.png')) iW, iH = dropboxImage.size() newHeight = iH * 300.0 / iW self.dropboxViewFinalPosition = NSRect((25, frame.size[1] - 43 - newHeight), (300, newHeight)) self.dropboxView = ShadowedImage.alloc().initWithFrame_(self.dropboxViewFinalPosition) self.dropboxView.setImageScaling_(NSScaleToFit) self.dropboxView.setImage_(dropboxImage) self.dropboxView.setShadowColor_(NSColor.colorWithCalibratedRed_green_blue_alpha_(0, 0, 0, 0.5)) self.dropboxView.setShadowOffset_((0.0, -2.0)) self.dropboxView.setShadowBlurRadius_(5.0) logoImage = NSImage.alloc().initWithContentsOfFile_(os.path.join(imageDir, u'dropboxlogo.png')) iW, iH = logoImage.size() newHeight = iH * 300.0 / iW self.logoViewFinalPosition = NSRect((25, frame.size[1] - 334 - newHeight), (300, newHeight)) self.logoView = NSImageView.alloc().initWithFrame_(self.logoViewFinalPosition) self.logoView.setImage_(logoImage) self.versionView = NSTextView.alloc().initWithFrame_(NSRect((0, 0), frame.size)) self.versionView.setDrawsBackground_(NO) self.versionView.setEditable_(NO) self.versionView.setSelectable_(NO) self.versionView.textStorage().mutableString().setString_(u'Version %s' % build_number.VERSION) self.versionView.textStorage().setFont_(NSFont.labelFontOfSize_(14)) self.versionView.layoutManager().glyphRangeForTextContainer_(self.versionView.textContainer()) textSize1 = self.versionView.layoutManager().usedRectForTextContainer_(self.versionView.textContainer()).size textAnchor1 = 5 self.versionView2 = NSTextView.alloc().initWithFrame_(NSRect((0, 0), frame.size)) self.versionView2.setDrawsBackground_(NO) self.versionView2.setEditable_(NO) self.versionView2.setSelectable_(NO) self.versionView2.textStorage().mutableString().setString_(u'Copyright \xa9 2007-2010 Dropbox Inc.') self.versionView2.setFont_(NSFont.systemFontOfSize_(NSFont.systemFontSizeForControlSize_(NSSmallControlSize))) self.versionView2.layoutManager().glyphRangeForTextContainer_(self.versionView2.textContainer()) textSize2 = self.versionView2.layoutManager().usedRectForTextContainer_(self.versionView2.textContainer()).size textAnchor2 = 4 bottomToLogoViewBaseline = self.logoView.frame().origin[1] + 17 textSeparation = 10 combinedHeight = textSize1[1] + textSize2[1] + textSeparation self.versionView2FinalPosition = NSRect(((frame.size[0] - textSize2[0]) / 2.0, (bottomToLogoViewBaseline - combinedHeight) / 2.0), (textSize2[0], textSize2[1] + textAnchor2)) self.versionView2.setFrame_(self.versionView2FinalPosition) self.versionViewFinalPosition = NSRect(((frame.size[0] - textSize1[0]) / 2.0, self.versionView2.frame().origin[1] + textSeparation + self.versionView2.frame().size[1]), (textSize1[0], textSize1[1] + textAnchor1)) self.versionView.setFrame_(self.versionViewFinalPosition) for _view in (self.dropboxView, self.logoView, self.versionView, self.versionView2): self.addSubview_(_view) return self
def __init__(self): # make window self.width *= 2 self.height = self.text_height + self.button_height*3 + self.padding*4 self.w = HUDFloatingWindow((self.width, self.height), "interpol preview") # get colors x = y = p = self.padding self.w.mark_color = ColorWell( (x, y, -p, self.button_height), color=NSColor.colorWithCalibratedRed_green_blue_alpha_(*self.mark_color)) y += self.button_height + p self.w.mark_color_2 = ColorWell( (x, y, -p, self.button_height), color=NSColor.colorWithCalibratedRed_green_blue_alpha_(*self.mark_color_2)) # show all fonts self.get_fonts() y += self.button_height + p self.w.f2 = PopUpButton( (x, y, -p, self.text_height), sorted(self.all_fonts.keys()), sizeStyle='small') # show preview checkbox y += self.text_height + p*0.5 self.w.on_off_button = CheckBox( (x, y, -p, self.button_height), "show preview", value=True, sizeStyle='small', callback=self.view_callback ) # turn visualization ON self.on() # add observers addObserver(self, "update_callback", "newFontDidOpen") addObserver(self, "update_callback", "fontDidOpen") addObserver(self, "update_callback", "fontDidClose") # open window self.setUpBaseWindowBehavior() 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 _drawDirtyStateImage(value): if value: imageName = "defconAppKitFontListDirtyStateTrue" else: imageName = "defconAppKitFontListDirtyStateFalse" image = NSImage.imageNamed_(imageName) if image is None: # make the image width = 13 height = 17 image = NSImage.alloc().initWithSize_((width, height)) image.lockFocus() # draw if dirty if value: rect = ((2, 4), (9, 9)) path = NSBezierPath.bezierPathWithOvalInRect_(rect) path.addClip() # colors color1 = NSColor.colorWithCalibratedRed_green_blue_alpha_(1.0, 0.1, 0.1, 1) color2 = NSColor.colorWithCalibratedRed_green_blue_alpha_(0.5, 0.0, 0.0, 1) # fill color1.set() path.fill() # shadow try: gradient = NSGradient.alloc().initWithColors_([color1, color2]) gradient.drawInBezierPath_angle_(path, -90) except NameError: pass # stroke color2.set() path.setLineWidth_(2) path.stroke() image.unlockFocus() image.setName_(imageName) image = NSImage.imageNamed_(imageName) return image
def __init__(self, ): self.w = FloatingWindow( (190, 140), self._title, closable=False) # layer self.w._layers_label = TextBox( (self._padding, self._padding, -self._padding, 17), "target layer:") self.w._layers_value = EditText( (self._padding, 35, -self._padding, 21), placeholder='layer name') # mark color self.w.mark_checkbox = CheckBox( (self._padding, 70, -self._padding, 20), "mark glyphs", value=True) self.w.mark_color = ColorWell( (120, 70, -13, 20), color=NSColor.colorWithCalibratedRed_green_blue_alpha_(*self._mark_color)) # buttons self.w.button_apply = Button( (self._padding, -45, 80, 0), "apply", callback=self.apply_callback) self.w.button_close = Button( (-90, -45, 80, 0), "close", callback=self.close_callback) # open window self.w.open()
def _drawArrow(self, position, kind, size, vector = (-1, 1)): if vector is None: vector = (-1, 1) angle = atan2(vector[0], -vector[1]) size *= 2 x, y = position head_ratio = 0.7 w = size * 0.5 tail_width = 0.3 chin = 0.5 * (w - w * tail_width) # part under the head 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.moveToPoint_( (0, 0) ) myPath.relativeLineToPoint_( (-size * head_ratio, w * 0.5) ) myPath.relativeLineToPoint_( (0, -chin) ) myPath.relativeLineToPoint_( (-size * (1 - head_ratio), 0) ) myPath.relativeLineToPoint_( (0, -w * tail_width) ) myPath.relativeLineToPoint_( (size * (1 - head_ratio), 0) ) myPath.relativeLineToPoint_( (0, -chin) ) myPath.closePath() myPath.transformUsingAffineTransform_(t) myPath.fill() if self.show_labels or distance_between_points(self.mouse_position, position) < size: self._drawTextLabel( transform = t, text = kind, size = size, vector = vector, )
def animateOneFrame(self): # choose a random point. (x, y), (fw, fh) = self.frame() x, y = randrange(0.0, fw), randrange(0.0, fw) ballSize = randrange(10.0, 90.0) path = NSBezierPath.bezierPathWithOvalInRect_(((x, y), (ballSize, ballSize))) # make a random color. randomColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(random(), random(), random(), random()) # set it. randomColor.set() # draw a new ball. path.fill()
def __init__(self): self.title = 'color' self.width = 123 self.height = (self.button_height * 4) + (self.padding_y * 4) self.w = FloatingWindow( (self.width, self.height), self.title) # mark color x = self.padding_x y = self.padding_y self.w.mark_color = ColorWell( (x, y, -self.padding_x, self.button_height), color=NSColor.colorWithCalibratedRed_green_blue_alpha_(*self.mark_color)) # paint button y += (self.button_height - 1) self.w.button_paint = SquareButton( (x, y, -self.padding_x, self.button_height), "paint", callback=self.paint_callback, sizeStyle=self.size_style) # select button y += (self.button_height + self.padding_y) self.w.button_select = SquareButton( (x, y, -self.padding_x, self.button_height), "select", callback=self.select_callback, sizeStyle=self.size_style) # clear button y += (self.button_height + self.padding_y) self.w.button_clear = SquareButton( (x, y, -self.padding_x, self.button_height), "clear", callback=self.clear_callback, sizeStyle=self.size_style) # open window self.w.open()
def __init__(self, posSize, delegate=None, paperSize=(1000, 1000), acceptsMouseMoved=False, hasHorizontalScroller=True, hasVerticalScroller=True, autohidesScrollers=False, backgroundColor=None, drawsBackground=True, width=200, height=1000): # Initializes group first. super(Paper, self).__init__(posSize) if backgroundColor is None: white = NSColor.colorWithCalibratedRed_green_blue_alpha_(1, 1, 1, 1) backgroundColor = white self.paperView = PaperNSView(paperSize, delegate, acceptsMouseMoved=acceptsMouseMoved) self.scrollView = ScrollView((0, 0, -0, -0), self.paperView, backgroundColor=backgroundColor, hasHorizontalScroller=hasHorizontalScroller, hasVerticalScroller=hasVerticalScroller, autohidesScrollers=autohidesScrollers, drawsBackground=drawsBackground) self.width = width self.height = height
def __init__(self): self.w = FloatingWindow( (self._width, self._height), self._title, closable=True) # mark color x = self._padding y = self._padding self.w.mark_color = ColorWell( (x, y, -self._padding, self._button_height), color=NSColor.colorWithCalibratedRed_green_blue_alpha_(*self._mark_color)) # paint button y += self._button_height - 1 self.w.button_paint = SquareButton( (x, y, -self._padding, self._button_height), "paint", callback=self.paint_callback, sizeStyle='small') # select button y += self._button_height + self._padding_top self.w.button_select = SquareButton( (x, y, -self._padding, self._button_height), "select", callback=self.select_callback, sizeStyle='small') # clear button y += self._button_height + self._padding_top self.w.button_clear = SquareButton( (x, y, -self._padding, self._button_height), "clear", callback=self.clear_callback, sizeStyle='small') # open window self.w.open()
def __init__(self): self.title = 'color' self.height = self.button_height*5 + self.padding*5 - 1 self.w = HUDFloatingWindow((self.width, self.height), self.title) x = y = p = self.padding # get color self.w.button_get = SquareButton( (x, y, -p, self.button_height), "get", callback=self.get_color_callback, sizeStyle=self.size_style) # color swatch y += self.button_height + p self.w.mark_color = ColorWell( (x, y, -p, self.button_height), color=NSColor.colorWithCalibratedRed_green_blue_alpha_(*self.mark_color)) # paint button y += self.button_height - 1 self.w.button_paint = SquareButton( (x, y, -p, self.button_height), "paint", callback=self.paint_callback, sizeStyle=self.size_style) # select button y += self.button_height - 1 + p self.w.button_select = SquareButton( (x, y, -p, self.button_height), "select", callback=self.select_callback, sizeStyle=self.size_style) # clear button y += self.button_height + p self.w.button_clear = SquareButton( (x, y, -p, self.button_height), "clear", callback=self.clear_callback, sizeStyle=self.size_style) # open window self.w.open()
def drawPath(path=None): # draws the path if path is None: path = currentPath if currentFillColor is not None: currentFillColor.set() path.fill() if currentGradient is not None: save() path.addClip() (gradientType, startPoint, endPoint, colors, locations) = currentGradient NSColors = [] for color in colors: a = 1 g = None if len(color) == 1: r = color[0] elif len(color) == 2: r, a = color elif len(color) == 3: r, g, b = color elif len(color) == 4: r, g, b, a = color if g is not None: NSColors.append(NSColor.colorWithCalibratedRed_green_blue_alpha_(r, g, b, a)) else: NSColors.append(NSColor.colorWithCalibratedWhite_alpha_(r, a)) gradient = NSGradient.alloc().initWithColors_atLocations_colorSpace_(NSColors, locations, NSColorSpace.deviceRGBColorSpace()) if gradientType == "linear": gradient.drawFromPoint_toPoint_options_(startPoint, endPoint, NSGradientDrawsBeforeStartingLocation | NSGradientDrawsAfterEndingLocation) elif gradient.gradientType == "radial": pass restore() if currentStrokeWidth is not None: path.setLineWidth_(currentStrokeWidth) if currentStrokeColor is not None: currentStrokeColor.set() path.stroke()
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)