示例#1
0
    def do_action(self):
        """ Scan a specified area of the screen for an image and store the location in a variable """

        try:
            img = Image.open(self.screenshot)
        except:
            if (self.screenshot is None):
                s = "No image selected in detect image action"
            else:
                s = "Image " + self.screenshot + " Not Found."
            messagebox.showinfo("Image Not Found",
                                s,
                                parent=ToplevelObserver.top())
            return False

        width, height = img.size
        pt = imgsearch.imagesearcharea(self.screenshot,
                                       self.scanPoint.x,
                                       self.scanPoint.y,
                                       self.scanPoint.x + self.scanWidth,
                                       self.scanPoint.y + self.scanHeight,
                                       precision=(float(self.precision) /
                                                  100.0))
        point = POINT(int(pt[0] + (width / 2) + self.scanPoint.x),
                      int(pt[1] + (height / 2 + self.scanPoint.y)))
        if (pt[0] is -1):
            if (self.failOption.get() == 'Set Default Value'):
                point = self.failDefaultValue
            elif (self.failOption.get() == 'Retry'):
                timer = time.time()
                while (pt[0] is -1
                       and (time.time() - timer) < self.retryTimer):
                    pt = imgsearch.imagesearcharea(
                        self.screenshot,
                        self.scanPoint.x,
                        self.scanPoint.y,
                        self.scanPoint.x + self.scanWidth,
                        self.scanPoint.y + self.scanHeight,
                        precision=(float(self.precision) / 100.0))
                if pt[0] is -1:
                    s = "Image not found after retry, stopping."
                    messagebox.showinfo("Image Not Found",
                                        s,
                                        parent=ToplevelObserver.top())
                    return False
                point = POINT(int(pt[0] + (width / 2) + self.scanPoint.x),
                              int(pt[1] + (height / 2 + self.scanPoint.y)))
            else:
                s = "Image not found, stopping."
                messagebox.showinfo("Image Not Found",
                                    s,
                                    parent=ToplevelObserver.top())
                return False

        s = str(point.x) + " " + str(point.y)
        VariableList.set(self.storeVariable.get(), point)
        return True
示例#2
0
    def add(self):
        """ Add a new item at the end of the variable list """

        name = self.nameEntry.get()
        if len(name) > 0:
            if VariableList.contains(name):
                if messagebox.askokcancel("Overwrite",
                                          "Overwrite Variable " + name + "?",
                                          parent=ToplevelObserver.top()):
                    self.delete(name)
                else:
                    return

            variable = VariableList.create_variable(self.variableType.get(),
                                                    name)
            VariableList.add_element(variable)
            index = len(self.tree.get_children())

            data = variable.get_data()

            iid = self.add_tree_item(index, data)
            self.treeItems[name] = iid
            self.tree.selection_set(iid)
            self.update_options()
示例#3
0
    def __init__(self, action, tree, iid):
        Toplevel.__init__(self)
        self.protocol("WM_DELETE_WINDOW", self.quit)
        self.attributes('-topmost', 'true')
        self.grab_set()
        self.action = action
        self.loopType = StringVar()
        self.tree = tree
        self.iid = iid
        top = ToplevelObserver.top()
        loc = '+' + str(top.winfo_x()) + '+' + str(top.winfo_y())
        self.geometry(loc)

        self.winfo_toplevel().minsize(250, 100)
        self.resizable(False, False)
        self.wm_title(action.actionType)

        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)

        content = Frame(self)
        content.grid(row=0, column=0, padx=10, pady=10, sticky=(N, S, E, W))

        content.columnconfigure(0, weight=1)
        content.rowconfigure(0, weight=1)
        content.rowconfigure(1, weight=1)

        #Action

        self.actionFrame = self.action.display(content)

        self.actionFrame.columnconfigure(0, weight=1)
        self.actionFrame.rowconfigure(0, weight=1)

        self.actionFrame.grid(row=0, column=0, pady=(0, 5), sticky=(N, W))

        optionsFrame = Frame(content)
        optionsFrame.grid(row=1, column=0, sticky=(S, E))

        optionsFrame.columnconfigure(0, weight=1)
        optionsFrame.columnconfigure(1, weight=1)
        optionsFrame.rowconfigure(0, weight=1)

        acceptFrame = Frame(optionsFrame, width=50, height=25)
        acceptFrame.grid(row=0, column=0, sticky=(E), padx=(0, 5))
        acceptFrame.grid_propagate(0)
        acceptFrame.columnconfigure(0, weight=1)
        acceptFrame.rowconfigure(0, weight=1)
        self.acceptButton = Button(acceptFrame,
                                   text="Accept",
                                   command=self.accept)
        self.acceptButton.grid(row=0, column=0, sticky=(N, S, E, W))

        cancelFrame = Frame(optionsFrame, width=50, height=25)
        cancelFrame.grid(row=0, column=1, sticky=(E))
        cancelFrame.grid_propagate(0)
        cancelFrame.columnconfigure(0, weight=1)
        cancelFrame.rowconfigure(0, weight=1)
        cancel = Button(cancelFrame, text="Cancel", command=self.quit)
        cancel.grid(row=0, column=0, sticky=(N, S, E, W))

        ToplevelObserver.add_element(self)