def viewer(imgdir, kind=Toplevel, cols=None): """ измененная версия, размещает миниатюры по сетке """ win = kind() win.title('Viewer: ' + imgdir) thumbs = makeThumbs(imgdir) if not cols: cols = int(math.ceil(math.sqrt( len(thumbs)))) # фиксированное или N x N rownum = 0 savephotos = [] while thumbs: thumbsrow, thumbs = thumbs[:cols], thumbs[cols:] colnum = 0 for (imgfile, imgobj) in thumbsrow: photo = PhotoImage(imgobj) link = Button(win, image=photo) handler = lambda savefile=imgfile: ViewOne(imgdir, savefile) link.config(command=handler) link.grid(row=rownum, column=colnum) savephotos.append(photo) colnum += 1 rownum += 1 Button(win, text='Quit', command=win.quit).grid(columnspan=cols, stick=EW) return win, savephotos
def viewer(imgdir, kind=Toplevel, cols=None): """ custom version that uses gridding """ win = kind() win.title('Viewer: ' + imgdir) thumbs = makeThumbs(imgdir) if not cols: cols = int(math.ceil(math.sqrt(len(thumbs)))) # fixed or N x N rownum = 0 savephotos = [] while thumbs: thumbsrow, thumbs = thumbs[:cols], thumbs[cols:] colnum = 0 for (imgfile, imgobj) in thumbsrow: photo = PhotoImage(imgobj) link = Button(win, image=photo) handler = lambda savefile=imgfile: ViewOne(imgdir, savefile) link.config(command=handler) link.grid(row=rownum, column=colnum) savephotos.append(photo) colnum += 1 rownum += 1 Button(win, text='Quit', command=win.quit).grid(columnspan=cols, stick=EW) return win, savephotos
def viewer(imgdir, kind=Toplevel, cols=None): """ custom version that lays out with fixed-size buttons """ win = kind() win.title('Viewer: ' + imgdir) thumbs = makeThumbs(imgdir) if not cols: cols = int(math.ceil(math.sqrt(len(thumbs)))) # fixed or N x N savephotos = [] while thumbs: thumbsrow, thumbs = thumbs[:cols], thumbs[cols:] row = Frame(win) row.pack(fill=BOTH) for (imgfile, imgobj) in thumbsrow: size = max(imgobj.size) # width, height photo = PhotoImage(imgobj) link = Button(row, image=photo) handler = lambda savefile=imgfile: ViewOne(imgdir, savefile) link.config(command=handler, width=size, height=size) link.pack(side=LEFT, expand=YES) savephotos.append(photo) Button(win, text='Quit', command=win.quit, bg='beige').pack(fill=X) return win, savephotos
def viewer(imgdir, kind=Toplevel, cols=None): """ измененная версия, выполняет размещение с использованием кнопок фиксированного размера """ win = kind() win.title('Viewer: ' + imgdir) thumbs = makeThumbs(imgdir) if not cols: cols = int(math.ceil(math.sqrt( len(thumbs)))) # фиксированное или N x N savephotos = [] while thumbs: thumbsrow, thumbs = thumbs[:cols], thumbs[cols:] row = Frame(win) row.pack(fill=BOTH) for (imgfile, imgobj) in thumbsrow: size = max(imgobj.size) # ширина, высота photo = PhotoImage(imgobj) link = Button(row, image=photo) handler = lambda savefile=imgfile: ViewOne(imgdir, savefile) link.config(command=handler, width=size, height=size) link.pack(side=LEFT, expand=YES) savephotos.append(photo) Button(win, text='Quit', command=win.quit, bg='beige').pack(fill=X) return win, savephotos
def viewer(imgdir, kind=Toplevel, numcols=None, height=300, width=300): """ use fixed-size buttons, scrollable canvas; sets scrollable (full) size, and places thumbs at absolute x,y coordinates in canvas; caveat: assumes all thumbs are same size """ win = kind() win.title('Simple viewer: ' + imgdir) quit = Button(win, text='Quit', command=win.quit, bg='beige') quit.pack(side=BOTTOM, fill=X) canvas = Canvas(win, borderwidth=0) vbar = Scrollbar(win) hbar = Scrollbar(win, orient='horizontal') vbar.pack(side=RIGHT, fill=Y) # pack canvas after bars hbar.pack(side=BOTTOM, fill=X) # so clipped first canvas.pack(side=TOP, fill=BOTH, expand=YES) vbar.config(command=canvas.yview) # call on scroll move hbar.config(command=canvas.xview) canvas.config(yscrollcommand=vbar.set) # call on canvas move canvas.config(xscrollcommand=hbar.set) canvas.config(height=height, width=width) # init viewable area size # changes if user resizes thumbs = makeThumbs(imgdir) # [(imgfile, imgobj)] numthumbs = len(thumbs) if not numcols: numcols = int(math.ceil(math.sqrt(numthumbs))) # fixed or N x N numrows = int(math.ceil(numthumbs / numcols)) # 3.x true div linksize = max(thumbs[0][1].size) # (width, height) fullsize = ( 0, 0, # upper left X,Y (linksize * numcols), (linksize * numrows)) # lower right X,Y canvas.config(scrollregion=fullsize) # scrollable area size rowpos = 0 savephotos = [] while thumbs: thumbsrow, thumbs = thumbs[:numcols], thumbs[numcols:] colpos = 0 for (imgfile, imgobj) in thumbsrow: photo = PhotoImage(imgobj) link = Button(canvas, image=photo) handler = lambda savefile=imgfile: ViewOne(imgdir, savefile) link.config(command=handler, width=linksize, height=linksize) link.pack(side=LEFT, expand=YES) canvas.create_window(colpos, rowpos, anchor=NW, window=link, width=linksize, height=linksize) colpos += linksize savephotos.append(photo) rowpos += linksize return win, savephotos
def viewer(imgdir, kind=Toplevel, numcols=None, height=300, width=300): """ использует кнопки фиксированного размера и холст с возможностью прокрутки; определяет размер области прокрутки (всего холста) и располагает миниатюры по абсолютным координатам x,y холста; предупреждение: предполагается, что все миниатюры имеют одинаковые размеры :param imgdir: :param kind: :param numcols: :param height: :param width: :return: """ win = kind() win.title('Simple viewer: ' + imgdir) quit = Button(win, text='Quit', command=win.quit, bg='beige') quit.pack(side=BOTTOM, fill=X) canvas = Canvas(win, borderwidth=0) vbar = Scrollbar(win) hbar = Scrollbar(win, orient='horizontal') vbar.pack(side=RIGHT, fill=Y) hbar.pack(side=BOTTOM, fill=X) canvas.pack(side=TOP, expand=YES, fill=BOTH) vbar.config(command=canvas.yview) hbar.config(command=canvas.xview) canvas.config(yscrollcommand=vbar.set) canvas.config(xscrollcommand=hbar.set) canvas.config(height=height, width=width) thumbs = makeThumbs(imgdir) numthumbs = len(thumbs) if not numcols: numcols = int(math.ceil(math.sqrt(numthumbs))) numrows = int(math.ceil(numthumbs / numcols)) linksize = max(thumbs[0][1].size) fullsize = (0, 0, # координаты верхнего левого угла (linksize * numcols), (linksize * numrows)) # координаты нижнего правого угла canvas.config(scrollregion=fullsize) rowpos = 0 savephotos = [] while thumbs: thumbsrow, thumbs = thumbs[:numcols], thumbs[numcols:] colpos = 0 for (imgfile, imgobj) in thumbsrow: photo = PhotoImage(imgobj) link = Button(canvas, image=photo) handler = lambda savefile=imgfile: ViewOne(imgdir, savefile) link.config(command=handler, width=linksize, height=linksize) link.pack(side=LEFT, expand=YES) canvas.create_window(colpos, rowpos, anchor=NW, window=link, width=linksize, height=linksize) colpos += linksize savephotos.append(photo) rowpos += linksize return win, savephotos
def viewer(imgdir, kind=Toplevel, numcols=None, height=300, width=300): win = kind() win.title('Simple viewer: ' + imgdir) quit = Button(win, text='Quit', command=win.quit, bg='beige') quit.pack(side=BOTTOM, fill=X) canvas = Canvas(win, borderwidth=0) vbar = Scrollbar(win) hbar = Scrollbar(win, orient='horizontal') vbar.pack(side=RIGHT, fill=Y) hbar.pack(side=BOTTOM, fill=X) canvas.pack(side=TOP, fill=BOTH, expand=YES) vbar.config(command=canvas.yview) hbar.config(command=canvas.xview) canvas.config(yscrollcommand=vbar.set) canvas.config(xscrollcommand=hbar.set) canvas.config(height=height, width=width) thumbs = makeThumbs(imgdir) numthumbs = len(thumbs) if not numcols: numcols = int(math.ceil(math.sqrt(numthumbs))) numrows = int(math.ceil(numthumbs / numcols)) linksize = max(thumbs[0][1].size) fullsize = (0, 0, (linksize * numcols), (linksize * numrows)) canvas.config(scrollregion=fullsize) rowpos = 0 savephotos = [] while thumbs: thumbsrow, thumbs = thumbs[:numcols], thumbs[numcols:] colpos = 0 for (imgfile, imgobj) in thumbsrow: photo = PhotoImage(imgobj) link = Button(canvas, image=photo) handler = lambda savefile=imgfile: ViewOne(imgdir, savefile) link.config(command=handler, width=linksize, height=linksize) link.pack(side=LEFT, expand=YES) canvas.create_window(colpos, rowpos, anchor=NW, window=link, width=linksize, height=linksize) colpos += linksize savephotos.append(photo) rowpos += linksize return win, savephotos
def viewer(imgdir, kind=Toplevel, cols=None): win = kind() win.title('Viewer: ' + imgdir) thumbs = makeThumbs(imgdir) if not cols: cols = math.ceil(math.sqrt(len(thumbs))) savephotos = [] while thumbs: thumbsrow, thumbs = thumbs[:cols], thumbs[cols:] row = Frame(win) row.pack(fill=BOTH) for (imgfile, imgobj) in thumbsrow: size = max(imgobj.size) photo = PhotoImage(imgobj) handler = lambda savefile=imgfile: ViewOne(imgdir,savefile) link = Button(row, image=photo) link.config(command=handler, width=size, height=size) link.pack(side=LEFT, expand=YES) savephotos.append(photo) Button(win, text='Quit', command=win.quit()).pack(side=TOP, fill=X) return win, savephotos