Last active
August 18, 2017 07:06
-
-
Save Dayof/da991d2a641d7f67c803e386978472e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import toga | |
class StartApp(toga.App): | |
def startup(self): | |
# Main window | |
self.main_window = toga.MainWindow(self.name) | |
self.main_window.app = self | |
# Tree widget from Toga | |
self.tree = toga.Tree(['Navigate']) | |
# Insert nodes top level on the tree | |
self.tree.insert('root1') | |
self.tree.insert('root2') | |
# Insert node with the children expanded | |
# Informs if a node is collapsed in the args of the insert method | |
self.r3 = self.tree.insert('root3', collapsed=False) | |
self.sub_r3 = self.tree.insert('sub_r3', self.r3) | |
# Informs that a node is expanded using a method call | |
self.sub_r3.expand() | |
self.tree.insert('sub_sub_r3', self.sub_r3) | |
# Update the tree layout | |
self.tree.apply_layout() | |
# Buttons to interact with the tree and update the tree visualization | |
update_tree_button_collapse = toga.Button('Collapse root3', | |
on_press=self.callbackCollapse) | |
update_tree_button_expand = toga.Button('Expand root3', | |
on_press=self.callbackExpand) | |
self.control_box = toga.Box(children=[update_tree_button_collapse, | |
update_tree_button_expand]) | |
# Main widget of the application, show both the Tree data and the | |
# buttons to control thee application | |
frame = toga.SplitContainer() | |
frame.content = [self.tree, self.control_box] | |
# Add the main widget inside of the main application | |
self.main_window.content = frame | |
# Show the application | |
self.main_window.show() | |
def callbackCollapse(self, event): | |
# Collapse the node using a method call | |
self.r3.collapse() | |
# Update the tree layout | |
self.tree.apply_layout() | |
def callbackExpand(self, event): | |
# Expand the node using a method call | |
self.r3.expand() | |
# Update the tree layout | |
self.tree.apply_layout() | |
def main(): | |
# Start the application with the title and the name of the organization | |
app = StartApp('Test Tree, expand and collapse features', | |
'org.pybee.test') | |
app.main_loop() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment