Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
UI button help
-
def button_tapped(sender): sender.title = str(int(not int(sender.title))) # toggles between 0 and 1
But since these buttons are toggles, perhaps they should be ui.Switches instead of UI.Buttons.
-
How can I access a subview (i.e. a label), that is in another subview of a NavigationView?
Expample: I have a Navigation View. Inside live two Subviews. Subview 1 has a label in it, subview 2 has a button. How can I change the label of the text, when the button is pressed? (Navigation View and the two SubViews are three different files. I have described my setup in another thread.)
-
@vcr80 Could you post some sample code on github for us to look at?
-
@vcr80 , I just did a iteration above to show you can get to the superview and then subviews without knowing what's there.
But if I think you are asking for is Something likelb = sender.superview.subviews['my_nav_view'].subviews['my_label']
Lb.text = 'hello'Should not matter they are loaded from different files. They are just views in the hierarchy.
Maybe I misunderstood you.
-
sure, @ccc here it is: https://gist.github.com/nitricware/f82416c411586404e5d2
unfortunately the iteration you posted, @Phuket2 just lists the subviews of the view where the pressed button is located... but not the subviews of the parent navigation view nor the subviews of the root view, that itself is loaded into the navigation view...
-
One of many solutions is to load your sub view just once as a global variable...
subview = ui.load_view('SubView.pyui') def pressButton(sender): dialogs.hud_alert('okay2') subview.name = 'What happened?!?' class NavView(object):
-
@vcr80 , but really just stop and think for a moment. No funky solution really needed. If you can understand the superviews and subviews you can find everything. I can't look at your Github code at the moment
-
Great, @ccc - that cleared things up!
I was able to set the text of a label inside another subview of the navigation view now.However, I still don't see how I could access the navigation view itself when a button inside the the subview is pressed.
NavView.push_view(root)
andNavView.v.push_view(root)
didn't work. Knowing how to access the navigation view from within a subview could come in handy if I'd like to close the current subview as soon as a button is pressed or if i want to load yet another subview when the button is pressed.Updated Gist: https://gist.github.com/nitricware/468b31a1b5363c4474e1
Lines 10 and 42 show my new issues...@Phuket2 I'd like to! Did I miss some kind of introduction to Pythonista UI creation? Or are you supposed to know how those kind of things work (Installed Pythonista less than a week ago.)?
-
Actually @Phuket2 it is not so intuitive when NavigationViews are involved... root_view, sub_view, and nav_view are three separate views and none of them are the subviews or the superviews of each other.
It is possible for sender, root_view, and sub_view to get to nav_view via their .navigation_view instance variable. However there is no convenient way for sender to easily get to subview except via a global or a class instance variable.
-
@vcr80 NavView can just be an object instead of a ui.NavigationView. See comments on the bottom of the gist.
-
@vcr80 , no I was not trying to be smart. But @ccc mentions that in the navigation view things are more disjointed. I have never used it. I am not sure how navigation view stands now, but for a long time it had known problems.
But still regardless of the disconnects with the views in navigation view, if you know how to get around the views in Pythonista , a myriad of solutions will come to you. You really have to understand them. I really sheds a lot of light on many things.
But really just trying to help. -
@ccc , fair enough. But given that you know it, you could dynamically create attrs for the object that has a callback func defined to point to something useful. Or a custom ui.View wrapper class. Well there are many ways.
I am not good. But with knowledge of views, I am never stuck to derive a reference to any ui component -
@ccc , I just did some work with ui.Navigation. But in all honesty this is not ready for prime time yet. Can write it yourself with out the issues.
There are 2 methods and 3 attributes and a very explicit required startup view.
I can see @omz idea, but it has become an orphan. My idea would be he should remove it until he has more time to devote to it. Personally, I would say it's not useful enough in its current state to publish. Actually the reverse, new users will see the promised land, but it's not there yet. Will not get them to the end of a solution and they will struggle with it.
Look, I am still a newbie, but that's my view 😱😎
If I am wrong then so be it -
Thanks for all the replies! Superview works great!
-
@ccc said:
Actually @Phuket2 it is not so intuitive when NavigationViews are involved... root_view, sub_view, and nav_view are three separate views and none of them are the subviews or the superviews of each other.
It is possible for sender, root_view, and sub_view to get to nav_view via their .navigation_view instance variable. However there is no convenient way for sender to easily get to subview except via a global or a class instance variable.
On this one I think there is a solution using dynamic attrs.
But I still get your point. But as I said in another post, I don't think this class/component offers enough functionality yet to even use it.
A view, with a list or 2 popping some items and some styling attrs. -
Thanks, @ccc - That works fine! Could you explain the part with
NavView(object)
? Why did you change it and what does it change in the background? The rest of your changes are clear to me.Sorry, @Phuket2 I didn't mean it in any offensive way. I am really searching for an introduction to UI Designer of Pythonista because I really want to know how things work. I too think that understanding how views work will help a lot! So again: did I miss something or are you simple supposed to find out on your own or should one already know how those things work because one should know how Python works?
-
@vcr80 , hey no problems. Also I was not either. Sometimes words can seem a little hash when they are not meant to be. I think as I have become more relaxed here, I write a little differently, as I sort of assume people start to get to know your meaning with not so many words.
Anyway. Regarding leaving about the ui the built in docs are really good. Some things missing. But still good. Also is the Pythonista Tools site/repo. Here is a link into the ui part of the Pythonista Tools
http://pythonista-tools.github.io/Pythonista-Tools/scripts.htmlAlso a lot of the guys public repo's on git hub are very good place to find good examples. @ccc , @JonB , @TutorialDoctor and not forgetting @omz. That's just few that come to mind
Another great place is searching this forum. The searching is a little hit and miss for me here. But, also great advise given by these guys.
Look I am still a newbie. At the same time I still have to challenge ideas. @ccc and many others here have taught me so much and still do. But occasionally I still have to challenge thier ideas 😱
Normally I crawl,away with my tail between my legs. -
@vcr80 wrote:
Could you explain the part with NavView(object)? Why did you change it and what does it change in the background?
The object in question, NavView has members (rootview, subview, navview) that are ui.Views or ui.NavigationViews but NavView is not a View. It is better thought of as a controller/coordinator/choreographer of Views.
These kind of objects a common in scripts that use .pyui views.