Пример #1
0
    def __init__(self, master, fileDirectory):
        global img
        global PILimg
        global edit

        #  print ("1")
        self.master = master
        self.frame = tk.Frame(self.master)
        #  print ("2")
        self.quitButton = tk.Button(self.frame,
                                    text='Quit',
                                    width=25,
                                    command=self.close_windows)

        self.BnWButton = tk.Button(self.frame,
                                   text='Make Black and White',
                                   width=25,
                                   command=self.BnW_windows)
        img = tk.PhotoImage(file=fileDirectory)
        PILimg = Image.open(fileDirectory)
        edit = PILimg.load()

        self.MCButton = tk.Button(self.frame,
                                  text='Make Monochrome',
                                  width=25,
                                  command=self.MC_windows)
        img = tk.PhotoImage(file=fileDirectory)
        PILimg = Image.open(fileDirectory)
        edit = PILimg.load()

        self.MirrorImageButton = tk.Button(self.frame,
                                           text='Mirror Image',
                                           width=25,
                                           command=self.MirrorImage_windows)
        img = tk.PhotoImage(file=fileDirectory)
        PILimg = Image.open(fileDirectory)
        edit = PILimg.load()

        self.TransposeButton = tk.Button(self.frame,
                                         text='Transpoe Top to Bottom',
                                         width=25,
                                         command=self.Transpose_windows)
        img = tk.PhotoImage(file=fileDirectory)
        PILimg = Image.open(fileDirectory)
        edit = PILimg.load()

        button = tk.Button(self.master, image=img)
        button.img = img
        #  print ("3")
        button.pack()  #  This packs the image on the button
        #  print("4")

        self.quitButton.pack()
        self.BnWButton.pack()
        self.MCButton.pack()
        self.MirrorImageButton.pack()
        self.TransposeButton.pack()

        self.frame.pack()
Пример #2
0
    def __init__(self, master, fileDirectory):
        global img
        global PILimg
        global edit
        
        #  print ("1")
        self.master = master
        self.frame = tk.Frame(self.master)
        #  print ("2")
        self.quitButton = tk.Button(self.frame, text = 'Quit', width = 25, command = self.close_windows)

        self.BnWButton = tk.Button(self.frame, text = 'Make Black and White', width = 25, command = self.BnW_windows)
        img = tk.PhotoImage(file = fileDirectory)
        PILimg=Image.open(fileDirectory)
        edit=PILimg.load()

        self.MCButton = tk.Button(self.frame, text = 'Make Monochrome', width = 25, command = self.MC_windows)
        img = tk.PhotoImage(file = fileDirectory)
        PILimg=Image.open(fileDirectory)
        edit=PILimg.load()

        self.MirrorImageButton = tk.Button(self.frame, text = 'Mirror Image', width = 25, command = self.MirrorImage_windows)
        img = tk.PhotoImage(file = fileDirectory)
        PILimg=Image.open(fileDirectory)
        edit=PILimg.load()

        self.TransposeButton = tk.Button(self.frame, text = 'Transpoe Top to Bottom', width = 25, command = self.Transpose_windows)
        img = tk.PhotoImage(file = fileDirectory)
        PILimg=Image.open(fileDirectory)
        edit=PILimg.load()
        
        button = tk.Button(self.master, image=img)
        button.img = img;
        #  print ("3")
        button.pack()    #  This packs the image on the button
        #  print("4")

        self.quitButton.pack()
        self.BnWButton.pack()
        self.MCButton.pack()
        self.MirrorImageButton.pack()
        self.TransposeButton.pack()
        
        self.frame.pack()
