|
1 | | -from uiautomation import Control, GetRootControl, ControlType, GetFocusedControl, SetWindowTopmost, IsTopLevelWindow, IsZoomed, IsIconic, IsWindowVisible |
| 1 | +from uiautomation import Control, GetRootControl, ControlType, GetFocusedControl, SetWindowTopmost, IsTopLevelWindow, IsZoomed, IsIconic, IsWindowVisible, ControlFromHandle |
2 | 2 | from src.desktop.config import EXCLUDED_APPS,BROWSER_NAMES |
3 | 3 | from src.desktop.views import DesktopState,App,Size |
4 | 4 | from fuzzywuzzy import process |
|
9 | 9 | from PIL import Image |
10 | 10 | import subprocess |
11 | 11 | import pyautogui |
12 | | -import winreg |
13 | 12 | import csv |
14 | 13 | import io |
15 | 14 |
|
@@ -89,8 +88,28 @@ def execute_command(self,command:str)->tuple[str,int]: |
89 | 88 | def is_app_browser(self,node:Control): |
90 | 89 | process=Process(node.ProcessId) |
91 | 90 | return process.name() in BROWSER_NAMES |
| 91 | + |
| 92 | + def resize_app(self,name:str,size:tuple[int,int]=None,loc:tuple[int,int]=None)->tuple[str,int]: |
| 93 | + apps=self.get_apps() |
| 94 | + matched_app:tuple[App,int]|None=process.extractOne(name,apps) |
| 95 | + if matched_app is None: |
| 96 | + return (f'Application {name.title()} not found.',1) |
| 97 | + app,_=matched_app |
| 98 | + app_control=ControlFromHandle(app.handle) |
| 99 | + if loc is None: |
| 100 | + x=app_control.BoundingRectangle.left |
| 101 | + y=app_control.BoundingRectangle.top |
| 102 | + loc=(x,y) |
| 103 | + if size is None: |
| 104 | + width=app_control.BoundingRectangle.width() |
| 105 | + height=app_control.BoundingRectangle.height() |
| 106 | + size=(width,height) |
| 107 | + x,y=loc |
| 108 | + width,height=size |
| 109 | + app_control.MoveWindow(x,y,width,height) |
| 110 | + return (f'Application {name.title()} resized to {width}x{height} at {x},{y}.',0) |
92 | 111 |
|
93 | | - def launch_app(self,name:str): |
| 112 | + def launch_app(self,name:str)->tuple[str,int]: |
94 | 113 | apps_map=self.get_apps_from_start_menu() |
95 | 114 | matched_app=process.extractOne(name,apps_map.keys()) |
96 | 115 | if matched_app is None: |
|
0 commit comments