Classes

This page contains a list of classes used by the pyto_ui API.

Views

A list of UI elements to be displayed on screen.

class pyto_ui.View

An object that manages the content for a rectangular area on the screen.

add_gesture_recognizer(gesture_recognizer: pyto_ui.GestureRecognizer)

Adds a gesture recognizer.

Parameters:gesture_recognizer – The gesture recognizer to be added.
add_subview(view: pyto_ui.View)

Adds the given view to the receiver’s hierarchy.

Parameters:view – The view to add.
alpha

The opacity of the view.

Return type:float
appearance

The appearance of the view. See Appearance constants for possible values.

Return type:Appearance
background_color

The background color of the view.

Return type:Color
become_first_responder() → bool

Becomes the first responder. On TextView and TextField objects, the keyboard will be shown. Returns a boolean indicating the success.

Return type:bool
border_color

The color of the view’s border

Return type:Color
border_width

The width of the view’s border.

Return type:float
button_items

A list of ButtonItem objects to be displayed on the top bar. Works only if the view is the root view presented with show_view() or push().

Return type:List[ButtonItem]
center

The center point of the view’s frame rectangle. Setting this value updates frame property appropiately. This value is a tuple with X and Y coordinates.

Return type:Tuple[float, float]
center_x

The center x-coordinate of the view’s frame rectangle. Setting this value updates frame property appropiately.

Return type:float
center_y

The center y-coordinate of the view’s frame rectangle. Setting this value updates frame property appropiately.

Return type:float
clips_to_bounds

A boolean value that determines whether subviews are confined to the bounds of the view.

Return type:bool
close()

Closes the view, if the receiver object is the root view presented to the user.

content_mode

A flag used to determine how a view lays out its content when its bounds change. See Content Mode <constants.html#content-mode>`_ constants for possible values.

Return type:Content Mode <constants.html#content-mode>`_
corner_radius

The radius to use when drawing rounded corners for the view’s background.

Return type:float
first_responder

(Read Only) A boolean indicating the view is first responder. UIKit dispatches some types of events, such as motion events, to the first responder initially.

Return type:bool
flex

A list that determines how the receiver resizes itself when its superview’s bounds change. See Auto Resizing constants for possible values.

Return type:List[Auto Resizing]
frame

The frame rectangle, which describes the view’s location and size in its superview’s coordinate system. This value is a tuple with X, Y, Width and Height values.

Return type:Tuple[float, float, float, float]
gesture_recognizers

(Read Only) Returns all gesture recognizers.

See add_gesture_recognizer().

Return type:List[GestureRecognizer]
height

The height of the view.

Return type:float
hidden

A boolean indicating whether the view is visible or not.

Return type:bool
insert_subview(view: pyto_ui.View, index: int)

Inserts the given view to the receiver’s hierarchy at the given index.

Parameters:
  • view – The view to insert.
  • index – The index where the view should be inserted.
insert_subview_above(view: pyto_ui.View, above_view: pyto_ui.View)

Inserts the given view to the receiver’s hierarchy above another given view.

Parameters:
  • view – The view to insert.
  • above_view – The view bellow the inserted view.
insert_subview_bellow(view: pyto_ui.View, bellow_view: pyto_ui.View)

Inserts the given view to the receiver’s hierarchy bellow another given view.

Parameters:
  • view – The view to insert.
  • bellow_view – The view above the inserted view.
layout

A function called when the view is resized. Takes the view as parameter.

Return type:Callable[[View], None]
name

The name identifying the view. To access a subview with its name, you can use the subview_with_name() function. View is also subscriptable, so you can do something like that:

import pyto_ui as ui

button = ui.Button()
button.name = "Button"

view = ui.View()
view.add_subview(button)
view["Button"] # -> Button object
Return type:str
navigation_bar_hidden

A boolean indicating whether the Navigation Bar of the View should be hidden.

Return type:bool
opaque

A boolean indicating whether the view is opaque or not. Setting to True should prevent the view from having a transparent background.

Return type:bool
origin

A point that specifies the coordinates of the view’s rectangle’s origin. This value is a tuple with X and Y coordinates.

Return type:Tuple[float, float]
pop()

Pops the visible view controller from the navigation controller.

push(view: pyto_ui.View)

