SHARE
TWEET

Full Circle magazine #39 - Beginning Python Pt.13

a guest Jul 8th, 2010 4,867 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import curses
  2. def DoMainMenu():
  3.     myscreen.erase()
  4.     myscreen.addstr(1,1,  "========================================")
  5.     myscreen.addstr(2,1,  "           Recipe Database")
  6.     myscreen.addstr(3,1,  "========================================")
  7.     myscreen.addstr(4,1,  "  1 - Show All Recipes")
  8.     myscreen.addstr(5,1,  "  2 - Search for a recipe")
  9.     myscreen.addstr(6,1,  "  3 - Show a recipe")
  10.     myscreen.addstr(7,1,  "  4 - Delete a recipe")
  11.     myscreen.addstr(8,1,  "  5 - Add a recipe")
  12.     myscreen.addstr(9,1,  "  6 - Print a recipe")
  13.     myscreen.addstr(10,1, "  0 - Exit")
  14.     myscreen.addstr(11,1, "========================================")
  15.     myscreen.addstr(12,1, "  Enter a selection: ")
  16.     myscreen.refresh()
  17. def ShowAllRecipesMenu():
  18.     myscreen.erase()
  19.     myscreen.addstr(1,1, "==================================================")
  20.     myscreen.addstr(2,1, "                 Show All Recipes")
  21.     myscreen.addstr(3,1, "==================================================")
  22.     myscreen.addstr(4,1, " This is a stub of the Show All Recipes Screen")
  23.     myscreen.addstr(6,1, "Item  Name                      Serves            Source")                        
  24.     myscreen.addstr(7,1, ("-"*70))
  25.     myscreen.addstr(10,1, "                  Press a key :")
  26.     myscreen.refresh()
  27.     myscreen.getch()
  28. def SearchForARecipeMenu():
  29.     myscreen.erase()    
  30.     myscreen.addstr(1,1, "==================================================")
  31.     myscreen.addstr(2,1, "                 Search for A Recipe")
  32.     myscreen.addstr(3,1, "==================================================")
  33.     myscreen.addstr(4,1, "-------------------------------")
  34.     myscreen.addstr(5,1, " Search in")
  35.     myscreen.addstr(6,1, "-------------------------------")
  36.     myscreen.addstr(7,1, " 1 - Recipe Name")
  37.     myscreen.addstr(8,1, " 2 - Recipe Source")
  38.     myscreen.addstr(9,1, " 3 - Ingredients")
  39.     myscreen.addstr(10,1," 0 - Exit")
  40.     myscreen.addstr(11,1,"Enter Search Type -> ")
  41.     myscreen.refresh()
  42. def InKey2():
  43.     key = 'X'
  44.     doloop = 1
  45.     while doloop == 1:
  46.         key = myscreen.getch(11,22)
  47.         myscreen.addch(11,22,key)
  48.         tmpstr = "Enter text to search in "
  49.         if key == ord('1'):
  50.             sstr = "'Recipe Name' for -> "
  51.             tmpstr = tmpstr + sstr
  52.             retstring = GetSearchLine(13,1,tmpstr)
  53.             break
  54.         elif key == ord('2'):
  55.             sstr = "'Recipe Source' for -> "
  56.             tmpstr = tmpstr + sstr
  57.             retstring = GetSearchLine(13,1,tmpstr)
  58.             break
  59.         elif key == ord('3'):
  60.             sstr = "'Ingredients' for -> "
  61.             tmpstr = tmpstr + sstr
  62.             retstring = GetSearchLine(13,1,tmpstr)
  63.             break
  64.         else:
  65.             retstring = ""
  66.             break
  67.     if retstring != "":
  68.         myscreen.addstr(15,1,"You entered - " + retstring)
  69.     else:
  70.         myscreen.addstr(15,1,"You entered a blank string")
  71.     myscreen.refresh()
  72.     myscreen.addstr(20,1,"Press a key")
  73.     myscreen.getch()
  74. def GetSearchLine(row,col,strng):
  75.     myscreen.addstr(row,col,strng)
  76.     myscreen.refresh()
  77.     instring = myscreen.getstr(row,len(strng)+1)
  78.     myscreen.addstr(row,len(strng)+1,instring)
  79.     myscreen.refresh()
  80.     return instring
  81. def ShowARecipeMenu():
  82.     myscreen.erase()
  83.     myscreen.addstr(1,1, "==================================================")
  84.     myscreen.addstr(2,1, "                 Show A Recipe")
  85.     myscreen.addstr(3,1, "==================================================")
  86.     myscreen.addstr(4,1, " This is a stub of the Show A Recipe Screen")
  87.     myscreen.addstr(6,1, "                  Press a key :")
  88.     myscreen.refresh()
  89.     myscreen.getch()
  90. def NotReady(prompt):
  91.     myscreen.erase()
  92.     strng = "Sorry...The %s routine is not yet ready." % prompt
  93.     myscreen.addstr(1,1,strng)
  94.     myscreen.refresh()
  95.     myscreen.getch()
  96. def MainInKey():
  97.     key = 'X'
  98.     while key != ord('0'):
  99.         key = myscreen.getch(12,22)
  100.         myscreen.addch(12,22,key)
  101.         if key == ord('1'):
  102.             ShowAllRecipesMenu()
  103.             DoMainMenu()
  104.         elif key == ord('2'):
  105.             SearchForARecipeMenu()
  106.             InKey2()
  107.             DoMainMenu()
  108.         elif key == ord('3'):
  109.             ShowARecipeMenu()
  110.             DoMainMenu()
  111.         elif key == ord('4'):
  112.             NotReady("'Delete A Recipe'")
  113.             DoMainMenu()
  114.         elif key == ord('5'):
  115.             NotReady("'Add A Recipe'")
  116.             DoMainMenu()
  117.         elif key == ord('6'):
  118.             NotReady("'Print A Recipe'")
  119.             DoMainMenu()
  120.         myscreen.refresh()      
  121. def LogicLoop():
  122.     DoMainMenu()
  123.     MainInKey()
  124.  
  125. #  MAIN LOOP
  126. try:
  127.     myscreen = curses.initscr()
  128.     LogicLoop()
  129. finally:
  130.     curses.endwin()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top