Anvil: Web Apps with Nothing but Python Transcripts
Chapter: Navigating between views
Lecture: Using the navigation module within a component

Login or purchase this course to watch this video and the rest of the course contents.
0:00 So we built up this navigation and one of the things I gave as motivation was well, yeah if all the navigation actually happened within the home form
0:10 well, we could just stick it in there and it'll all be well and good, right? However, it's mixed throughout all of these things and when I say compare
0:19 or especially when I say add measurement when this is finished what I would like to do is have it take me away. So let's see what it's doing now.
0:28 We come over here and I can add a measurement and I pick today, that's cool. I can say this let's put 180 and our validation works.
0:38 I don't know what my heart rate is but let's say it's 70. Boom! And we get a little print. Hey, we saved this, that's cool.
0:46 Great. And what would we really want to do? Not stay on this page. That's probably the worst possible thing. We would probably want to go home
0:53 and here's like a list of our recent measurements we've added or a graph. A graph would be even better. When we're done adding it successfully
1:01 we want to go home. Check this out. So over here this is part of the glory is say import navigation. This part, this would go home.
1:12 Let's just say navigation dot go home. Let's see it now. Come over here we're going to say add. I don't need that. Let's still say it's today
1:22 we're not actually saving in this. 179. I lost a pound in just as few seconds and my heart rate went up. Ready?
1:31 When I click this, it should print out that we're going to save it which will simulate saving it and we'll get to that when we actually work
1:35 with the database but the next thing to do is it should remove this component here and it should take us, effectively
1:42 from what the user's perspective is back to the home screen. Ready? Boom! Home anonymous because that's what we're loading up, right?
1:50 It should be the logged in one. I guess, sort of. Isn't that cool? How awesome is that? And look how easy it is to share this navigation function
1:58 throughout our entire application even other modules. Right? If we have other modules over here potentially they could do navigation.
2:07 Now, one final caveat within this function this initialization function the sequence of events happening here is
2:15 this add measurement component is about to be put into the main view most likely. It's not quite there yet. It's about to member the processes
2:24 allocate, set data and then put it in the component panel there. What that means is we're not ready to stop navigating here and go somewhere else.
2:33 So you can't do something like, I don't know if not account navigation go home or go account, I don't know. Let's put it the other way.
2:41 All right, if account we want you to go here instead you can do that within response to button clicks other behaviors, timers, and whatnot
2:49 but you cannot do that in the initialization here. Just because of that workflow that we talked about at the beginning.
2:56 We're not even done loading this component. We can't navigate away from it yet. Okay, so we just keep in mind
3:02 this navigation does not work in the initializers but it pretty much works everywhere else and it's a thing of beauty.


Talk Python's Mastodon Michael Kennedy's Mastodon