Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1. /////////////my code///////////////////
  2. import sys
  3. import os
  4. import menu
  5. mainMenu = menu.Menu(title,update=updateFunction)
  6.  
  7. /////////module's ___init___ code////////////
  8.  
  9. from menu import Menu
  10.  
  11. ////////module's source code///////////////////
  12.  
  13. import os
  14.  
  15. def doNothing(object=None):
  16.     pass
  17.  
  18. class notObject(object):
  19.     pass
  20.  
  21. class Menu(notObject):
  22.     def __init__(self,title,update=doNothing):
  23.         self.title = title
  24.         self.options = []
  25.         self.indicator = ">>>"
  26.         self.explicit()
  27.         self.update = update
  28.    
  29.     def __setattr__(self,name,value):
  30.         if isinstance(value,Menu) and name!="__parent__":
  31.             value.__parent__ = self
  32.         super(notObject,self).__setattr__(name, value)
  33.    
  34.     def addOptions(self,options):
  35.         self.options += options
  36.        
  37.     def show(self):
  38.         print (self.title)
  39.         print ("")
  40.         for (key,option) in enumerate(self.options):
  41.             print (str(key+1)+". "+option[self.NAME])
  42.         print ("")
  43.         print (self.indicator,)
  44.    
  45.     def input(self):
  46.         try:
  47.             option = int(raw_input())-1
  48.             return self.validate(option)
  49.         except ValueError:
  50.             return self.open
  51.    
  52.     def open(self):
  53.         os.system('cls' if os.name == 'nt' else 'clear')
  54.         self.show()
  55.         func = self.input()
  56.         print ("")
  57.         func()
  58.         self.update(self)
  59.         self.open()
  60.    
  61.     def validate(self,option):
  62.         if option>-1 and option<len(self.options):
  63.             return self.options[option][self.FUNCTION]
  64.         else:
  65.             return self.open
  66.        
  67.     def implicit(self):
  68.         self.NAME = 0
  69.         self.FUNCTION = 1
  70.  
  71.     def explicit(self):
  72.         self.NAME = "name"
  73.         self.FUNCTION = "function"
  74.        
  75.     def clearOptions(self):
  76.         self.options = []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement