 Hey everyone, welcome again to some more nPyScreen programming tutorials and videos in the Python language So here we go in the last video. We actually got a new kind of framework set up with our code We were actually getting the application objects working along with our form objects that we learned about in the video before that Right now our our code still doesn't really do anything. We don't really have any Interaction going on right now, but we're still learning so hopefully that's okay Now we added the form to our application Objects and the kind of the manager for us with this main ID We passed in the object and kind of gave it a few arguments But when we tried to run the code an interesting thing happened, right? We would get to split our form. We'd have our okay button Everything is nice dandy except the fact that we can't do anything and when I try and exit out of the program The enter button to okay. I Can't get out. So we got a control C to break out of this and why is that what's going on there? So I'm gonna hop back on over to our documentation before I do that. I'm going to save a new file 0 4 Cool and now I'll look at documentation as to what's really going on here So we've been looking at these functions that help run the Application object and of course we've got run, which is what we called to actually start the program and start our main loop Starting form. Oh, that's an interesting variable. I Want to lose touch upon it? I'll probably never use it But I do want to let you know that it exists if for any reason you need to change the name of the default form rather from rather than it being main I Just hit the page up button and now I don't know where I am Yeah, rather than having the default form with an idea of main you can change starting form variable to change what it should be so Okay Aside from that tangent. Here's what I want to look at now Once an application is running the following methods control which form is presented to the user now Here's an interesting one NPS app manage dot set next form what this does is it sets the form to be displayed when the current one exits huh There are other functions to you know set next form previous set the form to be displayed when the current one exits to go back to the Previous one in history switch form will get you from one form to another all by the ID here And you can bypass any exit logic of the current form if you'd like set up any you know like Closing functions or function calls or stuff like that and then a switch form previous will immediately switch you to the previous form That you were just asked in the history All those other functions probably things you can use later on for now I'm really curious what this set next form does because when we close out of our program when we try and exit When the current form exits We're not able to get out of our program. Why is that? So here we go, let's do a little bit more reading once all of your forms are ready and registered with the manage instance class You should call run Okay, that's what we do and this method will activate the default form What should have been given an ID of main you can change this to by Changing the starting form variable. Okay, we did that and we just learned about that. So what else? Thereafter the next form to be displayed will be the one specified by the instance variable next active form huh Whenever a form edit loop exits the form specified here will be activated if next active form is none Then the main loop will exit. Oh, okay So next active form should be set by calling the applications set next form form ID method Oh, that's the one that we just read about right up here But we want to set it to none so we'll actually exit our main loop and we'll close our program Okay, so this documentation used to suggest that you should set the attribute directly There aren't any plans to deprecate this attribute, but setting it directly should be avoided So we'll end up using that set next form method So we'll do a little bit more reading before we do that because it looks like it gives us kind of a warning here There are three mechanisms that form should use to control the next active form So all forms that are registered with the managed object that don't have a special method activate will have their method after editing called if they have it Okay, so all forms that are registered that do not have the special method activate I Don't know if we have activate. Do you guys know if we have activate? Anyway, let's just keep reading Logic to determine what the next active form should be will go there Okay, so it will go it'll have the method after editing called so that's what we should put our Set next active form to be that's where we should place that function call if you're expecting you use your users To select an okay your cancel button. This is the preferred way to switch screens So this after editing function is probably gonna be pretty handy for us The application method switch form causes the application to immediately stop editing the current form and switch to the other one Forms registered with the activate method We usually instead Call instead the usual edit method. This can contain additional logic. Oh, this is not the preferred method But may allow greater flexibility Okay If it's not the preferred method to use activate then I guess we'll use After editing that's fine okay So I think that's enough reading and understanding what we're actually doing here. So let's define that new method Let's define after editing in our app object And of course it takes the self argument because it's an inside of an object and we'll call that Set next form right. Well, here's an interesting thing We're calling this in the oh, sorry This is actually in the form Object not the app object Right all forms have to be registered with this activate method or the after editing method So it's in the form object All right, let's let's go down to The next page and documentation read a little bit more about that then or see if it has any stuff about it Displaying and editing forms we covered those Forms may exit It's like these are other possible forms that we can play with later on There's a lot of options here Menus that's pretty cool. Okay. I guess it doesn't give us any more explanation about that. That's fantastic I guess we'll look at the code that they offer then and hopefully we'll try and figure it out. So the code that we have to run is The after editing Function right, but we have to run it within our form object. So Define inside the form object now rather than the app object define after editing self keyword as we're inside of an object and It looks like what they're doing is they're saying parent app dot set next form That would make sense because that's the only way you can actually access the app object If that's like the keyword that allows you to do that So let's do that. Let's say self dot parent app dot set next form And if we set it to none then our main loop will exit, right? Let's try it Python zero four We got our end pie screen form to display if I hit the enter button. Hey our program exits awesome Okay, so that took a little bit of piecing together and a little bit of reading But I think now we understand what that next active form does for us so Okay Even if we had forms afterwards that we would want to use we can apply those we can set them with this function But for now since we want to exit out of the code exit out of the program We'll just pass in none and it looks like that's what it does for us. It lets us get out of the program Cool. I think we're good. I think that's all I wanted to touch upon on this video I know it was kind of long-winded a lot of me talking and doing a lot of reading but hey That's it's a good way to learn. I hope that my video is kind of supplement your understanding and Can guide you along with this documentation stuff his documentation is really a programmer's reference When you're working, you're not gonna be able to remember everything and I know I certainly don't remember everything I tried to but a lot of times we need to look up online and ask for help sometimes So definitely use the documentation and I hope for learning purposes We can go through it and then build some cool stuff. So thank you very much for watching guys Hope you're enjoying the series. I'm having a lot of fun with it. It's kind of nice and I'll see you in the next tutorial