Presents the given additional view on top of the receiver.

Parameters:view – The view to present.
remove_from_superview()

Removes the view from the parent’s hierarchy.

remove_gesture_recognizer(gesture_recognizer: pyto_ui.GestureRecognizer)

Removes a gesture recognizer.

Parameters:gesture_recognizer – The gesture recognizer to be removed.
resign_first_responder() → bool

Stops being the first responder. On TextView and TextField objects, the keyboard will be hidden. Returns a boolean indicating the success.

Return type:bool
size

A size that specifies the height and width of the rectangle. This value is a tuple with height and width values.

Return type:Tuple[float, float]
size_to_fit()

Sizes the view to fit its content.

subview_with_name(name) → pyto_ui.View

Returns the subview with the given name.

Raises NameError if no view is found.

Return type:View
subviews

(Read Only) A list of the view’s children.

See also add_subview().

Return type:List[View]
superview

(Read Only) The parent view containg the receiver view.

Return type:View
tint_color

The tint color of the view. If set to None, the tint color will be inherited from the superview. The tint color affects some views like Button for title color, TextView for cursor color, etc.

Return type:Color
title

If this view is directly presented, the top bar will show this view’s title.

Return type:str
user_interaction_enabled

A boolean indicating whether the view responds to touches.

Return type:bool
width

The width of the view.

Return type:float
x

The x-coordinate of the view.

Return type:float
y

The y-coordinate of the point.

Return type:float
class pyto_ui.ImageView(image: Optional[Image] = None, url: Optional[str] = None)

A view displaying an image. The displayed image can be a PIL image, an UIKit UIImage (see image_with_system_name()) or can be directly downloaded from an URL.

image

The image displayed on screen. Can be a PIL image or an UIKit UIImage. See image_with_system_name() for more information about how to get a symbol image.

Return type:Image.Image
load_from_url(url)

Loads and display the image at given url.

Parameters:url – The URL of the image.
class pyto_ui.Label(text: str = '')

A view displaying not editable and not selectable text.

adjusts_font_size_to_fit_width

A boolean indicating whether the label adjusts its font size to fit its size.

Return type:bool
font

The font of the text.

Return type:Font
line_break_mode

The line break mode.

Return type:Line Break Mode
load_html(html)

Loads HTML in the Label.

Parameters:html – The HTML code to load.
number_of_lines

The numbers of lines displayed in the label. Set to 0 to show all the text.

Return type:int
text

The text to be displayed on the view.

Return type:str
text_alignment

The text’s alignment. For possible values, see Text Alignment constants.

Return type:Text Alignment
text_color

The color of the text.

Return type:Color
class pyto_ui.TableViewCell(style: ui_constants.TABLE_VIEW_STYLE = TABLE_VIEW_CELL_STYLE_DEFAULT)

A cell contained in a TableView. Can have a title, a subtitle, an image and an accessory view.

For a list of supported style, see Table View Cell Style constants.

accessory_type

The type of accessory view placed to the right of the cell. See Accessory Type constants for possible values.

Return type:Accessory Type.
content_view

(Read Only) The view contained in the cell. Custom views should be added inside it.

Return type:View
detail_text_label

(Read Only) The label containing secondary text. May return None for some Table View Cell Style values.

Return type:Label
image_view

(Read Only) The view containing an image. May return None for some Table View Cell Style values.

Return type:Image View
movable

A boolean indicating whether the cell is movable. If set to True, the container TableViewSection object should handle the move.

Return type:bool
removable

A boolean indicating the cell is removable. If set to True, the container TableViewSection object should handle the removal.

Return type:bool
text_label

(Read Only) The label containing the main text of the cell.

Return type:Label
class pyto_ui.TableView(style: ui_constants.TABLE_VIEW_STYLE = TABLE_VIEW_STYLE_PLAIN, sections: List[pyto_ui.TableViewSection] = [])

A view containing a list of cells.

A Table View has a list of TableViewSection objects that represent groups of cells. A Table View has two possible styles. See Table View Style.

deselect_row()

Deselects the current selected row.

edit_button_item

Returns a bar button item that toggles its title and associated state between Edit and Done. The button item is setup to edit the Table View.

Return type:ButtonItem
reload_action

A function called when the button item is pressed. Takes the button item as parameter.

