def view_schedule_through_ui(self): get_schedule_task_instances = Menu( [ MenuItem( 'Daily Schedule', lambda: lambda start_date: self.model. get_task_instances_for_date(start_date)), MenuItem( 'Weekly Schedule', lambda: lambda start_date: self.model. get_task_instances_for_week_starting(start_date)), MenuItem( 'Monthly Schedule', lambda: lambda start_date: self.model. get_task_instances_for_month(start_date)) ], 'What type of schedule would you like to view?', ).process() start_date_field = Field( 'StartDate', 'Start Date', validate_date_string, "Must be a date in form YYYYMMDD", lambda start_date_string: datetime.strptime( start_date_string, '%Y%m%d').date()) CliController.populate_field(start_date_field) task_instances = get_schedule_task_instances(start_date_field.value) view = ScheduleView(task_instances) view.display()
def __init__(self, fileName): self.fileName = "menu.csv" self.menuItemDrinkList =[] # drink list self.menuItemAppetizerList = [] # appetizer list self.menuItemEntreeList = [] # entree list self.menuItemDessertList = [] # dessert list # this block of code reads through the csv file and adds the items to the proper list fileIn = open(self.fileName, "r") for line in fileIn: line = line.split(',') if line[1] == "Drink": line = MenuItem(line[0], line[1], line[2], line[3]) self.menuItemDrinkList.append(line) elif line[1] == "Appetizer": line = MenuItem(line[0], line[1], line[2], line[3]) self.menuItemAppetizerList.append(line) elif line[1] == "Entree": line = MenuItem(line[0], line[1], line[2], line[3]) self.menuItemEntreeList.append(line) elif line[1] == "Dessert": line = MenuItem(line[0], line[1], line[2], line[3]) self.menuItemDessertList.append(line) fileIn.close() #close the file
def create_task_through_ui(self): task_create_type: Type[Task] = Menu( [ MenuItem('Transient Task', lambda: TransientTask), MenuItem('Recurring Task', lambda: RecurringTask), MenuItem('Cancellation', lambda: AntiTask) ], 'What type of task would you like to create?', ).process() if Task not in type.mro(task_create_type): raise RuntimeError( 'Invalid task type resulting from CreateTaskMenuItem.create_task_through_ui()' ) fields = task_create_type.get_input_fields() CliController.populate_fields(fields) field_values = CliController.fields_as_dict(fields) task = task_create_type(field_values) try: self.model.add_task(task) except PSSValidationError as err: raise PSSInvalidOperationError( f'Could not complete operation: {err}') CliView.display_notification(f'Successfully added {task}')
def __init__(self, menuFile): self.menuItemDictionary = {} fileIn = open(menuFile, "r") for line in fileIn: line = line.strip() line = line.split(",") if line[1] not in self.menuItemDictionary: self.menuItemDictionary[line[1]] = [ MenuItem(line[0], line[1], line[2], line[3]) ] elif line[1] in self.menuItemDictionary: self.menuItemDictionary[line[1]].append( MenuItem(line[0], line[1], line[2], line[3])) fileIn.close()
def __init__(self, fileName="menu.csv"): # creates dictionary and makes the keys the types of foods self.menuItemDictionary = { Menu.MENU_ITEM_TYPES[0]: [], Menu.MENU_ITEM_TYPES[1]: [], Menu.MENU_ITEM_TYPES[2]: [], Menu.MENU_ITEM_TYPES[3]: [] } self.file = fileName ifile = open(self.file, "r") # reads menu.csv file for line in ifile: # separates each line of the file into a list object = line.strip() object = object.split(",") # Comments for if-else statement chain: # checks and matches the first index of the list with the MENU_ITEMS_TYPE list # assigns rest of values in list # appends MenuItem object to the menuItemDictionary # using the corresponding key found by conditional if statement if object[1] == Menu.MENU_ITEM_TYPES[0]: namef = str(object[0]) typef = str(object[1]) pricef = float(object[2]) descf = str(object[3]) self.menuItemDictionary[object[1]].append( MenuItem(namef, typef, pricef, descf)) elif object[1] == Menu.MENU_ITEM_TYPES[1]: namef = str(object[0]) typef = str(object[1]) pricef = float(object[2]) descf = str(object[3]) self.menuItemDictionary[object[1]].append( MenuItem(namef, typef, pricef, descf)) elif object[1] == Menu.MENU_ITEM_TYPES[2]: namef = str(object[0]) typef = str(object[1]) pricef = float(object[2]) descf = str(object[3]) self.menuItemDictionary[object[1]].append( MenuItem(namef, typef, pricef, descf)) elif object[1] == Menu.MENU_ITEM_TYPES[3]: namef = str(object[0]) typef = str(object[1]) pricef = float(object[2]) descf = str(object[3]) self.menuItemDictionary[object[1]].append( MenuItem(namef, typef, pricef, descf)) ifile.close()
def __init__(self, dict): self.__dict = dict self.__menuItemDictionary = {} self.__menuItemDictionary["Drink"] = [] self.__menuItemDictionary["Appetizer"] = [] self.__menuItemDictionary["Entree"] = [] self.__menuItemDictionary["Dessert"] = [] # Open and read the csv file and create a MenuItem object from each line in the file. fin = open(dict, "r") for line in fin: line = line.strip() dataList = line.split(",") name = dataList[0] t = dataList[1] price = dataList[2] description = dataList[3] item = MenuItem(name, t, price, description) # Add the new object to the dictionary by using its type as the key. if t == "Drink": self.__menuItemDictionary["Drink"].append(item) elif t == "Appetizer": self.__menuItemDictionary["Appetizer"].append(item) elif t =="Entree": self.__menuItemDictionary["Entree"].append(item) elif t == "Dessert": self.__menuItemDictionary["Dessert"].append(item) fin.close()
def __initMenus(self): if self.root == None: self.root = MenuItem() self.root.menuItems = self.__createMenus() self.activeMenu = self.root.menuItems[0] self.selectedMenu = self.root
def __init__(self, fileName): # EXTRA CREDIT: a single dictionary is used instead of four lists. # a dictionary containing all of the menu items is defined. # 4 keys within the dictionary are defined as strings that represent the types of the menu items. self.menuItemDictionary = {"Drink": [], "Appetizer": [], "Entree": [], "Dessert": []} # the csv file is opened and read. fileIn = open(fileName, "r") # the csv file is iterated through using a for loop. for line in fileIn: # each line in the file is stripped of trailing white space and split using a comma to be made into a list. # each line represents a different menu item. # splitting line into a list allows for the different attributes of the menu item to be separated by index. aList = line.strip().split(",") # obj is the MenuItem object that contains the information from the indices of the list of each line. # index 0 is the name, index 1 is the type, index 2 is the price, and index 3 is the description. # the name, type, and description are set to strings. the price is set to a float. obj = MenuItem(str(aList[0]), str(aList[1]), float(aList[2]), str(aList[3])) # index 1 in aList represents the type of menu item it is. # if/elif statements determine what type of menu item each obj is by comparing to class variable's values. if aList[1] == Menu.MENU_ITEM_TYPES[0]: # if determined to be a drink, the obj is appended to the Drink key within the dictionary. self.menuItemDictionary["Drink"].append(obj) elif aList[1] == Menu.MENU_ITEM_TYPES[1]: # if determined to be an appetizer, the obj is appended to the Appetizer key within the dictionary. self.menuItemDictionary["Appetizer"].append(obj) elif aList[1] == Menu.MENU_ITEM_TYPES[2]: # if determined to be an entree, the obj is appended to the Entree key within the dictionary. self.menuItemDictionary["Entree"].append(obj) elif aList[1] == Menu.MENU_ITEM_TYPES[3]: # if determined to be a dessert, the obj is appended to the Dessert key within the dictionary. self.menuItemDictionary["Dessert"].append(obj) # the file is closed fileIn.close()
def __init_attributes(self, editor): self.__editor = editor self.__manager = None self.__trigger = self.create_trigger( "show-advanced-configuration-window") from MenuItem import MenuItem self.__menuitem = MenuItem(editor) return
def __init_attributes(self, editor): self.__editor = editor from Manager import Manager self.__manager = Manager(editor) from MenuItem import MenuItem self.__menuitem = MenuItem(editor) self.__trigger = self.create_trigger("show-autoreplace-dialog") return
def __init__(self, editor): SignalManager.__init__(self) TriggerManager.__init__(self, editor) self.__init_attributes(editor) self.connect(self.__trigger1, "activate", self.__activate_cb) self.connect(self.__trigger2, "activate", self.__activate_cb) from MenuItem import MenuItem MenuItem(editor)
def __init__(self, filename): self.__menuItemDictionary = {} for t in self.MENU_ITEM_TYPES: self.__menuItemDictionary[t] = [] with open(filename) as f: reader = list(csv.reader(f)) for row in reader: menuItem = MenuItem(row[0], row[1], row[2], row[3], row[4]) self.__menuItemDictionary[menuItem.type].append(menuItem)
def add(self, number, name, price, ingredients, category, labels, availability=True): super().add( MenuItem(number, name, price, ingredients, category, labels, availability))
def __init__(self,filename): fileIn=open(filename,'r') self.__menuItemDictionary={} input=fileIn.readlines() for x in input: temp=x.split(',') tempitem=MenuItem(temp[0],temp[1],temp[2],temp[3]) if temp[1] in self.__menuItemDictionary.keys(): self.__menuItemDictionary[temp[1]].append(tempitem) else: self.__menuItemDictionary[temp[1]]=[tempitem]
def __init__(self, fileName): self.menuItemDictionary = {} for item_type in Menu.MENU_ITEM_TYPES: self.menuItemDictionary[item_type] = [] fileIn = open(fileName, "r") for line in fileIn: line = line.strip() item = line.split(",") menuItem = MenuItem(item[0], item[1], float(item[2]), item[3]) self.menuItemDictionary[item[1]].append(menuItem) fileIn.close()
def __init__(self, window): # positioning centerWidth = window.width / 2 y = window.height - 40 self.window = window self.titlePostition = (centerWidth, y) self.menuPosition = (centerWidth, self.titlePostition[1] - (window.height / 3)) self.fontSize = 32 self.menuSpacing = (float(self.fontSize) * 1.33)**1.1 # build menu hierarchy mainMenu = MenuNode(self.titlePostition, "game engine", self.fontSize) play = MenuItem(self.menuPosition, "play", self.fontSize) quit = MenuItem(self.menuPosition, "quit", self.fontSize) options = MenuNode(self.menuPosition, "options", self.fontSize) options.children.append( MenuItem(self.menuPosition, "volume", self.fontSize)) options.children.append( MenuItem(self.menuPosition, "sfx", self.fontSize)) options.children.append( MenuItem(self.menuPosition, "FoV", self.fontSize)) self.rootNode = mainMenu self.rootNode.children.append(play) self.rootNode.children.append(options) self.rootNode.children.append(quit) # setup the node stack self.currentNode = self.rootNode self.previousNodes = [] # layout children self.arrangeMenu(self.currentNode) # setup initial menu object focus self.focusFirstChild() # keyboard focus until mouse movement self.keyboardHighlight = True
def __init__(self, fileName): self.__menuItemDictionary = {} fileIn = open(fileName, 'r') for line in fileIn: attr = line.strip().split(',') type = attr[1] item = MenuItem(attr[0], attr[1], float(attr[2]), attr[3]) if type in self.__menuItemDictionary: self.__menuItemDictionary[type].append(item) else: itemList = [item] self.__menuItemDictionary[type] = itemList
def __init__(self, fileName): menuItemDictionary = {} for foodType in Menu.MENU_ITEM_TYPES: menuItemDictionary[foodType] = [] fileIn = open(fileName, "r") for line in fileIn: line = line.strip() dataList = line.split(",") menuItem = MenuItem(dataList[0], dataList[1], dataList[2], dataList[3]) menuItemDictionary[dataList[1]].append(menuItem) fileIn.close() self.menuItemDictionary = menuItemDictionary
def __init_attributes(self, editor): self.__editor = editor name, shortcut, description, category = ( "show-template-editor", "<alt>F12", _("Manage dynamic templates or snippets"), _("Miscellaneous Operations") ) self.__trigger = self.create_trigger(name, shortcut, description, category) self.__manager = None from MenuItem import MenuItem self.__menuitem = MenuItem(editor) return
def write_schedule_through_ui(self): get_schedule_task_instances = Menu( [ MenuItem( 'Daily Schedule', lambda: lambda start_date: self.model. get_task_instances_for_date(start_date)), MenuItem( 'Weekly Schedule', lambda: lambda start_date: self.model. get_task_instances_for_week_starting(start_date)), MenuItem( 'Monthly Schedule', lambda: lambda start_date: self.model. get_task_instances_for_month(start_date)) ], 'What type of schedule would you like to write?', ).process() start_date_field = Field( 'StartDate', 'Start Date', validate_date_string, "Must be a date in form YYYYMMDD", lambda start_date_string: datetime.strptime( start_date_string, '%Y%m%d').date()) filename_field = Field( 'Filename', 'filename', validate_data_filename, ) try: CliController.populate_fields([start_date_field, filename_field]) task_instances = get_schedule_task_instances( start_date_field.value) self.model.write_task_instances_to_file( filename=filename_field.value, task_instances=task_instances) CliView.display_notification( f'Exported schedule to "{filename_field.value}"') except Exception as err: raise PSSInvalidOperationError(f'Failed to export schedule: {err}')
def main(stdscr): default_colors = CursedColorScheme() stored_session_file = "./saved_sessions.json" session_storage = SessionStorage(stored_session_file) top_menu = SessionMenu(default_colors, session_storage) top_win = CursedWindow(True, default_colors, top_menu, "Actionables", True) bottom_menu = CursedMenu(default_colors) bottom_win = CursedWindow(True, default_colors, bottom_menu, "Values") window_group = CursedWindowGroup() window_group.add_sub_window(stdscr, bottom_win, CursedWindowGroup.Position.BOTTOM_HORIZONTAL_THIRD) window_group.add_sub_window(stdscr, top_win, CursedWindowGroup.Position.TOP_TWO_THIRDS) try: sessions = session_storage.load_sessions() for sess in sessions: item = ScreenItem(sess["session_id"], sess["windows"], sess) top_menu.add_menu_item(item) except FileNotFoundError: print("No stored sessions found") for num in range(40): bottom_menu.add_menu_item(MenuItem("Thing {0}".format(num))) # turn off cursor blinking curses.curs_set(0) stdscr.refresh() window_group.update_all() try: keep_going = True while keep_going: key = stdscr.getch() if key == ord('q'): keep_going = False else: window_group.handle_key_event(key) if key == curses.KEY_ENTER or key == 10: # If a screen session as entered, we will need the keypad mode back on stdscr.keypad(1) window_group.update_all() finally: top_menu.save()
def __init__(self, menuitemfile): self.menuItemDictionary = {} filein = open(menuitemfile, "r") #taking info from csv file and inputting it in dictionary with key as type and value as list of menuitem objects for line in filein: line = line.strip() datalist = line.split(",") Fooditem = MenuItem(datalist[0], datalist[1], float(datalist[2]), datalist[3]) if datalist[1] not in self.menuItemDictionary: MenuItemlist = [Fooditem] self.menuItemDictionary[datalist[1]] = MenuItemlist else: self.menuItemDictionary[datalist[1]].append(Fooditem) filein.close()
def __init__(self, menu): # set the constructor self.__menuItemDictionary = {} fileIn = open(menu, "r") # read from the file for line in fileIn: line = line.strip() lineList = line.split(",") # split every line into a list item = MenuItem(lineList[0], lineList[1], float(lineList[2]), lineList[3]) # create the menu item if lineList[1] not in self.__menuItemDictionary.keys( ): # if we have don't have this category yet, create a key value pair, and set the value to be a list of items self.__menuItemDictionary[lineList[1]] = [item] else: self.__menuItemDictionary[lineList[1]].append( item ) # if we have this category already, append the item to the list fileIn.close() # close the file
def addItem(self, item, asHTML=None, popup=None): if not hasattr(item, "setSubMenu"): item = MenuItem(item, asHTML, popup) if self.vertical: tr = DOM.createTR() DOM.appendChild(self.body, tr) else: tr = DOM.getChild(self.body, 0) DOM.appendChild(tr, item.getElement()) item.setParentMenu(self) item.setSelectionStyle(False) self.items.append(item) return item
def __init__(self, menufile): self.menufile = menufile # menufile from the variable self.fileIn = open(self.menufile, "r") # opens file self.items = {} # sets up empty dict for line in self.fileIn: # goes through the line line = line.strip() # strips the line data_list = line.split(",") # splits the lines cat = data_list[1] # category will be the first column price = data_list[2] # price is second column name = data_list[0] # name is the 0 column desc = data_list[3] # desc is third column menuentry = MenuItem(name, cat, price, desc) # menuentry combines the entries from the columns if cat in self.items: # if the category is already in the dictionary adds another entry from the menu to the key self.items[cat].append(menuentry) else: # if it is not already a key will add a new key and entry self.items[cat] = [menuentry] self.fileIn.close() # clsoes file
def __init__(self, menu): menuItemDictionary = {} self.menuItemDictionary = menuItemDictionary fileIn = open(menu, "r") for line in fileIn: # one LINE of the file line = line.strip() wordList = line.split(",") # words of a SINGLE in a list itemObject = MenuItem(wordList[0], wordList[1], wordList[2], wordList[3]) #extra credit if wordList[ 1] not in menuItemDictionary: # we have NOT SEEN this word before menuItemDictionary[wordList[1]] = [itemObject] else: # word is ALREADY in disctionary menuItemDictionary[wordList[1]].append(itemObject) #item += 1 keys = list(menuItemDictionary.keys()) keys.sort()
def handleEntry(): global item if (e1.get() == 'report'): l1.config(text="") keys = list(resources.keys()) e1.delete(0, 'end') mb.showinfo( "Resources", f"{keys[0]} : {resources[keys[0]]}ml\n{keys[1]} : {resources[keys[1]]}ml\n{keys[2]} : {resources[keys[2]]}gm\nMoney : ${money}" ) elif (e1.get() == 'latte' or e1.get() == "cappuccino" or e1.get() == "espresso"): txt = e1.get() item = MenuItem(txt) enough = check_resources(item) if enough == True: get_coins() else: e1.delete(0, 'end') l1.config(text="please enter a valid drink")
def __init__(self, menu="menu.csv"): # open up the file object readMenu = open(menu, "r") # initialize the menu item dictionary (extra credit) self.menuItemDict = { "Drink": [], "Appetizer": [], "Entree": [], "Dessert": [] } # counter for next for loop i = 0 for line in readMenu: # split the line into a list itemList = line.split(",") # assign the values of the new list to the MenuItem Object newItem = MenuItem(itemList[0], itemList[1], itemList[2], itemList[3]) # append object to proper list in menuItemDict self.menuItemDict[itemList[1]].append(newItem) # close the file object readMenu.close()
def __init__(self, csvFileName): # CSV file that contains info abt the menu items # initialize the single instance attribute to an empty dictionary self.__menuItemDictionary = {} # Open and read the csv file # Import CSV file: fileIn = open(csvFileName, "r") delimiter = "," # Create a blank list containing all objects allItems = [] # Create objects out of CSV file for line in fileIn: line = line.strip() # remove junks # create a list containing info of each item in the CSV eachItemInfo = line.split(delimiter) # create an object using MenuItem (name, type, price, desc) eachItem = MenuItem(eachItemInfo[0], eachItemInfo[1], eachItemInfo[2], eachItemInfo[3]) # append items to list # self.__menuItemDictionary[eachItemInfo[1]] = eachItem allItems.append(eachItem) # Close the file fileIn.close() # append items to the menu, using its type as the key # each menu type will have a list of values-objects for item in allItems: if item.getType() not in self.__menuItemDictionary: # append the new item to the existing menu type self.__menuItemDictionary[item.getType()] = [item] else: # create a new menu type in this slot self.__menuItemDictionary[item.getType()].append(item)
def Refresh(self, Items, Funcs, BackgroundColor=BLACK, Font=None, FontSize=30, FontColor=WHITE): self.BackgroundColor = BackgroundColor self.Funcs = Funcs self.Items = [] self.CurrentItem = None for Index, Item in enumerate(Items): MI = MenuItem(Item, Font, FontSize, FontColor) TotalHeight = len(Items) * MI.Height PosX = (self.ScreenWidth / 2) - (MI.Width / 2) #Formular to place all items in the center of the screen, # but according to the item order in the MenuItem array given PosY = (self.ScreenHeight / 2) - (TotalHeight / 2) + ( (Index * 2) + Index * MI.Height) MI.SetPosition(PosX, PosY) self.Items.append(MI)