本文整理汇总了Python中AppKit.NSFont类的典型用法代码示例。如果您正苦于以下问题:Python NSFont类的具体用法?Python NSFont怎么用?Python NSFont使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NSFont类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, posSize, titles, isVertical=True, callback=None, sizeStyle="regular"):
self._setupView(self.nsMatrixClass, posSize, callback=callback)
self._isVertical = isVertical
matrix = self._nsObject
matrix.setMode_(NSRadioModeMatrix)
matrix.setCellClass_(self.nsCellClass)
# XXX! this does not work for vertical radio groups!
matrix.setAutosizesCells_(True)
# we handle the control size setting here
# since the actual NS object is a NSMatrix
cellSizeStyle = _sizeStyleMap[sizeStyle]
font = NSFont.systemFontOfSize_(NSFont.systemFontSizeForControlSize_(cellSizeStyle))
# intercell spacing and cell spacing are based on the sizeStyle
if sizeStyle == "regular":
matrix.setIntercellSpacing_((4.0, 2.0))
matrix.setCellSize_((posSize[2], 18))
elif sizeStyle == "small":
matrix.setIntercellSpacing_((3.5, 2.0))
matrix.setCellSize_((posSize[2], 15))
elif sizeStyle == "mini":
matrix.setIntercellSpacing_((3.0, 2.0))
matrix.setCellSize_((posSize[2], 12))
else:
raise ValueError("sizeStyle must be 'regular', 'small' or 'mini'")
for _ in range(len(titles)):
if isVertical:
matrix.addRow()
else:
matrix.addColumn()
for title, cell in zip(titles, matrix.cells()):
cell.setButtonType_(NSRadioButton)
cell.setTitle_(title)
cell.setControlSize_(cellSizeStyle)
cell.setFont_(font)
示例2: init
def init(self, wizard):
self = super(SetupWizardWindow, self).initWithContentRect_styleMask_backing_defer_(NSRect((0, 0), (580, 500)), NSTitledWindowMask | NSClosableWindowMask, NSBackingStoreBuffered, NO)
if self is not None:
self._wizard = wizard
self._dropbox_app = wizard.dropbox_app
self.setReleasedWhenClosed_(NO)
self.center()
self.setLevel_(NSFloatingWindowLevel)
self._system_font = NSFont.systemFontOfSize_(NSFont.systemFontSizeForControlSize_(NSRegularControlSize))
self._small_system_font = NSFont.systemFontOfSize_(NSFont.systemFontSizeForControlSize_(NSSmallControlSize))
self.setTitle_(SetupWizardStrings.window_title)
self._renderers = {Button: self._create_button,
CenteredMultiControlLine: self._create_centered_multi_control_line,
Checkbox: self._create_checkbox,
Choice: self._create_choice,
CreditCardType: self._create_credit_card_type,
Date: self._create_date,
ExampleText: self._create_example_text,
FancyRadioGroup: self._create_fancy_radio_group,
FlagChoice: self._create_flag_choice,
HelpButton: self._create_help_button,
Image: self._create_image,
LocationChanger: self._create_location_changer,
MultiControlLine: self._create_multi_control_line,
MultiControlLineSimple: self._create_multi_control_line,
TextBlock: self._create_text_block,
TextInput: self._create_text_input,
PlanChoices: self._create_plan_choices,
RadioGroup: self._create_radio_group,
SelectiveSync: self._create_selective_sync,
Spacer: self._create_spacer}
self._buttons = {}
return self
示例3: drawFontVerticalMetrics
def drawFontVerticalMetrics(glyph, scale, rect, drawLines=True, drawText=True, color=None, backgroundColor=None, flipped=False):
font = glyph.font
if font is None:
return
if color is None:
color = getDefaultColor("fontVerticalMetrics")
if backgroundColor is None:
backgroundColor = getDefaultColor("background")
color.set()
# gather y positions
toDraw = (
("Descender", "descender"),
("X Height", "xHeight"),
("Cap Height", "capHeight"),
("Ascender", "ascender")
)
toDraw = [(name, getattr(font.info, attr)) for name, attr in toDraw if getattr(font.info, attr) is not None]
toDraw.append(("Baseline", 0))
positions = {}
for name, position in toDraw:
if position not in positions:
positions[position] = []
positions[position].append(name)
# create lines
xMin = rect[0][0]
xMax = xMin + rect[1][0]
lines = []
for y, names in sorted(positions.items()):
names = ", ".join(names)
lines.append(((xMin, y), (xMax, y), names))
# draw lines
if drawLines:
lineWidth = 1.0 * scale
for pt1, pt2, names in lines:
drawLine(pt1, pt2, lineWidth=lineWidth)
# draw text
if drawText:
fontSize = 9
shadow = NSShadow.shadow()
shadow.setShadowColor_(backgroundColor)
shadow.setShadowBlurRadius_(5)
shadow.setShadowOffset_((0, 0))
attributes = {
NSFontAttributeName: NSFont.systemFontOfSize_(fontSize),
NSForegroundColorAttributeName: color
}
glowAttributes = {
NSFontAttributeName: NSFont.systemFontOfSize_(fontSize),
NSForegroundColorAttributeName: color,
NSStrokeColorAttributeName: backgroundColor,
NSStrokeWidthAttributeName: 25,
NSShadowAttributeName: shadow
}
for pt1, pt2, names in lines:
x, y = pt1
x += 5 * scale
y -= (fontSize / 2.0) * scale
drawTextAtPoint(names, (x, y), scale, glowAttributes, flipped=flipped)
drawTextAtPoint(names, (x, y), scale, attributes, flipped=flipped)
示例4: init
def init(self):
self = super(LineNumberNSRulerView, self).init()
self._font = NSFont.labelFontOfSize_(NSFont.systemFontSizeForControlSize_(NSMiniControlSize))
self._textColor = NSColor.colorWithCalibratedWhite_alpha_(.42, 1)
self._rulerBackgroundColor = None
self._lineIndices = None
return self
示例5: SmallTextListCell
def SmallTextListCell(editable=False):
cell = NSTextFieldCell.alloc().init()
size = NSSmallControlSize
cell.setControlSize_(size)
font = NSFont.systemFontOfSize_(NSFont.systemFontSizeForControlSize_(size))
cell.setFont_(font)
cell.setEditable_(editable)
return cell
示例6: __init__
def __init__(self, posSize, title=None):
self._setupView(self.nsBoxClass, posSize)
if title:
self._nsObject.setTitle_(title)
if osVersionCurrent < osVersion10_10:
self._nsObject.titleCell().setTextColor_(NSColor.blackColor())
font = NSFont.systemFontOfSize_(NSFont.systemFontSizeForControlSize_(NSSmallControlSize))
self._nsObject.setTitleFont_(font)
else:
self._nsObject.setTitlePosition_(NSNoTitle)
示例7: __init__
def __init__(self, dimensions, font):
font_name = font.info.familyName
attribution = "{} by {}".format(font_name, font.info.designer)
attribution_attributes = {
NSFontAttributeName: NSFont.systemFontOfSize_(NSFont.systemFontSize()),
NSForegroundColorAttributeName: NSColor.whiteColor()
}
formatted_attribution = NSMutableAttributedString.alloc().initWithString_attributes_(attribution, attribution_attributes)
formatted_attribution.addAttribute_value_range_(NSFontAttributeName, NSFont.boldSystemFontOfSize_(NSFont.systemFontSize()), [0, len(font_name)])
super(AttributionText, self).__init__(dimensions, formatted_attribution)
示例8: initWithFrame_imageDir_
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
示例9: _setFont
def _setFont(self, font):
self.font.getNSTextField().setFont_(NSFont.fontWithName_size_(font.fontName(), 10))
size = font.pointSize()
if size == int(size):
size = int(size)
s = u"%s %spt" % (font.displayName(), size)
self.font.set(s)
示例10: drawTextAtPoint
def drawTextAtPoint(self, text, textPosition, fontSize=10.0, fontColor=NSColor.blackColor(), align='bottomleft'):
"""
Use self.drawTextAtPoint("blabla", myNSPoint) to display left-aligned text at myNSPoint.
"""
try:
alignment = {
'topleft': 6,
'topcenter': 7,
'topright': 8,
'left': 3,
'center': 4,
'right': 5,
'bottomleft': 0,
'bottomcenter': 1,
'bottomright': 2
}
currentZoom = self.getScale()
fontAttributes = {
NSFontAttributeName: NSFont.labelFontOfSize_(fontSize / currentZoom),
NSForegroundColorAttributeName: fontColor}
displayText = NSAttributedString.alloc().initWithString_attributes_(unicode(text), fontAttributes)
textAlignment = alignment[align] # top left: 6, top center: 7, top right: 8, center left: 3, center center: 4, center right: 5, bottom left: 0, bottom center: 1, bottom right: 2
displayText.drawAtPoint_alignment_(textPosition, textAlignment)
except:
self.logError(traceback.format_exc())
示例11: awakeFromNib
def awakeFromNib(self):
NSLog("Awake from nib.")
self.setPreviewMode(True)
self.bodyField.setDelegate_(self)
self.urlField.setDelegate_(self)
self.titleField.setDelegate_(self)
# Style the bodyField.
self.bodyField.setFont_(NSFont.fontWithName_size_("Monaco", 13))
self.bodyField.setRichText_(NO)
self.bodyField.setUsesFontPanel_(NO)
# Authenticate to twitter if we can.
if self.twitter.is_authenticated():
self.twitter.login()
self.twitterCheckbox.setState_(NSOnState)
self.ltp.syndicators.append(self.twitter)
# Authenticate to G+ if we can.
if self.gplus.is_authenticated():
self.gplus.login()
self.gplusCheckbox.setState_(NSOnState)
self.ltp.syndicators.append(self.gplus)
# Listen to the NSApplicationWillTerminateNotification.
center = NSNotificationCenter.defaultCenter()
center.addObserver_selector_name_object_(self, "applicationWillTerminateNotification:", NSApplicationWillTerminateNotification, None)
self.setupStatusBar()
self.didPublish = False
self.didPreview = False
示例12: initWithFrame_view_size_name_captionText_
def initWithFrame_view_size_name_captionText_(self, frame, view, size, name, caption_text):
self = super(PictureView, self).initWithFrame_(frame)
if not self:
return
_size = iW, iH = size
xOffset = (frame.size[0] - iW) / 2.0
yOffset = frame.size[1] - xOffset - iH
self.dropboxViewFinalPosition = NSRect((xOffset, yOffset), _size)
self.dropboxView = view
self.dropboxView.setFrame_(self.dropboxViewFinalPosition)
self.addSubview_(self.dropboxView)
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().beginEditing()
self.versionView.textStorage().mutableString().setString_(name)
self.versionView.textStorage().setForegroundColor_(NSColor.whiteColor())
self.versionView.textStorage().setFont_(NSFont.labelFontOfSize_(18))
self.versionView.textStorage().endEditing()
self.versionView.setAlignment_range_(NSCenterTextAlignment, NSMakeRange(0, self.versionView.string().length()))
self.versionView.layoutManager().glyphRangeForTextContainer_(self.versionView.textContainer())
textSize1 = self.versionView.layoutManager().usedRectForTextContainer_(self.versionView.textContainer()).size
textAnchor1 = 0
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().beginEditing()
self.versionView2.textStorage().mutableString().setString_(u'"%s"' % (caption_text,))
self.versionView2.textStorage().setForegroundColor_(NSColor.whiteColor())
self.versionView2.textStorage().setFont_(NSFont.labelFontOfSize_(13))
self.versionView2.textStorage().endEditing()
self.versionView2.setAlignment_range_(NSCenterTextAlignment, NSMakeRange(0, self.versionView2.string().length()))
self.versionView2.layoutManager().glyphRangeForTextContainer_(self.versionView2.textContainer())
textSize2 = self.versionView2.layoutManager().usedRectForTextContainer_(self.versionView2.textContainer()).size
textAnchor2 = 0
bottomToLogoViewBaseline = yOffset
textSeparation = (yOffset - textSize1[1] - textSize2[1]) * 0.2
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)
self.addSubview_(self.versionView)
self.addSubview_(self.versionView2)
return self
示例13: attributed_text_at_size
def attributed_text_at_size(text, size):
paragraph_style = NSMutableParagraphStyle.new()
paragraph_style.setAlignment_(NSCenterTextAlignment)
attrs = {
NSParagraphStyleAttributeName: paragraph_style,
NSFontAttributeName: NSFont.boldSystemFontOfSize_(size),
NSForegroundColorAttributeName: NSColor.whiteColor()
}
return NSAttributedString.alloc().initWithString_attributes_(text, attrs)
示例14: initWithDropboxApp_initialIgnoreList_takeAction_callback_remote_
def initWithDropboxApp_initialIgnoreList_takeAction_callback_remote_(self, dropbox_app, initial_ignore_list, take_action, callback, remote):
self = super(SelectiveSyncView, self).initWithFrame_(NSZeroRect)
if self is None:
return
self._initial_ignore_list = initial_ignore_list
self._callback = callback
self._take_action = take_action
self._remote = remote
self.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable)
self._dropbox_app = dropbox_app
self.initBrowser(self._remote)
self.initButtons()
f = NSFont.systemFontOfSize_(NSFont.smallSystemFontSize())
self.infoLabel = NSTextField.createLabelWithText_font_(selsync_strings.info, f)
self.addSubview_(self.infoLabel)
self.reloadInvalidState()
self.layoutForWidth_(DEFAULT_ADVANCED_WIDTH if self.forest.advanced_view else DEFAULT_SIMPLE_WIDTH)
return self
示例15: _set_defaults
def _set_defaults(self):
self._inner_padding = WIZARD_BOX_PADDING
self.titleCell().setLineBreakMode_(NSLineBreakByWordWrapping)
self.setTitleFont_(NSFont.boldSystemFontOfSize_(14))
self.titleCell().setTextColor_(Colors.black)
self.titleCell().setAlignment_(NSLeftTextAlignment)
self.setBackgroundColor_(Colors.setup_wizard_background)
self.setBorderColor_(Colors.setup_wizard_border)
self._resize_content_view()