Return type:Callable[[TableView], None]
sections

A list of TableViewSection containg cells to be displayed on the Table View. Setting a new value will reload automatically the contents of the Table View.

Return type:List[TableViewSection]
class pyto_ui.TextView(text='')

An editable, multiline and scrollable view containing text.

autocapitalization_type

The type of autocapitalization to use while editing th text. See Auto Capitalization constants for possible values.

Return type:Auto Capitalization
autocorrection

A boolean indicating whether autocorrection is enabled.

Return type:bool
did_begin_editing

A function called when the Text View begins editing. Takes the sender Text View as parameter.

Return type:Callable[[TextView], None]
did_change

A function called when the Text View’s text changes. Takes the sender Text View as parameter.

Return type:Callable[[TextView], None]
did_end_editing

A function called when the Text View ends editing. Takes the sender Text View as parameter.

Return type:Callable[[TextView], None]
editable

A boolean indicating whether the text is editable.

Return type:bool
font

The font of the text displayed on screen.

Return type:Font
keyboard_appearance

The appearance of the keyboard used while editing the text. See Keyboard Appearance constants for possible values.

Return type:Keyboard Appearance
keyboard_type

The type of keyboard to use while editing the text. See Keyboard Type constants for possible values.

Return type:Keyboard Type
load_html(html)

Loads HTML in the Text View.

Parameters:html – The HTML code to load.
return_key_type

The type of return key to show on the keyboard used to edit the text. See Return Key Type constants for possible values.

Return type:Return Key Type
secure

A boolean indicating whether the keyboard should be configured to enter sensitive data.

Return type:bool
selectable

A boolean indicating whether the text is selectable.

Return type:bool
selected_range

Returns the selected text range. A tuple of two integers (start, end).

Return type:Tuple[int, int]
smart_dashes

A boolean indicating whether smart dashes are enabled.

Return type:bool
smart_quotes

A boolean indicating whether smart quotes are enabled.

Return type:bool
text

The text contained in the view.

Return type:str
text_alignment

The alignment of the text displayed on screen. See Text Alignment constants for possible values.

Return type:Text Alignment
text_color

The color of the text displayed on screen.

Return type:Color
class pyto_ui.WebView(url: Optional[str] = None)

A View that displays web content.

exception JavaScriptException

An excpetion while running JavaScript code. Raised by evaluate_js().

can_go_back

(Read Only) A boolean indicating whether go_back() can be performed.

Return type:bool
can_go_forward

(Read Only) A boolean indicating whether go_forward() can be performed.

Return type:bool
did_fail_loading

A function called when the Web View failed to load contents. Takes the sender Web View and a string describing the error as parameters.

Return type:Callable[[WebView, str], None]
did_finish_loading

A function called when the Web View finished loading contents. Takes the sender Web View as parameter.

Return type:Callable[[WebView], None]
did_start_loading

A function called when the Web View starts loading contents. Takes the sender Web View as parameter.

Return type:Callable[[WebView], None]
evaluate_js(code) → str

Runs JavaScript code and returns a String representation of the evaluation result. Raises a JavaScriptException.

Parameters:code – JavaScript code to run.
Return type:str
go_back()

Goes back.

go_forward()

Goes forward.

is_loading

(Read Only) A boolean indicating whether the Web View is loading content.

Return type:bool
load_html(html: str, base_url: Optional[str] = None)

Loads an HTML string.

Parameters:
  • html – The HTML code to load.
  • base_url – An optional URL used to resolve relative paths.
load_url(url: str)

Loads an URL.

Parameters:url – The URL to laod. Can be ‘http://’, ‘https://’ or ‘file://’.
reload()

Reloads the Web View.

stop()

Stops loading content.

url

(Read Only) The current URL loaded into the Web View.

Return type:str

Controls

class pyto_ui.Control

The base class for controls, which are visual elements that convey a specific action or intention in response to user interactions.

Inherited by Button, SegmentedControl, Slider, Switch and TextField

action

A function called when the control triggers its action. For example, a Button object calls this function when it’s pressed.

Takes the Control object as parameter.

Return type:Callable[[Control], None]
enabled

A boolean indicating whether the control is enabled.

Return type:bool
horizontal_alignment

