Python pyautogui.size() Examples

The following are 14 code examples of pyautogui.size(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyautogui , or try the search function .
Example #1
Source File: tools.py    From Dindo-Bot with MIT License 6 votes vote down vote up
def adjust_click_position(click_x, click_y, window_width, window_height, dest_x, dest_y, dest_width, dest_height):
	# get screen size
	screen_width, screen_height = pyautogui.size()
	if screen_width > window_width and screen_height > window_height:
		# fit position to destination size
		new_x, new_y = fit_position_to_destination(click_x, click_y, window_width, window_height, dest_width, dest_height)
		#print('new_x: %d, new_y: %d, dest_x: %d, dest_y: %d' % (new_x, new_y, dest_x, dest_y))
		# scale to screen
		x = new_x + dest_x
		y = new_y + dest_y
	else:
		x = click_x
		y = click_y
	return (x, y)

# Perform a simple click or double click on x, y position 
Example #2
Source File: tools.py    From Dindo-Bot with MIT License 6 votes vote down vote up
def get_color_percentage(image, expected_color, tolerance=10):
	# get image colors
	width, height = image.size
	image = image.convert('RGB')
	colors = image.getcolors(width * height)
	# check if the expected color exist
	expected_color_count = 0
	for count, color in colors:
		if color_matches(color, expected_color, tolerance):
			expected_color_count += count
	# convert to percentage
	if height == 0: height = 1
	if width == 0: width = 1
	percentage = ((expected_color_count / height) / float(width)) * 100
	return round(percentage, 2)

# Return the dominant color in an image & his percentage 
Example #3
Source File: screen.py    From iris with Mozilla Public License 2.0 5 votes vote down vote up
def __repr__(self):
        return "%s(x: %r, y: %r, size: %r x %r)" % (
            self.__class__.__name__,
            self._bounds.x,
            self.y,
            self._bounds.width,
            self._bounds.height,
        ) 
Example #4
Source File: test_pyautogui.py    From pyautogui with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_size(self):
        width, height = pyautogui.size()

        self.assertTrue(isinstance(width, int), "Type of width is %s" % (type(width)))
        self.assertTrue(isinstance(height, int), "Type of height is %s" % (type(height)))
        self.assertTrue(width > 0, "Width is set to %s" % (width))
        self.assertTrue(height > 0, "Height is set to %s" % (height)) 
Example #5
Source File: test_pyautogui.py    From pyautogui with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def setUp(self):
        self.oldFailsafeSetting = pyautogui.FAILSAFE
        self.center = P(*pyautogui.size()) // 2

        pyautogui.FAILSAFE = False
        pyautogui.moveTo(*self.center)  # make sure failsafe isn't triggered during this test
        pyautogui.FAILSAFE = True 
Example #6
Source File: tools.py    From Dindo-Bot with MIT License 5 votes vote down vote up
def get_screen_size():
	#screen = Gdk.Screen.get_default()
	#return (screen.get_width(), screen.get_height())
	return pyautogui.size()

# Activate a window 
Example #7
Source File: tools.py    From Dindo-Bot with MIT License 5 votes vote down vote up
def take_window_screenshot(window, save_to='screenshot'):
	size = window.get_geometry()
	pb = Gdk.pixbuf_get_from_window(window, 0, 0, size.width, size.height)
	pb.savev(save_to + '.png', 'png', (), ())

# Return a screenshot of the game 
Example #8
Source File: tools.py    From Dindo-Bot with MIT License 5 votes vote down vote up
def fit_position_to_destination(x, y, window_width, window_height, dest_width, dest_height):
	# new coordinate = old coordinate / (window size / destination size)
	new_x = x / (window_width / float(dest_width))
	new_y = y / (window_height / float(dest_height))
	return (int(new_x), int(new_y))

# Adjust click position 
Example #9
Source File: tools.py    From Dindo-Bot with MIT License 5 votes vote down vote up
def get_screen_size():
	return pyautogui.size()

# Move mouse to position 
Example #10
Source File: Attendance_app.py    From Attendance-Management-using-Face-Recognition with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)

        self.title_font = tkfont.Font(family='Helvetica', size=18,
                                      weight="bold", slant="italic")
        geo = str(int(0.43 * x)) + 'x' + str(int(0.52 * y))
        self.geometry(geo)
        self.resizable(False, False)
        self.title('Attendance Management App')
        self.protocol("WM_DELETE_WINDOW", self.on_closing)
        # The container is where we'll stack a bunch of frames
        # on top of each other, then the one we want visible
        # will be raised above the others
        container = tk.Frame(self)
        container.pack(side="top", fill="both", expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.createInitialDirectories()

        self.frames = {}
        for F in (StartPage, StudentPanelPage, ManagerPanelPage,
                  CreateNewBatchPage, AddStudentPage):
            page_name = F.__name__

            frame = F(parent=container, controller=self)
            self.frames[page_name] = frame

            # Put all of the pages in the same location;
            # the one on the top of the stacking order
            # will be the one that is visible.
            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame("StartPage") 
Example #11
Source File: test_humanclicker.py    From pyclick with MIT License 5 votes vote down vote up
def test_simple(self):
        width, height = pyautogui.size()
        toPoint = (width//2, height//2)
        hc = HumanClicker()
        hc.move(toPoint)
        self.assertTrue(pyautogui.position() == toPoint) 
Example #12
Source File: test_humanclicker.py    From pyclick with MIT License 5 votes vote down vote up
def test_randomMove(self):
        width, height = pyautogui.size()
        toPoint = random.randint(width//2,width-1), random.randint(height//2,height-1)
        hc = HumanClicker()
        hc.move(toPoint)
        self.assertTrue(pyautogui.position() == toPoint) 
Example #13
Source File: playback.py    From xbmc with GNU General Public License v3.0 3 votes vote down vote up
def _Input(mousex=0, mousey=0, click=0, keys=None, delay='0.2'):
    import pyautogui
    '''Control the user's mouse and/or keyboard.
       Arguments:
         mousex, mousey - x, y co-ordinates from top left of screen
         keys - list of keys to press or single key
    '''
    g = Globals()
    screenWidth, screenHeight = pyautogui.size()
    mousex = int(screenWidth / 2) if mousex == -1 else mousex
    mousey = int(screenHeight / 2) if mousey == -1 else mousey
    exit_cmd = [('alt', 'f4'), ('ctrl', 'shift', 'q'), ('command', 'q')][(g.platform & -g.platform).bit_length() - 1]

    if keys:
        if '{EX}' in keys:
            pyautogui.hotkey(*exit_cmd)
        else:
            pyautogui.press(keys, interval=delay)
    else:
        pyautogui.moveTo(mousex, mousey)
        if click:
            pyautogui.click(clicks=click)

    Log('Input command: Mouse(x={}, y={}, click={}), Keyboard({})'.format(mousex, mousey, click, keys)) 
Example #14
Source File: test_pyautogui.py    From pyautogui with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
def test_onScreen(self):
        zero = P(0, 0)
        xone = P(1, 0)
        yone = P(0, 1)
        size = P(*pyautogui.size())
        half = size / 2

        on_screen = [zero, zero + xone, zero + yone, zero + xone + yone, half, size - xone - yone]
        off_screen = [zero - xone, zero - yone, zero - xone - yone, size - xone, size - yone, size]

        for value, coords in [(True, on_screen), (False, off_screen)]:
            for coord in coords:
                self.assertEqual(
                    value,
                    pyautogui.onScreen(*coord),
                    "onScreen({0}, {1}) should be {2}".format(coord.x, coord.y, value),
                )
                self.assertEqual(
                    value,
                    pyautogui.onScreen(list(coord)),
                    "onScreen([{0}, {1}]) should be {2}".format(coord.x, coord.y, value),
                )
                self.assertEqual(
                    value,
                    pyautogui.onScreen(tuple(coord)),
                    "onScreen(({0}, {1})) should be {2}".format(coord.x, coord.y, value),
                )
                self.assertEqual(
                    value, pyautogui.onScreen(coord), "onScreen({0}) should be {1}".format(repr(coord), value)
                )

        # These raise PyAutoGUIException.
        with self.assertRaises(pyautogui.PyAutoGUIException):
            pyautogui.onScreen([0, 0], 0)
        with self.assertRaises(pyautogui.PyAutoGUIException):
            pyautogui.onScreen((0, 0), 0)