Phlow for Python
PythonBridge comes with an implementation of Phlow for Python objects. It is meant to be used in the Glamorous Toolkit inspector, for instance through Lepiter pages.
The Python framework allows for views to be defined in Python code. To do this in a Python project, you will first have to install the gtoolkit_bridge module. Once it is installed, you will be able to add views to your objects.
Views in Python are methods that are annotated with the @gtView decorator. They take a view builder and return a built view. View exist for columnedList
, list
, textEditor
, columnedTree
, and forward
. If a view method decides not to display anything, empty
may be returned as well.
The API is generally quite similar to that in Smalltalk, though due to language differences necessarily a bit different.
A view for displaying single-column list data.
from gtoolkit_bridge import gtView class MyList: def __init__(self, lst): self.lst = lst @gtView def gt_view_list(self, builder): if not len(self.lst): return builder.empty() lst = builder.list() lst.title("List") lst.priority(1) lst.items(lambda: self.lst) lst.set_accessor(lambda idx: self.lst[idx] * 2) # for demo purposes, double the item in the click handler return lst MyList([1,2,3])
A view for displaying single-column list data.
from gtoolkit_bridge import gtView class MyColumnedList: def __init__(self, lst): self.lst = lst @gtView def gt_view_list(self, builder): if not len(self.lst): return builder.empty() lst = builder.columnedList() lst.title("List") lst.priority(1) lst.items(lambda: self.lst) lst.column("String", lambda each: each[0]) lst.column("Integer", lambda each: each[1]) return lst MyColumnedList([["hello", 1], [" ", 2], ["world", 3]])
A view for displaying textual data.
from gtoolkit_bridge import gtView class MyEditor: def __init__(self, txt): self.txt = txt @gtView def gt_view_editor(self, builder): editor = builder.textEditor() editor.title("Editor") editor.priority(1) editor.string = self.txt return editor MyEditor("hello, world!")
A view for displaying columnar tree data.
from gtoolkit_bridge import gtView class MyTree: def __init__(self, tree): self.tree = tree @gtView def gt_view_list(self, builder): tree = builder.columnedTree() tree.title("Columned tree") tree.priority(1) tree.items(lambda: self.tree) tree.children(lambda each: each["children"]) tree.column("Value", lambda each: each["value"]) return tree MyTree([ {"value": 1, "children": [ {"value": 2, "children": [ {"value": 2.5, "children": []}]}]}, {"value": 3, "children": []} ])
A view for forwarding views to other objects.
from gtoolkit_bridge import gtView class MyForward: def __init__(self, value): self.value = value @gtView def gt_view_fwd(self, builder): fwd = builder.forward() fwd.title("Forward") fwd.priority(1) fwd.object(lambda: self.value) fwd.view("gt_view_editor") return fwd MyForward(MyEditor("hello, world!"))
The view framework is based on Remote Phlow. It is an almost complete implementation of the framework, although currently tree views are missing. Usually, these can be emulated with single-column columned trees, however.