Anvil: Web apps with nothing but Python Transcripts
Chapter: Navigating between views
Lecture: Setting the title during navigation

Login or purchase this course to watch this video and the rest of the course contents.
0:00 When we run our app it's working
0:03 but notice the title up here is just the title of the app
0:06 and that may be okay
0:07 but, in this example, I would like to see
0:10 right now I'm on the compare page
0:11 or now I'm on the add page and so on
0:13 so let's go and update that.
0:16 So let's go down here for each one of these
0:18 and we're going to add a separate function.
0:21 Now, I could just directly work with the form
0:23 but again, I like have this nice and broken out
0:25 so I have def set_title
0:28 and what we're going to do is we're going to say
0:29 form = get_form() and our form
0:32 if we go look at it has a self.label_title.
0:37 So, labeled titles is what we want to work with
0:40 and we'll say label_title, that's the control
0:43 and then we want to say the text is equal to, well what?
0:47 We could just say text, right?
0:48 But what we actually want to do is have the base title
0:51 plus this.
0:53 So, let's go back to our home form and say
0:56 something to the effect of
0:58 self.base_title equals this at start up
1:01 that way we let people design it in the designer
1:04 we have access to this here.
1:06 So if we change up the designer we don't have to
1:08 go and change code as well.
1:09 So what we will do is say base_title = form.base_title.
1:18 We'll say if there's some text passed in
1:22 we'll do base title.
1:29 We just want to set it to base_title.
1:33 Like this. Okay, so this, I think this will do it.
1:36 Now we just have to call set_title.
1:37 So here we can say set_title("Add Measurement").
1:45 Just say, for this one let's set it to
1:47 just nothing, like that.
1:52 Compare. We'll have your account like that.
2:00 Now, let's see if this is going to work.
2:03 Form is not find. Where do we do this?
2:06 Yes, it's with the self.
2:11 Okay, notice nothing appeared. We click on add.
2:14 Add measurement, compare, add home goes back to nothing
2:19 remember that the colon is gone.
2:21 Actually I would like to have a dash I think, but I will
2:23 put that in a sec.
2:24 So over here, you see how cool that is?
2:26 Now it's super easy for us to give a little bit better
2:29 idea to the user on where they are.
2:32 'Cause we have this all centralized into one
2:35 beautiful place.
2:36 Make one change right there.
2:38 Every time it changes, every time that we navigate
2:40 somewhere it's going to take that change.
2:42 That's why we refactored it.
2:44 So, if we go here we're going to add, there's our dash
2:47 there's our compare, there's our count, there's our nothing.
2:51 All right, looks like we're setting our title, great.