def __init__(self, master=None, **kwargs): # Set the custom attributes and pop'em out self.max_length = kwargs.pop('max_length', None) self.on_change = kwargs.pop('on_change', None) self.paste_filter = kwargs.pop('paste_filter', None) # Initialize the frame super().__init__(master, **kwargs) # Set up our custom widget self.entry = Entry(self) self.entry.bind('<KeyRelease>', self.change) if self.max_length: self.entry.config(width=self.max_length) self.entry.grid(row=0, column=0) # Erase code button self.erase = Button(self, image=load_png('backspace'), command=self.clear) self.erase.grid(row=0, column=1) # Paste code button self.paste = Button(self, image=load_png('clipboard'), command=self.paste) self.paste.grid(row=0, column=2)
def create_widgets(self): # Title label self.title = Label(self, text='Backup generation for {}'.format(self.display), font='-weight bold -size 18', padding=(16, 0, 16, 16)) self.title.grid(row=0, columnspan=2) # -- Left column self.left_column = Frame(self, padding=(16, 0)) self.left_column.grid(row=1, column=0, sticky=NE) # Resume/pause backup download self.resume_pause = ToggleButton(self.left_column, text='Resume', image=load_png('resume'), checked_text='Pause', checked_image=load_png('pause'), on_toggle=self.resume_pause_backup) self.resume_pause.grid(row=0, sticky=NE) # Save (download) media self.save_media = ToggleButton(self.left_column, text='Save media', image=load_png('download'), checked_text='Cancel', checked_image=load_png('cancel'), on_toggle=self.prompt_save_media) self.save_media_dialog_shown = False self.save_media.grid(row=1, sticky=N) # Export backup self.export = Button(self.left_column, text='Export', image=load_png('export'), compound=LEFT, command=self.do_export) self.export.grid(row=2, sticky=NE) # Delete saved backup self.delete = Button(self.left_column, text='Delete', image=load_png('delete'), compound=LEFT, command=self.delete_backup) self.delete.grid(row=3, sticky=NE) # Margin label self.margin = Label(self.left_column) self.margin.grid(row=4, sticky=NE) # Go back self.back = Button(self.left_column, text='Back', image=load_png('back'), compound=LEFT, command=self.go_back) self.back.grid(row=5, sticky=NE) # -- Right column self.right_column = Frame(self) self.right_column.grid(row=1, column=1, sticky=NSEW) # Let this column (0) expand and contract with the window self.right_column.columnconfigure(0, weight=1) # Entity card showing stats self.entity_card = EntityCard(self.right_column, entity=self.entity, padding=16) self.entity_card.grid(row=0, sticky=EW) # Right bottom column self.bottom_column = Frame(self.right_column, padding=(0, 16, 0, 0)) self.bottom_column.grid(row=1, sticky=EW) # Let this column (0) also expand and contract with the window self.bottom_column.columnconfigure(0, weight=1) # Estimated time left self.etl = Label(self.bottom_column, text='Estimated time left: {}' .format(self.backuper.metadata.get('etl', '???'))) self.etl.grid(row=0, sticky=W) # Download progress bar self.progress = Progressbar(self.bottom_column) self.progress.grid(row=1, sticky=EW) # Downloaded messages/total messages self.text_progress = Label(self.bottom_column, text='???/??? messages saved') self.text_progress.grid(row=2, sticky=E) # Keep a tuple with all the buttons for easy access self.buttons = (self.resume_pause, self.save_media, self.export, self.delete, self.back)