def on_bb_accepted(self): activity = self.mem.data.activities.find_by_id( self.cmbActivity.itemData(self.cmbActivity.currentIndex())) weightwish = self.mem.data.weightwishes.find_by_id( self.cmbWeightWish.itemData(self.cmbWeightWish.currentIndex())) if activity is None or weightwish is None: qmessagebox( self.tr("You must select an activity and a weight wish")) return if self.biometric == None: self.biometric = Biometrics(self.mem, self.wdgDT.datetime(), self.spnHeight.value(), self.spnWeight.value(), self.mem.user, activity, weightwish, None) else: self.biometric.datetime = self.wdgDT.datetime() self.biometric.height = self.spnHeight.value() self.biometric.weight = self.spnWeight.value() self.biometric.activity = activity self.biometric.weightwish = weightwish self.biometric.save() self.mem.con.commit() self.mem.user.needStatus(1, downgrade_to=0) self.accept()
def on_bb_accepted(self): foodtype = None if self.cmbFoodtypes.currentIndex( ) == -1 else self.mem.data.foodtypes.find_by_id( self.cmbFoodtypes.itemData(self.cmbFoodtypes.currentIndex())) if foodtype == None: qmessagebox(self.tr("You need to set a food type"), ":/caloriestracker/book.png") return if self.elaboratedproduct is None: self.elaboratedproduct = ProductElaborated(self.mem) self.elaboratedproduct.name = self.txtName.text() self.elaboratedproduct.foodtype = foodtype self.elaboratedproduct.obsolete = self.chkObsolete.isChecked() self.elaboratedproduct.final_amount = self.spnFinalAmount.value() else: self.elaboratedproduct.name = self.txtName.text() self.elaboratedproduct.obsolete = self.chkObsolete.isChecked() self.elaboratedproduct.foodtype = foodtype self.elaboratedproduct.final_amount = self.spnFinalAmount.value() self.elaboratedproduct.last = datetime.now() self.elaboratedproduct.save() self.mem.con.commit() self.mem.data.elaboratedproducts.append_distinct( self.elaboratedproduct) self.mem.settings.setValue("frmProductsElaboratedAdd/qdialog", self.size()) self.accept()
def on_cmbUsers_currentIndexChanged(self, index): self.mem.user = self.mem.data.users.find_by_id( int(self.cmbUsers.itemData(self.cmbUsers.currentIndex()))) self.mem.user.needStatus(1) self.mem.settings.setValue("mem/currentuser", self.mem.user.id) self.on_actionBiometrics_triggered() qmessagebox("Changed user to {}".format(self.mem.user.name))
def on_bb_accepted(self): if self.qlepAmount.value()<=0: qmessagebox(self.tr("Amount value must be greater than 0"), ":/caloriestracker/book.png") return cmb_index=self.cmbCompanies.findText(self.cmbCompanies.currentText()) company=None if cmb_index==-1 else self.mem.data.companies.find_by_string_id(self.cmbCompanies.itemData(cmb_index)) foodtype=None if self.cmbFoodtypes.currentIndex()==-1 else self.mem.data.foodtypes.find_by_id(self.cmbFoodtypes.itemData(self.cmbFoodtypes.currentIndex())) if foodtype==None: qmessagebox(self.tr("You neet to set a food type"), ":/caloriestracker/book.png") return system_company=None if company==None else company.system_company if self.product==None: self.product=ProductPersonal( self.mem, self.txtName.text(), self.qlepAmount.value(), self.qlepFat.value(), self.qlepProtein.value(), self.qlepCarbohydrate.value(), company, datetime.now(), None, None, self.qlepCalories.value(), self.qlepSalt.value(), self.qlepCholesterol.value(), self.qlepSodium.value(), self.qlepPotassium.value(), self.qlepFiber.value(), self.qlepSugar.value(), self.qlepSaturatedFat.value(), system_company, foodtype, self.cmbsAdditives.selected(), None) self.mem.data.products.append(self.product) self.mem.data.products.order_by_name() else: self.product.name=self.txtName.text() self.product.amount=self.qlepAmount.value() self.product.fat=self.qlepFat.value() self.product.protein=self.qlepProtein.value() self.product.carbohydrate=self.qlepCarbohydrate.value() self.product.company=company self.product.calories=self.qlepCalories.value() self.product.salt=self.qlepSalt.value() self.product.cholesterol=self.qlepCholesterol.value() self.product.sodium=self.qlepSodium.value() self.product.potassium=self.qlepPotassium.value() self.product.fiber=self.qlepFiber.value() self.product.sugars=self.qlepSugar.value() self.product.saturated_fat=self.qlepSaturatedFat.value() self.product.system_company=system_company self.product.foodtype=foodtype self.product.additives=self.cmbsAdditives.selected() self.product.save() self.mem.con.commit() self.accept()
def keyPressEvent(self, event): print(event.key()) if self.mem.user.biometrics.last() is None: if event.key() == Qt.Key_Escape: qmessagebox(self.tr("You must add your biometric data")) event.ignore() return event.accept()
def on_actionBiometricsDelete_triggered(self): if self.mem.con.cursor_one_field("select count(*) from biometrics")==1: qmessagebox(self.tr("This is your last biometric data. You can't delete")) return if qmessagebox_question( self.tr("This action can't be undone.\nDo you want to delete this record?"))==True: self.tblBiometrics.selected.delete() self.mem.con.commit() self.mem.user.needStatus(1, downgrade_to=0) self.update()
def on_actionMealPaste_triggered(self): for meal in self.mem.clipboard: if meal.__class__.__name__ == "Meal": meal.datetime = self.mem.now() meal.save() else: qmessagebox(self.tr("Clipboard hasn't meals")) self.mem.clipboard.clean() return self.calendar.setSelectedDate(date.today())
def on_actionUserDelete_triggered(self): if self.mem.data.users.selected.is_deletable()==False: qmessagebox(self.tr("This product can't be removed, because is marked as not remavable")) return reply = QMessageBox.question(None, self.tr('Asking your confirmation'), self.tr("This action can't be undone.\nDo you want to delete this record?"), QMessageBox.Yes, QMessageBox.No) if reply==QMessageBox.Yes: self.mem.data.users.selected.delete() self.mem.con.commit() self.mem.data.users.remove(self.mem.data.users.selected) self.update()
def on_actionFormatEdit_triggered(self): if self.product.system_product==False or self.mem.isProductsMaintainerMode()==True: from caloriestracker.ui.frmFormatsAdd import frmFormatsAdd w=frmFormatsAdd(self.mem, self.product, self.tblFormats.selected, self) w.exec_() self.product.formats.qtablewidget(self.tblFormats) else: qmessagebox( self.tr("This format is of a system product so you can't edit it.") + "\n" + self.tr("Please, if it's something wrong with it create an issue at") + "\n" + "https://github.com/turulomio/caloriestracker/issues"+ "\n" + self.tr("I'll fix it as soon as posible. ;)"))
def on_actionFormatDelete_triggered(self): if self.product.system_product==False: self.tblFormats.selected.delete() self.product.formats.remove(self.tblFormats.selected) self.mem.con.commit() self.product.formats.qtablewidget(self.tblFormats) else: qmessagebox( self.tr("This format is of a system product so you can't edit it.") + "\n" + self.tr("Please, if it's something wrong with it create an issue at") + "\n" + "https://github.com/turulomio/caloriestracker/issues"+ "\n" + self.tr("I'll fix it as soon as posible. ;)"))
def on_database_created(connectionqt): from caloriestracker.database_update import database_update from caloriestracker.version import __versiondatetime__ from caloriestracker.ui.myqwidgets import qmessagebox database_update(connectionqt, "caloriestracker", __versiondatetime__, "Console") connectionqt.commit() qmessagebox( qApp.translate( "Mem", "Calories Tracker have been correctly installed. Please login again" )) exit(qApp.exec_())
def on_actionCompanyEdit_triggered(self): if self.companies.selected.system_company==True and self.mem.isProductsMaintainerMode()==False: qmessagebox( self.tr("This is a system company so you can't edit it.") + "\n" + self.tr("Please, if it's something wrong with it create an issue at") + "\n" + "https://github.com/turulomio/caloriestracker/issues"+ "\n" + self.tr("I'll fix it as soon as posible. ;)") ) else: from caloriestracker.ui.frmCompaniesAdd import frmCompaniesAdd w=frmCompaniesAdd(self.mem, self.companies.selected, self) w.exec_() self.on_cmd_pressed()
def on_bb_accepted(self): if self.product==None: qmessagebox(self.tr("You must select a product from the popup list")) return if self.meal==None: self.meal=Meal(self.mem, self.wdgDT.datetime(), self.product, self.spnAmount.value(), self.mem.user, self.product.system_product, None) else: self.meal.datetime=self.wdgDT.datetime() self.meal.product=self.product self.meal.amount=self.spnAmount.value() self.meal.system_product=self.product.system_product self.meal.save() self.mem.con.commit() self.accept()
def on_actionProductDelete_triggered(self): if self.products.selected.is_deletable()==False: qmessagebox(self.tr("This product can't be removed, because is marked as not remavable")) return if self.products.selected.elaboratedproducts_id!=None:#Elaborated: qmessagebox(self.tr("Not developed yet, for elaborated product")) return reply = QMessageBox.question(None, self.tr('Asking your confirmation'), self.tr("This action can't be undone.\nDo you want to delete this record?"), QMessageBox.Yes, QMessageBox.No) if reply==QMessageBox.Yes: self.products.selected.delete() self.mem.con.commit() self.mem.data.products.remove(self.products.selected) self.on_cmd_pressed()
def on_bb_accepted(self): if self.origin is not None and self.wdg.selected is not None: r = self.tr( "Moving data from personal product '{}' to system product '{}'" ).format(self.origin, self.wdg.selected) reply = QMessageBox.question( None, self.tr('Moving data between products'), r + "\n" + self.tr( "This action can't be undone.\nDo you want to continue?"), QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.Yes: move_product_personal_to_system(self.mem, self.origin, self.wdg.selected) self.parent.accept() else: qmessagebox(self.tr("You must select a system product"))
def setReadOnly(self): self.lbl.setText(self.tr("Product information")) qmessagebox( self.tr("This is a system product so you can't edit it.") + "\n" + self. tr("Please, if it's something wrong with it, you can create an issue at" ) + "\n" + "https://github.com/turulomio/caloriestracker/issues" + "\n" + self.tr("I'll fix it as soon as posible. ;)")) for widget in self.findChildren(QWidget): if widget.__class__ == QLineEdit: widget.setReadOnly(True) elif widget.__class__ == QCheckBox: widget.setEnabled(False) widget.blockSignals(True) self.bb.button(QDialogButtonBox.Ok).setEnabled(False) self.bb.blockSignals(False) self.bb.button(QDialogButtonBox.Cancel).blockSignals(False)
def on_actionProductEdit_triggered(self): if self.elaboratedproduct.products_in.selected.product.system_product==True: qmessagebox( self.tr("This is a system product so you can't edit it.") + "\n" + self.tr("Please, if it's something wrong with it create an issue at") + "\n" + "https://github.com/turulomio/caloriestracker/issues"+ "\n" + self.tr("I'll fix it as soon as posible. ;)") ) elif self.elaboratedproduct.products_in.selected.product.system_product==False: if self.elaboratedproduct.products_in.selected.product.elaboratedproducts_id==None: from caloriestracker.ui.frmProductsAdd import frmProductsAdd w=frmProductsAdd(self.mem, self.elaboratedproduct.products_in.selected.product, self) w.exec_() else:#Elaborated product from caloriestracker.ui.frmProductsElaboratedAdd import frmProductsElaboratedAdd elaborated=self.mem.data.elaboratedproducts.find_by_id(self.elaboratedproduct.products_in.selected.product.elaboratedproducts_id) w=frmProductsElaboratedAdd(self.mem, elaborated, self) w.exec_() self.elaboratedproduct.products_in.qtablewidget(self.tblProductsIn)
def on_bb_accepted(self): if self.product == None: qmessagebox( self.tr("You must select a product from the popup list")) return if self.productinelaboratedproduct == None: self.productinelaboratedproduct = ProductInElaboratedProduct( self.mem, self.product, self.product.system_product, self.spnAmount.value(), self.elaboratedproduct, None) else: self.productinelaboratedproduct.product = self.product self.productinelaboratedproduct.amount = self.spnAmount.value() self.productinelaboratedproduct.system_product = self.product.system_product self.productinelaboratedproduct.save() self.elaboratedproduct.products_in.append_distinct( self.productinelaboratedproduct) self.elaboratedproduct.save() self.mem.con.commit() self.accept()
def on_cmdCreate_released(self): if qmessagebox_question( self.tr("Do you want to create {} database in {}?".format( self.txtDB.text(), self.cmbLanguage.currentText()))) == True: admin = AdminPG(self.txtUser.text(), self.txtPass.text(), self.txtServer.text(), self.txtPort.text()) if admin.db_exists(self.txtDB.text()) == True: qmessagebox("Database already exists") return if admin.create_db(self.txtDB.text()) == True: newcon = admin.connect_to_database(self.txtDB.text()) database_update(newcon, "caloriestracker", __versiondatetime__, "Qt") qmessagebox( self. tr("Database created. Please run Calories Tracker and login" )) logging.info("App correctly closed") self.close() else: logging.error("Something went wrong")
def on_cmdCreate_released(self): respuesta = QMessageBox.warning( self, self.windowTitle(), self.tr("Do you want to create {} database in {}?".format( self.txtDB.text(), self.cmbLanguage.currentText())), QMessageBox.Ok | QMessageBox.Cancel) if respuesta == QMessageBox.Ok: admin = AdminPG(self.txtUser.text(), self.txtPass.text(), self.txtServer.text(), self.txtPort.text()) if admin.db_exists(self.txtDB.text()) == True: qmessagebox("Database already exists", self.mem.app_resouce()) return if admin.create_db(self.txtDB.text()) == True: newcon = admin.connect_to_database(self.txtDB.text()) database_update(newcon, "caloriestracker", __versiondatetime__, "Qt") qmessagebox( self. tr("Database created. Please run Calories Tracker and login" ), self.mem.app_resource()) logging.info("App correctly closed") self.close() else: logging.error("Something went wrong")
def on_actionCompanyDelete_triggered(self): if self.mem.isProductsMaintainerMode()==True: if self.companies.selected.is_deletable()==True: self.companies.selected.delete() self.mem.deleteCompanies.append(self.companies.selected) self.mem.data.companies.remove(self.companies.selected) else: self.companies.selected.logical_delete() self.mem.updateCompanies.append(self.companies.selected) else: if self.companies.selected.is_deletable()==False: qmessagebox(self.tr("This company can't be removed, because it has dependent data")) return if self.companies.selected.system_company==True: qmessagebox(self.tr("This company can't be removed, because it's a system one")) return reply = QMessageBox.question(None, self.tr('Asking your confirmation'), self.tr("This action can't be undone.\nDo you want to delete this record?"), QMessageBox.Yes, QMessageBox.No) if reply==QMessageBox.Yes: self.companies.selected.delete() self.mem.con.commit() self.mem.data.companies.remove(self.companies.selected) self.on_cmd_pressed()
def on_bb_accepted(self): if self.qlepAmount.value() <= 0: qmessagebox(self.tr("Amount value must be greater than 0"), ":/caloriestracker/book.png") return cmb_index = self.cmbCompanies.findText(self.cmbCompanies.currentText()) company = None if cmb_index == -1 else self.mem.data.companies.find_by_string_id( self.cmbCompanies.itemData(cmb_index)) foodtype = None if self.cmbFoodtypes.currentIndex( ) == -1 else self.mem.data.foodtypes.find_by_id( self.cmbFoodtypes.itemData(self.cmbFoodtypes.currentIndex())) if foodtype == None: qmessagebox(self.tr("You need to set a food type"), ":/caloriestracker/book.png") return system_company = None if company == None else company.system_company if self.product == None: if self.mem.isProductsMaintainerMode(): productclass = Product else: productclass = ProductPersonal self.product = productclass(self.mem) self.product.name = self.txtName.text() self.product.amount = self.qlepAmount.value() self.product.fat = self.qlepFat.value() self.product.protein = self.qlepProtein.value() self.product.carbohydrate = self.qlepCarbohydrate.value() self.product.company = company self.product.calories = self.qlepCalories.value() self.product.salt = self.qlepSalt.value() self.product.cholesterol = self.qlepCholesterol.value() self.product.sodium = self.qlepSodium.value() self.product.potassium = self.qlepPotassium.value() self.product.fiber = self.qlepFiber.value() self.product.sugars = self.qlepSugar.value() self.product.saturated_fat = self.qlepSaturatedFat.value() self.product.system_company = system_company self.product.foodtype = foodtype self.product.additives = self.cmbsAdditives.selected() self.product.last = datetime.now() self.product.glutenfree = self.chkGlutenFree.isChecked() self.product.ferrum = self.qlepFerrum.value() self.product.magnesium = self.qlepMagnesium.value() self.product.phosphor = self.qlepPhosphor.value() self.product.calcium = self.qlepCalcium.value() self.product.obsolete = self.chkObsolete.isChecked() self.product.save() if self.mem.isProductsMaintainerMode(): if self.__insert == True: self.parent.products.append( self.product) #Manager of the parent widget self.mem.data.products.append( self.product) #Manager of the singleton self.mem.insertProducts.append(self.product) else: self.mem.updateProducts.append(self.product) else: #Not maintainer mode if self.__insert == True: self.parent.products.append( self.product) #Manager of the parent widget self.mem.data.products.append( self.product) #Manager of the singleton self.mem.con.commit() self.mem.data.products.order_by_name() self.accept()
def on_cmdNext_pressed(self): if self.year == self.lastyear: qmessagebox(self.tr("I can't show the next year")) return self.year = self.year + 1 self.set(self.year)
def closeEvent(self, event): if self.mem.user.biometrics.last() is None: qmessagebox(self.tr("You must add your biometric data")) event.ignore() return event.accept()
def on_cmdPrevious_pressed(self): if self.firstyear == self.year: qmessagebox(self.tr("I can't show the previous year")) return self.year = self.year - 1 self.set(self.year)
def inactivity_timeout(self): self.hide() qmessagebox( self.tr("Disconnecting due to {} minutes of inactivity.".format( self.mem.con.connectionTimeout() / 60))) self.on_actionExit_triggered()