(self, kdb_file=None, remote = False)
The main loop. The program alway return to this method.
The main loop. The program alway return to this method.
The main loop . The program alway return to this method .
def main_loop(self, kdb_file=None, remote = False):
        '''The main loop. The program alway return to this method.'''

        if remote is True:
            self.remote_interface()
        else:
            # This is needed to remember last database and open it directly
            self.get_last_db()

            if kdb_file is not None:
                self.cur_dir = kdb_file
                if self.open_db(True) is True:
                    db = DBBrowser(self)
                    del db
                    last = self.cur_dir.split('/')[-1]
                    self.cur_dir = self.cur_dir[:-len(last) - 1]
            elif self.last_file is not None and self.config['rem_db'] is True:
                self.cur_dir = self.last_file
                if self.open_db(True) is True:
                    db = DBBrowser(self)
                    del db
                    last = self.cur_dir.split('/')[-1]
                    self.cur_dir = self.cur_dir[:-len(last) - 1]

        while True:
            self.get_last_db()
            menu = self.gen_menu(1, ((1, 0, 'Open existing database (1)'),
                                  (2, 0, 'Create new database (2)'),
                                  (3, 0, 'Connect to a remote database(3)'),
                                  (4, 0, 'Configuration (4)'),
                                  (5, 0, 'Quit (5)')),
                                 (7, 0, 'Type \'F1\' for help inside the editor, '
                                        'file or database browser.'),
                                 (8, 0, 'Type \'F5\' to return to the previous'
                                        ' dialog at any time.'))
            if menu == 1:
                if self.open_db() is False:
                    continue
                db = DBBrowser(self)
                del db
                last = self.cur_dir.split('/')[-1]
                self.cur_dir = self.cur_dir[:-len(last) - 1]
            elif menu == 2:
                while True:
                    auth = self.gen_menu(1, (
                                         (1, 0, 'Use a password (1)'),
                                         (2, 0, 'Use a keyfile (2)'),
                                         (3, 0, 'Use both (3)')))
                    password = None
                    confirm = None
                    filepath = None
                    self.db = KPDBv1(new=True)
                    if auth is False:
                        break
                    elif auth == -1:
                        self.db = None
                        self.close()
                    if auth == 1 or auth == 3:
                        while True:
                            password = self.get_password('Password: ')
                            if password is False:
                                break
                            elif password == -1:
                                self.db = None
                                self.close()
                            confirm = self.get_password('Confirm: ')
                            if confirm is False:
                                break
                            elif confirm == -1:
                                self.db = None
                                self.close()
                            if password == confirm:
                                self.db.password = password
                                break
                            else:
                                self.draw_text(False,
                                               (1, 0,
                                                'Passwords didn\' match!'),
                                               (3, 0, 'Press any key'))
                                if self.any_key() == -1:
                                    self.db = None
                                    self.close()
                        if auth != 3:
                            self.db.keyfile = None
                    if password is False or confirm is False:
                        continue
                    if auth == 2 or auth == 3:
                        while True:
                            filepath = FileBrowser(self, False, True, None)()
                            if filepath is False:
                                break
                            elif filepath == -1:
                                self.close()
                            elif not isfile(filepath):
                                self.draw_text(False,
                                               (1, 0, 'That\' not a file!'),
                                               (3, 0, 'Press any key'))
                                if self.any_key() == -1:
                                    self.db = None
                                    self.close()
                                continue
                            break
                        if filepath is False:
                            continue
                        self.db.keyfile = filepath
                        if auth != 3:
                            self.db.password = None

                    if auth is not False:
                        db = DBBrowser(self)
                        del db
                        last = self.cur_dir.split('/')[-1]
                        self.cur_dir = self.cur_dir[:-len(last) - 1]
                    else:
                        self.db = None
                    break
            elif menu == 3:
                self.remote_interface()
            elif menu == 4:
                self.gen_config_menu()
            elif menu == 5 or menu is False or menu == -1:
                self.close()
def main_loop ( self , kdb_file = None , remote = False ) : if remote is True : self . remote_interface ( ) else : # This is needed to remember last database and open it directly self . get_last_db ( ) if kdb_file is not None : self . cur_dir = kdb_file if self . open_db ( True ) is True : db = DBBrowser ( self ) del db last = self . cur_dir . split ( '/' ) [ - 1 ] self . cur_dir = self . cur_dir [ : - len ( last ) - 1 ] elif self . last_file is not None and self . config [ 'rem_db' ] is True : self . cur_dir = self . last_file if self . open_db ( True ) is True : db = DBBrowser ( self ) del db last = self . cur_dir . split ( '/' ) [ - 1 ] self . cur_dir = self . cur_dir [ : - len ( last ) - 1 ] while True : self . get_last_db ( ) menu = self . gen_menu ( 1 , ( ( 1 , 0 , 'Open existing database (1)' ) , ( 2 , 0 , 'Create new database (2)' ) , ( 3 , 0 , 'Connect to a remote database(3)' ) , ( 4 , 0 , 'Configuration (4)' ) , ( 5 , 0 , 'Quit (5)' ) ) , ( 7 , 0 , 'Type \'F1\' for help inside the editor, ' 'file or database browser.' ) , ( 8 , 0 , 'Type \'F5\' to return to the previous' ' dialog at any time.' ) ) if menu == 1 : if self . open_db ( ) is False : continue db = DBBrowser ( self ) del db last = self . cur_dir . split ( '/' ) [ - 1 ] self . cur_dir = self . cur_dir [ : - len ( last ) - 1 ] elif menu == 2 : while True : auth = self . gen_menu ( 1 , ( ( 1 , 0 , 'Use a password (1)' ) , ( 2 , 0 , 'Use a keyfile (2)' ) , ( 3 , 0 , 'Use both (3)' ) ) ) password = None confirm = None filepath = None self . db = KPDBv1 ( new = True ) if auth is False : break elif auth == - 1 : self . db = None self . close ( ) if auth == 1 or auth == 3 : while True : password = self . get_password ( 'Password: ' ) if password is False : break elif password == - 1 : self . db = None self . close ( ) confirm = self . get_password ( 'Confirm: ' ) if confirm is False : break elif confirm == - 1 : self . db = None self . close ( ) if password == confirm : self . db . password = password break else : self . draw_text ( False , ( 1 , 0 , 'Passwords didn\' match!' ) , ( 3 , 0 , 'Press any key' ) ) if self . any_key ( ) == - 1 : self . db = None self . close ( ) if auth != 3 : self . db . keyfile = None if password is False or confirm is False : continue if auth == 2 or auth == 3 : while True : filepath = FileBrowser ( self , False , True , None ) ( ) if filepath is False : break elif filepath == - 1 : self . close ( ) elif not isfile ( filepath ) : self . draw_text ( False , ( 1 , 0 , 'That\' not a file!' ) , ( 3 , 0 , 'Press any key' ) ) if self . any_key ( ) == - 1 : self . db = None self . close ( ) continue break if filepath is False : continue self . db . keyfile = filepath if auth != 3 : self . db . password = None if auth is not False : db = DBBrowser ( self ) del db last = self . cur_dir . split ( '/' ) [ - 1 ] self . cur_dir = self . cur_dir [ : - len ( last ) - 1 ] else : self . db = None break elif menu == 3 : self . remote_interface ( ) elif menu == 4 : self . gen_config_menu ( ) elif menu == 5 or menu is False or menu == - 1 : self . close ( )