def load_config(path=None): try: Util.check_masters() except Exception as e: log('check_masters', str(e)) pass if not path: path = get_file("Select a master file: ", Util.CONFIG_ROOT, Util.CONFIG_EXT) config = None with open(path, 'r') as f: config = json.loads(f.read()) config['path'] = path return config
def get_sheet(self, caller, key): if self.job: self.job.caller = caller Picker(get_options=lambda: Util.get_sheet_name(self.job, key), return_callback=lambda e=caller: self.job.validate(e), return_view=self.content, master=self).show()
def get_column(self, caller, key): if self.job: self.job.caller = caller Picker(get_options=lambda: Util.get_column_names(self.job, key), return_callback=self.job.validate, return_view=self.content, master=self).show()
def fill_cols(self, caller, key): if self.job: self.job.caller = caller Split(key, get_options=lambda: Util.get_column_names(self.job, key), return_callback=self.__fill_cols, return_view=self.content, master=self).show()
def add(self): key = 'add_col' print 'showing split' Split(key, get_options=lambda: Util.get_column_names(self.job, key), return_callback=self.__add, return_view=self.content, master=self.parent).show()
def get_file(self, path, ext, callback): if self.showing == None: prompt = "Select a master file to load." picker = Picker( get_options=lambda: Util.get_file_list(path, ext), return_callback=lambda e: self.__get_file(e, callback), return_view=self.content, master=self, prompt=prompt) self.showing = picker picker.show()
def show(self, command): if command in self.showing: return win = Toplevel() win.wm_title("%s Help" % command.title()) self.showing[command] = win self.image = PhotoImage(file=Util.get_resource('%s.gif' % command)) image = Label(win, image=self.image) image.pack() text = Util.get_help_text(command) label = Label(win, text=text) label.pack(fill=X) b = Button(win, text="Close", command=lambda: self.close(win)) b.pack()
def select_file(self, col): self.show() key = 'filters' prompt = 'Please select a that contains the desired filters.' Split(key, column=col, get_options=lambda: Util.get_file_list(Util.FILTER_ROOT, Util. FILTER_EXT), return_callback=self.add_file_callback, return_view=self.content, master=self.parent, prompt=prompt).show()
def select_values(self, col): self.show() key = 'filters' path = 'source_file' sheet = 'source_tab' prompt = 'Please double click values to move them. \nThe values in the right column are selected and will be used in filtering.' Split(key, column=col, get_options=lambda: Util.get_values(self.job, path, sheet, col), return_callback=self.add_callback, return_view=self.content, master=self.parent, prompt=prompt).show()
def load_config(self, config=None): Util.check_masters() if self.display and self.display.job: tkMessageBox.showinfo( "Warning", "Please submit or cancel the current task before changing files." ) return if config and len(config) == 2: index, options = config name = options[index] full_path = options[index] try: with open(full_path, 'r') as f: self.config = json.loads(f.read()) self.config['path'] = full_path self.ribbon.update_file_label(name) self.summary.show_actions() except Exception as e: print(e) else: if self.display: self.display.get_file(Util.CONFIG_ROOT, Util.CONFIG_EXT, self.load_config)
def get_name(self, caller): if self.job: self.job.caller = caller f = Free(return_callback=self.job.validate, return_view=self.content, master=self) f.show() try: count = len(self.parent.config['work'][self.job.action]) choice = Util.get_output_name(self.job, count + 1) except: choice = None f.set_default_text(choice if choice else Util.DEFAULT_PROMPT) f.entry.focus() f.entry.select_range(0, END)
def __list_options(self): self.rebuild() scrollbar = Scrollbar(self.content) scrollbar.pack(side=RIGHT, fill=Y) prompt = "List of filters to be applied.\nFORMAT (Column Name:Column Value).\nFilter files have a grey background." Label(self.content, text=prompt).pack(fill=X, padx=10, pady=10) self.listbox = Listbox(self.content) self.listbox.pack(fill=BOTH, expand=1) self.listbox.config(yscrollcommand=scrollbar.set) scrollbar.config(command=self.listbox.yview) self.__write_list(self.options) sv = StringVar() sv.trace("w", lambda name, index, mode, sv=sv: self.filter_listbox(sv)) self.entry = Entry(self.content, textvariable=sv) self.entry.pack(fill=X) buttons = Frame(self.content) buttons.pack() back = Button(buttons, text='Done', command=self.hide) back.pack(fill=X, side=LEFT, padx=10, pady=10) clear = Button(buttons, text='Clear', command=self.clear_entry) clear.pack(fill=X, side=LEFT, padx=10, pady=10) delete = Button(buttons, text='Remove', command=self.remove) delete.pack(fill=X, side=LEFT, padx=10, pady=10) prompt = 'Choose a column to filter on.\nClick a column and then click submit to make a selection. \nYou can double click a row to submit.' p = Picker(get_options=lambda: Util.get_column_names(self.job, 0), return_callback=self.add, return_view=self.content, master=self.parent, prompt=prompt) add = Button(buttons, text='Add', command=p.show) add.pack(fill=X, side=LEFT, padx=10, pady=10)