ImageView(posSize, horizontalAlignment='center', verticalAlignment='center', scale='proportional')¶
A view that displays an image.
import AppKit from vanilla import ImageView, Window class ImageViewExample: def __init__(self): self.w = Window((80, 80)) self.w.imageView = ImageView( (10, 10, 40, 40), horizontalAlignment="center", verticalAlignment="center", scale="proportional" ) image = AppKit.NSImage.imageWithSystemSymbolName_accessibilityDescription_("pencil.and.outline", "") self.w.imageView.setImage(imageObject=image) self.w.open() ImageViewExample()
posSize Tuple of form (left, top, width, height) or “auto” representing the position and size of the view.
horizontalAlignment A string representing the desired horizontal alignment of the image in the view. The options are:
“left” Image is aligned left. “right” Image is aligned right. “center” Image is centered.
verticalAlignment A string representing the desired vertical alignment of the image in the view. The options are:
“top” Image is aligned top. “bottom” Image is aligned bottom. “center” Image is centered.
scale A string representing the desired scale style of the image in the view. The options are:
“proportional” Proportionally scale the image to fit in the view if it is larger than the view. “fit” Distort the proportions of the image until it fits exactly in the view. “none” Do not scale the image.
Add auto layout rules for controls/view in this view.
rules must be a list of rule definitions. Rule definitions may take two forms:
- strings that follow the Visual Format Language
- dictionaries with the following key/value pairs:
key value “view1” The vanilla wrapped view for the left side of the rule. “attribute1” The attribute of the view for the left side of the rule. See below for options. “relation” (optional) The relationship between the left side of the rule and the right side of the rule. See below for options. The default value is “==”. “view2” The vanilla wrapped view for the right side of the rule. “attribute2” The attribute of the view for the right side of the rule. See below for options. “multiplier” (optional) The constant multiplied with the attribute on the right side of the rule as part of getting the modified attribute. The default value is 1. “constant” (optional) The constant added to the multiplied attribute value on the right side of the rule to yield the final modified attribute. The default value is 0.
The attribute1 and attribute2 options are:
value AppKit equivalent “left” NSLayoutAttributeLeft “right” NSLayoutAttributeRight “top” NSLayoutAttributeTop “bottom” NSLayoutAttributeBottom “leading” NSLayoutAttributeLeading “trailing” NSLayoutAttributeTrailing “width” NSLayoutAttributeWidth “height” NSLayoutAttributeHeight “centerX” NSLayoutAttributeCenterX “centerY” NSLayoutAttributeCenterY “baseline” NSLayoutAttributeBaseline “lastBaseline” NSLayoutAttributeLastBaseline “firstBaseline” NSLayoutAttributeFirstBaseline
Refer to the NSLayoutAttribute documentation for the information about what each of these do.
The relation options are:
value AppKit equivalent “<=” NSLayoutRelationLessThanOrEqual “==” NSLayoutRelationEqual “>=” NSLayoutRelationGreaterThanOrEqual
Refer to the NSLayoutRelation documentation for the information about what each of these do.
metrics may be either None or a dict containing key value pairs representing metrics keywords used in the rules defined with strings.
Enable or disable the object. onOff should be a boolean.
Return the NSImageView that this object wraps.
The position and size of the object as a tuple of form (left, top, width, height).
Return a bool indicating if the object is visible or not.
Move the object by x units and y units.
Change the size of the object to width and height.
setImage(imagePath=None, imageNamed=None, imageObject=None)¶
Set the image in the view.
imagePath A file path to an image.
imageNamed The name of an image already load as a NSImage by the application.
imageObject A NSImage object.
Only one of imagePath, imageNamed, imageObject should be set.
Set the position and size of the object.
posSize A tuple of form (left, top, width, height).
animate A boolean flag telling to animate the transition. Off by default.
Show or hide the object.
onOff A boolean value representing if the object should be shown or not.