コード例 #1
0
ファイル: topLevel8.py プロジェクト: ddevost/PYTHON
    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 sellSuggestionItemsToCustomer(img):
    writeLog("check customer interesting..." + str(img))
    found = False
    if clickImage(img):
        writeLog("found customer")
        found = True
        if Image("customer-interactions/sell.png").exists():
            writeLog("sell an item to customer " + str(img))
            clickImage(Image("customer-interactions/sell.png"), 0.8)
        else:
            writeLog("want to sell item to customer but out of item " +
                     str(img))
            suggestionItem.remove(img)
            os.remove(img)
            #os.rename(str(img), str(img))
            clickImage(Image("customer-interactions/refuse.png"), 0.8)
    return found
コード例 #3
0
ファイル: topLevel7.py プロジェクト: ddevost/PYTHON
    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()
コード例 #4
0
def removeTeamViewer():
    try:
        msg = u'贊助工作階段'
        switch_to(msg)
        if Image("teamviewer/check.png").exists():
            writeLog("remove teamviewer")
            clickImage("teamviewer/check.png", 0.8)
        switch_to('Edgebee')
    except LookupError:
        return ""
コード例 #5
0
ファイル: not_mnist.py プロジェクト: bigchange/python-pro
def disp_samples(data_folders, sample_size):
    """each class data folder"""
    for folder in data_folders:
        print(folder)
        image_files = os.listdir(folder)
        image_sample = random.sample(image_files, sample_size)
        for image in image_sample:
            image_file = os.path.join(folder, image)
            i = Image(filename=image_file)
            display(i)
コード例 #6
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()
コード例 #7
0
def clickImage(img,
               similarity=0.85
               ):  # can not go higher than 0.8 due to close item select button
    #writeLog("clickImage " + str(img))
    # Determine if we're going to sleep after click
    sleepy = 0
    if img in sleep_for:
        sleepy = 2

    # is_suggestion = img == suggest

    # Convert to an image
    found = True
    if img == str(img):
        if img == "buttons/next.png":
            similarity = 0.5
        img = Image(img, similarity)
        found = img.exists()

    # Search for the image
    #writeLog("check for image " + str(img))
    print "check image " + str(img)
    if found:
        writeLog("found image " + str(img))
        try:

            # Click it
            click(img)
            # Handle customer suggestions
            # if is_suggestion:
            #       suggestSomething()

            if sleepy:
                writeLog("sleep " + str(sleepy))
                time.sleep(sleepy)
        except Exception as e:
            # writeLog(e)
            print(e)
            writeLog("couldn't click it")
            found = False
    return found
コード例 #8
0
def suggestSomething():

    # Attempt to build something that we're out of
    targets = find_all(Image("lvl-target.png"))
    random.shuffle(targets)
    while len(targets):
        target = targets.pop()
        if target.y > 600:
            continue  # Don't count level targets that are too low
        if clickImage(target):
            if not clickImage("buttons/small-ok.png"):
                return True
コード例 #9
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)
コード例 #10
0
def customerInteraction():
    found = False
    # Search for customer
    for img in customers:
        if clickImage(img):
            if not Image("customer-interactions/check-if-opened.png").exists():
                clickImage("buttons/closeitemselect.png")
                clickImage("buttons/closeresource.png")
                clickImage("buttons/closeconstruction.png")
                continue
            found = True
            # Interact with customer
            for img in customer_interactions:
                if clickImage(img, 0.95):
                    break
            if random.randint(1, 100) <= 5:  # 5% chance
                # Check for an employee again
                employeeInteraction(loop=False)

    return found
コード例 #11
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
コード例 #12
0
def employeeInteraction(loop=True):

    # Check for employees
    found = False
    random.shuffle(employees)
    for img in employees:
        if clickImage(img):

            if not Image("employee-interactions/empty-queue.png",
                         0.75).exists():
                # This employee is already building something
                writeLog("queue is not empty")
                clickImage("buttons/closeitemselect.png")
                continue

            # Attempt to use a build cycle for that employee+
            employee = os.path.basename(img).split(".")[0]
            print "employee is " + str(employee)
            employeeBuildCycle(employee)

            clickImage("buttons/closeitemselect.png")
            clickImage("buttons/closeresource.png")

    return found
コード例 #13
0
from Tkinter import Image

from wand.image import Image
from PIL import Image as PI
import pyocr
import pyocr.builders

import io

tool = pyocr.get_available_tools()[0]
lang = tool.get_available_languages()[1]

req_image = []
final_text = []

image_pdf = Image(filename="./frmVisualizarBula.pdf", resolution=300)
image_jpeg = image_pdf.convert('jpeg')

for img in image_jpeg.sequence:
    img_page = Image(image=img)
    req_image.append(img_page.make_blob('jpeg'))

for img in req_image:
    txt = tool.image_to_string(PI.open(io.BytesIO(img)),
                               lang=lang,
                               builder=pyocr.builders.TextBuilder())
    final_text.append(txt)

print(final_text)
コード例 #14
0
def openStore():
    if Image("buttons/start.png").exists():
        clickImage(Image("buttons/start.png"))
    return
コード例 #15
0
ファイル: Entry.py プロジェクト: hoaicao94/AddressBook
import Tkinter as tk
from Tkinter import Image

FILENAME = 'image.png'
root = tk.Tk()
canvas = tk.Canvas(root, width=250, height=250)
canvas.pack()
tk_img = Image.PhotoImage(file=FILENAME)
canvas.create_image(125, 125, image=tk_img)
quit_button = tk.Button(root,
                        text="Quit",
                        command=root.quit,
                        anchor='w',
                        width=10,
                        activebackground="#33B5E5")
quit_button_window = canvas.create_window(10,
                                          10,
                                          anchor='nw',
                                          window=quit_button)
root.mainloop()
コード例 #16
0
    # Keep clicking on employees when available
    # print("employeeInteraction")
    # employeeInteraction(loop=True)

    # Keep clicking on customers when available
    loop = 0
    #print (not Image("summary.png").exists())
    #print loop < MAXLOOP
    #print (not Image("summary.png").exists()) & loop < MAXLOOP
    #print False & True
    while (loop < MAXLOOP):
        loop = loop + 1
        employeeInteraction(loop=True)
        for img in suggestionItem:
            sellSuggestionItemsToCustomer(img)
        if Image("summary.png").exists():
            break
        if Image("customers/buy.png").exists():
            clickImage("customers/buy.png", 0.8)
            clickImage("customer-interactions/buy.png", 0.8)
        if loop == 2:
            # Check for other buttons and such only if nothing else matched
            for img in always_click:
                img = Image(img, 0.8)
                clickImage(img)
    while clickImage("buttons/done.png"):
        time.sleep(1)
        continue
    if Image("buttons/next.png").exists():
        clickImage("buttons/next.png", 0.8)
    writeLog("Garbage collected " + str(gc.collect()) + " objects")
コード例 #17
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')
コード例 #18
0
from Tkinter import Image

image = Image.open('smiley.jpg')
image.show()
コード例 #19
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)
コード例 #20
0
ファイル: gui.py プロジェクト: omrikiantman/dmex4
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'))
コード例 #21
0
ファイル: form.py プロジェクト: Sheldan/screenPaper
    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)