Example #1
0
 def editQuantity(self, row, col):
     self.ui.dishAddedTable.cellChanged.disconnect()
     if self.ui.dishAddedTable.item(row,col).text() == "":
         if self.ui.dishAddedTable.item(row, col + 1).text() in nompy_core.getDishNames():
             self.ui.dishAddedTable.item(row, col).setText("1x")
         else:
             pass
     else:
         # Cleans up everything but digits and dots. TODO: Alert dialogue if it contains more than one dot.
         self.newQuantity = re.sub("[^0123456789\.]", "", self.ui.dishAddedTable.item(row, col).text())
         print("Cleaned up Qty value " + self.ui.dishAddedTable.item(row, col).text() + " to " + self.newQuantity)
         if int(self.newQuantity) > 999:
             # Input greater than 999 will reset the value to 1 to avoid MemoryError
             # TODO: Alert Dialogue
             if self.ui.dishAddedTable.item(row, col + 1).text() in nompy_core.getDishNames():
                 self.ui.dishAddedTable.item(row, col).setText("1x")
                 self.calculate()
             else:
                 pass
         elif self.newQuantity == "0":
             self.removeDish()
         else:
             if self.ui.dishAddedTable.item(row, col + 1).text() in nompy_core.getDishNames():
                 self.ui.dishAddedTable.item(row, col).setText(self.newQuantity + "x")
                 self.calculate()
             else:
                 pass
Example #2
0
 def search(self):
     self.searchString = self.ui.searchBox.text()
     # making the string lowercase for case insensitivity
     self.searchString = self.searchString.lower()
     self.ui.dishList.clear()
     self.ui.buttonAddDish.setEnabled(False)
     # http://stackoverflow.com/questions/4843158/check-if-a-python-list-item-contains-a-string-inside-another-string
     self.matchingDishes = [s for s in nompy_core.getDishNames() if self.searchString in s.lower()]
     self.ui.dishList.addItems(self.matchingDishes)
Example #3
0
    def __init__(self):
        QtWidgets.QMainWindow.__init__(self)
        self.mainWindow = QtWidgets.QMainWindow
        self.about = AboutWindow()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.actionQuit.triggered.connect(QtCore.QCoreApplication.instance().quit)
        self.ui.actionAbout.triggered.connect(lambda: self.about.exec_())
        self.ui.buttonAddDish.clicked.connect(self.addDish)
        self.ui.buttonAddDish.setEnabled(False)
        self.ui.buttonPlusQty.clicked.connect(self.buttonPlusQtyClicked)
        self.ui.buttonPlusQty.setEnabled(False)
        self.ui.buttonMinusQty.clicked.connect(self.buttonMinusQtyClicked)
        self.ui.buttonMinusQty.setEnabled(False)
        self.ui.buttonRemoveDish.clicked.connect(self.removeDish)
        self.ui.buttonRemoveDish.setEnabled(False)
        self.ui.searchBox.textEdited["QString"].connect(self.search)
        self.ui.dishIngredientTabWidget.currentChanged.connect(self.tabChanged)

        # Fill Dish list with names from dishes.json
        self._translate = QtCore.QCoreApplication.translate
        for self.index, self.dishName in enumerate(nompy_core.getDishNames()):
            self.ui.item = QtWidgets.QListWidgetItem()
            self.ui.dishList.addItem(self.ui.item)
            self.ui.item = self.ui.dishList.item(self.index)
            self.ui.item.setText(self._translate("MainWindow", self.dishName))
        self.ui.dishList.sortItems()
        self.ui.dishList.itemClicked.connect(self.dishListClicked)

        # Fill Ingredient list with names from ingredients.json
        for self.index, self.ingredientName in enumerate(nompy_core.getIngredientNames()):
            self.ui.item = QtWidgets.QListWidgetItem()
            self.ui.ingredientList.addItem(self.ui.item)
            self.ui.item = self.ui.ingredientList.item(self.index)
            self.ui.item.setText(self._translate("MainWindow", self.ingredientName))
        self.ui.ingredientList.sortItems()
        self.ui.ingredientList.itemClicked.connect(self.ingredientListClicked)

        self.ui.dishAddedTable.cellDoubleClicked.connect(self.dishAddedTableDoubleclicked)
        #self.changeQuantity.connect(self.editQuantity)
        self.ui.dishAddedTable.cellClicked.connect(self.dishAddedTableCellClicked)