def __init__(self, parent, name='Test Program'): Frame.__init__(self, parent.master) self.parent = parent self.name = name self.window = Panedwindow(self, orient=HORIZONTAL) self.lframe = Labelframe(self) self.lframe = TestprogramPane(self) self.rframe = Labelframe(self) self.rframe = PinsPane(self)
def open_base(root: tk.Tk, pane: ttk.Panedwindow, selected: int): """ Автор: Цель: открывает загруженную базу данных и создает для нее таблицу с полями, добавляя ее на главный экран Вход: объект главного окна, объект растягиваемого виджета, индекс базы в Listbox Выход: нет """ glob.current_base_list_id = selected glob.current_base, glob.current_base_name = glob.work_list.get( glob.base_list.get(selected).replace('*', '')), glob.base_list.get(selected) work_frame4check = create_workspace(root, pane) pane.forget(1) pane.add(work_frame4check, weight=10000)
class MainBody(Frame): ''' classdocs ''' def __init__(self, parent, name='Test Program'): Frame.__init__(self, parent.master) self.parent = parent self.name = name self.window = Panedwindow(self, orient=HORIZONTAL) self.lframe = Labelframe(self) self.lframe = TestprogramPane(self) self.rframe = Labelframe(self) self.rframe = PinsPane(self) def show(self): self.window.pack(fill=BOTH, expand=True) self.window.add(self.lframe, weight=1) self.window.add(self.rframe, weight=1)
def unload(self): self.parent.tp = None newBody = MainBody(self.parent.master) newBody.window = Panedwindow(self.parent.master, orient=HORIZONTAL) newBody.rframe = PinsPane(newBody.window, tp=None) newBody.lframe = TestprogramPane(newBody.window, tp=None) self.parent.mainBody.window.destroy() self.parent.mainBody.destroy() self.parent.mainBody = newBody self.parent.mainBody.show()
def close_event(pane: ttk.Panedwindow, save): """ Автор: Цель: закрывает открытую базу и показывает приглащение к открытию новой на правой стороне pane, save вызывается для сохранения базы, по решению пользователя Вход: pane - растягивающийся виджет, save - объект функции save_event из main Выход: нет """ # открыта ли база? if not glob.is_db_open(): return "break" # сохранена ли база? if not glob.is_saved(): ans = err.yes_no("Сохранить изменения?") if ans: save() glob.delete_current_base() pane.forget(1) pls_select_frame = show_invitation(pane) pane.add(pls_select_frame, weight=9)
def load(self): filepath = filedialog.askopenfile() fileHandler = FileHandler(filepath) self.tp = fileHandler.load(self.parent.tp) self.parent.tp = self.tp newBody = MainBody(self.parent.master) newBody.window = Panedwindow(self.parent.master, orient=HORIZONTAL) newBody.rframe = PinsPane(newBody.window, self.tp) newBody.lframe = TestprogramPane(newBody.window, self.tp) self.parent.mainBody.window.destroy() self.parent.mainBody.destroy() self.parent.mainBody = newBody self.parent.mainBody.show()
def remember_divider_positions( panedwindow: ttk.Panedwindow, option_name: str, defaults: List[int] ) -> None: # exist_ok=True to allow e.g. calling this once for each tab add_option(option_name, defaults, List[int], exist_ok=True) def settings2panedwindow(junk: object = None) -> None: value = get(option_name, List[int]) pane_count = len(panedwindow.panes()) # type: ignore[no-untyped-call] if len(value) == pane_count - 1: _log.info(f"setting panedwindow widths from {option_name} setting: {value}") # Prevent funny bug with invisible panes becoming huge # # TODO: figure out how to handle panes other than first pane # (need to know width of the dragging handle?) if value and value[0] == 0: value[0] = 1 for index, pos in enumerate(value): panedwindow.sashpos(index, pos) else: # number of panes can change if e.g. a plugin is enabled/disabled _log.info( f"{option_name} is set to {value}, of length {len(value)}, " f"but there are {pane_count} panes" ) def panedwindow2settings(junk: object) -> None: set_(option_name, [panedwindow.sashpos(i) for i in range(len(panedwindow.panes()) - 1)]) # type: ignore[no-untyped-call] # don't know why after_idle is needed, but it is panedwindow.bind( "<Map>", (lambda event: panedwindow.after_idle(settings2panedwindow)), add=True ) panedwindow.bind("<<DividersFromSettings>>", settings2panedwindow, add=True) panedwindow.bind("<ButtonRelease-1>", panedwindow2settings, add=True)
def __init__(self, root): self.config = Config("tkc.ini") root.title("Tkinter Commander") root.protocol("WM_DELETE_WINDOW", self.on_delete) self.root = root root.geometry(self.config.get("fm_geometry")) root.grid_columnconfigure(0, weight=1) root.grid_rowconfigure(1, weight=1) pw = Panedwindow(root, orient="horizontal", takefocus=False) frame = Frame(pw) self.left = Panel(frame, Local_fs(), self.config) pw.add(frame) pw.pane(frame, weight=1) frame = Frame(pw) self.right = Panel(frame, Local_fs(), self.config) self.right.oposite = ref(self.left) self.left.oposite = ref(self.right) self.left.activate() pw.add(frame) pw.pane(frame, weight=1) pw.grid(column=0, row=1, columnspan=2, sticky="senw") self.add_menu() self.add_btns() root.tk.call( "wm", "iconphoto", root._w, PhotoImage(file=join(dirname(__file__), "data", "favicon.gif")))
print("Complete!") window = Tk() window.title("Youtube Downloader") window.geometry('560x500') # Text title = Label(window, text="Youtube Downloader", font=("Roboto", 20)) title.grid(column=0, row=0, columnspan=5) title = Label(window, text=" ", font=("Roboto", 20)) title.grid(column=1, row=0) p = Panedwindow(window, orient=VERTICAL) p.grid(column=2, row=1, sticky="ew") source = Labelframe(p, text='Source', width=500, height=200) metadata = Labelframe(p, text='Metadata', width=500, height=200) destination = Labelframe(p, text='Destination', width=500, height=200) p.add(source) p.add(metadata) p.add(destination) source_text = Label( source, text='Source:', ) source_text.grid(row=1, column=0, rowspan=2, pady=10, padx=5) source_input = Entry(source, width=55)
def initUI(self): self.parent.title("PyWave") self.style = Style() self.style.theme_use("default") self.user_waves, self.user_labels = [], [] self.save_wave = True self.RF = None self.columnconfigure(1, weight=1) self.columnconfigure(3, pad=7) self.rowconfigure(3, weight=1) self.rowconfigure(5, pad=7) self.RFparams = { 'n_estimators': 100, 'random_state': 1, 'n_jobs': -1, 'max_depth': 7, 'oob_score': True, 'warm_start': True } #### Geometry #### abtn = Button(self.parent, text='Capture', command=self.capture_and_store) abtn.pack(side=BOTTOM, expand=1, fill='x') tbtn = Button(self.parent, text='Train', command=self.train_model) tbtn.pack(side=BOTTOM, expand=1, fill='x') cbtn = Button(self.parent, text='Close', command=self.quit) cbtn.pack(side=BOTTOM, expand=1, fill='x') hbtn = Button(self.parent, text='Predict on Capture', command=self.capture_and_plot) hbtn.pack(side=BOTTOM, expand=1, fill='x') p = Panedwindow(self.parent, orient=VERTICAL) p.pack(side=LEFT) f1 = Labelframe(p, text='Models', width=200, height=1000) p.add(f1) self.mdlist = Listbox(self.parent, height=900, width=400) self.mdlist.pack(side=LEFT) #### Creating top menu bars and callbacks #### menubar = Menu(self.parent) self.parent.config(menu=menubar) modelMenu = Menu(menubar, tearoff=0) menubar.add_cascade(label="Model", menu=modelMenu) modelMenu.add_command(label='Import Dataset', command=self.import_dataset) modelMenu.add_command(label='Import Model', command=self.import_model) modelMenu.add_command(label='Train Random Forest', command=self.rf) modelMenu.add_command(label='Train Gradient Boosted Classifier', command=self.gbc) modelMenu.add_command(label='Train K-Nearest Neighbors', command=self.knn) modelMenu.add_command(label='Save', command=self.saveas) modelMenu.add_command(label='Save as', command=self.saveas) waveMenu = Menu(menubar, tearoff=0) menubar.add_cascade(label="Waveform", menu=waveMenu) waveMenu.add_command(label="Import Waveform", command=self.import_waveform) waveMenu.add_command(label="Features", command=self.get_features)
def __init__(self, fileManager) -> None: super().__init__() # variable initiation self.gridsquarelist = [] self.hideonassignvar = tk.BooleanVar() self.hideonassignvar.set(True) self.hidemovedvar = tk.BooleanVar() self.showhiddenvar = tk.BooleanVar() self.squaresperpage = tk.IntVar() self.squaresperpage.set(120) self.sessionpathvar = tk.StringVar() self.imagewindowgeometry = str( int(self.winfo_screenwidth() * 0.80)) + "x" + str(self.winfo_screenheight() - 120) + "+365+60" # store the reference to the file manager class. self.fileManager = fileManager self.geometry( str(self.winfo_screenwidth() - 5) + "x" + str(self.winfo_screenheight() - 120)) self.geometry("+0+60") self.buttons = [] self.hotkeys = "123456qwerty7890uiop[asdfghjkl;zxcvbnm,.!@#$%^QWERT&*()_UIOPASDFGHJKLZXCVBNM<>" # Paned window that holds the almost top level stuff. self.toppane = Panedwindow(self, orient="horizontal") # Frame for the left hand side that holds the setup and also the destination buttons. self.leftui = tk.Frame(self.toppane) #self.leftui.grid(row=0, column=0, sticky="NESW") self.leftui.columnconfigure(0, weight=1) self.toppane.add(self.leftui, weight=1) self.panel = tk.Label( self.leftui, wraplength=300, justify="left", text="""Select a source directory to search for images in above. The program will find all png, gif, jpg, bmp, pcx, tiff, Webp, and psds. It can has as many sub-folders as you like, the program will scan them all (except exclusions). Enter a root folder to sort to for the "Destination field" too. The destination directory MUST have sub folders, since those are the folders that you will be sorting to. \d (unless you delete prefs.json). Remember that it's one per line, no commas or anything. You can change the hotkeys in prefs.json, just type a string of letters and numbers and it'll use that. It differentiates between lower and upper case (anything that uses shift), but not numpad. By default the program will only load a portion of the images in the folder for performance reasons. Press the "Add Files" button to make it load another chunk. You can configure how many it adds and loads at once in the program. Right-click on Destination Buttons to show which images are assigned to them. (Does not show those that have already been moved) Right-click on Thumbnails to show a zoomable full view. You can also **rename** images from this view. Thanks to FooBar167 on stackoverflow for the advanced (and memory efficient!) Zoom and Pan tkinter class. Thank you for using this program!""") self.panel.grid(row=1, column=0, columnspan=200, rowspan=200, sticky="NSEW") self.columnconfigure(0, weight=1) self.buttonframe = tk.Frame(master=self.leftui) self.buttonframe.grid(column=0, row=1, sticky="NSEW") self.buttonframe.columnconfigure(0, weight=1) self.entryframe = tk.Frame(master=self.leftui) self.entryframe.columnconfigure(1, weight=1) self.sdpEntry = tk.Entry(self.entryframe, takefocus=False) # scandirpathEntry self.ddpEntry = tk.Entry(self.entryframe, takefocus=False) # dest dir path entry sdplabel = tk.Button(self.entryframe, text="Source Folder:", command=partial(self.filedialogselect, self.sdpEntry, "d")) ddplabel = tk.Button(self.entryframe, text="Destination Folder:", command=partial(self.filedialogselect, self.ddpEntry, "d")) self.activebutton = tk.Button(self.entryframe, text="New Session", command=partial(fileManager.validate, self)) ToolTip( self.activebutton, delay=1, msg="Start a new Session with the entered source and destination") self.loadpathentry = tk.Entry(self.entryframe, takefocus=False, textvariable=self.sessionpathvar) self.loadbutton = tk.Button(self.entryframe, text="Load Session", command=self.fileManager.loadsession) ToolTip(self.loadbutton, delay=1, msg="Load and start the selected session data.") loadfolderbutton = tk.Button(self.entryframe, text="Session Data:", command=partial(self.filedialogselect, self.loadpathentry, "f")) ToolTip(loadfolderbutton, delay=1, msg="Select a session json file to open.") loadfolderbutton.grid(row=3, column=0, sticky='e') self.loadbutton.grid(row=3, column=2, sticky='ew') self.loadpathentry.grid(row=3, column=1, sticky='ew', padx=2) sdplabel.grid(row=0, column=0, sticky="e") self.sdpEntry.grid(row=0, column=1, sticky="ew", padx=2) ddplabel.grid(row=1, column=0, sticky="e") self.ddpEntry.grid(row=1, column=1, sticky="ew", padx=2) self.activebutton.grid(row=1, column=2, sticky="ew") self.excludebutton = tk.Button(self.entryframe, text="Manage Exclusions", command=self.excludeshow) self.excludebutton.grid(row=0, column=2) # show the entry frame, sticky it to the west so it mostly stays put. self.entryframe.grid(row=0, column=0, sticky="ew") # Finish setup for the left hand bar. # Start the grid setup imagegridframe = tk.Frame(self.toppane) imagegridframe.grid(row=0, column=1, sticky="NSEW") self.imagegrid = tk.Text(imagegridframe, wrap='word', borderwidth=0, highlightthickness=0, state="disabled", background='#a9a9a9') vbar = tk.Scrollbar(imagegridframe, orient='vertical', command=self.imagegrid.yview) vbar.grid(row=0, column=1, sticky='ns') self.imagegrid.configure(yscrollcommand=vbar.set) self.imagegrid.grid(row=0, column=0, sticky="NSEW") imagegridframe.rowconfigure(0, weight=1) imagegridframe.columnconfigure(0, weight=1) self.toppane.add(imagegridframe, weight=3) self.toppane.grid(row=0, column=0, sticky="NSEW") self.toppane.configure() self.columnconfigure(0, weight=10) self.columnconfigure(1, weight=0) self.rowconfigure(0, weight=10) self.rowconfigure(1, weight=0) self.protocol("WM_DELETE_WINDOW", self.closeprogram) self.winfo_toplevel().title( "Simple Image Sorter: Multiview Edition v2.4") self.leftui.bind("<Configure>", self.buttonResizeOnWindowResize) self.buttonResizeOnWindowResize("a")
class GUIManager(tk.Tk): thumbnailsize = 256 def __init__(self, fileManager) -> None: super().__init__() # variable initiation self.gridsquarelist = [] self.hideonassignvar = tk.BooleanVar() self.hideonassignvar.set(True) self.hidemovedvar = tk.BooleanVar() self.showhiddenvar = tk.BooleanVar() self.squaresperpage = tk.IntVar() self.squaresperpage.set(120) self.sessionpathvar = tk.StringVar() self.imagewindowgeometry = str( int(self.winfo_screenwidth() * 0.80)) + "x" + str(self.winfo_screenheight() - 120) + "+365+60" # store the reference to the file manager class. self.fileManager = fileManager self.geometry( str(self.winfo_screenwidth() - 5) + "x" + str(self.winfo_screenheight() - 120)) self.geometry("+0+60") self.buttons = [] self.hotkeys = "123456qwerty7890uiop[asdfghjkl;zxcvbnm,.!@#$%^QWERT&*()_UIOPASDFGHJKLZXCVBNM<>" # Paned window that holds the almost top level stuff. self.toppane = Panedwindow(self, orient="horizontal") # Frame for the left hand side that holds the setup and also the destination buttons. self.leftui = tk.Frame(self.toppane) #self.leftui.grid(row=0, column=0, sticky="NESW") self.leftui.columnconfigure(0, weight=1) self.toppane.add(self.leftui, weight=1) self.panel = tk.Label( self.leftui, wraplength=300, justify="left", text="""Select a source directory to search for images in above. The program will find all png, gif, jpg, bmp, pcx, tiff, Webp, and psds. It can has as many sub-folders as you like, the program will scan them all (except exclusions). Enter a root folder to sort to for the "Destination field" too. The destination directory MUST have sub folders, since those are the folders that you will be sorting to. \d (unless you delete prefs.json). Remember that it's one per line, no commas or anything. You can change the hotkeys in prefs.json, just type a string of letters and numbers and it'll use that. It differentiates between lower and upper case (anything that uses shift), but not numpad. By default the program will only load a portion of the images in the folder for performance reasons. Press the "Add Files" button to make it load another chunk. You can configure how many it adds and loads at once in the program. Right-click on Destination Buttons to show which images are assigned to them. (Does not show those that have already been moved) Right-click on Thumbnails to show a zoomable full view. You can also **rename** images from this view. Thanks to FooBar167 on stackoverflow for the advanced (and memory efficient!) Zoom and Pan tkinter class. Thank you for using this program!""") self.panel.grid(row=1, column=0, columnspan=200, rowspan=200, sticky="NSEW") self.columnconfigure(0, weight=1) self.buttonframe = tk.Frame(master=self.leftui) self.buttonframe.grid(column=0, row=1, sticky="NSEW") self.buttonframe.columnconfigure(0, weight=1) self.entryframe = tk.Frame(master=self.leftui) self.entryframe.columnconfigure(1, weight=1) self.sdpEntry = tk.Entry(self.entryframe, takefocus=False) # scandirpathEntry self.ddpEntry = tk.Entry(self.entryframe, takefocus=False) # dest dir path entry sdplabel = tk.Button(self.entryframe, text="Source Folder:", command=partial(self.filedialogselect, self.sdpEntry, "d")) ddplabel = tk.Button(self.entryframe, text="Destination Folder:", command=partial(self.filedialogselect, self.ddpEntry, "d")) self.activebutton = tk.Button(self.entryframe, text="New Session", command=partial(fileManager.validate, self)) ToolTip( self.activebutton, delay=1, msg="Start a new Session with the entered source and destination") self.loadpathentry = tk.Entry(self.entryframe, takefocus=False, textvariable=self.sessionpathvar) self.loadbutton = tk.Button(self.entryframe, text="Load Session", command=self.fileManager.loadsession) ToolTip(self.loadbutton, delay=1, msg="Load and start the selected session data.") loadfolderbutton = tk.Button(self.entryframe, text="Session Data:", command=partial(self.filedialogselect, self.loadpathentry, "f")) ToolTip(loadfolderbutton, delay=1, msg="Select a session json file to open.") loadfolderbutton.grid(row=3, column=0, sticky='e') self.loadbutton.grid(row=3, column=2, sticky='ew') self.loadpathentry.grid(row=3, column=1, sticky='ew', padx=2) sdplabel.grid(row=0, column=0, sticky="e") self.sdpEntry.grid(row=0, column=1, sticky="ew", padx=2) ddplabel.grid(row=1, column=0, sticky="e") self.ddpEntry.grid(row=1, column=1, sticky="ew", padx=2) self.activebutton.grid(row=1, column=2, sticky="ew") self.excludebutton = tk.Button(self.entryframe, text="Manage Exclusions", command=self.excludeshow) self.excludebutton.grid(row=0, column=2) # show the entry frame, sticky it to the west so it mostly stays put. self.entryframe.grid(row=0, column=0, sticky="ew") # Finish setup for the left hand bar. # Start the grid setup imagegridframe = tk.Frame(self.toppane) imagegridframe.grid(row=0, column=1, sticky="NSEW") self.imagegrid = tk.Text(imagegridframe, wrap='word', borderwidth=0, highlightthickness=0, state="disabled", background='#a9a9a9') vbar = tk.Scrollbar(imagegridframe, orient='vertical', command=self.imagegrid.yview) vbar.grid(row=0, column=1, sticky='ns') self.imagegrid.configure(yscrollcommand=vbar.set) self.imagegrid.grid(row=0, column=0, sticky="NSEW") imagegridframe.rowconfigure(0, weight=1) imagegridframe.columnconfigure(0, weight=1) self.toppane.add(imagegridframe, weight=3) self.toppane.grid(row=0, column=0, sticky="NSEW") self.toppane.configure() self.columnconfigure(0, weight=10) self.columnconfigure(1, weight=0) self.rowconfigure(0, weight=10) self.rowconfigure(1, weight=0) self.protocol("WM_DELETE_WINDOW", self.closeprogram) self.winfo_toplevel().title( "Simple Image Sorter: Multiview Edition v2.4") self.leftui.bind("<Configure>", self.buttonResizeOnWindowResize) self.buttonResizeOnWindowResize("a") def isnumber(self, char): return char.isdigit() def showall(self): for x in self.fileManager.imagelist: if x.guidata["show"] == False: x.guidata["frame"].grid() self.hidemoved() self.hideassignedsquare(self.fileManager.imagelist) def closeprogram(self): if self.fileManager.hasunmoved: if askokcancel( "Designated but Un-Moved files, really quit?", "You have destination designated, but unmoved files. (Simply cancel and Move All if you want)" ): saveprefs(self.fileManager, self) self.destroy() exit(0) else: saveprefs(self.fileManager, self) self.destroy() exit(0) def excludeshow(self): excludewindow = tk.Toplevel() excludewindow.winfo_toplevel().title( "Folder names to ignore, one per line. This will ignore sub-folders too." ) excludetext = tkst.ScrolledText(excludewindow) for x in self.fileManager.exclude: excludetext.insert("1.0", x + "\n") excludetext.pack() excludewindow.protocol( "WM_DELETE_WINDOW", partial(self.excludesave, text=excludetext, toplevelwin=excludewindow)) def excludesave(self, text, toplevelwin): text = text.get('1.0', tk.END).splitlines() exclude = [] for line in text: exclude.append(line) self.fileManager.exclude = exclude try: toplevelwin.destroy() except: pass def tooltiptext(self, imageobject): text = "" if imageobject.dupename: text += "Image has Duplicate Filename!\n" text += "Leftclick to select this for assignment. Rightclick to open full view" return text def makegridsquare(self, parent, imageobj, setguidata): frame = tk.Frame(parent, width=self.thumbnailsize + 14, height=self.thumbnailsize + 24) frame.obj = imageobj try: if setguidata: if not os.path.exists(imageobj.thumbnail): self.fileManager.makethumb(imageobj) try: buffer = pyvips.Image.new_from_file(imageobj.thumbnail) img = ImageTk.PhotoImage( Image.frombuffer("RGB", [buffer.width, buffer.height], buffer.write_to_memory())) except: # Pillow fallback img = ImageTk.PhotoImage(Image.open(imageobj.thumbnail)) else: img = imageobj.guidata['img'] canvas = tk.Canvas(frame, width=self.thumbnailsize, height=self.thumbnailsize) tooltiptext = tk.StringVar(frame, self.tooltiptext(imageobj)) ToolTip(canvas, msg=tooltiptext.get, delay=1) canvas.create_image(self.thumbnailsize / 2, self.thumbnailsize / 2, anchor="center", image=img) check = Checkbutton(frame, textvariable=imageobj.name, variable=imageobj.checked, onvalue=True, offvalue=False) canvas.grid(column=0, row=0, sticky="NSEW") check.grid(column=0, row=1, sticky="N") frame.rowconfigure(0, weight=4) frame.rowconfigure(1, weight=1) frame.config(height=self.thumbnailsize + 12) if ( setguidata ): # save the data to the image obj to both store a reference and for later manipulation imageobj.setguidata({ "img": img, "frame": frame, "canvas": canvas, "check": check, "show": True, "tooltip": tooltiptext }) # anything other than rightclicking toggles the checkbox, as we want. canvas.bind("<Button-1>", partial(bindhandler, check, "invoke")) canvas.bind("<Button-3>", partial(self.displayimage, imageobj)) check.bind("<Button-3>", partial(self.displayimage, imageobj)) canvas.bind("<MouseWheel>", partial(bindhandler, parent, "scroll")) frame.bind("<MouseWheel>", partial(bindhandler, self.imagegrid, "scroll")) check.bind("<MouseWheel>", partial(bindhandler, self.imagegrid, "scroll")) if imageobj.moved: frame.configure(highlightbackground="green", highlightthickness=2) if os.path.dirname( imageobj.path) in self.fileManager.destinationsraw: color = self.fileManager.destinations[indexOf( self.fileManager.destinationsraw, os.path.dirname(imageobj.path))]['color'] frame['background'] = color canvas['background'] = color frame.configure(height=self.thumbnailsize + 10) if imageobj.dupename: frame.configure(highlightbackground="yellow", highlightthickness=2) except Exception as e: logging.error(e) return frame def displaygrid(self, imagelist, range): for i in range: gridsquare = self.makegridsquare(self.imagegrid, imagelist[i], True) self.gridsquarelist.append(gridsquare) self.imagegrid.window_create("insert", window=gridsquare) def buttonResizeOnWindowResize(self, b=""): if len(self.buttons) > 0: for x in self.buttons: x.configure(wraplength=(self.buttons[0].winfo_width() - 1)) def displayimage(self, imageobj, a): path = imageobj.path if hasattr(self, 'imagewindow'): self.imagewindow.destroy() self.imagewindow = tk.Toplevel() imagewindow = self.imagewindow imagewindow.rowconfigure(1, weight=1) imagewindow.columnconfigure(0, weight=1) imagewindow.wm_title("Image: " + path) imagewindow.geometry(self.imagewindowgeometry) imageframe = CanvasImage(imagewindow, path) # takes the smaller scale (since that will be the limiting factor) and rescales the image to that so it fits the frame. imageframe.rescale( min(imagewindow.winfo_width() / imageframe.imwidth, imagewindow.winfo_height() / imageframe.imheight)) imageframe.grid(column=0, row=1) imagewindow.bind("<Button-3>", partial(bindhandler, imagewindow, "destroy")) renameframe = tk.Frame(imagewindow) renameframe.columnconfigure(1, weight=1) namelabel = tk.Label(renameframe, text="Image Name:") namelabel.grid(column=0, row=0, sticky="W") nameentry = tk.Entry(renameframe, textvariable=imageobj.name, takefocus=False) nameentry.grid(row=0, column=1, sticky="EW") renameframe.grid(column=0, row=0, sticky="EW") imagewindow.protocol("WM_DELETE_WINDOW", self.saveimagewindowgeo) imagewindow.obj = imageobj def saveimagewindowgeo(self): self.imagewindowgeometry = self.imagewindow.winfo_geometry() self.checkdupename(self.imagewindow.obj) self.imagewindow.destroy() def filedialogselect(self, target, type): if type == "d": path = tkFileDialog.askdirectory() elif type == "f": d = tkFileDialog.askopenfile( initialdir=os.getcwd(), title="Select Session Data File", filetypes=(("JavaScript Object Notation", "*.json"), )) path = d.name if isinstance(target, tk.Entry): target.delete(0, len(self.sdpEntry.get())) target.insert(0, path) def guisetup(self, destinations): sdpEntry = self.sdpEntry ddpEntry = self.ddpEntry sdpEntry.config(state=tk.DISABLED) ddpEntry.config(state=tk.DISABLED) panel = self.panel buttonframe = self.buttonframe hotkeys = self.hotkeys for key in hotkeys: self.unbind_all(key) for x in self.buttons: x.destroy() # clear the gui panel.destroy() guirow = 1 guicol = 0 itern = 0 smallfont = tkfont.Font(family='Helvetica', size=10) columns = 1 if len(destinations) > int((self.leftui.winfo_height() / 35) - 2): columns = 2 buttonframe.columnconfigure(1, weight=1) if len(destinations) > int((self.leftui.winfo_height() / 15) - 4): columns = 3 buttonframe.columnconfigure(2, weight=1) for x in destinations: color = x['color'] if x['name'] != "SKIP" and x['name'] != "BACK": if (itern < len(hotkeys)): newbut = tk.Button( buttonframe, text=hotkeys[itern] + ": " + x['name'], command=partial(self.fileManager.setDestination, x, {"widget": None}), anchor="w", wraplength=(self.leftui.winfo_width() / columns) - 1) self.bind_all(hotkeys[itern], partial(self.fileManager.setDestination, x)) fg = 'white' if luminance(color) == 'light': fg = "black" newbut.configure(bg=color, fg=fg) if (len(x['name']) >= 13): newbut.configure(font=smallfont) else: newbut = tk.Button(buttonframe, text=x['name'], command=partial( self.fileManager.setDestination, x, {"widget": None}), anchor="w") itern += 1 newbut.config(font=("Courier", 12), width=int( (self.leftui.winfo_width() / 12) / columns), height=1) ToolTip( newbut, msg="Rightclick to show images assigned to this destination", delay=1) if len(x['name']) > 20: newbut.config(font=smallfont) newbut.dest = x if guirow > ((self.leftui.winfo_height() / 35) - 2): guirow = 1 guicol += 1 newbut.grid(row=guirow, column=guicol, sticky="nsew") newbut.bind("<Button-3>", partial(self.showthisdest, x)) self.buttons.append(newbut) guirow += 1 self.entryframe.grid_remove() # options frame optionsframe = tk.Frame(self.leftui) # have this just get checked when setting dstination then hide or not hideonassign = tk.Checkbutton(optionsframe, text="Hide Assigned", variable=self.hideonassignvar, onvalue=True, offvalue=False) hideonassign.grid(column=0, row=0, sticky='W') ToolTip( hideonassign, delay=1, msg= "When checked, images that are assigned to a destination be hidden from the grid." ) showhidden = tk.Checkbutton(optionsframe, text="Show Hidden Images", variable=self.showhiddenvar, onvalue=True, offvalue=False, command=self.showhiddensquares) showhidden.grid(column=0, row=1, sticky="W") hidemoved = tk.Checkbutton(optionsframe, text="Hide Moved", variable=self.hidemovedvar, onvalue=True, offvalue=False, command=self.hidemoved) hidemoved.grid(column=1, row=1, sticky="w") ToolTip( hidemoved, delay=1, msg= "When checked, images that are moved will be hidden from the grid." ) self.showhidden = showhidden self.hideonassign = hideonassign valcmd = self.register(self.isnumber) squaresperpageentry = tk.Entry(optionsframe, textvariable=self.squaresperpage, validate="key", validatecommand=(valcmd, "%P"), takefocus=False) ToolTip(squaresperpageentry, delay=1, msg="How many more images to add when Load Images is clicked") for n in range(0, itern): squaresperpageentry.unbind(hotkeys[n]) addpagebut = tk.Button(optionsframe, text="Load More Images", command=self.addpage) ToolTip(addpagebut, msg="Add another batch of files from the source folders.", delay=1) squaresperpageentry.grid(row=2, column=0, sticky="E") addpagebut.grid(row=2, column=1, sticky="EW") hideonassign.grid(column=1, row=0) # save button savebutton = tk.Button(optionsframe, text="Save Session", command=partial(self.fileManager.savesession, True)) ToolTip( savebutton, delay=1, msg= "Save this image sorting session to a file, where it can be loaded at a later time. Assigned destinations and moved images will be saved." ) savebutton.grid(column=0, row=0, sticky="ew") moveallbutton = tk.Button(optionsframe, text="Move All", command=self.fileManager.moveall) moveallbutton.grid(column=1, row=3, sticky="EW") ToolTip( moveallbutton, delay=1, msg= "Move all images to their assigned destinations, if they have one." ) clearallbutton = tk.Button(optionsframe, text="Clear Selection", command=self.fileManager.clear) ToolTip( clearallbutton, delay=1, msg= "Clear your selection on the grid and any other windows with checkable image grids." ) clearallbutton.grid(row=3, column=0, sticky="EW") optionsframe.columnconfigure(0, weight=1) optionsframe.columnconfigure(1, weight=3) self.optionsframe = optionsframe self.optionsframe.grid(row=0, column=0, sticky="ew") self.bind_all("<Button-1>", self.setfocus) def setfocus(self, event): event.widget.focus_set() # todo: make 'moved' and 'assigned' lists so the show all etc just has to iterate over those. def hideassignedsquare(self, imlist): if self.hideonassignvar.get(): for x in imlist: if x.dest != "": self.imagegrid.window_configure(x.guidata["frame"], window='') x.guidata["show"] = False def hideallsquares(self): for x in self.gridsquarelist: self.imagegrid.window_configure(x, window="") def showhiddensquares(self): if self.showhiddenvar.get(): for x in self.gridsquarelist: try: x.obj.guidata["frame"] = x self.imagegrid.window_create("insert", window=x) except: pass else: self.hideassignedsquare(self.fileManager.imagelist) self.hidemoved() def showunassigned(self, imlist): for x in imlist: if x.guidata["show"] or x.dest == "": self.imagegrid.window_create("insert", window=x.guidata["frame"]) def showthisdest(self, dest, *args): destwindow = tk.Toplevel() destwindow.geometry( str(int(self.winfo_screenwidth() * 0.80)) + "x" + str(self.winfo_screenheight() - 120) + "+365+60") destwindow.winfo_toplevel().title("Files designated for" + dest['path']) destgrid = tk.Text(destwindow, wrap='word', borderwidth=0, highlightthickness=0, state="disabled", background='#a9a9a9') destgrid.grid(row=0, column=0, sticky="NSEW") destwindow.columnconfigure(0, weight=1) destwindow.rowconfigure(0, weight=1) vbar = tk.Scrollbar(destwindow, orient='vertical', command=destgrid.yview) vbar.grid(row=0, column=1, sticky='ns') for x in self.fileManager.imagelist: if x.dest == dest['path']: newframe = self.makegridsquare(destgrid, x, False) destgrid.window_create("insert", window=newframe) def hidemoved(self): if self.hidemovedvar.get(): for x in self.fileManager.imagelist: if x.moved: try: self.imagegrid.window_configure(x.guidata["frame"], window='') except Exception as e: #logging.error(e) pass def addpage(self, *args): filelist = self.fileManager.imagelist if len(self.gridsquarelist) < len(filelist) - 1: listmax = min( len(self.gridsquarelist) + self.squaresperpage.get(), len(filelist) - 1) ran = range(len(self.gridsquarelist), listmax) sublist = filelist[ran[0]:listmax] self.fileManager.generatethumbnails(sublist) self.displaygrid(self.fileManager.imagelist, ran) def checkdupename(self, imageobj): if imageobj.name.get() in self.fileManager.existingnames: imageobj.dupename = True imageobj.guidata["frame"].configure(highlightbackground="yellow", highlightthickness=2) else: imageobj.dupename = False imageobj.guidata["frame"].configure(highlightthickness=0) self.fileManager.existingnames.add(imageobj.name.get()) imageobj.guidata['tooltip'].set(self.tooltiptext(imageobj))
def initUI(self): self.parent.title("PyWave") self.style = Style() self.style.theme_use("default") self.user_waves, self.user_labels = [], [] self.save_wave = True self.RF = None self.columnconfigure(1, weight=1) self.columnconfigure(3, pad=7) self.rowconfigure(3, weight=1) self.rowconfigure(5, pad=7) self.RFparams = { 'n_estimators' : 100, 'random_state' : 1, 'n_jobs' : -1, 'max_depth' : 7, 'oob_score' : True, 'warm_start' : True } #### Geometry #### abtn = Button(self.parent, text='Capture', command=self.capture_and_store) abtn.pack(side=BOTTOM, expand=1, fill='x') tbtn = Button(self.parent, text='Train', command=self.train_model) tbtn.pack(side=BOTTOM, expand=1, fill='x') cbtn = Button(self.parent, text='Close', command=self.quit) cbtn.pack(side=BOTTOM, expand=1, fill='x') hbtn = Button(self.parent, text='Predict on Capture', command=self.capture_and_plot) hbtn.pack(side=BOTTOM, expand=1, fill='x') p = Panedwindow(self.parent, orient=VERTICAL) p.pack(side=LEFT) f1 = Labelframe(p, text='Models', width=200, height=1000) p.add(f1) self.mdlist = Listbox(self.parent, height = 900, width=400) self.mdlist.pack(side=LEFT) #### Creating top menu bars and callbacks #### menubar = Menu(self.parent) self.parent.config(menu=menubar) modelMenu = Menu(menubar, tearoff=0) menubar.add_cascade(label="Model", menu=modelMenu) modelMenu.add_command(label='Import Dataset', command=self.import_dataset) modelMenu.add_command(label='Import Model', command=self.import_model) modelMenu.add_command(label='Train Random Forest', command=self.rf) modelMenu.add_command(label='Train Gradient Boosted Classifier', command=self.gbc) modelMenu.add_command(label='Train K-Nearest Neighbors', command=self.knn) modelMenu.add_command(label='Save', command=self.saveas) modelMenu.add_command(label='Save as', command=self.saveas) waveMenu = Menu(menubar, tearoff=0) menubar.add_cascade(label="Waveform", menu=waveMenu) waveMenu.add_command(label="Import Waveform", command=self.import_waveform) waveMenu.add_command(label="Features", command=self.get_features)