Beispiel #1
0
    def create(self):
        self.native = NSTextField.alloc().init()

        self.native.drawsBackground = False
        self.native.editable = False
        self.native.bezeled = False

        # Add the layout constraints
        self.add_constraints()
Beispiel #2
0
    def setup(self):
        self.imageView = NSImageView.alloc().init()
        self.textField = NSTextField.alloc().init()

        self.textField.cell.lineBreakMode = NSLineBreakMode.byTruncatingTail
        self.textField.bordered = False
        self.textField.drawsBackground = False

        self.imageView.translatesAutoresizingMaskIntoConstraints = False
        self.textField.translatesAutoresizingMaskIntoConstraints = False

        self.addSubview(self.imageView)
        self.addSubview(self.textField)

        # center icon vertically in cell
        self.iv_vertical_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(  # NOQA:E501
            self.imageView, NSLayoutAttributeCenterY, NSLayoutRelationEqual,
            self, NSLayoutAttributeCenterY, 1, 0)
        # align left edge of icon with left edge of cell
        self.iv_left_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(  # NOQA:E501
            self.imageView, NSLayoutAttributeLeft, NSLayoutRelationEqual, self,
            NSLayoutAttributeLeft, 1, 0)
        # set fixed width of icon
        self.iv_width_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(  # NOQA:E501
            self.imageView, NSLayoutAttributeWidth, NSLayoutRelationEqual,
            None, NSLayoutAttributeNotAnAttribute, 1, 16)
        # align text vertically in cell
        self.tv_vertical_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(  # NOQA:E501
            self.textField,
            NSLayoutAttributeCenterY,
            NSLayoutRelationEqual,
            self,
            NSLayoutAttributeCenterY,
            1,
            0,
        )
        # align left edge of text with right edge of icon
        self.tv_left_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(  # NOQA:E501
            self.textField,
            NSLayoutAttributeLeft,
            NSLayoutRelationEqual,
            self.imageView,
            NSLayoutAttributeRight,
            1,
            5  # 5 pixels padding between icon and text
        )
        # align right edge of text with right edge of cell
        self.tv_right_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(  # NOQA:E501
            self.textField, NSLayoutAttributeRight, NSLayoutRelationEqual,
            self, NSLayoutAttributeRight, 1, -5)

        self.addConstraint(self.iv_vertical_constraint)
        self.addConstraint(self.iv_left_constraint)
        self.addConstraint(self.iv_width_constraint)
        self.addConstraint(self.tv_vertical_constraint)
        self.addConstraint(self.tv_left_constraint)
        self.addConstraint(self.tv_right_constraint)
Beispiel #3
0
    def create(self):
        self.native = NSTextField.new()
        self.native.interface = self.interface

        self.native.bezeled = True
        self.native.bezelStyle = NSTextFieldSquareBezel

        # Add the layout constraints
        self.add_constraints()
Beispiel #4
0
    def create(self):
        self.native = NSTextField.alloc().init()
        self.native.impl = self
        self.native.interface = self.interface

        self.native.drawsBackground = False
        self.native.editable = False
        self.native.bezeled = False

        # Add the layout constraints
        self.add_constraints()
Beispiel #5
0
def _construct_alert(
        title,
        message,
        details=None,
        details_title="Traceback",
        button_labels=("Ok", ),
        checkbox_text=None,
        level="info",
        icon=None,
):
    a = NSAlert.alloc().init()
    a.alertStyle = alert_style_for_level_str[level]
    a.messageText = title
    a.informativeText = message
    a.icon = icon

    if details:
        scroll = NSScrollView.alloc().initWithFrame(NSMakeRect(0, 0, 500, 250))
        scroll.hasVerticalScroller = True
        scroll.hasHorizontalScroller = False
        scroll.autohidesScrollers = False
        scroll.borderType = NSBezelBorder

        trace = NSTextView.alloc().init()
        trace.editable = False
        trace.verticallyResizable = True
        trace.horizontallyResizable = True
        trace.insetText(details)

        scroll.documentView = trace

        title = NSTextField.labelWithString(details_title)
        title.font = Font(SYSTEM, 12, weight=BOLD).bind(factory).native

        stack = NSStackView.alloc().initWithFrame(NSMakeRect(0, 0, 500, 265))
        stack.orientation = NSUserInterfaceLayoutOrientationVertical
        stack.alignment = NSLayoutAttributeLeading
        stack.addView(title, inGravity=NSStackViewGravityBottom)
        stack.addView(scroll, inGravity=NSStackViewGravityBottom)

        a.accessoryView = stack

    if checkbox_text:
        a.showsSuppressionButton = True
        a.suppressionButton.title = checkbox_text

    for name in button_labels:
        a.addButtonWithTitle(name)

    return a
Beispiel #6
0
    def setup(self):
        iv = NSImageView.alloc().initWithFrame(NSMakeRect(0, 0, 16, 16))
        tf = NSTextField.alloc().init()

        iv.autoresizingMask = NSViewMinYMargin | NSViewMaxYMargin
        iv.imageScaling = NSImageScaleProportionallyDown
        iv.imageAlignment = NSImageAlignment.Center

        tf.autoresizingMask = NSViewMinYMargin | NSViewMaxYMargin
        tf.bordered = False
        tf.drawsBackground = False

        self.imageView = iv
        self.textField = tf
        self.addSubview(iv)
        self.addSubview(tf)
        return self
Beispiel #7
0
    def create(self):
        self.native = TogaView.alloc().init()

        self.input = NSTextField.new()
        self.input.interface = self.interface
        self.input.bezeled = True
        self.input.bezelStyle = NSTextFieldSquareBezel
        self.input.translatesAutoresizingMaskIntoConstraints = False

        self.stepper = TogaStepper.alloc().init()
        self.stepper.interface = self.interface
        self.stepper._impl = self
        self.stepper.translatesAutoresizingMaskIntoConstraints = False

        self.stepper.target = self.stepper
        self.stepper.action = SEL('onChange:')

        self.stepper.controller = self.input
        self.input.delegate = self.stepper

        # Add the input and stepper to the constraining box.
        self.native.addSubview(self.input)
        self.native.addSubview(self.stepper)

        # Add constraints to lay out the input and stepper.
        # Stepper is always top right corner.
        self.native.addConstraint(
            NSLayoutConstraint.
            constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.native, NSLayoutAttributeTop, NSLayoutRelationEqual,
                self.stepper, NSLayoutAttributeTop, 1.0, 0))
        self.native.addConstraint(
            NSLayoutConstraint.
            constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.native, NSLayoutAttributeRight, NSLayoutRelationEqual,
                self.stepper, NSLayoutAttributeRight, 1.0, 0))

        # Stepper height matches container box height
        self.native.addConstraint(
            NSLayoutConstraint.
            constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.native, NSLayoutAttributeBottom, NSLayoutRelationEqual,
                self.stepper, NSLayoutAttributeBottom, 1.0, 0))

        # Input is always left, centred vertically on the stepper
        self.native.addConstraint(
            NSLayoutConstraint.
            constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.stepper, NSLayoutAttributeCenterY, NSLayoutRelationEqual,
                self.input, NSLayoutAttributeCenterY, 1.0, 0))
        self.native.addConstraint(
            NSLayoutConstraint.
            constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.native, NSLayoutAttributeLeft, NSLayoutRelationEqual,
                self.input, NSLayoutAttributeLeft, 1.0, 0))

        # Stepper and input meet in the middle with a small gap
        self.native.addConstraint(
            NSLayoutConstraint.
            constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.stepper, NSLayoutAttributeLeft, NSLayoutRelationEqual,
                self.input, NSLayoutAttributeRight, 1.0, 2))

        # Add the layout constraints for the main box
        self.add_constraints()
Beispiel #8
0
    def create(self):
        self.native = TogaView.alloc().init()

        self.input = NSTextField.new()
        self.input.interface = self.interface
        self.input.bezeled = True
        self.input.bezelStyle = NSTextFieldSquareBezel
        self.input.translatesAutoresizingMaskIntoConstraints = False

        self.stepper = TogaStepper.alloc().init()
        self.stepper.interface = self.interface
        self.stepper._impl = self
        self.stepper.translatesAutoresizingMaskIntoConstraints = False

        self.stepper.target = self.stepper
        self.stepper.action = SEL('onChange:')

        self.stepper.controller = self.input
        self.input.delegate = self.stepper

        # Add the input and stepper to the constraining box.
        self.native.addSubview(self.input)
        self.native.addSubview(self.stepper)

        # Add constraints to lay out the input and stepper.
        # Stepper is always top right corner.
        self.native.addConstraint(
            NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.native, NSLayoutAttributeTop,
                NSLayoutRelationEqual,
                self.stepper, NSLayoutAttributeTop,
                1.0, 0
            )
        )
        self.native.addConstraint(
            NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.native, NSLayoutAttributeRight,
                NSLayoutRelationEqual,
                self.stepper, NSLayoutAttributeRight,
                1.0, 0
            )
        )

        # Stepper height matches container box height
        self.native.addConstraint(
            NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.native, NSLayoutAttributeBottom,
                NSLayoutRelationEqual,
                self.stepper, NSLayoutAttributeBottom,
                1.0, 0
            )
        )

        # Input is always left, centred vertically on the stepper
        self.native.addConstraint(
            NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.stepper, NSLayoutAttributeCenterY,
                NSLayoutRelationEqual,
                self.input, NSLayoutAttributeCenterY,
                1.0, 0
            )
        )
        self.native.addConstraint(
            NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.native, NSLayoutAttributeLeft,
                NSLayoutRelationEqual,
                self.input, NSLayoutAttributeLeft,
                1.0, 0
            )
        )

        # Stepper and input meet in the middle with a small gap
        self.native.addConstraint(
            NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.stepper, NSLayoutAttributeLeft,
                NSLayoutRelationEqual,
                self.input, NSLayoutAttributeRight,
                1.0, 2
            )
        )

        # Add the layout constraints for the main box
        self.add_constraints()