def openNutritionRecepie(id): nutritionWindow = tk.Toplevel() myFont = font.Font(size=30) labelTitleNutrition = Label(nutritionWindow, text="Nutrition") labelTitleNutrition['font'] = myFont labelTitleNutrition.grid(row=0, column=0, sticky='we', padx=10) functionality = Functionality() nutritientsTuple = functionality.getRecepieNutritionDictById(id) # tuple(bad, good) do tupli kuła jak do listy[1] bad = nutritientsTuple[0] listOfBad = [] for everyDict in bad: listOfBad.append( everyDict['title'] + ": " + str(everyDict['amount']) + ", daily percent need: " + str( everyDict['percentOfDailyNeeds']) + "%") good = nutritientsTuple[1] for everyDict in good: listOfBad.append( everyDict['title'] + ": " + str(everyDict['amount']) + ", daily percent need: " + str( everyDict['percentOfDailyNeeds']) + "%") separator = '\n' ingredients = separator.join(listOfBad) ingredientsLabel = Label(nutritionWindow, text=ingredients) ingredientsLabel.grid(column=0, row=1, sticky="we", padx=10) nutritionWindow.title("Nutrition") nutritionWindow.mainloop()
class SlaveNode: LOOP_DELAY = 10 def __init__(self): self.mesh = MeshNet(master=False) self.id = get_serial() self.functionality = None self.is_init = False def _init_node(self): message_dict = {'id': self.id} init_message = to_json_string(message_dict) self.mesh.send_message(MeshNet.MSG_TYPE_INIT, init_message) def run(self): self.mesh.add_message_callback(MeshNet.MSG_TYPE_UPDATE, self._on_update) self._init_node() timer = Timer() while True: self.mesh.update() if timer.time_passed() > INIT_INTERVAL and not self.is_init: self._init_node() timer.reset() delay(SlaveNode.LOOP_DELAY) def _on_update(self, from_node, message): self.is_init = True message_dict = from_json_string(message) has_succeeded = self._try_update(message_dict) response_dict = {'success': has_succeeded, 'id': self.id} confirm_message = to_json_string(response_dict) self.mesh.send_message(MeshNet.MSG_TYPE_UPDATE_CONFIRM, confirm_message) def _try_update(self, message_dict): if message_dict['reboot']: force_reboot() if self.functionality is not None: self.functionality.stop() del self.functionality if message_dict['sleep']: self.functionality = None return True setup, loop = message_dict['setup'], message_dict['loop'] self.functionality = Functionality(setup, loop, self.mesh) func_is_working = self.functionality.test() if func_is_working: self.functionality.start() return func_is_working
def __init__(self, displayID, friendlyName): Functionality.__init__(self) QWidget.__init__(self) # Create empty layout self._vbx = QtGui.QGridLayout(self) self._vbx.setContentsMargins(0, 0, 0, 0) self._vbx.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.setID(displayID) self.name = friendlyName
def openSummaryRecepie(id): summaryWindow = tk.Toplevel() functionality = Functionality() titleLabel = Label(summaryWindow, text="Summary:") titleLabel.config(font=("Courier", 30)) titleLabel.pack(padx=5, pady=5) listSummary = functionality.getRecepieDictSummaryById(id) listSummaryToPrint = listSummary.replace("<b>", " ").replace("</b>", " ") newString = re.sub('<[^>]+>', '', listSummaryToPrint) summaryLabel = Label(summaryWindow, text=newString, wraplength=400) summaryLabel.pack(fill=BOTH, expand=1, padx=15, pady=(0, 15)) summaryWindow.title("Summary") summaryWindow.mainloop()
def _try_update(self, message_dict): if message_dict['reboot']: force_reboot() if self.functionality is not None: self.functionality.stop() del self.functionality if message_dict['sleep']: self.functionality = None return True setup, loop = message_dict['setup'], message_dict['loop'] self.functionality = Functionality(setup, loop, self.mesh) func_is_working = self.functionality.test() if func_is_working: self.functionality.start() return func_is_working
def processData(): functionality = Functionality() intolerances = self.ifNuts.get() + self.ifEggs.get() + self.ifGluten.get() + self.ifDairy.get() + self.ifGrain.get() + self.ifSeafood.get() if self.clickedDiet.get() == 'none': diet = '' else: diet = self.clickedDiet.get() if self.clickedCuisine.get() == 'none': cuisine = '' else: cuisine = self.clickedCuisine.get() intolerance = intolerances time = self.timeEntry.get() food = self.foodEntry.get() number = self.numberEntry.get() functionality.chooseDiet(diet) functionality.chooseCuisine(cuisine) functionality.searchByIntolerance(intolerance) functionality.searchMaxCookingTime(time) functionality.howManyRecepies(number) functionality.serchWhatToEat(food) resultBox = functionality.getRecepieList() if not resultBox: messagebox.showinfo("Sorry", "Sorry we do not have this kind of recepies, try different combination") else: windowList = tk.Toplevel() windowList.geometry("400x300") frameTitle = Frame(windowList, width=400, height=50) frameTitle.pack() ###################### myFont = font.Font(size=20) foundRecepiesLabel = Label(frameTitle, text="Found recepies:") foundRecepiesLabel['font'] = myFont foundRecepiesLabel.grid(column=0, row=0, columnspan=2, sticky="we", padx=(5, 0), pady=(0, 5)) ############################ frameListBox = Frame(windowList, width=400, height=0) scrollbar = Scrollbar(frameListBox, orient="vertical") listBox = Listbox(frameListBox, yscrollcommand=scrollbar.set) scrollbar.pack(side=RIGHT, fill=Y) frameListBox.pack() listBox.pack() ############################# # listBox=Listbox(windowList) # listBox.pack() dictListRowId = [] max_len = 0 for elem in functionality.getRecepieListDict(): for idElem, titleElem in elem.items(): listBox.insert(END, idElem) index = listBox.get(0, END).index(idElem) dictListRowId.append({str(index): (str(idElem), titleElem)}) if len(idElem) > max_len: max_len = len(idElem) listBox.configure(width=max_len) scrollbar.config(command=listBox.yview) def getIdSelectedItem(): name = listBox.get(listBox.curselection()) id_item = None for elem in dictListRowId: for elementList, value in elem.items(): if value[0] == name: id_item = value[1] openRecepieWindow(id_item) frameButtons=Frame(windowList) frameButtons.pack() buttonGoToRecepie = Button(frameButtons, text="select", command=getIdSelectedItem) buttonGoToRecepie.grid(column=0, row=0) buttonHelpList= Button(frameButtons, text="help", command=openHelpForListBox) buttonHelpList.grid(column=1, row=0) label = Label(windowList, text='') label.pack()
def openRecepieWindow(id): windowRecepie = tk.Toplevel() functionality = Functionality() Grid.columnconfigure(windowRecepie, 0, weight=1) Grid.columnconfigure(windowRecepie, 1, weight=1) frameLeft = Frame(windowRecepie) frameLeft.grid(row=2, column=0) title = Label(frameLeft, text=functionality.getRecepieTitleById(id), wraplength=300) title.config(font=( 15)) title.grid(column=0, row=0, padx=(10, 5), pady=5, sticky='we') titleLabelFrameLeft = Label(frameLeft, text="Ingredients:", wraplength=300) titleLabelFrameLeft.config(font= 12) titleLabelFrameLeft.grid(column=0, row=1, padx=(10,5), pady=5, sticky='we') # frameRight = Frame(windowRecepie) frameRight.grid(row=2, column=1, padx=(10,5), pady=5) list = functionality.getRecepieIngredientsById(id) separator = '\n' ingredients = separator.join(list) ingredientsLabel = Label(frameLeft, text=ingredients, wraplength=300) ingredientsLabel.grid(column=0, row=2, padx=5, pady=5, sticky='w') frameBottom = Frame(windowRecepie, width=450, height=200) frameBottom.grid(row=3, column=0, columnspan=2) titleLabelFrameBottom = Label(frameBottom, text="Instructions:") titleLabelFrameBottom.config(font=12) titleLabelFrameBottom.grid(column=0, columnspan=2, row=0, padx=10, pady=(5, 15), sticky='we') listSummary = functionality.getRecepieStepsAnalyzedById(id) separator = '' steps = separator.join(listSummary) instructionsLabel = Label(frameBottom, text=steps, wraplength=500) instructionsLabel.grid(column=0, columnspan=2, row=1, padx=5, pady=5, stick='we') #################### imageRecepie = functionality.getRecepieImageAdresById(id) displayImages(imageRecepie, frameRight, 200, 200) #################### def saveAndInform(id): messagebox.showinfo("Information", "New record saved") functionality.saveToNormalFile(id) toolbar = Frame(windowRecepie, bd=1, relief=RAISED) toolbar.config(bg="beige") buttonSaveQuestion = Button(toolbar, text="Summary", command=lambda: openSummaryRecepie(id)) # , command=lambda: openSummaryRecepie(id) buttonSaveQuestion.pack(side=tk.LEFT, padx=2, pady=2) buttonManageQuestions = Button(toolbar, text="Nutrition", command=lambda: openNutritionRecepie( id)) # , command=lambda: openNutritionRecepie(id) buttonManageQuestions.pack(side=tk.LEFT, padx=2, pady=2) buttonShowQuestions = Button(toolbar, text="Save Recepie", command=lambda: saveAndInform(id)) buttonShowQuestions.pack(side=tk.LEFT, padx=2, pady=2) buttonHelp=Button(toolbar, text="help", command=openHelpForRecepieWindow) buttonHelp.pack(side=tk.LEFT, padx=2, pady=2) buttonExit = Button(toolbar, text="Exit application", command=windowRecepie.quit) buttonExit.pack(side=tk.LEFT, padx=2, pady=2) toolbar.grid(column=0, columnspan=2, row=0, sticky="we", pady=(0, 5)) windowRecepie.title("Choosen Recepie")
def showRecepiesSaved(): functionality=Functionality() windowSaved=tk.Toplevel() windowSaved.geometry('400x300') frameTitle = Frame(windowSaved, width=400, height=50) frameTitle.pack() ###################### myFont = font.Font(size=20) savedLebel = Label(frameTitle, text="Your saved recepies:") savedLebel['font'] = myFont savedLebel.grid(column=0, row=0, columnspan=2,sticky="we", padx=(5, 5), pady=(0, 10)) ###################### frameListBox=Frame(windowSaved, width=400, height=0) scrollbar = Scrollbar(frameListBox, orient="vertical") listBox = Listbox(frameListBox, yscrollcommand = scrollbar.set) scrollbar.pack(side=RIGHT, fill=Y) frameListBox.pack() listBox.pack() dictListRowId = [] max_len=0 for elem in functionality.getSavedList(): for idElem, titleElem in elem.items(): listBox.insert(END, idElem) index = listBox.get(0, END).index(idElem) dictListRowId.append({str(index): (str(idElem), titleElem)}) if len(idElem)>max_len: max_len=len(idElem) listBox.configure(width=max_len) scrollbar.config(command=listBox.yview) def getIdSelectedItem(): name = listBox.get(listBox.curselection()) id_item = None for elem in dictListRowId: for elementList, value in elem.items(): if value[0] == name: id_item = value[1] openRecepieWindow(id_item) frameForInformation=Frame(windowSaved) frameForInformation.pack() buttonChose = Button(frameForInformation, text="select", command=getIdSelectedItem) buttonChose.grid(column=2, row=0, sticky='we') buttonHelp = Button(frameForInformation, text="help", command=openHelpForSavedWindow) buttonHelp.grid(column=3, row=0, sticky='we') labelInfo=Label(frameForInformation, text="Get the name of recepie : ") labelInfo.grid(column=0, row=1) recepieWanted = StringVar() labelRecepie = Label(frameForInformation, textvariable=recepieWanted).grid(column=0, row=2, columnspan=4) def guickLabelUpdate(): recepieWanted.set(functionality.getTheQuickestSavedRecepie()) def healthyLabelUpdate(): recepieWanted.set(functionality.getTheHealthiestSavedRecepie()) def lastLabelUpdate(): recepieWanted.set(functionality.getLastSaved()) buttonTime=Button(frameForInformation, text="the quickest", command=guickLabelUpdate).grid(column=1, row=1) buttonHealty=Button(frameForInformation, text="the healthiest", command=healthyLabelUpdate).grid(column=2, row=1) buttonLast=Button(frameForInformation, text="the last added", command=lastLabelUpdate).grid(column=3, row=1) windowSaved.mainloop()
from PyQt5 import QtCore, QtGui, QtWidgets from functionality import Functionality from UI import Ui_MainWindow if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) app.setStyle("Fusion") MainWindow = QtWidgets.QMainWindow() func = Functionality(MainWindow, sys.argv[1:]) func.more() MainWindow.show() sys.exit(app.exec_())