本文整理汇总了Python中AppKit.NSColor类的典型用法代码示例。如果您正苦于以下问题:Python NSColor类的具体用法?Python NSColor怎么用?Python NSColor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NSColor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drawWithFrame_inView_
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)))
示例2: __init__
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()
示例3: __init__
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()
示例4: drawHashMarksAndLabelsInRect_
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()
示例5: __init__
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()
示例6: drawRect_
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()
示例7: drawRect_
def drawRect_(self, rect):
printB("drawRect", rect )
"""."""
NSColor.whiteColor().set()
NSBezierPath.fillRect_(rect)
self.itemColor().set()
NSBezierPath.fillRect_(self.calculatedItemBounds())
示例8: drawRect_
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()
示例9: draw_ground
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()
示例10: draw_color
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()
示例11: stroke
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)
示例12: linearGradient
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
示例13: check_signature_matcher
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))
示例14: draw_color
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()
示例15: drawline
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()