The horizontal alignment of the view’s contents. See Horizontal Alignment constants for possible values.

Return type:Horizontal Alignment
vertical_alignment

The vertical alignment of the view’s contents. See Vertical Alignemnt constants for possible values.

Return type:Vertical Alignment
class pyto_ui.SegmentedControl(segments: List[str] = [])

A horizontal control made of multiple segments, each segment functioning as a discrete button. The function passed to action will be called when the segmented control changes its selection.

segments

A list of strings representing segments titles.

Return type:List[str]
selected_segment

The index of selected segment.

Return type:int
class pyto_ui.Slider(value: float = 0.5)

A control used to select a single value from a continuous range of values. The default range is located between 0 and 1. The function passed to action will be called when the slider changes its value.

maximum_track_color

The color used to tint the default maximum track.

Return type:Color
maximum_value

The maximum value of the slider.

Return type:float
minimum_track_color

The color used to tint the default minimum track.

Return type:Color
minimum_value

The minimum value of the slider.

Return type:float
set_value_with_animation(value: float)

Sets the value of the slider with an animation.

Parameters:value – The value of the slider.
thumb_color

The color used to tint the default thumb.

Return type:Color
value

The value of the slider between its range.

Return type:float
class pyto_ui.Switch(on=False)

A control that offers a binary choice, such as On/Off. The function passed to action will be called when the switch changes its value.

on

A boolean indicating whether the switch is On.

Return type:bool
on_color

The color used to tint the appearance of the switch when it is turned on.

Return type:Color
set_on_with_animation(on: bool)

Sets the state of the switch to On or Off with an animation.

Parameters:on – A boolean indicating whether the switch should be On.
thumb_color

The color used to tint the appearance of the thumb.

Return type:Color
class pyto_ui.Button(type: ui_constants.BUTTON_TYPE = BUTTON_TYPE_SYSTEM, title: str = '', image: Optional[Image] = None)

A control that executes your custom code in response to user interactions. To add an action, set action.

For types of buttons, see Button Type constants.

font

The font to be applied to the text.

Return type:Font
image

The image displayed on the button. Can be a PIL image or an UIKit symbol image. For more information about symbols, see image_with_system_name().

Return type:PIL.Image.Image
title

The title of the button

Return type:str
title_color

The color of the title.

Return type:Color
class pyto_ui.TextField(text: str = '', placeholder: Optional[str] = None)

A field to type single line text. The function passed to action will be called when the text field changes its text.

autocapitalization_type

The type of autocapitalization to use while editing th text. See Auto Capitalization constants for possible values.

Return type:Auto Capitalization
autocorrection

A boolean indicating whether autocorrection is enabled.

Return type:bool
did_begin_editing

A function called when the Text Field begins editing. Takes the sender Text Field as parameter.

Return type:Callable[[TextField], None]
did_end_editing

A function called when the Text Field ends editing. Takes the sender Text Field as parameter.

Return type:Callable[[TextField], None]
font

The font of the text displayed on screen.

Return type:Font
keyboard_appearance

The appearance of the keyboard used while editing the text. See Keyboard Appearance constants for possible values.

Return type:Keyboard Appearance
keyboard_type

The type of keyboard to use while editing the text. See Keyboard Type constants for possible values.

Return type:Keyboard Type
placeholder

A gray text shown when there is no text.

Return type:str
return_key_type

The type of return key to show on the keyboard used to edit the text. See Return Key Type constants for possible values.

Return type:Return Key Type
secure

A boolean indicating whether the keyboard should be configured to enter sensitive data. The text entered by the user will be hidden.

Return type:bool
smart_dashes

A boolean indicating whether smart dashes are enabled.

Return type:bool
smart_quotes

A boolean indicating whether smart quotes are enabled.

Return type:bool
text

The text contained in the Text Field.

Return type:str
text_alignment

The alignment of the text displayed on screen. See Text Alignment constants for possible values.

Return type:Text Alignment
text_color

The color of the text displayed on screen.

Return type:Color

Other classes

A list of classes that don’t represent views.

class pyto_ui.Color(py_color)

A Color object represents a color to be displayed on screen.

Example:

import pyto_ui as ui

# RGB
black = ui.Color.rgb(0, 0, 0, 1)

