****************************** IX_menu_i.txt (text) ****************************** #IX_menu_i.py #By D@CC #On 2021 E May 19 #Article: 206, 207, 208 and 209.html #uSD: none # #Purpose: to demonstrate the use of a Python menu program # that permits the user to select/unselect any program on # the menu. # #Functions Used: # test1_i(n,name="test1_i") # test2_i(n,name="test2_i") # IX_exit_i(n,name="exit_i") # v=0 def test1_i(n,name="test1_i"): reply=input(str(n)+" "+name+":") # show as a menu item if reply=="": return True # do next menu item #programmer should insert all the code for the menu item # # here # print("This runs: ",name) return True #if end #def end def test2_i(n,name="test2_i"): reply=input(str(n)+" "+name+":") # show as a menu item if reply=="": return True # do next menu item #programmer should insert all the code for the menu item # # here # print("This runs: ",name) return True #if end #def end # module IX_exit_i() must be included with IX_menu_i.py def IX_exit_i(n,name="exit_i"): reply=input(str(n)+" "+name+":") # show as a menu item if reply=="": return True # do next menu item else: reply=input("Do you really want to exit?") if len(reply)>0: reply1=reply[0] #print("You replied:",reply1) strYes="yYoO" # Yes or Oui or OK p=strYes.find(reply1) # check first letter of reply #print("p:",p) if p>-1 : #print("telling menu to exit") return False # exit from the menu #if end #if end return True # do next menu item #if end #def end of IX_exit_i.py #the following multi-line statement must be created by the IXp program # to define the list of modules to be in the menu # it must follow the exit_i.py module and # it must precede the IX_menu_i.py program #IX_list_i.py moduleList=[ \ test1_i, \ test2_i, \ IX_exit_i ] #end of IX_list_i.py #IX_menu_i.py # by D@CC on 2023JOct26 # tested on 2023JOct26 #Purpose: a Python menu for "_i" routines # "_i" means "improvised" as in "an improvised program" # Every "_i" function is put in the moduleList # The user hits CR to NOT run the module # hits any key (eg "Y" CR) to run the module # IX_exit_i() if run, can exit from this program # but only if CR is NOT hit eg "Y" CR # each module will return True to return to the menu # or False to exit from the menu # It is suggested that the module name and the menu prompt be identical # eg test1_i.py # At least 4 modules must be in the IX_menu_i system: # 1. one or more modules to be called by the menu eg test1_i.py # 2. the exit module eg IX_exit_i.py # 3. the module list eg IX_list_i.py # 4. the menu module ie IX_menu_i.py # module 1 must be written by the programmer # module 3 must be created by the IXp program # modules 2 and 4 must be used "as is" progName="IX_menu_i" if len(moduleList)>1: isExit=False print("This program is part of the IX group of programs") print("Source: https://www.ePhotoCaption.com") print("hit CR to NOT select the menu item") else: isExit=True print("Error: IX_menu_i was called with an empty moduleList") #if end while isExit==False: nn=0 print() print(progName+":") print("-------") for module in moduleList: nn+=1 # call the module # it will list itself on the submenu # and will run if the user wishes if module(nn)==False: isExit=True #if end if isExit : exit("normal exit") #if end #for end #while end if isExit : exit("normal exit") #if end ***************************************************************** #/IX_menu_i_py.txt