def addExistingDB(self, data): logging.debug("Add existing DB with parameters {}".format(data)) #add to config self.__userConfig.addDBForCurrentUser(data[DataField.PATH], data[DataField.PASSWORD]) try: #add to DB manager db = self.__dbManager.registerDB(data[DataField.PATH], data[DataField.PASSWORD]) #add to panel categoryPanel = self.__view.getCategoryPanel() categoryPanel.tree.insert( "", 'end', db.id, text=db.path, image=self.__getImage('db_disconnected_image'), open=True) except Exceptions.DataBaseException: md.showError(self.__view, title=self.__localization.getWord('invalid_value'), text=self.__localization.getWord('db_exist'), buttonsText=[self.__localization.getWord('ok')]) logging.debug("Existing DB {} successfully added".format(data))
def loginPress(self): #check the match of user name and password login = self.__view.getLogin().encode('utf8') password = self.__view.getPassword().encode('utf8') logging.debug("Login %s, Password %s ", login, password) try: self.__userConfig.loadUserConfig(login, password) except WrongUserException: md.showError( self.__view, title=self.__localization.getWord('invalid_value'), text=self.__localization.getWord('you_entered_wrong_login'), buttonsText=[self.__localization.getWord('ok')]) return except WrongPasswordException: md.showError( self.__view, title=self.__localization.getWord('invalid_value'), text=self.__localization.getWord('you_entered_wrong_password'), buttonsText=[self.__localization.getWord('ok')]) return #send signal about successful logging and pass login and password self.__view.destroy() self.__notifier.sendSignal(Signal.LOGIN_OK, [login, password])
def removeDBFromFileSystem(self, data): logging.debug("Remove selected DB from file system") if not self.__currentDB: return res = md.showYesNo(self.__view, title=self.__localization.getWord('removing_db'), text=self.__localization.getWord( 'remove_db_from_filesystem_question'), buttonsText=[ self.__localization.getWord('yes'), self.__localization.getWord('no') ]) if res: if os.path.isfile(self.__currentDB.path.decode('utf8')): os.remove(self.__currentDB.path.decode('utf8')) #remove from DB manager self.__dbManager.deleteDB(self.__currentDB.id) #remove from userConfig self.__userConfig.removeDBFromCurrentUser( self.__currentDB.path) #remove from panel categoryPanel = self.__view.getCategoryPanel() categoryPanel.tree.delete(self.__currentDB.id) #remove from file system #os.remove(self.__currentDB.path.decode('utf8')) self.__setCurrentDB(None) else: #remove from DB manager dbpath = self.__currentDB.path self.__dbManager.deleteDB(self.__currentDB.id) #remove from userConfig self.__userConfig.removeDBFromCurrentUser( self.__currentDB.path) #remove from panel categoryPanel = self.__view.getCategoryPanel() categoryPanel.tree.delete(self.__currentDB.id) #remove from file system #os.remove(self.__currentDB.path.decode('utf8')) self.__setCurrentDB(None) #show info dialog abot missing database file md.showInfo(self.__view, title=self.__localization.getWord('removing_db'), text="{} {}. {}".format( self.__localization.getWord( 'remove_db_from_filesystem_no_file'), dbpath, self.__localization.getWord( 'db_from_config_remove_ok')), buttonsText=[self.__localization.getWord('ok')]) logging.debug("DB removed successfully from file system")
def checkUserValues(self, path, name, password, comments): if not self.__dbManager.checkEntryData(path, DataField.PATH): md.showError(self.__view, title = self.__localization.getWord('invalid_value'), text = "{} {}".format(self.__localization.getWord('path'), self.__localization.getWord('contains_invalid_value')), buttonsText=[self.__localization.getWord('ok')]) return False if not self.__dbManager.checkEntryData(name, DataField.NAME): md.showError(self.__view, title = self.__localization.getWord('invalid_value'), text = "{} {}".format(self.__localization.getWord('db_name'), self.__localization.getWord('contains_invalid_value')), buttonsText=[self.__localization.getWord('ok')]) return False if not self.__dbManager.checkEntryData(password, DataField.PASSWORD): md.showError(self.__view, title = self.__localization.getWord('invalid_value'), text = "{} {}".format(self.__localization.getWord('password'), self.__localization.getWord('contains_invalid_value')), buttonsText=[self.__localization.getWord('ok')]) return False if not self.__dbManager.checkEntryData(comments, DataField.COMMENTS): md.showError(self.__view, title = self.__localization.getWord('invalid_value'), text = "{} {}".format(self.__localization.getWord('comments'), self.__localization.getWord('contains_invalid_value')), buttonsText=[self.__localization.getWord('ok')]) return False return True
def removeRecord(self, data): logging.debug("Removing record") res = md.showYesNo( self.__view, title=self.__localization.getWord('removing_record'), text=self.__localization.getWord('remove_record'), buttonsText=[ self.__localization.getWord('yes'), self.__localization.getWord('no') ]) if res: if self.__currentDB: recordPanel = self.__view.getRecordPanel() clickedItem = recordPanel.tree.focus() if clickedItem: #remove from data structure self.__currentDB.removeEntry(DBObjectType.RECORD, clickedItem) #remove from record panel recordPanel.tree.delete(clickedItem) self.__setCurrentRecord(recordPanel.tree.focus()) logging.debug( "Removed record successfully {}".format(clickedItem)) self.__notifier.sendSignal(Signal.DB_SELECTED_CHANGED, self.__currentDB) self.__notifier.sendSignal(Signal.RECORD_SELECTED_CHANGED, None)
def removeCategory(self, data): logging.debug("Removing category") res = md.showYesNo( self.__view, title=self.__localization.getWord('removing_category'), text=self.__localization.getWord('remove_category'), buttonsText=[ self.__localization.getWord('yes'), self.__localization.getWord('no') ]) if res: if self.__currentDB: categoryPanel = self.__view.getCategoryPanel() clickedItem = categoryPanel.tree.focus() if clickedItem: #remove from data structure self.__currentDB.removeEntry(DBObjectType.CATEGORY, clickedItem) #remove from record panel categoryPanel.tree.delete(clickedItem) self.__setCurrentCategory(None) self.__cleanRecordPanel() self.__notifier.sendSignal(Signal.DB_SELECTED_CHANGED, self.__currentDB) self.__notifier.sendSignal( Signal.CATEGORY_SELECTED_CHANGED, None) logging.debug( "Removed category successfully {}".format(clickedItem))
def checkUserValues(self, path, password): #check path if not self.__dbManager.dbPathUniqueCheck(path): md.showError(self.__view, title = self.__localization.getWord('invalid_value'), text = self.__localization.getWord('db_exist'), buttonsText=[self.__localization.getWord('ok')]) return False #check password if not self.__dbManager.checkEntryData(password, DataField.PASSWORD): md.showError(self.__view, title = self.__localization.getWord('invalid_value'), text = "{} {}".format(self.__localization.getWord('password'), self.__localization.getWord('contains_invalid_value')), buttonsText=[self.__localization.getWord('ok')]) return False return True
def _doFieldsCheck(self, name, comments): if not self.__dbManager.checkEntryData(name, DataField.NAME): md.showError( self._view, title=self.__localization.getWord('invalid_value'), text="{} {}".format( self.__localization.getWord('name'), self.__localization.getWord('contains_invalid_value')), buttonsText=[self.__localization.getWord('ok')]) return False if not self.__dbManager.checkEntryData(comments, DataField.COMMENTS): md.showError( self._view, title=self.__localization.getWord('invalid_value'), text="{} {}".format( self.__localization.getWord('comments'), self.__localization.getWord('contains_invalid_value')), buttonsText=[self.__localization.getWord('ok')]) return False return True
def addNewDB(self, data): logging.debug("Add new DB with data {}".format(data)) try: #create new DB add add it to DB manager #path, name, password, comments='') db = self.__dbManager.createDB(**data) #add new DB to config self.__userConfig.addDBForCurrentUser(data[DataField.PATH], data[DataField.PASSWORD]) #add to the panel categoryPanel = self.__view.getCategoryPanel() categoryPanel.tree.insert( "", 'end', db.id, text=db.path, image=self.__getImage('db_disconnected_image'), open=True) except Exceptions.DataBaseException: md.showError(self.__view, title=self.__localization.getWord('invalid_value'), text=self.__localization.getWord('db_exist'), buttonsText=[self.__localization.getWord('ok')])
def quitApp(self, data): logging.debug("Quitting the application") if not data: self.__view.quit() else: #show confirmation dialog res = md.showYesNo( self.__view, title=self.__localization.getWord('quit'), text=self.__localization.getWord('do_you_want_to_quit_app'), buttonsText=[ self.__localization.getWord('yes'), self.__localization.getWord('no') ]) if res: self.__view.quit()
def connectDB(self, data): """ Connect to the given database @type data: DataBase @param data: reference of the database to which to connect """ logging.debug("Connecting to DB {}".format(data)) db = self.__getCurrDB() #do checks if not db: return if db.status == DBStatus.CONNECTED: return categoryPanel = self.__view.getCategoryPanel() try: db.connect() #load root content to panels self.__loadSubcategoriesToPanel(db.id, None) self.__loadRecordsToPanel(db.id, None) #change DB image to connected categoryPanel.tree.item( db.id, open=True, image=self.__getImage('db_connected_image')) #change text to db name if setting if (self.__userConfig.getCurrentUserSetting( DataField.CHANGE_DB_PATH_TO_NAME_AFTER_CONN)): categoryPanel.tree.item(db.id, text=db.name) self.__notifier.sendSignal(Signal.DB_SELECTED_CHANGED, db) except Exceptions.NoFileException: md.showError(self.__view, title=self.__localization.getWord('invalid_value'), text="{} {} {}".format( self.__localization.getWord('database_with_file'), db.path, self.__localization.getWord('no_exist')), buttonsText=[self.__localization.getWord('ok')]) except Exceptions.DataBaseException: md.showError( self.__view, title=self.__localization.getWord('invalid_value'), text="{} {} {}".format( self.__localization.getWord('can_not_connect_to_db'), db.path, self.__localization.getWord('corrupted')), buttonsText=[self.__localization.getWord('ok')]) except Exceptions.WrongPasswordException: md.showError( self.__view, title=self.__localization.getWord('invalid_value'), text=self.__localization.getWord('wrong_password_provided'), buttonsText=[self.__localization.getWord('ok')])
def removeDBFromConfig(self, data): logging.debug("Removing DB from config") res = md.showYesNo( self.__view, title=self.__localization.getWord('removing_db'), text=self.__localization.getWord('remove_db_from_config_question'), buttonsText=[ self.__localization.getWord('yes'), self.__localization.getWord('no') ]) if res: if self.__currentDB: #remove from category panel categoryPanel = self.__view.getCategoryPanel() categoryPanel.tree.delete(self.__currentDB.id) #remove from DB manager id = self.__currentDB.id path = self.__currentDB.path self.__dbManager.deleteDB(id) self.__setCurrentDB(None) #remove from userConfig self.__userConfig.removeDBFromCurrentUser(path) logging.debug("Removing DB from config successfully")
def _checkData(self): """Check if the user provided valid data""" #get the values from entries site = self._view.getSite() if len(site) == 0: md.showError(self._view, title = self.__localization.getWord('invalid_value'), text = self.__localization.getWord('site_empty'), buttonsText=[self.__localization.getWord('ok')]) return False if not self.__dbManager.checkEntryData(site, DataField.SITE): md.showError(self._view, title = self.__localization.getWord('invalid_value'), text = "{} {}".format(self.__localization.getWord('site'), self.__localization.getWord('contains_invalid_value')), buttonsText=[self.__localization.getWord('ok')]) return False username = self._view.getSite() if not self.__dbManager.checkEntryData(username, DataField.USERNAME): md.showError(self._view, title = self.__localization.getWord('invalid_value'), text = "{} {}".format(self.__localization.getWord('username'), self.__localization.getWord('contains_invalid_value')), buttonsText=[self.__localization.getWord('ok')]) return False email = self._view.getEmail() if not self.__dbManager.checkEntryData(email, DataField.EMAIL): md.showError(self._view, title = self.__localization.getWord('invalid_value'), text = "{} {}".format(self.__localization.getWord('email'), self.__localization.getWord('contains_invalid_value')), buttonsText=[self.__localization.getWord('ok')]) return False password = self._view.getPassword() if not self.__dbManager.checkEntryData(password, DataField.PASSWORD): md.showError(self._view, title = self.__localization.getWord('invalid_value'), text = "{} {}".format(self.__localization.getWord('password'), self.__localization.getWord('contains_invalid_value')), buttonsText=[self.__localization.getWord('ok')]) return False comments = self._view.getComments() if not self.__dbManager.checkEntryData(comments, DataField.COMMENTS): md.showError(self._view, title = self.__localization.getWord('invalid_value'), text = "{} {}".format(self.__localization.getWord('comments'), self.__localization.getWord('contains_invalid_value')), buttonsText=[self.__localization.getWord('ok')]) return False return True
def notImplementedYet(self, data): md.showError(self.__view, title=self.__localization.getWord('not_implemented'), text=self.__localization.getWord('not_yet_available'), buttonsText=[self.__localization.getWord('ok')])
def registerPress(self): #get entered information login = self.__view.getLoginEntry().get() password = self.__view.getPasswordEntry().get() confirmPassword = self.__view.getConfirmPasswordEntry().get() #check if not 0 in length if len(login) == 0: #showerror(self.__localization.getWord('invalid_login'), # self.__localization.getWord('login_at_least_1_symbol')) md.showError( self.__view, title=self.__localization.getWord('invalid_value'), text=self.__localization.getWord('login_at_least_1_symbol'), buttonsText=[self.__localization.getWord('ok')]) return #check if user doesn't contains correct symbols if not self.__userConfig.checkNewLogin(login): # showerror(self.__localization.getWord('invalid_symbols'), # "{}. \n{} {}".format( # self.__localization.getWord('login_contains_invalid_symbols'), # self.__localization.getWord('should_be_only'), # self.__localization.getWord('login_valid_symbols') # )) md.showError( self.__view, title=self.__localization.getWord('invalid_value'), text="{} {}. \n{} {}".format( self.__localization.getWord('login'), self.__localization.getWord('contains_invalid_value'), self.__localization.getWord('should_be_only'), self.__localization.getWord('login_valid_symbols')), buttonsText=[self.__localization.getWord('ok')]) return #check if there is no such user in the config DB if self.__userConfig.userExist(login): #showerror(self.__localization.getWord('duplicate_login'), # self.__localization.getWord('user_exist')) md.showError(self.__view, title=self.__localization.getWord('duplicate_login'), text=self.__localization.getWord('user_exist'), buttonsText=[self.__localization.getWord('ok')]) return #check length of the password if len(password) == 0: #showerror(self.__localization.getWord('invalid_password'), # self.__localization.getWord('password_at_least_1_symbol')) md.showError( self.__view, title=self.__localization.getWord('invalid_password'), text=self.__localization.getWord('password_at_least_1_symbol'), buttonsText=[self.__localization.getWord('ok')]) return #check if the password contains correct symbols if not self.__userConfig.checkNewPassword(password): # showerror(self.__localization.getWord('invalid_symbols'), # "{}. \n{} {}".format( # self.__localization.getWord('password_contains_invalid_symbols'), # self.__localization.getWord('should_be_only'), # self.__localization.getWord('password_valid_symbols') # )) md.showError( self.__view, title=self.__localization.getWord('invalid_symbols'), text="{} {}. \n{} {}".format( self.__localization.getWord('password'), self.__localization.getWord('contains_invalid_value'), self.__localization.getWord('should_be_only'), self.__localization.getWord('password_valid_symbols')), buttonsText=[self.__localization.getWord('ok')]) return #check if password and confirm match if password != confirmPassword: #showerror(self.__localization.getWord('mismatch'), # self.__localization.getWord('password_confirm_mismatch') ) md.showError( self.__view, title=self.__localization.getWord('mismatch'), text=self.__localization.getWord('password_confirm_mismatch'), buttonsText=[self.__localization.getWord('ok')]) return #add new user try: self.__userConfig.addNewUser(login, password) except Exceptions.NotUniqueValueException: #showerror(self.__localization.getWord('duplicate_login'), # self.__localization.getWord('user_exist')) md.showError(self.__view, title=self.__localization.getWord('duplicate_login'), text=self.__localization.getWord('user_exist'), buttonsText=[self.__localization.getWord('ok')]) return #send signal self.__notifier.sendSignal(Signal.NEW_USER_REGISTER_OK, (login, password)) #close register dialog self.__view.destroy()