Tools
Items
- ezui.makeItem(description, container=None, controller=None, descriptionData={})
Make an item from a description dictionary or a text shortcut.
The dictionary must have a
"type"key that defines the class to use.All other key/value pairs will be used to make the item.
Colors
Images
Fonts
- ezui.makeFont(systemStyle=None, name=None, size=None, sizeStyle='regular', weight=None, designStyle=None)
systemStyleOne of the system defined styles."largeTitle""title1""title2""title3""headline""subheadline""body"(default)"callout""footnote""caption1""caption2"
weightOne of the system defined weight styles, only avaible whennameis set to"system"or"system-monospaced";"ultraLight""thin""light""regular""medium""semibold""bold""heavy""black"
designStyleOne fo the system defined desing styles, only avaible whennameis set to"system"or"system-bold";"default""monospaced""rounded""serif"
Value Conversion and Formatting
Converting object values (ie numbers) to strings for display in an interface and then back to object values after user editing is a non-trivial task. Several items in ezui have built in support for doing this automatically. Additionally, they have support for modifying the display of the string (ie changing the color of the text).
Value Conversion
Automatic value conversion is available in some items for these value types:
"string"Convert from a string to a string and back."stringList"Convert from a list of strings to a single string and back."number"Convert from a number (integer or float) to a string and back."numberList"Convert from a list of numbers to a single string and back."integer"Convert from a integer to a string and back."integerList"Convert from a list of integers to a single string and back."float"Convert from a float to a string and back."floatList"Convert from a list of floats to a single string and back.
Specify these as the valueType in TextField, Table, etc. to enable the automatic conversion.
If you want to format the string, pass a stringFormatter function where allowed. This function must take a single attributes argument. The value for this will be a dictionary with the following items:
valueThe original object value.stringThe value converted to a string.fontA font name or"system".weightA font weight name.pointSizeA point size value.lineHeightA line height factor.figureStyleA figure style.fillColorA fill color.
The full meanings and options for these are defined in Merz’s Attributed String.
That stringFormatter function may alter any of these items as needed. If the formatter wants to create a full NSAttributedString it may store this under the attributedString key in the dictionary and the stored value will be used without any further processing.
If the built-in converters do not handle a needed conversion, you may pass valueToStringConverter and stringToValueConverter functions. Refer to vanilla.List2 for the details.
Examples
A string formatter that makes negative numbers red, zero blue and positive numbers green.
def colorNumberFormatter(attributes):
value = attributes["value"]
if value is None:
color = (0.5, 1, 0, 1)
elif value < 0:
color = (1, 0, 0, 1)
elif value > 0:
color = (0, 1, 0, 1)
else:
color = (0, 0, 1, 1)
attributes["fillColor"] = color
Value converters that convert specific strings to emoji and back.
stringToEmojiMap = dict(
robot="🤖",
pen="🖋️",
rainbow="🌈"
)
emojiToStringMap = {v : k for k, v in stringToEmojiMap.items()}
fallbackEmoji = "🥴"
fallbackString = "unknown"
def stringToEmojiConverter(value):
emoji = stringToEmojiMap.get(value, fallbackEmoji)
return emoji
def emojiToStringConverter(value):
value = emojiToStringMap.get(value, fallbackString)
return value
Deep Details
These are the low-level functions that power all of this in case you want to read the full documentation:
Metrics
- ezui.metrics()
Common values.
"windowMarginH"Horizontal spacing between the frame of a window and inset items."windowMarginV"Vertical spacing between the frame of a window and inset items."windowMarginLeft"Spacing between the left of the window and inset items."windowMarginRight"Spacing between the right of the window and inset items."windowMarginTop"Spacing between the left of the window and inset items."windowMarginBottom"Spacing between the bottom of the window and inset items."boxContentMarginH"Horizontal spacing between the frame of boxes and inset items."boxContentMarginV"Vertical spacing between the frame of boxes and inset items."tabContentMarginH"Horizontal spacing between the frame of tabs and inset items."tabContentMarginV"Vertical spacing between the frame of tabs and inset items."tabContentMarginLeft"Spacing between the left of tabs and inset items."tabContentMarginRight"Spacing between the right of tabs and inset items."tabContentMarginTop"Spacing between the left of tabs and inset items."tabContentMarginBottom"Spacing between the bottom of tabs and inset items."itemSpacingH"Horizontal spacing between items."itemSpacingV"Vertical spacing between items.