def _init_popover(self): print 'init popover' #import pdb; pdb.set_trace() rect = NSMakeRect(0, 0, 40, 40) self.button = NSButton.alloc().initWithFrame_(rect) self.button.setImage_(self._app['_icon_nsimage']) self.button.setAction_('mycallback:') #self.button.setTransparent_(True) self.button.setBordered_(False) self.button.setTitle_('W') self.button.setButtonType_(AppKit.NSMomentaryChangeButton) print 'BUTTON ', self.nsstatusitem.action #rect2 = NSMakeRect(0, 0, 100, 100) self.popover = NSPopover.alloc().init() #myBundle = NSBundle bundleWithPath:@"/Library/MyBundle.bundle"] myBundle = NSBundle.alloc().initWithPath_("/Users/pfitzsimmons/repos/webchiver/app/webchiver.bundle") #view_controller = NSViewController.alloc().initWithNibName_bundle_('SnippetPopoverViewController.nib', myBundle) view_controller = PopViewController.alloc().init() #self.popover.setContentViewController_(view_controller) #self.nsstatusitem.setAction_('mycallback:') self.nsstatusitem.setView_(self.button) #import pdb; pdb.set_trace() rect3 = NSMakeRect(500, 500, 600, 600) self.window = MyWindow.alloc().initWithContentRect_styleMask_backing_defer_( rect3, AppKit.NSBorderlessWindowMask, #AppKit.NSTexturedBackgroundWindowMask, NSBackingStoreBuffered, True ) self.window.setOpaque_(False)
def addUnderlineButton(self, notification): try: Tab = notification.object() if hasattr(Tab, "addViewToBottomToolbar_"): button = NSButton.alloc().initWithFrame_( NSMakeRect(0, 0, 18, 14)) button.setBezelStyle_(NSTexturedRoundedBezelStyle) button.setBordered_(False) button.setButtonType_(NSToggleButton) button.setTitle_("") button.cell().setImagePosition_(NSImageOnly) button.cell().setImageScaling_(NSImageScaleNone) button.setImage_(self.toolBarIcon) Tab.addViewToBottomToolbar_(button) Tab.userData["underlineButton"] = button userDefaults = NSUserDefaultsController.sharedUserDefaultsController( ) button.bind_toObject_withKeyPath_options_( "value", userDefaults, "values.GeorgSeifert_showUnderline", None) userDefaults.addObserver_forKeyPath_options_context_( Tab.graphicView(), "values.GeorgSeifert_showUnderline", 0, 123) except: NSLog(traceback.format_exc())
def _create_button(self, form_item, val, form_view): TRACE("Creating button '%s'" % form_item.label) control = NSButton.createNormalRoundButtonWithTitle_(form_item.label) control.setAction_(self.buttonAction_) control.setTarget_(self) self._form_y_offset -= NSHeight(control.frame()) control.setFrameOrigin_(NSPoint(control.frame().origin.x, self._form_y_offset)) return (control, None)
def __init__(self): ''' initializes an alert with custom view containing username and password fields with a save to keychain checkbox''' # Create an dialog with ok and cancel buttons self.alert = NSAlert.alloc().init() self.alert.setMessageText_('Please enter your username and password!') self.alert.addButtonWithTitle_('Ok') self.alert.addButtonWithTitle_('Cancel') # create the view for username and password fields accessory_view = NSView.alloc().initWithFrame_( NSMakeRect(0, 114, 250, 110)) # setup username field and label self.username_field = NSTextField.alloc().initWithFrame_( NSMakeRect(0, 70, 250, 22)) username_label = NSTextField.alloc().initWithFrame_( NSMakeRect(0, 94, 250, 20)) username_label.setStringValue_('Username:'******'Password:'******'Save to Keychain') self.keychain_checkbox.cell().setBordered_(False) self.keychain_checkbox.cell().setEnabled_(True) self.keychain_checkbox.cell().setState_(True) # add various objects as subviews accessory_view.addSubview_(self.keychain_checkbox) accessory_view.addSubview_(username_label) accessory_view.addSubview_(self.username_field) accessory_view.addSubview_(password_label) accessory_view.addSubview_(self.password_field) # add custom view to alert dialog self.alert.setAccessoryView_(accessory_view)
def __init__(self): ''' initializes an alert with custom view containing username and password fields with a save to keychain checkbox''' # Create an dialog with ok and cancel buttons self.alert = NSAlert.alloc().init() self.alert.setMessageText_('Please enter your username and password!') self.alert.addButtonWithTitle_('Ok') self.alert.addButtonWithTitle_('Cancel') # create the view for username and password fields accessory_view = NSView.alloc().initWithFrame_(NSMakeRect(0, 114, 250, 110)) # setup username field and label self.username_field = NSTextField.alloc().initWithFrame_(NSMakeRect(0, 70, 250, 22)) username_label = NSTextField.alloc().initWithFrame_(NSMakeRect(0, 94, 250, 20)) username_label.setStringValue_('Username:'******'Password:'******'Save to Keychain') self.keychain_checkbox.cell().setBordered_(False) self.keychain_checkbox.cell().setEnabled_(True) self.keychain_checkbox.cell().setState_(True) # add various objects as subviews accessory_view.addSubview_(self.keychain_checkbox) accessory_view.addSubview_(username_label) accessory_view.addSubview_(self.username_field) accessory_view.addSubview_(password_label) accessory_view.addSubview_(self.password_field) # add custom view to alert dialog self.alert.setAccessoryView_(accessory_view)
def addUnderlineButton_(self, notification): try: Tab = notification.object() if hasattr(Tab, "addViewToBottomToolbar_"): button = NSButton.alloc().initWithFrame_(NSMakeRect(0, 0, 18, 14)) button.setBezelStyle_(NSTexturedRoundedBezelStyle) button.setBordered_(False) button.setButtonType_(NSToggleButton) button.setTitle_("") button.cell().setImagePosition_(NSImageOnly) button.cell().setImageScaling_(NSImageScaleNone) button.setImage_(self.toolBarIcon) Tab.addViewToBottomToolbar_(button) Tab.userData["underlineButton"] = button userDefaults = NSUserDefaultsController.sharedUserDefaultsController() button.bind_toObject_withKeyPath_options_("value", userDefaults, "values.GeorgSeifert_showUnderline", None) userDefaults.addObserver_forKeyPath_options_context_(Tab.graphicView(), "values.GeorgSeifert_showUnderline", 0, 123) except: NSLog(traceback.format_exc())
def settings(self): try: #NSBundle.loadNibNamed_owner_('View', self) self.name = 'Reporters' width = 160 self.reporterArray = list(Glyphs.reporters) self.reporterArray = sorted(self.reporterArray, ReporterSort) self.checkboxes = [] for i, reporter in enumerate(self.reporterArray): # Glyphs.activeReporters # print reporter.classCode() frame = NSMakeRect(0, 0, 18, 18) checkBox = NSButton.alloc().initWithFrame_(frame) checkBox.setTitle_(reporter.title()) checkBox.setButtonType_(NSSwitchButton) checkBox.setTarget_(self) checkBox.setAction_(self.toggle_) if reporter in Glyphs.activeReporters: isActive = NSOnState else: isActive = NSOffState checkBox.setState_(isActive) checkBox.setControlSize_(ControllSize) font = NSFont.systemFontOfSize_(NSFont.systemFontSizeForControlSize_(ControllSize)) checkBox.setFont_(font) self.checkboxes.append(checkBox) self.dialog = NSStackView.stackViewWithViews_(self.checkboxes) self.dialog.setOrientation_(1) self.dialog.setAlignment_(1) self.dialog.setSpacing_(5) self.dialog.setEdgeInsets_((2, 8, 8, 1)) self.dialog.setClippingResistancePriority_forOrientation_(250, NSLayoutConstraintOrientationHorizontal) self.dialog.setViews_inGravity_(self.checkboxes, NSStackViewGravityLeading) self.dialog.setNeedsLayout_(True) #self.dialog = self.view except: print traceback.format_exc()
def _add_buttons(self, buttons, view): self._buttons = {} button_x = self.width - self.BUTTON_PADDING_WIDTH first = True for title, action in reversed(buttons): button = NSButton.createNormalRoundButtonWithTitle_default_origin_(title, first, (button_x, self._window_y_offset)) button.setAction_(self.clicked_) if action is not None: self.current_actions[title] = action else: button.setEnabled_(NO) first = False button_x -= NSWidth(button.frame()) button.setFrameOrigin_(NSPoint(button_x, self._window_y_offset)) view.addSubview_(button) button.alignBottomInSuperview() self._buttons[title] = button self._window_y_offset += 19 self._window_y_offset += NSHeight(button.frame()) + button.verticalPadding()
"hex": color_to_hex, "uicolor": color_to_uicolor, "rgba": color_to_rgba, "rgb": color_to_rgb }.get(format, color_to_hex)(color)) self.close() def close(self): app.terminate_(None) cb = Callback.alloc().init() accessory = NSView.alloc().initWithFrame_(NSMakeRect(0, 0, 200, 34)) for i, name in enumerate(['Cancel', 'Copy']): button = NSButton.alloc().init() button.setBezelStyle_(NSRoundedBezelStyle) button.setTitle_(name) button.sizeToFit() x = (i + 0.5) / 2 * 200 - button.frame().size.width / 2 frame = NSMakeRect(x, (34 - button.frame().size.height) / 2, button.frame().size.width, button.frame().size.height) button.setFrame_(frame) button.setAutoresizingMask_(NSViewMaxXMargin | NSViewMinXMargin | NSViewMaxYMargin | NSViewMinYMargin) button.setTarget_(cb) button.setAction_({"Cancel": "close", "Copy": "copy"}[name]) accessory.addSubview_(button) NSApp.activateIgnoringOtherApps_(True)
copy_to_clipboard({ "hex": color_to_hex, "uicolor": color_to_uicolor, "uicolor_swift": color_to_uicolor_swift, "rgba": color_to_rgba, "rgb": color_to_rgb }.get(format, color_to_hex)(color)) self.close() def close(self): app.terminate_(None) cb = Callback.alloc().init() accessory = NSView.alloc().initWithFrame_(NSMakeRect(0,0,200,34)) for i, name in enumerate(['Cancel', 'Copy']): button = NSButton.alloc().init() button.setBezelStyle_(NSRoundedBezelStyle) button.setTitle_(name) button.sizeToFit() x = (i + 0.5) / 2 * 200 - button.frame().size.width / 2 frame = NSMakeRect(x, (34 - button.frame().size.height)/2, button.frame().size.width, button.frame().size.height) button.setFrame_(frame) button.setAutoresizingMask_(NSViewMaxXMargin | NSViewMinXMargin | NSViewMaxYMargin | NSViewMinYMargin) button.setTarget_(cb) button.setAction_({"Cancel": "close", "Copy": "copy"}[name]) accessory.addSubview_(button) NSApp.activateIgnoringOtherApps_(True) panel = NSColorPanel.sharedColorPanel() panel.setShowsAlpha_(True) panel.setAccessoryView_(accessory)
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
def __init__(self, position, size): Control.__init__(self, NSButton.alloc().initWithFrame_(((position.x, position.y), (size.width, size.height)))) self.ns_control.setBezelStyle_(2) # NSRegularSquareBezelStyle self.ns_control.setTarget_(Delegate.instance()) self.ns_control.setAction_("onClick:") Delegate.instance().bind(self, self.click_validation)
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)