Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
Esempio n. 3
0
        color = r, g, b, a
        copy_to_clipboard({
            "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)
Esempio n. 4
0
		a = panel.alpha()
		color = r,g,b,a
		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()
Esempio n. 5
0
 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
Esempio n. 6
0
    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)