Пример #3
0
    def capture(self, map):
	self.map = map
        box_size = 15
	print map
        # create a new frame
        wrap = Frame(self, bg="black")

        self.hide_top()
        # label showing the image
        self.image = Image.open(self.path + "/" + map + ".gif")
        draw = ImageDraw.Draw(self.image) 
        
        for x in range(1, 240//box_size):
	        draw.line((box_size*x, 0, box_size*x, 240), fill=128, width=1)
        for y in range(1, 240//box_size):
	        draw.line((0, box_size*y, 240, box_size*y), fill=128, width=1)
        
        
        self.image = ImageTk.PhotoImage(self.image)
        imagelabel = Label(wrap, image=self.image)
        imagelabel.grid(row=0, column=0, columnspan=2, sticky=C.W + C.E + C.N + C.S)


        imagelabel.bind('<Button-1>', self.printcoords)

   
        # when there were previous frames, hide the top one and add a back button for the new one
        if len(self.framestack):
            self.hide_top()

            back = FlatButton(
                wrap,
                text='Back…',
                image=self.get_icon("arrow.left"),
                command= self.go_back,
            )

            exitbtn = FlatButton(
                wrap,
                text='Exit…',
                image=self.get_icon("exit"),
                command=self.app_exit,
            )

            back.set_color("#00a300")  # green
            exitbtn.set_color("#00a300")  # green

            back.grid(row=1, column=0, padx=1, pady=1, sticky=C.W + C.E + C.N + C.S)
            exitbtn.grid(row=1, column=1, padx=1, pady=1, sticky=C.W + C.E + C.N + C.S)
            #num += 1

        # add the new frame to the stack and display it
            self.framestack.append(wrap)
        self.show_top()
        self.parent.update()
Пример #4
0
    def realtime(self):
        global realt
        box_size = 15

        # create a new frame
        wrap = Frame(self, bg="black")

        self.hide_top()
        # label showing the image
        self.image = Image.open(self.path + "/kirk-auditorium2.gif")
        draw = ImageDraw.Draw(self.image)
        self.image = ImageTk.PhotoImage(self.image)
        imagelabel = Label(wrap, image=self.image)
        imagelabel.grid(row=0, column=0, columnspan=2, sticky=C.W + C.E + C.N + C.S)

        num = 0
        # when there were previous frames, hide the top one and add a back button for the new one
        if len(self.framestack):
            self.hide_top()

            back = FlatButton(
                wrap,
                text='Back…',
                image=self.get_icon("arrow.left"),
                command= self.go_back,
            )

            exitbtn = FlatButton(
                wrap,
                text='Exit…',
                image=self.get_icon("exit"),
                command=self.app_exit,
            )

            back.set_color("#00a300")  # green
            exitbtn.set_color("#00a300")  # green

            back.grid(row=1, column=0, padx=1, pady=1, sticky=C.W + C.E + C.N + C.S)
            exitbtn.grid(row=1, column=1, padx=1, pady=1, sticky=C.W + C.E + C.N + C.S)
            num += 1

        realt = True
        

        # add the new frame to the stack and display it
        self.framestack.append(wrap)
        self.show_top()
        self.parent.update()
        self.after(1,self.realtime_calculation, imagelabel)
Пример #5
0
 def clean(self):
     cleaned_data = super(AvatarForm, self).clean()
     image = cleaned_data.get("avatar", None)
     if image:
         if image.content_type not in ['image/jpeg', 'image/png']:
             raise forms.ValidationError(u'你上传的是图片吗?')
         else:
             from Tkinter import Image
             img = Image.open(image)
             w, h = img.size
             max_width = max_height = 1000
             if w >= max_width or h >= max_height:
                 raise forms.ValidationError(u'上传的图片要尺寸要小于或等于%s宽,%s高' % (max_width, max_height))
             if img.format.lower() not in ['jpeg', 'pjpeg', 'png', 'jpg']:
                 raise forms.ValidationError(u'暂时只接纳JPEG or PNG.')
             #validate file size
             if len(image) > (1 * 1024 * 1024):
                 raise forms.ValidationError('Image file too large ( maximum 1mb )')
     else:
         raise forms.ValidationError(u'额,图片呢?')
     return cleaned_data
Пример #6
0
def convert_png_to_gif(fig_path):
    # convert png images saved on disk to gif images
    im = Image.open(fig_path)
    im = im.convert('RGB').convert('P', palette=Image.ADAPTIVE)
    im.save(fig_path.replace('.png', '.gif'))
Пример #7
0
from Tkinter import Image

image = Image.open('smiley.jpg')
image.show()
Пример #8
0
    def realtime_calculation(self, imagelabel):
        global realt
        global box_size
        fingerprint_file = open(self.path+'/fingerprint.pkl', 'rb')
        fingerprint = pickle.load(fingerprint_file)
        fingerprint_file.close()
 
        max_x = 0
        max_y = 0

	difference = {}
	num_macs = {}
        for mac in fingerprint:
            for z in fingerprint[mac]:
		difference.update({z:[]})
		num_macs.update({z:[]})
                if len(fingerprint[mac][z]) > max_x:
                    max_x = len(fingerprint[mac][z])
                    for x in range(len(fingerprint[mac][z])):
                            if len(fingerprint[mac][z][x]) > max_y:
                                    max_y = len(fingerprint[mac][z][x])
        while realt:
            compare = {}
	    bl_count = 0
	    wifi_count = 0
	    #os.system("sudo hciconfig hci0 reset")
	    #p = Popen([self.path+"/ibeacon_scan","-b"], stdout=PIPE, stderr=PIPE, preexec_fn=os.setsid)
            packets = sca.sniff(iface=iface, timeout=1)
	    #sys.stdout.flush()
	    #os.killpg(p.pid, signal.SIGTERM)
            #bl_packets = p.stdout.read().split('\n')
	    bl_packets = [] # empty until bluetooth works
            for pkt in packets:
                mac, strength = parsePacket(pkt)
                if mac is not None and strength is not None and strength < 0:
                    if mac in compare:
                        compare[mac].append(strength)
                    else:
			wifi_count = wifi_count + 1
                        arr = []
                        compare.update({mac:arr})
                        compare[mac].append(strength)	
	    for pkt in bl_packets:
                content = pkt.split()
                if len(content) == 2:
                    mac = str(content[0])
                    strength = int(content[1])
		    print mac, strength
		    if mac is not None and strength is not None and strength < 0:
                        if mac in compare:
                            compare[mac].append(strength)
                        else:
			    bl_count = bl_count + 1
                            arr = []
                            compare.update({mac:arr})
                            compare[mac].append(strength)  

            compare_avg = {}
            for mac in compare:
                l = compare[mac]
                avg = n.mean(l)
                #avg = trimmean(l, 80)
                compare_avg.update({mac:avg})

            guess = []
            weight = []
	    for z in difference:
                difference[z] = [[None]*max_y for _ in range(max_x)]
		num_macs[z] = [[0]*max_y for _ in range(max_x)]
            for mac in compare_avg:
                least = None
                location = []
                if mac in fingerprint:
		    for z in fingerprint[mac]:
                        for x in range(len(fingerprint[mac][z])):
                            for y in range(len(fingerprint[mac][z][x])):
	                            if fingerprint[mac][z][x][y] != None:
		                        c = abs(fingerprint[mac][z][x][y] - compare_avg[mac])
		                        num_macs[z][x][y] = num_macs[z][x][y] + 1
		                        if difference[z][x][y] != None:
		                                difference[z][x][y] += c
		                        else:
		                                difference[z][x][y] = c	
            final_z = ''
	    final_x = 0
            final_y = 0
	    print difference
	    for z in difference:
                for x in range(len(difference[z])):
                    for y in range(len(difference[z][x])):
			if(final_z == ''):
			    final_z = z
                        if(difference[final_z][final_x][final_y] is None and difference[z][x][y] is not None):
                            final_z = z
			    final_x = x
                            final_y = y
                        if(difference[z][x][y] != None and difference[final_z][final_x][final_y]/num_macs[final_z][final_x][final_y] > difference[z][x][y]/num_macs[z][x][y]):
                            final_z = z
			    final_x = x
                            final_y = y  
            print(final_z, final_x, final_y)
            im = Image.open(self.path + "/"+ final_z +".gif").copy()
            draw = ImageDraw.Draw(im) 
            draw.line((box_size*x, 0, box_size*x, 240), fill=128, width=1)
            draw.rectangle([final_x*box_size, final_y*box_size, final_x*box_size+box_size, final_y*box_size+box_size], fill=100)
	    draw.text([5,5], str(wifi_count))
	    draw.text([5,15], str(bl_count))
            self.image = ImageTk.PhotoImage(im)            

            imagelabel.configure(image = self.image)
            self.parent.update()
            self.after(50, self.realtime_calculation, imagelabel)
Пример #9
0
#     if True or True:
#         # 除完之后还是整数
#         # print 10 // 3
#         # hashmap = {'1': '1', '2': '2'}
#         # array = ['1', '2', '3']
#         # print array
#         # print hashmap
#         # print 'ok'
#         # abs 函数
#         print abs(-1)
# #         max函数
#         print max(1,2)
# #         min 函数
#         print min(2,3)
#     # 转换成字符串
#     str(1)
# #     转换成int
#     int('2')
# #     转换成bool
#     bool(
#
#     )
#     float()
from Tkinter import Image

from PIL import Image, ImageFilter

with Image.open('aaa.jpg') as image:
    w, h = image.size
    image.filter(ImageFilter.BLUR).save('aa.jpg', 'jpeg')
Пример #10
0
    def create_gui_elements(self):
        top_frame = Frame(self)
        top_frame.grid(row=0, column=0, columnspan=9, rowspan=6)
        # top_frame.pack(fill=X)
        # image display
        photo2 = ImageTk.PhotoImage(Image.open('back.png'))
        image_display = Label(top_frame)
        image_display.configure(image=photo2)
        image_display.image = photo2
        image_display.grid(row=0, columnspan=9, column=1, rowspan=6)
        # image_lb.pack(side=TOP)
        self.add_gui_element(GUI_ELEMENT.IMAGE_DISPLAY_LABEL, image_display)
        close_button = Button(self, text='Close', command=close)
        close_button.grid(row=9, column=9)
        # close_button.pack(side=RIGHT, padx=5, pady=5)
        self.add_gui_element(GUI_ELEMENT.CLOSE_BTN, close_button)

        bottom_frame = Frame(self)
        bottom_frame.grid(row=5, column=0, columnspan=9, rowspan=3)
        # bottom_frame.pack(fill=X)
        config_frame = Frame(bottom_frame)
        config_frame.grid(row=5, column=6, columnspan=3, rowspan=3)
        # config_frame.pack(fill=X)

        list_box_frame = Frame(config_frame)
        list_box_frame.grid(row=5, column=6, columnspan=3, rowspan=3)
        # list_box_frame.pack(side=RIGHT)
        scrollbar = Scrollbar(list_box_frame)
        # scrollbar.pack(side=RIGHT, fill=Y)
        resolution_lb = Listbox(list_box_frame, selectmode=SINGLE, height=4, yscrollcommand=scrollbar.set)
        i = 0
        for resolution in ScreenPaper.get_resolution():
            resolution_lb.insert(i, '%dx%d' % (resolution[0], resolution[1]))
            i += 1
        scrollbar.grid(row=5, column=9, rowspan=9)
        resolution_lb.grid(row=5, column=6, rowspan=4, columnspan=3)
        scrollbar.config(command=resolution_lb.yview)
        # resolution_lb.pack(side=RIGHT)

        self.add_gui_element(GUI_ELEMENT.RESOLUTION_LB, resolution_lb)
        ok_btn = Button(self, text='Create', command=self.create_pape)
        ok_btn.grid(row=9, column=7)
        # ok_btn.pack(side=RIGHT)
        self.add_gui_element(GUI_ELEMENT.OK_BTN, ok_btn)
        save_btn = Button(self, text='Save', command=self.save_image_as)
        save_btn.grid(row=9, column=8)
        # save_btn.pack(side=RIGHT)
        self.add_gui_element(GUI_ELEMENT.SAVE_BTN, save_btn)

        checkbox_frame = Frame(config_frame)
        checkbox_frame.grid(row=5, column=0, rowspan=3, columnspan=6)
        auto_save_var = IntVar()
        auto_save_chk = Checkbutton(checkbox_frame, text="Save automatically", variable=auto_save_var, onvalue=1, offvalue=0)
        auto_save_chk.grid(row=5, column=1)
        # auto_save_chk.pack(side=BOTTOM)
        self.add_gui_element(GUI_ELEMENT.AUTOMATICALLY_SAVE_CK, {'element':auto_save_chk, 'var': auto_save_var})

        auto_upload_var = IntVar()
        auto_upload_chk = Checkbutton(checkbox_frame, text="Upload to imgur automatically", variable=auto_upload_var, onvalue=1, offvalue=0)
        auto_upload_chk.grid(row=6, column=1)
        # auto_upload_chk.pack(side=BOTTOM)
        self.add_gui_element(GUI_ELEMENT.AUTOMATICALLY_UPLOAD_CK, {'element': auto_upload_chk, 'var': auto_upload_var})
        # checkbox_frame.pack(side=RIGHT)
        message_lb = Label(self)
        message_lb.grid(row=7, column=1)
        # message_lb.pack(side=BOTTOM)
        self.add_gui_element(GUI_ELEMENT.MESSAGE_LABEL, message_lb)