Пример #1
0
    def setImage(self, image):
        if image is self.imageView.image:
            # don't do anything if image did not change
            return

        if image:
            self.imageView.image = image
            self.imageView.frame = NSMakeRect(5, 0, 16, 16)
            self.textField.frameOrigin = NSMakePoint(25, 0)
        else:
            self.imageView.image = None
            self.imageView.frame = NSMakeRect(0, 0, 0, 0)
            self.textField.frameOrigin = NSMakePoint(0, 0)
Пример #2
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
Пример #3
0
    def create(self):
        # OSX origin is bottom left of screen, and the screen might be
        # offset relative to other screens. Adjust for this.
        screen = NSScreen.mainScreen.visibleFrame
        position = NSMakeRect(
            screen.origin.x + self.interface.position[0],
            screen.size.height + screen.origin.y - self.interface.position[1] -
            self.interface._size[1], self.interface._size[0],
            self.interface._size[1])

        mask = NSTitledWindowMask
        if self.interface.closeable:
            mask |= NSClosableWindowMask

        if self.interface.resizeable:
            mask |= NSResizableWindowMask

        if self.interface.minimizable:
            mask |= NSMiniaturizableWindowMask

        self.native = NSWindow.alloc().initWithContentRect(
            position,
            styleMask=mask,
            backing=NSBackingStoreBuffered,
            defer=False)
        self.native.setFrame(position, display=True, animate=False)
        self.native.interface = self.interface
        self.native.impl = self

        self.delegate = WindowDelegate.alloc().init()
        self.delegate.interface = self.interface
        self.delegate.impl = self

        self.native.setDelegate_(self.delegate)
Пример #4
0
    def __init__(self, interface, title, position, size):
        self.interface = interface
        self.interface._impl = self

        mask = NSTitledWindowMask
        if self.interface.closeable:
            mask |= NSClosableWindowMask

        if self.interface.resizeable:
            mask |= NSResizableWindowMask

        if self.interface.minimizable:
            mask |= NSMiniaturizableWindowMask

        # Create the window with a default frame;
        # we'll update size and position later.
        self.native = NSWindow.alloc().initWithContentRect(
            NSMakeRect(0, 0, 0, 0),
            styleMask=mask,
            backing=NSBackingStoreBuffered,
            defer=False)

        self.set_title(title)
        self.set_size(size)
        self.set_position(position)

        self.delegate = WindowDelegate.alloc().init()
        self.delegate.interface = self.interface
        self.delegate.impl = self

        self.native.delegate = self.delegate
Пример #5
0
    def documentRect(self) -> NSRect:
        rect = send_super(__class__,
                          self,
                          'documentRect',
                          restype=NSRect,
                          argtypes=[])

        if self.superview and self.superview.refreshTriggered:
            return NSMakeRect(
                rect.origin.x,
                rect.origin.y - self.superview.refreshView.frame.size.height,
                rect.size.width, rect.size.height +
                self.superview.refreshView.frame.size.height)
        return rect
Пример #6
0
    def set_bounds(self, x, y, width, height):
        super().set_bounds(x, y, width, height)

        # Restrict dimensions of content to dimensions of ScrollContainer
        # along any non-scrolling directions. Set dimensions of content
        # to its layout dimensions along the scrolling directions.

        if self.interface.horizontal:
            width = self.interface.content.layout.width

        if self.interface.vertical:
            height = self.interface.content.layout.height

        self.interface.content._impl.native.frame = NSMakeRect(0, 0, width, height)
Пример #7
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
Пример #8
0
    def createRefreshView(self) -> None:
        # delete old stuff if any
        if self.refreshView:
            self.refreshView.removeFromSuperview()
            self.refreshView.release()
            self.refreshView = None

        self.verticalScrollElasticity = NSScrollElasticityAllowed

        # create new content view
        self.createContentView()

        self.contentView.postsFrameChangedNotifications = True
        self.contentView.postsBoundsChangedNotifications = True

        NSNotificationCenter.defaultCenter.addObserver(
            self,
            selector=SEL('viewBoundsChanged:'),
            name=NSViewBoundsDidChangeNotification,
            object=self.contentView,
        )

        # Create view to hold the refresh widgets refreshview
        contentRect = self.contentView.documentView.frame
        self.refreshView = NSView.alloc().init()
        self.refreshView.translatesAutoresizingMaskIntoConstraints = False

        # Create spinner
        self.refreshIndicator = NSProgressIndicator.alloc().init()
        self.refreshIndicator.style = NSProgressIndicatorSpinningStyle
        self.refreshIndicator.translatesAutoresizingMaskIntoConstraints = False
        self.refreshIndicator.displayedWhenStopped = True
        self.refreshIndicator.usesThreadedAnimation = True
        self.refreshIndicator.indeterminate = True
        self.refreshIndicator.bezeled = False
        self.refreshIndicator.sizeToFit()

        # Center the spinner in the header
        self.refreshIndicator.setFrame(
            NSMakeRect(
                self.refreshView.bounds.size.width / 2 -
                self.refreshIndicator.frame.size.width / 2,
                self.refreshView.bounds.size.height / 2 -
                self.refreshIndicator.frame.size.height / 2,
                self.refreshIndicator.frame.size.width,
                self.refreshIndicator.frame.size.height))

        # Put everything in place
        self.refreshView.addSubview(self.refreshIndicator)
        # self.refreshView.addSubview(self.refreshArrow)
        self.contentView.addSubview(self.refreshView)

        # set layout constraints
        indicatorHCenter = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(  # noqa: E501
            self.refreshIndicator,
            NSLayoutAttributeCenterX,
            NSLayoutRelationEqual,
            self.refreshView,
            NSLayoutAttributeCenterX,
            1.0,
            0,
        )
        self.refreshView.addConstraint(indicatorHCenter)

        indicatorVCenter = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(  # noqa: E501
            self.refreshIndicator,
            NSLayoutAttributeCenterY,
            NSLayoutRelationEqual,
            self.refreshView,
            NSLayoutAttributeCenterY,
            1.0,
            0,
        )
        self.refreshView.addConstraint(indicatorVCenter)

        refreshWidth = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(  # noqa: E501
            self.refreshView,
            NSLayoutAttributeWidth,
            NSLayoutRelationEqual,
            self.contentView,
            NSLayoutAttributeWidth,
            1.0,
            0,
        )
        self.contentView.addConstraint(refreshWidth)

        refreshHeight = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(  # noqa: E501
            self.refreshView,
            NSLayoutAttributeHeight,
            NSLayoutRelationEqual,
            None,
            NSLayoutAttributeNotAnAttribute,
            1.0,
            HEADER_HEIGHT,
        )
        self.contentView.addConstraint(refreshHeight)

        refreshHeight = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(  # noqa: E501
            self.refreshView,
            NSLayoutAttributeTop,
            NSLayoutRelationEqual,
            self.contentView,
            NSLayoutAttributeTop,
            1.0,
            -HEADER_HEIGHT,
        )
        self.contentView.addConstraint(refreshHeight)

        # Scroll to top
        self.contentView.scrollToPoint(NSMakePoint(contentRect.origin.x, 0))
        self.reflectScrolledClipView(self.contentView)
 def set_bounds(self, x, y, width, height):
     super().set_bounds(x, y, width, height)
     self.interface.content._impl.native.frame = NSMakeRect(
         0, 0,
         self.interface.content.layout.width, self.interface.content.layout.height
     )