 Hey everyone, welcome back to another Python programming tutorial. We're still looking at the Npy screen module. In the last video we were checking out different kinds of forms. As you know, our Npy screen module works kind of with three different core objects and classes and things that we work with, which are the form objects, the application objects, and the widget objects. So we've got an application manager that manages all of our forms, forms that are what we kind of see on the screen, and of course the widgets that the things we interact with and work with on the screen. So we were looking at action form and split form. We were checking them out in a documentation and seeing the differences that they had from each other and from the normal form. Now the action form was interesting because it allowed us to create both an okay button as well as a cancel button, and we had these two nifty little functions that we could, there were pretty much callback functions that would interact with and they would run when the user pressed the okay button or the cancel button. So when we worked with this in our code, what we set it up was that just so we could visualize and see what button you had pressed, we had turned off the next form, next active form attribute, and so that way we would never exit the program really, but whenever we press the okay button, the first text box that we have up on our form here, that would display oh, the okay button was pressed. If we press the cancel button, the second text box that was displayed in reform would say oh, the cancel button was pressed. So that's how it worked, and this is it when we actually run the code. Like if I hit the cancel button, you can see cancel button is pressed down there, and if I hit the okay button, okay button is pressed up there. But the thing is normally these will exit our program. They will exit the form, and if we don't have any next active form set, then we'd kind of stop executing the program. We'd be all done with the code. But since we've turned this off, that was just for learning purposes, of course. We never actually want to leave the user stuck at this infinitely running program. So we have to control C to get out of it, and in this video I want to use this as an interesting segue to talk about notification messages and dialogue pop-ups, and that sort of thing within end-py screen. So I'm going to use action form as a way to kind of take advantage of that. I'm going to save this as a new file 08.py. You notice that I've already kind of gotten started with it, so I'm going to replace that. And in our documentation, right up here at the top of the link, it's actually, it's pretty far long in the documentation, but URL is messages.html. So I'm going to fire up that, and I'll get us back to where we were, hopefully. Good enough. Hope you guys don't mind seeing that gray bar up the top. It's whatever. So yeah, these are the functions that allow us to kind of display brief messages and choices. So these functions do just that. There's a big long list of them, and we'll kind of walk through each of them, but you'll notice that a lot of them have a ton of optional arguments here. Typically, they all have a default value, so we normally don't have to worry about them, but I want you to know that they exist and you have the capability to change them if you so desire. So, okay, this first function, notify, is really simple. All it does is it displays a message on the screen. Now it does not block and the user cannot interact with it. So you can use it to display message like please wait while other things are happening. So if we use this as a small little message box in our on okay and on cancel functions, it tells us that this function doesn't block and the user can interact with it. Now the fact that it doesn't block, I mean that it's going to go right on to the next line of code immediately after this is run. So since we've pressed the okay button and by default the okay's button functionality will go to the next screen. It'll exit the current form. It'll just go on to the next form. We actually have to turn that back on remember. So re-uncomment what we had up here in our after editing function for the form object. So let's go back to our notify function though. The message is of course the first argument that we need and that's the string that it's actually kind of displaying and the title is going to be the title of it. The other arguments for like form color will get into colors real real soon. There is wrap if the text in the message will wrap around if it's too long for a single line and wide which I'm wondering if there's any description for. I think wide would mean that it would take up the entirety of the screen. Let's actually take a look at it and see what it does. So I'm going to supply the title to be okay button and And We'll copy and paste that same functionality for the cancel button. I'll remove these small comments But remember like I was saying since this does not block If I press one of these buttons You'll see oh, hey the okay button was pressed I can see that message up there and we can see this like kind of blue box acting as our message box But I'm way back at my terminal prompt like The program exited I wasn't able to see that box for real so What else can we do with it actually? Yeah, I'll look at the wide tag on this next one or notify wait Notify wait is another function that displays the message on the screen and then blocks for a brief amount of time So the user still can't interact with it, but it's just going to display it out on the screen Let's try and change these functions to that notify wait and notify wait Now when I run this I hit the cancel button and says the cancel button was pressed You see there's no buttons here, and hey it closes the program after a Brief moment of time. I think it was what three seconds Yeah, and we can interact with it. There's no button there, but it's just a notification message. Okay What's next? Oh Let's actually let's take a look at that wide function that wide argument wide tag so Since these are keyword arguments or at least to have a default we can it jump to that just by entering wide equals true Rather than having to have to enter all of these default variables Yes, I think it'll work with that functionality. Let's see Yeah, okay, so wide will fill up the entire width of the screen Nice Now you know knowing is half the battle According to GI Joe Notify confirm this is very simple It'll display a message and the okay button the user can scroll through the message if needed edit w I would assume this is edit widget that is a is a command line argument Oh, sorry not a command line argument But an argument to the function that controls which widget is immediately selected when the dialogue is displayed So zero there aren't any widgets that it can kind of look at but if you set it to one and the okay button will already be Active it'll already be focused on when the message pops up. So I'll show you what this looks like in the code Simple we'll just change our function name to notify confirm and now this will block infinitely until we press that okay button right so you can see the okay button is right down here at the bottom right corner if I hit enter okay is now in focus It's have probably would have done the same thing doesn't really matter as long as you're interacting with the form now I'd enter again now we exit of our program because uh All that really did for us was kind of confirmed that we read it Hence to notify confirm Now if we said edit w To one Like it told us in the documentation by default Okay, we'll already be highlighted See now okay is already in focus. I just have to hit enter once now so that's kind of handy if You know you kind of want your users to be able to breeze through things What else have we got notify okay cancel this one is good because it has a similar functionality as the action form and That it just displays okay as well as cancel But you can kind of do a little bit of logic testing here because it'll return true if you press okay And it'll say false if the user selected cancel so We can we can play with that right? What is that notify okay cancel is the name of the function see now? We got those two options and Is edit w in there yeah edit w is I kind of wonder which numbers for to what edit w One might be the okay button No, it's cancel And then edit w probably to We'll refer to The okay, but nice So it probably goes like from left to right in the order of the buttons being displayed so that's a good thing to know and Yes, and no has the same sort of functionality except yes and no and they'll return true or false depending on what you answer So those are the ones that I want to talk about now. I also kind of want to show you A little bit more. I guess we can do some of that logic testing So we can notify confirm that say Form has been saved if you hit the okay button and let's do notify. Yes. No Are you sure you want to cancel so since this will return? Yes, or no So if exiting Then we'll say I want to say We can notify Form has not been saved and the title can be Or something and then we can do else So if they say no, I'm curious how we can get back to our Original form without having to have to actually exit the form exit the form. Can we do that? I'm kind of curious if we can Set the next form rather than doing it in the after editing function. We can do it in our okay Which means that okay? Yeah, we do want to exit we have saved it the form but if we say and Then we can do it down here as well So if we are exiting if not, then we'll notify confirm like you may continue working and then Hopefully It'll let you stay in the form. Let's let's try it. Let's check it out Zero eight. My name is John Hammon, so if I say okay form has been saved Okay, and then we exit of the program cool if I say John then I cancel Are you sure I want to cancel and if I say? Yes, then it says okay form is not been saved. Goodbye. I get okay and an exit of my form cool if I say John If I go to cancel I say are you sure you want to cancel and I say no says okay You may continue working and then we get right back to our form cool. That's kind of nice So the way that I got that to work was because The set next form has only been set when we actually okay out of it or cancel out of it So that's when we actually want to exit the program So I took it out of the after editing function from our form object and just kind of set up that Functionality instead in the on okay or on cancel function calls So that's a little bit of a I don't know shift around that I mean if you want to do you certainly can do That's I think one of the simplest ways to kind of Confirm whether or not you want to stay on the form or not if you hit cancel or okay It's just determining what you want to do But a good thing to remember is that notify yes. No and notify. Okay cancel these two Choice functions that have a little pop-up message. They'll return true or false So you can just do an if statement and test with those guys if you want to exit or not if you do agree to some terms and conditions if you I Want to copy or move a file you can set up all of these choices however you want them to but I wanted to show off that functionality to you those are the Brief messages and choice functions in the end-by-screen module. Thank you guys for sticking with me I know this probably turned into a bit of a longer tutorial just for showing off these small functions But hey, hope you enjoyed it and well. I'll see you in the next tutorial