def insert_or_update_distribution(self): if self.distr_name.get(): if self.distr_record: # update did = self.distr_record.did kwargs = { 'name': self.distr_name.get(), 'system_id': self.system.get(), } try: save_data(DistSet, did, **kwargs) except BabelError as e: messagebox.showerror( 'Database error', f'Something went wrong:\n{e}') else: user_id = get_id_from_index( self.profile.get(), self.profile_idx) kwargs = { 'name': self.distr_name.get(), 'system_id': self.system.get(), 'user_id': user_id } try: save_data(DistSet, **kwargs) # update gui self.distr_record = get_record(DistSet, **kwargs) except BabelError as e: messagebox.showerror( 'Database error', f'Something went wrong:\n{e}') # refresh distributions list self.update_distributionLst() disable_widgets([self.distnameEnt])
def save_access(self): missing = [] if not self.db_name.get().strip(): missing.append('db name') if not self.user.get().strip(): missing.append('user') if not self.passw.get().strip(): missing.append('password') if not self.host.get().strip(): missing.append('host') if not self.port.get().strip(): missing.append('port') if not missing: user_data = shelve.open(USER_DATA) db_config = dict(db_name=self.db_name.get().strip(), user=self.user.get().strip(), host=self.host.get().strip(), port=self.port.get().strip()) user_data['db_config'] = db_config user_data.close() # save password try: store_in_vault(self.db_name.get().strip(), self.user.get().strip(), self.passw.get().strip()) except BabelError as e: mlogger.error(f'DB store_in_vault error. Error: {e}') disable_widgets(self.detFrm.winfo_children()) else: messagebox.showwarning( 'Input Error', 'Missing element(s): \n -{}'.format('\n -'.join(missing)))
def userDetailFrame(self, name='', bpl_code='', nyp_code=''): mlogger.debug('userDetailFrame activated.') if bpl_code is None: bpl_code = '' if nyp_code is None: nyp_code = '' Label(self.detFrm, text='user').grid( row=0, column=0, sticky='snw', padx=5, pady=5) Label(self.detFrm, text='BPL code').grid( row=1, column=0, sticky='snw', padx=5, pady=5) Label(self.detFrm, text='NYPL code').grid( row=2, column=0, sticky='snw', padx=5, pady=5) self.nameEnt = Entry( self.detFrm, font=RFONT) self.nameEnt.grid( row=0, column=1, columnspan=3, padx=5, pady=5) self.bplcodeEnt = Entry( self.detFrm, font=RFONT) self.bplcodeEnt.grid( row=1, column=1, columnspan=3, padx=5, pady=5) self.nypcodeEnt = Entry( self.detFrm, font=RFONT) self.nypcodeEnt.grid( row=2, column=1, columnspan=3, padx=5, pady=5) self.nameEnt.insert(0, name) self.bplcodeEnt.insert(0, bpl_code) self.nypcodeEnt.insert(0, nyp_code) disable_widgets( [self.nameEnt, self.bplcodeEnt, self.nypcodeEnt])
def mattypeDetailFrame( self, name='', bpl_bib_code='', bpl_ord_code='', nyp_bib_code='', nyp_ord_code=''): mlogger.debug('mattypeDetailFrame activated.') if bpl_bib_code is None: bpl_bib_code = '' if bpl_ord_code is None: bpl_ord_code = '' if nyp_bib_code is None: nyp_bib_code = '' if nyp_ord_code is None: nyp_ord_code = '' Label(self.detFrm, text='name').grid( row=0, column=0, sticky='snw', padx=5, pady=5) Label(self.detFrm, text='BPL bib code').grid( row=1, column=0, sticky='snw', padx=5, pady=5) Label(self.detFrm, text='BPL ord code').grid( row=2, column=0, sticky='snw', padx=5, pady=5) Label(self.detFrm, text='NYP bib code').grid( row=3, column=0, sticky='snw', padx=5, pady=5) Label(self.detFrm, text='NYP ord code').grid( row=4, column=0, sticky='snw', padx=5, pady=5) self.nameEnt = Entry( self.detFrm, font=RFONT) self.nameEnt.grid( row=0, column=1, columnspan=3, padx=5, pady=5) self.bplbibcodeEnt = Entry( self.detFrm, font=RFONT,) self.bplbibcodeEnt.grid( row=1, column=1, columnspan=3, padx=5, pady=5) self.bplordcodeEnt = Entry( self.detFrm, font=RFONT,) self.bplordcodeEnt.grid( row=2, column=1, columnspan=3, padx=5, pady=5) self.nypbibcodeEnt = Entry( self.detFrm, font=RFONT,) self.nypbibcodeEnt.grid( row=3, column=1, columnspan=3, padx=5, pady=5) self.nypordcodeEnt = Entry( self.detFrm, font=RFONT,) self.nypordcodeEnt.grid( row=4, column=1, columnspan=3, padx=5, pady=5) self.nameEnt.insert(0, name) self.bplbibcodeEnt.insert(0, bpl_bib_code) self.bplordcodeEnt.insert(0, bpl_ord_code) self.nypbibcodeEnt.insert(0, nyp_bib_code) self.nypordcodeEnt.insert(0, nyp_ord_code) disable_widgets([ self.nameEnt, self.bplbibcodeEnt, self.bplordcodeEnt, self.nypbibcodeEnt, self.nypordcodeEnt])
def system_observer(self, *args): if self.activeW.get() == 'ReportWizView': if self.system.get() == 1: self.library.set('branches') disable_widgets([self.libCbx]) else: enable_widgets([self.libCbx]) self.libCbx['state'] = 'readonly' self.library.set('any')
def create_loc_widgets(self, locs=[(None, '', '', '')]): # reset locations dictionary self.locations = OrderedDict() self.delete_locations = [] self.last_row = 0 for loc in locs: self.create_loc_unit(loc) self.create_add_locationBtn() disable_widgets([self.gridEnt]) disable_widgets(self.locFrm.winfo_children())
def insert_or_update_data(self): missing = [] if not self.system.get(): missing.append('system') if not self.fund_code.get(): missing.append('fund code') if not self.branchInLst.get(0, END): missing.append('valid branches') if self.system.get() == 2 and not self.libInLst.get(0, END): missing.append('valid library') if not self.audnInLst.get(0, END): missing.append('valid audiences') if not self.mattypeInLst.get(0, END): missing.append('valid material types') if not missing: self.cur_manager.busy() try: if self.system.get() == 1: libraries = ['branches'] else: libraries = self.libInLst.get(0, END) kwargs = dict(system_id=self.system.get(), code=self.fund_code.get().strip(), describ=self.fund_desc.get().strip(), branches=self.branchInLst.get(0, END), libraries=libraries, audns=self.audnInLst.get(0, END), matTypes=self.mattypeInLst.get(0, END)) if not self.record: try: self.record = insert_fund(**kwargs) except BabelError as e: messagebox.showerror('Save Error', e) else: kwargs['did'] = self.record.did try: update_fund(**kwargs) except BabelError as e: messagebox.showerror('Update Error', e) self.display_funds() disable_widgets(self.detFrm.winfo_children()) except BabelError as e: self.cur_manager.notbusy() messagebox.showerror(e) finally: self.cur_manager.notbusy() else: msg = 'Missing requried elements:\n-{}'.format('\n-'.join(missing)) messagebox.showwarning('Input Error', msg)
def show_frame(self, page_name): """show frame for the given page name""" self.activeW.set(page_name) mlogger.debug("show_frame activewW: {}".format(self.activeW.get())) # disable system switching when appropriate if self.activeW.get() in ["CartView", "SettingsView"]: disable_widgets(self.app_data["systemBtns"]) else: enable_widgets(self.app_data["systemBtns"]) frame = self.frames[page_name] frame.tkraise()
def show_fund(self, *args): mlogger.debug('Displaying fund details.') self.cur_manager.busy() enable_widgets(self.detFrm.winfo_children()) self.record = get_record(Fund, code=self.fundLst.get(ACTIVE)) self.display_branches() self.display_library() self.display_audiences() self.display_mattypes() fund_data = get_fund_data(self.record) mlogger.debug('Fund data: {}'.format(fund_data)) # display code & description self.fund_code.set(fund_data['code']) self.fund_desc.set(fund_data['describ']) # convert values to listbox indices and add conditions # branchLst branch_idx = self.get_listbox_indices('branches', self.branchOutLst, fund_data['branches']) mlogger.debug('branchOutLst index matches: {}'.format(branch_idx)) self.add_condition('branchLst', self.branchOutLst, self.branchInLst, branch_idx) # audnLst audn_idx = self.get_listbox_indices('audns', self.audnOutLst, fund_data['audns']) mlogger.debug('audnOutLst index matches: {}'.format(audn_idx)) self.add_condition('audnLst', self.audnOutLst, self.audnInLst, audn_idx) # libLst library_idx = self.get_listbox_indices('libraries', self.libOutLst, fund_data['libraries']) mlogger.debug('libOutLst index matches: {}'.format(library_idx)) self.add_condition('libLst', self.libOutLst, self.libInLst, library_idx) if self.system.get() == 1: disable_widgets(self.libraryFrm.winfo_children()) # mattypeOutLst mattype_idx = self.get_listbox_indices('mattypes', self.mattypeOutLst, fund_data['matTypes']) mlogger.debug('mattypeOutLst index matches: {}'.format(mattype_idx)) self.add_condition('mattypeLst', self.mattypeOutLst, self.mattypeInLst, mattype_idx) # lock the interface disable_widgets(self.detFrm.winfo_children()) self.cur_manager.notbusy()
def add_data(self): if self.system.get(): self.record = None self.fund_code.set('') self.fund_desc.set('') enable_widgets(self.detFrm.winfo_children()) self.display_branches() self.display_library() self.display_audiences() self.display_mattypes() else: msg = 'Please select system first.' messagebox.showwarning('Input Error', msg) if self.system.get() == 1: disable_widgets(self.libraryFrm.winfo_children())
def show_distribution(self, *args): name = self.distLst.get(ACTIVE) self.distr_name.set(name) self.distr_record = get_record( DistSet, name=name, system_id=self.system.get(), user_id=get_id_from_index( self.profile.get(), self.profile_idx)) # mlogger.debug(f'Selected Distr{self.distr_record}') self.update_gridLst() self.recreate_location_widgets() disable_widgets([self.distnameEnt])
def observer(self, *args): if self.activeW.get() == 'FundView': mlogger.debug('FundView: observer activated.') self.record = None self.fund_code.set('') self.fund_desc.set('') enable_widgets(self.detFrm.winfo_children()) self.all_branches.set(0) # pull data from data store only self.display_funds() self.display_audiences() self.display_mattypes() if self.system.get(): # self.display_branches() self.display_library() disable_widgets(self.detFrm.winfo_children())
def observer(self, *args): if self.activeW.get() == 'SettingsView': # pull & display data self.dialect.set(DB_DIALECT) self.driver.set(DB_DRIVER) self.chr_enc.set(DB_CHARSET) user_data = shelve.open(USER_DATA) db_config = user_data['db_config'] self.db_name.set(db_config['db_name']) self.user.set(db_config['user']) self.host.set(db_config['host']) self.port.set(db_config['port']) user_data.close() self.passw.set('dummy passw') disable_widgets(self.detFrm.winfo_children())
def shelfcodeDetailFrame(self, name='', code='', includes_audn=True): mlogger.debug('shelfcodeDetailFrame activated.') self.includes_audn = IntVar() if includes_audn: self.includes_audn.set(1) else: self.includes_audn.set(0) if code is None: code = '' Label(self.detFrm, text='name').grid( row=0, column=0, sticky='snw', padx=5, pady=5) Label(self.detFrm, text='code').grid( row=1, column=0, sticky='snw', padx=5, pady=5) Label(self.detFrm, text='includes audn code').grid( row=2, column=0, sticky='snw', padx=5, pady=5) self.nameEnt = Entry( self.detFrm, font=RFONT) self.nameEnt.grid( row=0, column=1, columnspan=3, padx=5, pady=5) self.codeEnt = Entry( self.detFrm, font=RFONT) self.codeEnt.grid( row=1, column=1, columnspan=3, padx=5, pady=5) self.includesaudnChx = Checkbutton( self.detFrm, variable=self.includes_audn, onvalue=1, offvalue=0) self.includesaudnChx.grid( row=2, column=1, columnspan=3, padx=5, pady=5) self.nameEnt.insert(0, name) self.codeEnt.insert(0, code) if includes_audn: self.includes_audn.set(1) else: self.includes_audn.set(0) disable_widgets( [self.nameEnt, self.codeEnt, self.includesaudnChx])
def simpleDetailFrame(self, name='', code=''): mlogger.debug('simpleDetailFrame activated.') if code is None: code = '' Label(self.detFrm, text='name').grid( row=0, column=0, sticky='snw', padx=5, pady=5) Label(self.detFrm, text='code').grid( row=1, column=0, sticky='snw', padx=5, pady=5) self.nameEnt = Entry( self.detFrm, font=RFONT) self.nameEnt.grid( row=0, column=1, columnspan=3, padx=5, pady=5) self.codeEnt = Entry( self.detFrm, font=RFONT,) self.codeEnt.grid( row=1, column=1, columnspan=3, padx=5, pady=5) self.nameEnt.insert(0, name) self.codeEnt.insert(0, code) disable_widgets([self.nameEnt, self.codeEnt])
def reset(self): self.distr_name.set('') self.grid_name.set('') self.distr_record = None self.grid_record = None self.locations = OrderedDict() self.delete_locations = [] self.last_row = 0 self.loc_tally.set('') self.update_gridLst() self.update_distributionLst() self.recreate_location_widgets() disable_widgets([self.distnameEnt]) disable_widgets([self.gridEnt]) disable_widgets(self.locFrm.winfo_children())
def observer(self, *args): if self.activeW.get() == 'GridView': user_data = shelve.open(USER_DATA) self.profile.set(user_data['profile']) user_data.close() # retireve datastore values and id to populate widgets # and create a quick reference if self.system.get(): self.branch_idx = create_code_index( Branch, system_id=self.system.get()) self.shelf_idx = create_code_index( ShelfCode, system_id=self.system.get()) self.recreate_location_widgets() disable_widgets([self.distnameEnt]) disable_widgets([self.gridEnt]) disable_widgets(self.locFrm.winfo_children())
def edit_data(self): if self.record: enable_widgets(self.detFrm.winfo_children()) if self.system.get() == 1: disable_widgets(self.libraryFrm.winfo_children())
def insert_or_update_data(self): # check what table it is mlogger.debug('Save btn clicked.') kwargs = {} error_msg = False try: if self.gen_list_select.get() in ( 'Audiences', 'Branches', 'Languages'): name = self.nameEnt.get().strip() code = self.codeEnt.get().strip() kwargs = { 'name': name, 'code': code} elif self.gen_list_select.get() in ( 'Users', 'Vendors'): name = self.nameEnt.get().strip() bpl_code = self.bplcodeEnt.get().strip() nyp_code = self.nypcodeEnt.get().strip() kwargs = { 'name': name, 'bpl_code': bpl_code, 'nyp_code': nyp_code} if self.gen_list_select.get() == 'Vendors': kwargs['note'] = self.noteEnt.get().strip() elif self.gen_list_select.get() == 'Shelf Codes': name = self.nameEnt.get().strip() code = self.codeEnt.get().strip() includes_audn = self.includes_audn.get() kwargs = { 'name': name, 'code': code, 'includes_audn': includes_audn} elif self.gen_list_select.get() == 'Material Types': name = self.nameEnt.get().strip() bpl_bib_code = self.bplbibcodeEnt.get().strip() bpl_ord_code = self.bplordcodeEnt.get().strip() nyp_bib_code = self.nypbibcodeEnt.get().strip() nyp_ord_code = self.nypordcodeEnt.get().strip() kwargs = { 'name': name, 'bpl_bib_code': bpl_bib_code, 'bpl_ord_code': bpl_ord_code, 'nyp_bib_code': nyp_bib_code, 'nyp_ord_code': nyp_ord_code } for k, v in kwargs.items(): if v == '': kwargs[k] = None model, kwargs = self.get_corresponding_model(**kwargs) except TclError: pass if self.record: mlogger.debug('Saving existing data.') try: save_data( model, did=self.record.did, **kwargs) except BabelError as e: error_msg = True messagebox.showerror('Database error', e) else: mlogger.debug('Saving new data.') if model is not None: try: save_data(model, **kwargs) except BabelError as e: messagebox.showerror('Database error', e) if model is not None and model.__name__ == 'User': messagebox.showwarning( 'Restart', 'For changes to Users to take effect\n' 'Babel needs to be restarted.\n' 'Please close and reopen Babel.') self.populate_detail_list(redo_detail_frame=False) if not error_msg: disable_widgets(self.detFrm.winfo_children())
def insert_or_update_grid(self): if self.distr_record: if self.grid_name.get(): if self.grid_record: grid_id = self.grid_record.did else: grid_id = None if self.delete_locations: for did in self.delete_locations: delete_data_by_did(GridLocation, did) gridlocs = [] total_qty = 0 total_loc = 0 for loc in self.locations.values(): gridlocs.append( dict( gridloc_id=loc['did'], distgrid_id=grid_id, branch=loc['branchCbx'].get().strip(), shelf=loc['shelfCbx'].get().strip(), qty=loc['qtySbx'].get() ) ) total_loc += 1 try: total_qty += int(loc['qtySbx'].get()) except ValueError: pass # update copy/branch tally self.update_tally(total_qty, total_loc) # validate valid, issues = self.validate_gridLocations(gridlocs) if valid: try: self.grid_record = save_grid_data( grid_did=grid_id, name=self.gridEnt.get().strip(), distset_id=self.distr_record.did, gridlocs=gridlocs, branch_idx=self.branch_idx, shelf_idx=self.shelf_idx, ) self.update_gridLst() disable_widgets([self.gridEnt]) disable_widgets(self.locFrm.winfo_children()) except BabelError as e: messagebox.showerror( 'Database Error', f'Something went wrong:\n{e}') else: messagebox.showerror( 'Validation Error', '\n'.join(issues)) else: messagebox.showwarning( 'Input Error', "Please enter grid's name")