106 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			106 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Python
		
	
	
	
| """
 | |
| This subfile to Grail handles window settings and calculations.
 | |
| -> Only works on MS Windows!
 | |
| """
 | |
| 
 | |
| __author__ = "Lukas Mahler"
 | |
| __copyright__ = "Copyright 2018-2021"
 | |
| __version__ = "1.0.0"
 | |
| __date__ = "25.11.2020"
 | |
| __email__ = "lm@ankerlab.de"
 | |
| __status__ = "Development"
 | |
| 
 | |
| 
 | |
| import win32api
 | |
| import win32gui
 | |
| 
 | |
| 
 | |
| def getCursorPos():
 | |
|     flags, hcursor, (x, y) = win32gui.GetCursorInfo()
 | |
|     return {"x": x, "y": y}
 | |
| 
 | |
| 
 | |
| def getMonitors():
 | |
|     monitors = []
 | |
|     for hMonitor, hdcMonitor, pyRect in win32api.EnumDisplayMonitors():
 | |
|         monitors.append(pyRect)
 | |
|     #print(monitors)
 | |
|     return monitors
 | |
| 
 | |
| 
 | |
| def getResolution(monitors):
 | |
|     resolutions = {}
 | |
|     index = 0
 | |
|     for monitor in monitors:
 | |
|         x_from	= monitor[0]
 | |
|         x_to	= monitor[2]
 | |
|         y_from	= monitor[1]
 | |
|         y_to	= monitor[3]
 | |
|         res_x = x_to - x_from
 | |
|         res_y = y_to - y_from
 | |
|         res = (res_x, res_y)
 | |
|         resolutions['Monitor'+str(index)] = res
 | |
|         index += 1
 | |
| 
 | |
|     return resolutions
 | |
| 
 | |
| 
 | |
| def getScreenInfo():
 | |
|     return {"x": win32api.GetSystemMetrics(0), "y": win32api.GetSystemMetrics(1)}
 | |
| 
 | |
| 
 | |
| def getStartingpoint():
 | |
|     return getCursorPos()
 | |
| 
 | |
| 
 | |
| def getEndpoint():
 | |
|     return getCursorPos()
 | |
| 
 | |
| 
 | |
| def getRectangle():
 | |
| 
 | |
|     # Source: https://stackoverflow.com/a/41930485/5593051
 | |
|     state_left = win32api.GetKeyState(0x01)  # Left button down = 0 or 1. Button up = -127 or -128
 | |
|     state_right = win32api.GetKeyState(0x02)  # Right button down = 0 or 1. Button up = -127 or -128
 | |
| 
 | |
|     while True:
 | |
|         a = win32api.GetKeyState(0x01)
 | |
|         b = win32api.GetKeyState(0x02)
 | |
| 
 | |
|         if a != state_left:  # Button state changed
 | |
|             state_left = a
 | |
|             if a < 0:
 | |
|                 print('Left Button Pressed')
 | |
|                 pos_start = getStartingpoint()
 | |
|             else:
 | |
|                 print('Left Button Released')
 | |
|                 pos_end = getEndpoint()
 | |
|                 break
 | |
| 
 | |
|     print(pos_start)
 | |
|     print(pos_end)
 | |
| 
 | |
|     calcScreenshotFrame(pos_start, pos_end)
 | |
| 
 | |
| 
 | |
| def calcScreenshotFrame(pos_start, pos_end):
 | |
|     # If dragging began from top
 | |
|     if pos_start['x'] < pos_end['x']:
 | |
|         left = pos_start['x']
 | |
|         right = pos_end['x']
 | |
|         top = pos_start['y']
 | |
|         bottom = pos_end['y']
 | |
|     # If dragging began from bottom
 | |
|     else:
 | |
|         left = pos_end['x']
 | |
|         right = pos_start['x']
 | |
|         top = pos_end['y']
 | |
|         bottom = pos_start['y']
 | |
| 
 | |
|     print("Screenshot needs to be taken from: x:", left, "->", right, "and y:", top, "->", bottom)
 | |
| 
 | |
| 
 | |
| if __name__ == '__main__':
 | |
|     print("This is a Subfile from grail, it can't be executed on its own.")
 | |
|     exit()
 |