 Hey everyone welcome back again into some more Python programming tutorials We're still looking at the end-py screen module in the last couple of videos We've been checking out form objects, you know We were looking at code for the action form for the split form and even the action form We were looking at special functions like on okay and on cancel that gave us functionality Whenever the user press the okay button or the cancel button we looked at pop-up messages kind of dialogue boxes that can give us choices or just display a simple message Or we could also have the yes and no or okay cancel buttons So that was kind of nice for us and we actually even set up a new system where the set next form and Set next form set next active form whether or not we want to stay on our form or exit the program has functionality between these on okay and on cancel functions, so we can actually remove our defined or DEF for after editing function, so I'll kill that and I want to show you guys something new here Actually, I'll save this as a zero nine dot pie before I do any of that stuff and I'll save this Old one again a zero eight get back over there zero nine. Okay, cool so This time around I want to show us how we can be using both the action form and the split form and Maybe even a new type of form that we can get into in this video So notice that we actually inherit all of the properties of action forms because they're objects They're classes that we can inherit from you know, that's object oriented programming. That's mother child inheritance. Who's to say we couldn't also inherit from the split form Like in our class declaration all it takes is a kind of like arguments and In a kind of definition or declaration You just use a comma and then add the other one that you want to inherit from it's just inside the parentheses for a Class declaration definition now when I run this code You'll notice we've got our split form horizontal bar as well as okay and cancel for our action form cool So I'll just kind of quickly make a little bit more Functionality with that. I'll say draw line at equals seven I do want to Set edit w to one for our save thing so I can just quickly get out of there and and Now we'll actually take a look at the documentation and see what we can add what we can do next Like I said, we were looking at form objects. We've been checking out action forms We've been checking out split forms and now I finally want to get into forms with menus So this is similar to the form class But provides the additional functionality of pop-up menus to add a new menu to the form You use the method new menu name equals whatever and this will create the menu and return a proxy to it For more details see the check the section on menus below. So before I forget Let's just add N pi screen Form with menus and you'll notice there is an action form with menus class it also has a action form class as well as the pop-up menu functionality, but We can achieve the exact same thing with our multiple inheritance So right now I don't see any problem with this method But I mean if you guys do or it gives us trouble, then of course we can always change it back So let's take a look at that menu section way way down at the bottom of the documentation Do here we go. I'm gonna do a little bit of reading here Hope you guys are okay with that the menu section tells us that some form classes support the use of pop-up menus menus could in theory be used as widgets on their own and Note that pop-up menus here are being selected to use instead of drop-down menus now You might be used to drop-down menus on other gooey interfaces like your web browser or anything else here like You might be able to see this drop-down menu that I've just got with Firefox So They're being used Pop-up menus are being used instead of drop-down menus because they're more suitable for keyboard environments They make better use of the available screen space and are kind of easier to deploy on terminals of varied sizes So how it works or at least what you'll see is that the supporting forms will display an advert the menu system is available and A shortcut to the list of menus if the form has multiple menus a root menu listing all of them will be displayed Now menus are usually created by the forms new menu method The recent version adds the argument shortcut to this method and that allows you like a keyboard button that you can press like a key binding to activate the menu So after a menu has been created the following methods on that object are useful So let's go ahead and dive right into this in our code. Let's create a Menu object self dot menu and that will kind of keep track of what it's doing Like the actual menu object kind of like the widgets we have up here So it says new underscore menu we can give it a name Let's say main menu and then there was also a shortcut option that said we could use like M So I think we have to add it, but I don't know let's take a look if I run the code python zero nine Hey, we've got our menu right down here if I hit at control X. That's what this I'll show you one more time. That's what this little advert label shows us that control X That carrot means control control X will pop up the menu and you can see our main menu title right up here now Note there's nothing in the menu So if I enter we're gonna get an error because there's no list index we can actually grab But we have to add stuff to the menu the documentation shows us Hey, we've got an add item function and these of course have a lot of optional arguments The text of course is the string that should be displayed on the menu on select This next one is a function to be called if that item is selected and There's a warning here by the author that this is one of the few easy Opportunities in this module to create circular references. You may want to pass in a proxy to the function instead So the author he's tried to guard us against circular references as much as possible But this is just one of those times where we can't really see what you're gonna do We can't seem to the future or try and guess how your program works And of course there's the ability to add a shortcut and you can also have a list of arguments or a dictionary of keywords That can be passed to that function so Let's try and do some real quick self dot menu dot add item Let's say okay. It doesn't take any keyword arguments. It's just the text right away Let's say item one and then the function it wants so Let's say Press underscore one so if you if you press one, you know And let's actually supply the shortcut So we're good. It can just be one and we don't need any arguments or anything else to it But we'll have to create this press one function and we'll do the same thing with a second argument I'll do press to and it'll add another option for exit form and Exit form will be the function and let's do control X I Wanted to use X but when I did some experimentation with this earlier I noticed that X that button actually kind of acts as the enter button or the select button on a form and In end pi screen so control X is a better idea You just use this carrot symbol to denote that you want to use control now. Let's define these functions Let's define press one self and We'll use and pie screens Notify confirm message dialog box. He says you pressed Item one item one can be our title and yeah, we'll actually select the We'll do the same thing for press to and now let's actually build a function for our Exit program or exit form now. Here's an interesting thing You know that this self dot parent app dot set next form that sets the next active form But if we exit this form if we choose this menu option There isn't a signal a signal to our form or application that we want to go to the next form So we actually have to do self dot parent app Dot switch form with capital F and then we select it to none So now it'll know okay go to this form, but if we say none it'll know to close our program For us cool. Let's try and run this code now Really simple really easy. Oh global name press one. It's not to find okay. Remember that because we're in an object Have to use our self keyword With just about everything we do Now we run this control X menu Item one and item two you can see those shortcuts being displayed I can enter to of course select these or I can go ahead and press the shortcut like two And I get we press item two now if I do control X To exit the form the control X not work for me. I might need to use a capital X Now let's try it control X control X. Yeah, and we exit out of our form just like that cool What else is there? What more can we do? add items from list This actually includes a text and function and shortcut stuff that you can use But it's actually looping through them as if they were a list so rather than me going through all of this And adding items one by one calling these functions over and over again You could just kind of line up things in two arrays between the text that you want for each item and the function that Corresponds with each item. I won't show that off, but know that you can do that and sub menus. Okay, cool Let's take a look at those. Let's create an object for it self dot sub menu and The function that it says to use the documentation is actually new menu dot add new sub menu And it has all the similar functionality and kind of arguments as the regular menu, but here's an interesting one free display function So this actually allows you to have a function that will be called before the menu is displayed So depending on the circumstance and situation in your program What's currently going on in the form? Maybe if you want you can adjust the content of the menu before it's being displayed and of course the arguments and the Keywords correspond to this PD funk or this pre display function So I'm not going to play with that, but I want you to know that that has functionality there add new sub menu So let's say a sub menu and then we can use shortcut s right there self dot sub menu dot add item now. We just kind of treat it like a regular I want to say menu here of course and Then we'll be like woo subscribe blocks I'm not I won't I won't give this a function to go along with it I won't give it any functionality or a shortcut or anything But just wanting to show how you can set that up with the sub menu real simple just creating it like an object Control X menu a sub menu. It's way down there If I hit s or enter I hit s this time It says hey, we've got our sub menu title and then our woo subscribe blocks option Nifty All right Now here's the interesting thing that I want to touch upon before I leave you notice that the sub menu doesn't really go away Or the menu doesn't really go away. That's pretty much because our I want to tell you that our form is so tiny right? It's over here if we had not changed it if we hadn't changed the size or anything like that The sub menu will look like it's gone away because it's going to be hidden behind actually the the form So I think I wonder if we can draw a line out of negative number So it'll know to go from the back backwards up Nope, it does not know to draw with a negative number So let's say 22. So, okay Now we've got our MPI screen form at the full screen fight control X our main menu appears and Then once all of us over with it hides behind the the form that we've got created for us cool So that's everything I wanted to show you guys in this video Thank you for sticking with me I know this kind of turn into a longer video and that's what they're all doing at this point but hey, I want you guys to learn and know what the documentation is telling you and Kind of have a walkthrough for it. So thanks guys. Hope you enjoyed this and I'll see you in the next tutorial