All pastes #802406 Raw Edit

Untitled

public python v1 · immutable
#802406 ·published 2007-11-30 03:35 UTC
rendered paste body
from Tkinter import *import tkFileDialogfrom picture import *from PIL import ImageTkimport image_manipulationdef quit(window):    window.destroy()    def save_file(window):    photo = c_pic.save_pic.get_image()    filename = tkFileDialog.asksaveasfilename()    photo.save(filename + '.bmp')    def open_file(window):       pic = make_picture(pick_a_file())    photo = ImageTk.PhotoImage(pic.get_image())    w.create_image(320,400, image = photo)    def rotate_callback():    top = Toplevel()    top.minsize(width=100, height=100)    top.title("Rotate Image")    rotate_method = StringVar()    degrees = IntVar()    cw = Radiobutton (top, text="cw", variable=rotate_method, \                                   value="cw", justify=CENTER)    cw.grid(row=0, column=0)    ccw = Radiobutton (top, text="ccw", variable=rotate_method, \                                   value="ccw", justify=CENTER)    ccw.grid(row=0, column=1)      rotate_label = Label (top, text="Degrees")    rotate_label.grid(row=1, column=0)    rotate_entry = Entry(top, textvariable=degrees)    rotate_entry.grid(row=1, column=1)    ok_button = Button (top, text="Ok", command=lambda: process_rotate \                        (rotate_method, degrees), padx=12)    ok_button.grid(row=2, column=1)def process_rotate(rotate_method, degrees):    method = rotate_method.get()    degrees = degrees.get()    if method == "cw":        degrees = degrees * -1            pic = c_pic.save_pic.get_image()     new_pic = image_manipulation.rotate(pic, degrees)    photo = ImageTk.PhotoImage(new_pic.get_image())    c_pic.config(image=photo)    c_pic.config(width=photo.width())    c_pic.config(height=photo.height())    c_pic.image = photo    c_pic.save_pic = new_picdef mirror_callback():    pic = c_pic.save_pic    new_pic = image_manipulation.mirror(pic)    photo = ImageTk.PhotoImage(new_pic.get_image())    c_pic.config(image=photo)    c_pic.config(width=photo.width())    c_pic.config(height=photo.height())    c_pic.image = photo    c_pic.save_pic = new_picdef greyscale_callback():    pic = c_pic.save_pic    new_pic = image_manipulation.grey_scale(pic)    photo = ImageTk.PhotoImage(new_pic.get_image())    c_pic.config(image=photo)    c_pic.config(width=photo.width())    c_pic.config(height=photo.height())    c_pic.image = photo    c_pic.save_pic = new_pic    def redeye_callback():    pic = c_pic.save_pic    new_pic = image_manipulation.red_eye(pic)    photo = ImageTk.PhotoImage(new_pic.get_image())    c_pic.config(image=photo)    c_pic.config(width=photo.width())    c_pic.config(height=photo.height())    c_pic.image = photo    c_pic.save_pic = new_pic    def crop_callback():    #Starts a new windows (TopLevel) and calls layout (see below)    temp_win = Toplevel()    temp_win.minsize(width=80, height=100)    temp_win.title("Crop Image")    crop_layout(temp_win)def crop_layout(temp_win):    # Builds layout of the window and sends info to "Process Crop" fn see below    crop_left=IntVar()    crop_right=IntVar()    crop_top=IntVar()    crop_bottom=IntVar()    left_label = Label (temp_win, text="Left")    left_label.grid(row=0, column=0)    right_label = Label (temp_win, text="right")    right_label.grid(row=1, column=0)    top_label = Label (temp_win, text="Top")    top_label.grid(row=2, column=0)    bottom_label = Label (temp_win, text="Bottom")    bottom_label.grid(row=3, column=0)    left = Entry (temp_win, textvariable=crop_left)    left.grid(row=0, column=1)    right = Entry (temp_win, textvariable=crop_right)    right.grid(row=1, column=1)    top = Entry(temp_win, textvariable=crop_top)    top.grid(row=2, column=1)    bottom = Entry(temp_win,textvariable=crop_bottom)    bottom.grid(row=3, column=1)    ok_button = Button (temp_win, text="Ok", command=lambda: process_crop\                        (crop_left,crop_right, crop_bottom,crop_top), padx=12)    ok_button.grid(row=4, column=1)def process_crop (crop_left, crop_right, crop_bottom, crop_top):    pic = c_pic.save_pic    new_pic = image_manipulation.crop_image(pic, crop_left, crop_right,\                                            crop_top, crop_bottom)    photo = ImageTk.PhotoImage(new_pic.get_image())    c_pic.config(image=photo)    c_pic.config(width=photo.width())    c_pic.config(height=photo.height())    c_pic.image = photo    c_pic.save_pic = new_picdef sharpness_callback():    top = Toplevel()    top.minsize(width=100, height=100)    top.title("Sharpness Mod")    factor_label = Label (top, text="factor")    factor_label.grid(row=0,column=0)    factor = DoubleVar()    factor_entry = Entry (top, textvariable=factor)    factor_entry.grid(row=0, column=1)    ok_button = Button    ok_button = Button (top, text="Ok", command=lambda: process_sharpness \                        (factor), padx=12)    ok_button.grid(row=1, column=1)    def process_sharpness(factor):    pic = c_pic.save_pic    new_pic = image_manipulation.sharpness(pic,factor.get())    photo = ImageTk.PhotoImage(new_pic.get_image())    c_pic.config(image=photo)    c_pic.config(width=photo.width())    c_pic.config(height=photo.height())    c_pic.image = photo    c_pic.save_pic = new_pic     def contrast_callback():    top = Toplevel()    top.minsize(width=100, height=100)    top.title("Contrast Mod")    factor_label = Label (top, text="factor")    factor_label.grid(row=0,column=0)    factor = DoubleVar()    factor_entry = Entry (top, textvariable=factor)    factor_entry.grid(row=0, column=1)    ok_button = Button    ok_button = Button (top, text="Ok", command=lambda: process_sharpness \                        (factor), padx=12)    ok_button.grid(row=1, column=1)def contrast_process():    pic = c_pic.save_pic    new_pic = image_manipulation.contrast(pic,factor.get())    photo = ImageTk.PhotoImage(new_pic.get_image())    c_pic.config(image=photo)    c_pic.config(width=photo.width())    c_pic.config(height=photo.height())    c_pic.image = photo    c_pic.save_pic = new_pic     def resize_callback():    temp_win = Toplevel()    temp_win.minsize(width=100, height=100)    temp_win.title("Resize Image")    width=IntVar()    height=IntVar()    width_label = Label (temp_win, text="width")    width_label.grid(row=0, column=0)    height_label = Label (temp_win, text="heights")    height_label.grid(row=1, column=0)    width_entry = Entry(temp_win, textvariable=width)    width_entry.grid(row=0, column=1)    height_entry = Entry(temp_win,textvariable=height)    height_entry.grid(row=1, column=1)    ok_button = Button (temp_win, text="Ok", command=lambda: process_resize\                        (width, height), padx=12)    ok_button.grid(row=2, column=1)    def process_resize(width, height):    pic = c_pic.save_pic    new_pic = image_manipulation.resize(pic, width.get(), height.get())    photo = ImageTk.PhotoImage(new_pic.get_image())    c_pic.config(image=photo)    c_pic.config(width=photo.width())    c_pic.config(height=photo.height())    c_pic.image = photo    c_pic.save_pic = new_pic    if __name__ == '__main__':    window = Tk()    window.minsize(740,640)    window.title("Image Tweak v1.0")    frame = Frame (window)    frame.pack(side=TOP, fill=X)        menubar = Menu(window)    filemenu = Menu(menubar)    open_command = lambda : open_file(window)    filemenu.add_command(label="Open", command=open_command)    save_command = lambda : save_file(window)    filemenu.add_command(label="Save", command=save_command)    quit_command = lambda : quit(window)    filemenu.add_command(label="Quit", command=quit_command)    menubar.add_cascade(label="File", menu=filemenu)            window.config(menu=menubar)        b1 = Button(frame, text="rotate", width=6, command=rotate_callback)    b1.pack(side=LEFT, padx=1, fill=BOTH, expand=1)    b2 = Button(frame, text="Grey Scale", width=6, command=greyscale_callback)    b2.pack(side=LEFT, padx=1, fill=BOTH, expand=1)    b3 = Button(frame, text="Mirror Image", width=6, command=mirror_callback)    b3.pack(side=LEFT, padx=1, fill=BOTH, expand=1)    b4 = Button(frame, text="Remove RedEye", width=6, command=redeye_callback)    b4.pack(side=LEFT, padx=1, fill=BOTH, expand=1)    b5 = Button(frame, text="Crop", width=6, command=crop_callback)    b5.pack(side=LEFT, padx=1, fill=BOTH, expand=1)    b6 = Button(frame, text="Resize", width=6, command=resize_callback)    b6.pack(side=LEFT, padx=1, fill=BOTH, expand=1)    b7 = Button(frame, text="Sharpness", width=6, command=sharpness_callback)    b7.pack(side=LEFT, padx=1, fill=BOTH, expand=1)    b8 = Button(frame, text="Contrast", width=6, command=contrast_callback)    b8.pack(side=LEFT, padx=1, fill=BOTH, expand=1)    w = Canvas(window, width=200, height=100)    w.pack()       scrollbar_y = Scrollbar (window)    scrollbar_y.pack(side=RIGHT, fill=Y)    scrollbar_x = Scrollbar (window)    scrollbar_x.pack(side=BOTTOM, fill=X)        scrollbar_x.config(orient=HORIZONTAL)    window.config(menu=menubar)        window.mainloop()