Instantly share code, notes, and snippets.
Created
August 15, 2018 03:30
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save encela95dus/aff2b7f6eb909e27364c135b18e686c9 to your computer and use it in GitHub Desktop.
navtest_mainview.pyui
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
[ | |
{ | |
"class" : "View", | |
"attributes" : { | |
"name" : "Main View", | |
"background_color" : "RGBA(1.000000,1.000000,1.000000,1.000000)", | |
"tint_color" : "RGBA(0.000000,0.478000,1.000000,1.000000)", | |
"enabled" : true, | |
"border_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)", | |
"flex" : "" | |
}, | |
"frame" : "{{0, 0}, {600, 400}}", | |
"selected" : false, | |
"nodes" : [ | |
{ | |
"class" : "Label", | |
"attributes" : { | |
"font_size" : 18, | |
"text" : "main view", | |
"font_name" : "<System>", | |
"name" : "label1", | |
"class" : "Label", | |
"alignment" : "left", | |
"frame" : "{{45, 104}, {150, 32}}", | |
"uuid" : "0B1C41A7-4126-448B-9280-0FC8579D0774" | |
}, | |
"frame" : "{{224, 166}, {150, 55}}", | |
"selected" : false, | |
"nodes" : [ | |
] | |
} | |
] | |
} | |
] |
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
[ | |
{ | |
"class" : "View", | |
"attributes" : { | |
"name" : "Subview1", | |
"background_color" : "RGBA(1.000000,1.000000,1.000000,1.000000)", | |
"tint_color" : "RGBA(0.000000,0.478000,1.000000,1.000000)", | |
"enabled" : true, | |
"border_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)", | |
"flex" : "" | |
}, | |
"frame" : "{{0, 0}, {600, 400}}", | |
"selected" : false, | |
"nodes" : [ | |
{ | |
"class" : "Label", | |
"attributes" : { | |
"font_size" : 18, | |
"text" : "Subview 1", | |
"font_name" : "<System>", | |
"name" : "label1", | |
"class" : "Label", | |
"alignment" : "left", | |
"frame" : "{{45, 104}, {150, 32}}", | |
"uuid" : "5ACF2819-96A2-4C54-89E4-D7E8963A15E1" | |
}, | |
"frame" : "{{222, 171}, {150, 32}}", | |
"selected" : true, | |
"nodes" : [ | |
] | |
} | |
] | |
} | |
] |
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
[ | |
{ | |
"class" : "View", | |
"attributes" : { | |
"name" : "Subview2", | |
"background_color" : "RGBA(1.000000,1.000000,1.000000,1.000000)", | |
"tint_color" : "RGBA(0.000000,0.478000,1.000000,1.000000)", | |
"enabled" : true, | |
"border_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)", | |
"flex" : "" | |
}, | |
"frame" : "{{0, 0}, {600, 400}}", | |
"selected" : false, | |
"nodes" : [ | |
{ | |
"class" : "Label", | |
"attributes" : { | |
"font_size" : 18, | |
"text" : "Subview 2", | |
"font_name" : "<System>", | |
"name" : "label1", | |
"class" : "Label", | |
"alignment" : "left", | |
"frame" : "{{45, 104}, {150, 32}}", | |
"uuid" : "590803AC-D7E1-4D8A-B5B7-E7F2CAFDD034" | |
}, | |
"frame" : "{{224, 174}, {150, 58}}", | |
"selected" : false, | |
"nodes" : [ | |
] | |
} | |
] | |
} | |
] |
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 ui | |
from functools import partial | |
class SimpleNavigationView(ui.View): | |
def add_close_buttonitem(self, v): | |
close = ui.ButtonItem() | |
close.image = ui.Image.named('ionicons-close-24') | |
close.action = self.bt_close | |
v.left_button_items = [close] | |
def add_right_buttonitem(self, v, action): | |
right = ui.ButtonItem() | |
right.image = ui.Image.named('ionicons-arrow-right-b-24') | |
right.action = action | |
v.right_button_items = [right] | |
def bt_close(self, sender): | |
self.nav_view.superview.close() | |
def bt_subview(self, i, sender): | |
subview = ui.load_view(self.subviews_pyui[i]) | |
if i < (len(self.subviews_pyui)-1): | |
self.add_right_buttonitem(subview, self.bt_subviews[i+1]) | |
self.nav_view.push_view(subview) | |
def make_bt_subview(self): | |
for i in range(len(self.subviews_pyui)-1, 0, -1): | |
self.bt_subviews[i] = partial(self.bt_subview, i) | |
def __init__(self, w=600, h=400, subviews_pyui=None): | |
super().__init__(frame=(0,0,w,h)) | |
self.subviews_pyui = subviews_pyui | |
self.bt_subviews = [None]*len(self.subviews_pyui) | |
if len(self.subviews_pyui) > 1: | |
self.main_view = ui.load_view(self.subviews_pyui[0]) | |
self.make_bt_subview() | |
self.add_close_buttonitem(self.main_view) | |
self.add_right_buttonitem(self.main_view, self.bt_subviews[1]) | |
self.nav_view = ui.NavigationView(self.main_view) | |
self.nav_view.width = w | |
self.nav_view.height = h | |
self.add_subview(self.nav_view) | |
SimpleNavigationView(w=600, h=400, | |
subviews_pyui=('navtest_mainview', 'navtest_subview1', 'navtest_subview2') | |
).present('sheet', hide_title_bar=True) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment