Exemplo n.º 1
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)
Exemplo n.º 2
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()
Exemplo n.º 3
0
Arquivo: label.py Projeto: pybee/toga
    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()
Exemplo n.º 4
0
Arquivo: cells.py Projeto: yconst/toga
    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