# White
white = ui.Color.white(1, 1)

# Dynamic
background = ui.Color.dynamic(light=white, dark=black)

For pre-defined colors, see Color constants.

alpha() → float

Returns the alpha value of the color.

Return type:float
blue() → float

Returns the blue value of the color.

Return type:float
classmethod dynamic(light: pyto_ui.Color, dark: pyto_ui.Color) → pyto_ui.Color

Initializes and returns a color that dynamically changes in dark or light mode.

Parameters:
  • lightColor object to be displayed in light mode.
  • darkColor object to be displayed in dark mode.
Return type:

Color

green() → float

Returns the green value of the color.

Return type:float
red() → float

Returns the red value of the color.

Return type:float
classmethod rgb(red: float, green: float, blue, alpha: float) → pyto_ui.Color

Initializes a color from RGB values.

All values should be located between 0 and 1, not between 0 and 255.

Parameters:
  • red – The red value.
  • green – The geen value.
  • blue – The blue value.
  • alpha – The opacity value.
Return type:

Color

classmethod white(white: float, alpha: float) → pyto_ui.Color

Initializes and returns a color from white value.

All values should be located between 0 and 1, not between 0 and 255.

Parameters:
  • white – The grayscale value.
  • alpha – The opacity value.
Return type:

Color

class pyto_ui.Font(name: str, size: float)

A Font object represents a font (with name and size) to be used on labels, buttons, text views etc.

classmethod bold_system_font_of_size(size: float) → pyto_ui.Font

Returns the font object used for standard interface items that are rendered in boldface type in the specified size

Parameters:size – The size (in points) for the font. This value must be greater than 0.0.
Return type:Font
classmethod font_names_for_family_name(name: str) → List[str]

Returns an array of font names available in a particular font family.

Parameters:name – The name of the font family. Use the font_family_names() function to get an array of the available font family names on the system.
Return type:List[str]
classmethod font_with_style(style: ui_constants.FONT_TEXT_STYLE) → pyto_ui.Font

Returns an instance of the system font for the specified text style and scaled appropriately for the user’s selected content size category.

Parameters:style – The text style for which to return a font. See Font Text Style constants for possible values.
Return type:Font
classmethod italic_system_font_of_size(size: float) → pyto_ui.Font

Returns the font object used for standard interface items that are rendered in italic type in the specified size.

Parameters:size – The size (in points) for the font. This value must be greater than 0.0.
Return type:Font
classmethod system_font_of_size(size: float) → pyto_ui.Font

Returns the font object used for standard interface items in the specified size.

Parameters:size – The size (in points) to which the font is scaled. This value must be greater than 0.0.
Return type:Font
with_size(size: float) → pyto_ui.Font

Returns a font object that is the same as the receiver but which has the specified size instead.

Parameters:size – The desired size (in points) of the new font object. This value must be greater than 0.0.
Return type:Font
class pyto_ui.GestureRecognizer(type: ui_constants.GESTURE_TYPE, action: Optional[Callable[[pyto_ui.GestureRecognizer], None]] = None)

A gesture-recognizer object—or, simply, a gesture recognizer—decouples the logic for recognizing a sequence of touches (or other input) and acting on that recognition. When one of these objects recognizes a common gesture or, in some cases, a change in the gesture, it sends an action message to each designated target object.

This class represents the type of gesture passed to the type initializer parameter. See Gesture Type constants for possible values. When the gesture is starting, cancelling or changig, action is called with the gesture recognizer as parameter. You can then access the location and the state from it.

Example:

'''
Move a circle with finger.
'''

import pyto_ui as ui

view = ui.View()
view.background_color = ui.COLOR_SYSTEM_BACKGROUND

circle = ui.View()
circle.size = (50, 50)
circle.center = (view.width/2, view.height/2)
circle.flexible_margins = True
circle.corner_radius = 25
circle.background_color = ui.COLOR_LABEL
view.add_subview(circle)

def move(sender: ui.GestureRecognizer):
    if sender.state == ui.GESTURE_STATE_CHANGED:
        circle.center = sender.location

gesture = ui.GestureRecognizer(ui.GESTURE_TYPE_PAN)
gesture.action = move
view.add_gesture_recognizer(gesture)

ui.show_view(view)
action

