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)
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)
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()
def text_Bold(text): size = NSRegularControlSize attrs = {} string = NSMutableAttributedString.alloc().initWithString_attributes_( text, attrs) attrs[NSFontAttributeName] = NSFont.boldSystemFontOfSize_( NSFont.systemFontSizeForControlSize_(size)) attributedString = NSMutableAttributedString.alloc( ).initWithString_attributes_(text, attrs) return attributedString
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)
def drawGlyphAnchors(glyph, scale, rect, drawAnchor=True, drawText=True, color=None, textColor=None, backgroundColor=None, flipped=False): if not glyph.anchors: return if color is None: color = getDefaultColor("glyphAnchor") fallbackColor = color if backgroundColor is None: backgroundColor = getDefaultColor("background") anchorSize = 5 * scale anchorHalfSize = anchorSize / 2 for anchor in glyph.anchors: if anchor.color is not None: color = colorToNSColor(anchor.color) else: color = fallbackColor x = anchor.x y = anchor.y name = anchor.name context = NSGraphicsContext.currentContext() context.saveGraphicsState() #shadow = NSShadow.alloc().init() #shadow.setShadowColor_(backgroundColor) #shadow.setShadowOffset_((0, 0)) #shadow.setShadowBlurRadius_(3) #shadow.set() if drawAnchor: r = ((x - anchorHalfSize, y - anchorHalfSize), (anchorSize, anchorSize)) color.set() drawFilledOval(r) if drawText and name: attributes = { NSFontAttributeName: NSFont.boldSystemFontOfSize_(12), NSForegroundColorAttributeName: textColor, } y += 25 * scale drawTextAtPoint(name, (x, y), scale, attributes, xAlign="center", yAlign="top", flipped=flipped) context.restoreGraphicsState()
def __init__(self, dimensions, font): font_name = font.info.familyName or "" attribution = "{} by {}".format(font_name, font.info.openTypeNameDesigner) 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)
def layout(self): self._thumbnail = ThumbnailBoxView.alloc().initWithFrame_(NSZeroRect) self._thumbnail.setImage_(Images.Box64) self._thumbnail.setImageAlignment_(NSImageAlignCenter) self._thumbnail.setImageScaling_(NSScaleToFit) self._thumbnail.setFrameSize_(self.THUMBNAIL_SIZE) self._thumbnail.setFrameOrigin_(self.THUMBNAIL_ORIGIN) self._thumbnail.setShadowOffset_(self.SHADOW_OFFSET) self._thumbnail.setShadowBlurRadius_(self.SHADOW_BLUR) self._thumbnail.setShadowColor_(NSColor.blackColor().colorWithAlphaComponent_(0.3)) self._label = NSTextField.createLabelWithText_font_('', NSFont.boldSystemFontOfSize_(13)) self._label.setFrameOrigin_(self.LABEL_ORIGIN) self._progress_bar = NSProgressIndicator.alloc().initWithFrame_(NSRect(self.PROGRESS_ORIGIN, self.PROGRESS_SIZE)) self._progress_bar.setStyle_(NSProgressIndicatorBarStyle) self._progress_bar.setIndeterminate_(YES) self._progress_bar.setFrameOrigin_(self.PROGRESS_ORIGIN) self._estimate = NSTextField.createLabelWithText_font_('', NSFont.systemFontOfSize_(NSFont.smallSystemFontSize())) self._estimate.setFrameOrigin_(self.ESTIMATE_ORIGIN) self._hide_button = self.addNormalRoundButtonWithTitle_action_(MiscStrings.hide_button, self.handleHideButton_) self._hide_button.setKeyEquivalent_(ENTER_KEY) self._hide_button.alignRightInSuperview() self._hide_button.alignBottomInSuperview() self._cancel_button = self.addNormalRoundButtonWithTitle_action_(MiscStrings.cancel_button, self.handleCancelButton_) self._cancel_button.placeLeftOfButton_(self._hide_button) self.addSubview_(self._thumbnail) self.addSubview_(self._label) self.addSubview_(self._progress_bar) self.addSubview_(self._estimate) @message_sender(AppHelper.callAfter) def handleMessage(message): self._label.setStringValue_(message) self._label.sizeToFit() @message_sender(AppHelper.callAfter) def handleTotalBytes(total_bytes): self._progress_bar.setIndeterminate_(YES if total_bytes == 0 else NO) self._progress_bar.setMinValue_(0.0) self._progress_bar.setMaxValue_(total_bytes) self._progress_bar.setDoubleValue_(self.ui.cur_bytes.get()) @message_sender(AppHelper.callAfter) def handleCurBytes(cur_bytes): self._progress_bar.setDoubleValue_(cur_bytes) self._estimate.setStringValue_(self.ui.get_remaining_message()) self._estimate.sizeToFit() @message_sender(AppHelper.callAfter) def handleLastPhoto(path): if path: if time.time() - self.last_photo_time > self.THUMBNAIL_TIMEOUT: image = NSImage.alloc().initByReferencingFile_(unicode(path)) if image.isValid(): self._thumbnail.setBorder_(True) self._thumbnail.setImage_(image) self.last_photo_time = time.time() else: self._thumbnail.setBorder_(False) self._thumbnail.setImage_(Images.Box64) handleMessage(self.ui.message.get()) handleTotalBytes(self.ui.total_bytes.get()) handleCurBytes(self.ui.cur_bytes.get()) handleLastPhoto(self.ui.last_photo.get()) self.ui.message.register(handleMessage) self.ui.total_bytes.register(handleTotalBytes) self.ui.cur_bytes.register(handleCurBytes) self.ui.last_photo.register(handleLastPhoto)
def addCountBadgeToIcon(count, iconImage=None): if iconImage is None: iconImage = NSImage.alloc().initWithSize_((40, 40)) iconImage.lockFocus() NSColor.colorWithCalibratedRed_green_blue_alpha_(0, 0, 1, .5).set() path = NSBezierPath.bezierPath() path.appendBezierPathWithOvalInRect_(((0, 0), iconImage.size())) path.fill() iconImage.unlockFocus() # badge text textShadow = NSShadow.alloc().init() textShadow.setShadowOffset_((2, -2)) textShadow.setShadowColor_( NSColor.colorWithCalibratedRed_green_blue_alpha_(0, 0, 0, 1.0)) textShadow.setShadowBlurRadius_(2.0) paragraph = NSMutableParagraphStyle.alloc().init() paragraph.setAlignment_(NSCenterTextAlignment) paragraph.setLineBreakMode_(NSLineBreakByCharWrapping) attributes = { NSFontAttributeName: NSFont.boldSystemFontOfSize_(12.0), NSForegroundColorAttributeName: NSColor.whiteColor(), NSParagraphStyleAttributeName: paragraph, NSShadowAttributeName: textShadow } text = NSAttributedString.alloc().initWithString_attributes_( str(count), attributes) rectWidth, rectHeight = NSString.stringWithString_( str(count)).sizeWithAttributes_(attributes) rectWidth = int(round(rectWidth + 8)) rectHeight = int(round(rectHeight + 4)) rectLeft = 0 rectBottom = 0 # badge shadow badgeShadow = NSShadow.alloc().init() badgeShadow.setShadowOffset_((0, -2)) badgeShadow.setShadowColor_(NSColor.blackColor()) badgeShadow.setShadowBlurRadius_(4.0) # badge path badgePath = roundedRectBezierPath( ((rectLeft, rectBottom), (rectWidth, rectHeight)), 3) # badge image badgeWidth = rectWidth + 3 badgeHeight = rectHeight + 3 badgeImage = NSImage.alloc().initWithSize_((badgeWidth, badgeHeight)) badgeImage.lockFocus() transform = NSAffineTransform.transform() transform.translateXBy_yBy_(1.5, 1.5) transform.concat() NSColor.colorWithCalibratedRed_green_blue_alpha_(.2, .2, .25, 1.0).set() badgePath.fill() NSColor.colorWithCalibratedRed_green_blue_alpha_(.8, .8, .9, 1.0).set() badgePath.setLineWidth_(1.0) badgePath.stroke() text.drawInRect_(((0, -1), (rectWidth, rectHeight))) badgeImage.unlockFocus() # make the composite image imageWidth, imageHeight = iconImage.size() imageWidth += (badgeWidth - 15) imageHeight += 10 badgeLeft = imageWidth - badgeWidth - 3 badgeBottom = 3 image = NSImage.alloc().initWithSize_((imageWidth, imageHeight)) image.lockFocus() context = NSGraphicsContext.currentContext() # icon iconImage.drawAtPoint_fromRect_operation_fraction_( (0, 10), ((0, 0), iconImage.size()), NSCompositeSourceOver, 1.0) # badge context.saveGraphicsState() badgeShadow.set() badgeImage.drawAtPoint_fromRect_operation_fraction_( (badgeLeft, badgeBottom), ((0, 0), badgeImage.size()), NSCompositeSourceOver, 1.0) context.restoreGraphicsState() # done image.unlockFocus() return image
def layout(self): height = self.BORDER + self.IMAGE_PADDING width = self.VIEW_SIZE[0] - self.BORDER * 2 image = NonBlurryImageView.alloc().initWithFrame_(NSZeroRect) image.setImage_(self.image) image.setFrameSize_(self.image.size()) self.addSubview_(image) image.setFrameOrigin_((0, height)) image.centerHorizontallyInSuperview() height += NSHeight(image.frame()) + self.HEADER_PADDING label1 = NSTextField.createLabelWithText_font_maxWidth_origin_(self.header, NSFont.boldSystemFontOfSize_(self.HEADER_SIZE) if self.BOLD_HEADER else NSFont.systemFontOfSize_(self.HEADER_SIZE), width, NSPoint(0, height)) self.addSubview_(label1) label1.centerHorizontallyInSuperview() label1.setTextColor_(self.HEADER_COLOR) height += NSHeight(label1.frame()) + self.SUBHEADER_PADDING label2 = NSTextField.createLabelWithText_font_maxWidth_origin_(NSAttributedString.boldify(self.subheader, font=NSFont.systemFontOfSize_(self.SUBHEADER_SIZE), bold_font=NSFont.boldSystemFontOfSize_(self.SUBHEADER_SIZE), center=True, line_height=self.SUBHEADER_LINE_HEIGHT), NSFont.systemFontOfSize_(self.SUBHEADER_SIZE), width, NSPoint(0, height)) self.addSubview_(label2) label2.setAlignment_(NSCenterTextAlignment) label2.setTextColor_(self.SUBHEADER_COLOR) label2.balancedWrapToWidth_(width) label2.centerHorizontallyInSuperview() if self.checkbox_text: checkbox = NSButton.alloc().initWithFrame_(NSZeroRect) self.addSubview_(checkbox) checkbox.setButtonType_(NSSwitchButton) checkbox.setAttributedTitle_(NSAttributedString.boldify(self.checkbox_text, font=NSFont.systemFontOfSize_(self.CHECKBOX_SIZE), bold_font=NSFont.boldSystemFontOfSize_(self.CHECKBOX_SIZE))) checkbox.setTextColor_(Colors.camera_font) checkbox.sizeToFit() if NSWidth(checkbox.frame()) > width: checkbox.setAttributedTitle_(CameraStrings.splash_always_import_no_name) checkbox.setTextColor_(Colors.camera_font) checkbox.sizeToFit() checkbox.setState_(True) checkbox.centerHorizontallyInSuperview() checkbox.alignBottomInSuperview(self.BORDER - checkbox.flippedBaselineOffset()) self.checkbox = checkbox else: self.checkbox = None height += NSHeight(label2.frame()) + self.FINE_PRINT_PADDING if self.fine_print: fine_print = NSTextField.createLabelWithText_font_maxWidth_origin_(self.fine_print, NSFont.systemFontOfSize_(self.FINE_PRINT_SIZE), width, NSPoint(0, height)) self.addSubview_(fine_print) fine_print.setAlignment_(NSCenterTextAlignment) fine_print.setTextColor_(Colors.fine_print) fine_print.balancedWrapToWidth_(width) fine_print.centerHorizontallyInSuperview() self.fine_print_label = fine_print else: self.fine_print_label = None self.combo = None if self.choice_selector: subview = NSView.alloc().initWithFrame_(NSZeroRect) combo_descriptor = NSTextField.createLabelWithText_(NSAttributedString.boldify(self.choice_selector.text, font=NSFont.systemFontOfSize_(NSRegularControlSize), bold_font=NSFont.boldSystemFontOfSize_(NSRegularControlSize))) combo_descriptor.setTextColor_(self.SUBHEADER_COLOR) subview.addSubview_(combo_descriptor) combo = NSPopUpButton.createNormalPopUpButtonWithChoices_default_(self.choice_selector.selections, self.choice_selector.default_index) combo.sizeToFit() subview.addSubview_(combo) descriptor_frame = combo_descriptor.frame() half = combo.frame().size.height / 2.0 descriptor_half = descriptor_frame.size.height / 2.0 combo_descriptor.setFrameOrigin_(NSPoint(descriptor_frame.origin.x, half - descriptor_half + 2.0)) combo.setFrameOrigin_(NSPoint(descriptor_frame.origin.x + descriptor_frame.size.width, 0)) subview.setFrameSize_((combo.frame().size.width + descriptor_frame.size.width, combo.frame().size.height)) self.addSubview_(subview) subview.centerHorizontallyInSuperview() subview.alignBottomInSuperview(CONTENT_BORDER + self.CHOICE_SELECTOR_PADDING) self.combo = combo
(at your option) any later version. Robo-CJK is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Robo-CJK. If not, see <https://www.gnu.org/licenses/>. """ import mojo.drawingTools as mjdt from utils import interpolation from AppKit import NSFont, NSColor, NSFontAttributeName, NSForegroundColorAttributeName attributes = { NSFontAttributeName: NSFont.boldSystemFontOfSize_(9), NSForegroundColorAttributeName: NSColor.whiteColor(), } red = NSColor.colorWithCalibratedRed_green_blue_alpha_(.8, .2, .2, .5) def getChar(dcname): try: code = dcname.split("_")[1] return chr(int(code, 16)) except Exception as e: print(e) return False class Drawer():
def settings(self): self.name = Glyphs.localize({ 'en': 'Alignment', 'de': 'Ausrichtung', 'es': 'Alineación', 'fr': 'Alignement', 'pt': 'Alinhamento', }) width = 150 self.marginTop = 7 self.marginLeft = 7 self.lineSpacing = 21 smallSize = NSFont.systemFontSizeForControlSize_( NSFont.smallSystemFontSize() ) textFieldHeight = smallSize + 7 textFieldWidth = 50 # lockHeight = textFieldHeight innerWidth = width - 2 * self.marginLeft height = ( MAX_ZONES + 4 ) * self.lineSpacing + self.marginTop * 3 self.posx_TextField = width - textFieldWidth - self.marginLeft # Create Vanilla window and group with controls self.paletteView = Window( (width, height), minSize=(width, height - 10), maxSize=(width, height + 200 ) ) self.paletteView.group = Group( (0, 0, width, height ) ) posy = self.marginTop # set up fields for center headlineBbox = NSAttributedString.alloc().initWithString_attributes_( 'Bounding box', { NSFontAttributeName:NSFont.boldSystemFontOfSize_( smallSize ) } ) self.paletteView.group.headlineBbox = TextBox( ( 10, posy, innerWidth, 18 ), headlineBbox, sizeStyle='small' ) posy += self.lineSpacing self.paletteView.group.centerXLabel = TextBox( ( 10, posy + 3, innerWidth, 18 ), 'center x', sizeStyle='small' ) self.posy_centerX = posy # self.paletteView.group.lockX = ImageButton( ( self.posx_TextField - lockHeight - 5, posy, lockHeight, lockHeight ), imageNamed='GSLockUnlockedTemplate', bordered=False, imagePosition='top', callback=self.lockCallback, sizeStyle='regular' ) # self.lockXlocked = False self.paletteView.group.centerX = ArrowEditText( ( self.posx_TextField, posy, textFieldWidth, textFieldHeight ), callback=self.editTextCallback, continuous=False, readOnly=False, formatter=None, placeholder='multiple', sizeStyle='small' ) posy += self.lineSpacing self.paletteView.group.centerYLabel = TextBox( ( 10, posy + 3, innerWidth, 18 ), 'center y', sizeStyle='small' ) self.posy_centerY = posy # self.paletteView.group.lockY = ImageButton( ( self.posx_TextField - lockHeight - 5, posy, lockHeight, lockHeight ), imageNamed='GSLockUnlockedTemplate', bordered=False, imagePosition='top', callback=self.lockCallback, sizeStyle='regular' ) # self.lockYlocked = False self.paletteView.group.centerY = ArrowEditText( ( self.posx_TextField, posy, textFieldWidth, textFieldHeight ), callback=self.editTextCallback, continuous=False, readOnly=False, formatter=None, placeholder='multiple', sizeStyle='small' ) posy += self.lineSpacing + self.marginTop # set up fields for overshoot headlineOvershoot = NSAttributedString.alloc().initWithString_attributes_( 'Overshoot', { NSFontAttributeName:NSFont.boldSystemFontOfSize_( NSFont.systemFontSizeForControlSize_( smallSize ) ) } ) self.paletteView.group.headlineOvershoot = TextBox( ( 10, posy, innerWidth, 18 ), headlineOvershoot, sizeStyle='small' ) posy += self.lineSpacing self.paletteView.group, 'lineAbove', HorizontalLine( ( self.marginLeft, posy - 3, innerWidth, 1 ) ) for i in range( MAX_ZONES ): setattr( self.paletteView.group, 'name' + str( i ), TextBox( ( 10, posy, innerWidth, 18 ), '', sizeStyle='small' ) ) setattr( self.paletteView.group, 'value' + str( i ), TextBox( ( self.posx_TextField, posy, textFieldWidth - 3, textFieldHeight ), '', sizeStyle='small', alignment='right' ) ) posy += self.lineSpacing setattr( self.paletteView.group, 'line' + str( i ), HorizontalLine( ( self.marginLeft, posy - 3, innerWidth, 1 ) ) ) # set dialog to NSView self.dialog = self.paletteView.group.getNSView() # set self.font self.font = None windowController = self.windowController() if windowController: self.font = windowController.document().font
def _setupContentView(self): # ------------------------------------------ # # Table View # # ------------------------------------------ # rect = NSMakeRect(0, 0, self.WIDTH, self.HEIGHT) containerView = NSView.alloc().initWithFrame_(rect) # Startup btn height = 20 margin = 20 width = self.WIDTH - 2 * margin self.startupBtn = NSButton.buttonWithTitle_target_action_( "Run safetyapp on startup", self, "startupDidChanged:") self.startupBtn.setButtonType_(NSButtonTypeSwitch) self.startupBtn.setFrame_( NSMakeRect(margin, self.HEIGHT - 2 * height, width, height)) self.startupBtn.setState_(self.data["startup"]) containerView.addSubview_(self.startupBtn) # API Key settings titleLabel = NSTextField.labelWithString_("API Key") titleLabel.setTextColor_(NSColor.blackColor()) rect = NSMakeRect( self.startupBtn.frame().origin.x, self.startupBtn.frame().origin.y - self.startupBtn.frame().size.height - height, width, height) titleLabel.setFrame_(rect) titleLabel.setFont_(NSFont.boldSystemFontOfSize_(14)) containerView.addSubview_(titleLabel) # API Key Sub-label titleSubLabel = NSTextField.labelWithString_( "Lorem lpsum dolor sit amet") titleSubLabel.setTextColor_(NSColor.blackColor()) rect = NSMakeRect( titleLabel.frame().origin.x, titleLabel.frame().origin.y - titleLabel.frame().size.height - height / 2, width, height) titleSubLabel.setFrame_(rect) titleSubLabel.setFont_(NSFont.systemFontOfSize_(14)) containerView.addSubview_(titleSubLabel) # API Key text field self.apiTextField = NSTextField.textFieldWithString_("") rect = NSMakeRect( titleSubLabel.frame().origin.x, titleSubLabel.frame().origin.y - titleSubLabel.frame().size.height - height / 2, width, 1.2 * height) self.apiTextField.setFrame_(rect) self.apiTextField.setFocusRingType_(NSFocusRingTypeNone) self.apiTextField.setTitleWithMnemonic_(self.data["api_key"]) self.apiTextField.setEditable_(True) containerView.addSubview_(self.apiTextField) self.window().makeFirstResponder_(self.apiTextField) # Table title tableTitleLabel = NSTextField.labelWithString_("Directories") tableTitleLabel.setTextColor_(NSColor.blackColor()) rect = NSMakeRect( self.apiTextField.frame().origin.x, self.apiTextField.frame().origin.y - self.apiTextField.frame().size.height - height, width, height) tableTitleLabel.setFrame_(rect) tableTitleLabel.setFont_(NSFont.boldSystemFontOfSize_(14)) containerView.addSubview_(tableTitleLabel) # Table sub-title tableSubTitleLabel = NSTextField.labelWithString_( "Lorem lpsum dolor sit amet") tableSubTitleLabel.setTextColor_(NSColor.blackColor()) rect = NSMakeRect( tableTitleLabel.frame().origin.x, tableTitleLabel.frame().origin.y - tableTitleLabel.frame().size.height - height / 2, width, height) tableSubTitleLabel.setFrame_(rect) tableSubTitleLabel.setFont_(NSFont.systemFontOfSize_(14)) containerView.addSubview_(tableSubTitleLabel) # ------------------------------------------ # # Toolbar button # # ------------------------------------------ # rect = NSMakeRect(20, 20, 67, 21) segControl = NSSegmentedControl.alloc().initWithFrame_(rect) segControl.setSegmentCount_(2) segControl.setSegmentStyle_(NSSegmentStyleSmallSquare) segControl.setWidth_forSegment_(32, 0) segControl.setWidth_forSegment_(32, 1) segControl.setImage_forSegment_( NSImage.imageNamed_(NSImageNameAddTemplate), 0) segControl.setImage_forSegment_( NSImage.imageNamed_(NSImageNameRemoveTemplate), 1) segControl.setTarget_(self) segControl.setAction_("segControlDidClicked:") containerView.addSubview_(segControl) rect = NSMakeRect(86, 21, self.WIDTH - 2 * margin - rect.size.width + 1, 21) toolbar = NSButton.alloc().initWithFrame_(rect) toolbar.setTitle_("") toolbar.setRefusesFirstResponder_(True) toolbar.setBezelStyle_(NSBezelStyleSmallSquare) containerView.addSubview_(toolbar) height = tableSubTitleLabel.frame().origin.y - segControl.frame( ).origin.y - margin - segControl.frame( ).size.height + 1 + tableSubTitleLabel.frame().size.height / 2 rect = NSMakeRect( tableSubTitleLabel.frame().origin.x, tableSubTitleLabel.frame().origin.y - tableSubTitleLabel.frame().size.height / 2 - height, width, height) scrollView = NSScrollView.alloc().initWithFrame_(rect) scrollView.setBorderType_(NSBezelBorder) self.tableView = NSTableView.alloc().initWithFrame_( scrollView.bounds()) self.tableView.setDataSource_(self) self.tableView.setDelegate_(self) self.tableView.setFocusRingType_(NSFocusRingTypeNone) # Path column pathCol = NSTableColumn.alloc().initWithIdentifier_( self.PATH_COL_IDENTIFIER) pathCol.setTitle_("Directory") # <-- Table view directory column title pathCol.setWidth_(self.WIDTH * 0.8) textCell = NSTextFieldCell.alloc().init() textCell.setEditable_(True) textCell.setTarget_(self) pathCol.setDataCell_(textCell) # Enable column enableCol = NSTableColumn.alloc().initWithIdentifier_( self.ENALBE_COL_IDENTIFIER) enableCol.setTitle_("Enable?") # <-- Enable column title enableCol.setWidth_(self.WIDTH * 0.2) cell = NSButtonCell.alloc().init() cell.setButtonType_(NSButtonTypeSwitch) cell.setTitle_("") cell.setTarget_(self) enableCol.setDataCell_(cell) self.tableView.addTableColumn_(pathCol) self.tableView.addTableColumn_(enableCol) scrollView.setDocumentView_(self.tableView) scrollView.setHasVerticalScroller_(True) containerView.addSubview_(scrollView) self.window().setContentView_(containerView)
def bold(size): return {NSFontAttributeName: NSFont.boldSystemFontOfSize_(size)}
class DefconAppKitTopAnchoredNSView(NSView): def isFlipped(self): return True # title attributes shadow = NSShadow.alloc().init() shadow.setShadowColor_(NSColor.colorWithCalibratedWhite_alpha_(1, 1)) shadow.setShadowBlurRadius_(1.0) shadow.setShadowOffset_((1.0, -1.0)) titleControlAttributes = { NSForegroundColorAttributeName: NSColor.colorWithCalibratedWhite_alpha_(.4, 1), NSShadowAttributeName: shadow, NSFontAttributeName: NSFont.boldSystemFontOfSize_(NSFont.systemFontSizeForControlSize_(NSSmallControlSize)) } # all script and language tags _scriptTags = """arab armn beng bopo brai byzm cans cher hani cyrl DFLT