A function called to handle the gesture. Takes the sender gesture recognizer as parameter.

Return type:Callable[[GestureRecognizer], None]
allowedTouchTypes

An array of touch types used to distinguish type of touches. For possible values, see Touch Type constants.

Return type:List[Touch Type]
allowed_touch_types

An array of touch types used to distinguish type of touches. For possible values, see Touch Type constants.

Return type:List[Touch Type]
cancels_touches_in_view

A Boolean value affecting whether touches are delivered to a view when a gesture is recognized.

Return type:bool
delays_touches_began

A Boolean value determining whether the receiver delays sending touches in a begin phase to its view.

Return type:bool
delays_touches_ended

A Boolean value determining whether the receiver delays sending touches in a end phase to its view.

Return type:bool
enabled

A boolean indicating whether the gesture recognizer is enabled.

Return type:bool
location

(Read Only) Returns a tuple with the X and the Y position of the gesture in its container view.

Return type:Tuple[float, float]
number_of_touches

(Read Only) Returns the number of touches involved in the gesture represented by the receiver.

Return type:int
requires_exclusive_touch_type

A Boolean indicating whether the gesture recognizer considers touches of different types simultaneously.

Return type:bool
state

(Read Only) The current state of the gesture recognizer.

Return type:Gesture State
view

(Read Only) Returns the view associated with the gesture.

Return type:View
x

(Read Only) Returns the X position of the gesture in its container view.

Return type:float
y

(Read Only) Returns the Y position of the gesture in its container view.

class pyto_ui.TableViewSection(title: str, cells: List[TableViewCell])

An object representing a section in a Table View. A section has a title and a list of cells contained in.

cells

Cells contained in the section. After setting a value, the section will be reloaded automatically.

Return type:TableViewCell
did_delete_cell

A function called when a cell contained in the section is deleted. Takes the sender section and the selected deleted cell’s index as parameters. This function should be used to remove the data corresponding to the cell from the database.

Return type:Callable[[TableViewSection, int], None]
did_move_cell

A function called when a cell contained in the section is moved. Takes the sender section, the moved deleted cell’s index and the destination index as parameters. This function should be used to move the data corresponding to the cell from the database.

Return type:Callable[[TableViewSection, int, int], None]
did_select_cell

A function called when a cell contained in the section is selected. Takes the sender section and the selected cell’s index as parameters.

Return type:Callable[[TableViewSection, int], None]
did_tap_cell_accessory_button

A function called when the accessory button of a cell contained in the section is pressed. Takes the sender section and the cell’s index as parameters.

Return type:Callable[[TableViewSection, int], None]
table_view

(Read Only) Returns the Table view associated with the section.

Return type:TableView
title

The title of the section displayed on screen.

Return type:str
class pyto_ui.ButtonItem(title: Optional[str] = None, image: Optional[Image] = None, system_item: Optional[ui_constants.SYSTEM_ITEM] = None, style: ui_constants.BUTTON_ITEM_STYLE = BUTTON_ITEM_STYLE_PLAIN)

A special kind of button that can be placed on the view’s navigation bar. Can have a title, and image or a system type.

action

A function called when the button item is pressed. Takes the button item as parameter.

Return type:Callable[[ButtonItem], None]
enabled

A boolean indicating whether the button is enabled.

Return type:bool
image

A PIL image object displayed on screen. May also be an UIKit UIImage symbol. See image_with_system_name().

Return type:PIL.Image.Image
style

The button item style. See Button Item Style constants for possible values.

Return type:Button Item Style
title

The title of the button displayed on screen.

Return type:str
class pyto_ui.Alert(title: str, message: str)

A class representing an alert.

Example:

from pyto_ui import Alert

alert = Alert("Hello", "Hello World!")
alert.add_action("Ok")
alert.add_cancel_action("Cancel")
if (alert.show() == "Ok"):
    print("Good Bye!")
add_action(title: str)

Adds an action with given title.

Parameters:title – The title of the action.
add_cancel_action(title: str)

Adds a cancel action with given title. Can only be added once.

Parameters:title – The title of the action.
add_destructive_action(title: str)

Adds a destructive action with given title.

Parameters:title – The title of the action.
show() → str

Shows alert.

Returns the title of the selected action.

Return type:str