├── .gitignore ├── .vscode └── settings.json ├── Fun.py ├── LICENSE ├── README.md ├── RemoteCT-For-Java ├── RemoteCT.java ├── RemoteCommands.java └── RemoteToolkitError.java ├── RemoteConnectionToolkit.py └── ThanksList & Copyrights /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/latest/usage/project/#working-with-version-control 110 | .pdm.toml 111 | .pdm-python 112 | .pdm-build/ 113 | 114 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 115 | __pypackages__/ 116 | 117 | # Celery stuff 118 | celerybeat-schedule 119 | celerybeat.pid 120 | 121 | # SageMath parsed files 122 | *.sage.py 123 | 124 | # Environments 125 | .env 126 | .venv 127 | env/ 128 | venv/ 129 | ENV/ 130 | env.bak/ 131 | venv.bak/ 132 | 133 | # Spyder project settings 134 | .spyderproject 135 | .spyproject 136 | 137 | # Rope project settings 138 | .ropeproject 139 | 140 | # mkdocs documentation 141 | /site 142 | 143 | # mypy 144 | .mypy_cache/ 145 | .dmypy.json 146 | dmypy.json 147 | 148 | # Pyre type checker 149 | .pyre/ 150 | 151 | # pytype static type analyzer 152 | .pytype/ 153 | 154 | # Cython debug symbols 155 | cython_debug/ 156 | 157 | # PyCharm 158 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 159 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 160 | # and can be added to the global gitignore or merged into this file. For a more nuclear 161 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 162 | #.idea/ 163 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp.default.compilerPath": "d:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX64\\x64\\cl.exe" 3 | } -------------------------------------------------------------------------------- /Fun.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | import os 3 | from os.path import abspath, dirname 4 | import tkinter 5 | import tkinter.simpledialog 6 | 7 | G_UIElementUserDataArray = {} 8 | G_UIElementArray = {} 9 | G_UIElementVariableArray = {} 10 | G_UIInputDataArray = {} 11 | G_UIElementAlias = {} 12 | G_UIGroupDictionary = {} 13 | G_UIStyleDictionary = {} 14 | G_CurrentFilePath = None 15 | G_CutContent = None 16 | 17 | 18 | # 注册一个控件,用于记录它:参数1:界面类名, 参数2:控件名称,参数3:控件。 19 | def Register(uiName, elementName, element, alias=None, groupName=None, styleName=None): 20 | if uiName not in G_UIElementArray: 21 | G_UIElementArray[uiName] = {} 22 | G_UIElementAlias[uiName] = {} 23 | G_UIGroupDictionary[uiName] = {} 24 | G_UIStyleDictionary[uiName] = {} 25 | G_UIElementArray[uiName][elementName] = element 26 | if alias: 27 | G_UIElementAlias[uiName][alias] = elementName 28 | if groupName: 29 | G_UIGroupDictionary[uiName][elementName] = groupName 30 | if styleName: 31 | G_UIStyleDictionary[uiName][elementName] = styleName 32 | 33 | 34 | # 取得控件:参数1:界面类名, 参数2:控件名称。 35 | def GetElement(uiName, elementName): 36 | if uiName in G_UIElementAlias: 37 | if ( 38 | uiName in G_UIElementAlias.keys() 39 | and elementName in G_UIElementAlias[uiName].keys() 40 | ): 41 | elementName = G_UIElementArray[uiName][elementName] 42 | if uiName in G_UIElementArray: 43 | if elementName in G_UIElementArray[uiName]: 44 | return G_UIElementArray[uiName][elementName] 45 | return None 46 | 47 | 48 | # 为控件增加一个Tkinter的内置控件变量,参数1:界面类名, 参数2:控件名称,参数3:默认值。 49 | def AddTKVariable(uiName, elementName, defaultValue=None): 50 | if uiName not in G_UIElementVariableArray: 51 | G_UIElementVariableArray[uiName] = {} 52 | NameLower = elementName.lower() 53 | if NameLower.find("combobox_") >= 0: 54 | G_UIElementVariableArray[uiName][elementName] = tkinter.IntVar() 55 | elif NameLower.find("group_") >= 0: 56 | G_UIElementVariableArray[uiName][elementName] = tkinter.IntVar() 57 | elif NameLower.find("checkbutton_") >= 0: 58 | G_UIElementVariableArray[uiName][elementName] = tkinter.BooleanVar() 59 | else: 60 | G_UIElementVariableArray[uiName][elementName] = tkinter.StringVar() 61 | if defaultValue: 62 | G_UIElementVariableArray[uiName][elementName].set(defaultValue) 63 | return G_UIElementVariableArray[uiName][elementName] 64 | 65 | 66 | # 设置控件的tkinter变量.参数1:界面类名, 参数2:控件名称,参数3:值。 67 | def SetTKVariable(uiName, elementName, value): 68 | if uiName in G_UIElementVariableArray: 69 | if ( 70 | uiName in G_UIElementAlias.keys() 71 | and elementName in G_UIElementAlias[uiName].keys() 72 | ): 73 | elementName = G_UIElementAlias[uiName][elementName] 74 | if elementName in G_UIElementVariableArray[uiName]: 75 | G_UIElementVariableArray[uiName][elementName].set(value) 76 | if elementName in G_UIGroupDictionary[uiName]: 77 | GroupName = G_UIGroupDictionary[uiName][elementName] 78 | if GroupName in G_UIElementVariableArray[uiName]: 79 | G_UIElementVariableArray[uiName][GroupName].set(value) 80 | 81 | 82 | # 取得控件的tkinter变量.参数1:界面类名, 参数2:控件名称。 83 | def GetTKVariable(uiName, elementName): 84 | if uiName in G_UIElementVariableArray: 85 | if ( 86 | uiName in G_UIElementAlias.keys() 87 | and elementName in G_UIElementAlias[uiName].keys() 88 | ): 89 | elementName = G_UIElementAlias[uiName][elementName] 90 | if elementName in G_UIElementVariableArray[uiName]: 91 | return G_UIElementVariableArray[uiName][elementName].get() 92 | if elementName in G_UIGroupDictionary[uiName]: 93 | GroupName = G_UIGroupDictionary[uiName][elementName] 94 | if GroupName in G_UIElementVariableArray[uiName]: 95 | return G_UIElementVariableArray[uiName][GroupName].get() 96 | return None 97 | 98 | 99 | # 为控件添加一个用户数据,参数dataname为数据名,datatype为数据类型,可以包括int、float、string、list、dictionary等,一般在设计软件中用鼠标右键操作控件,在弹出的“绑定数据”对话枉中设置,参数datavalue为数据值,而ismaptotext则是是否将数据直接反映到控件的text变量中。 100 | def AddUserData(uiName, elementName, dataName, datatype, datavalue, isMapToText): 101 | global G_UIElementUserDataArray 102 | if uiName not in G_UIElementUserDataArray: 103 | G_UIElementUserDataArray[uiName] = {} 104 | if ( 105 | uiName in G_UIElementAlias.keys() 106 | and elementName in G_UIElementAlias[uiName].keys() 107 | ): 108 | elementName = G_UIElementAlias[uiName][elementName] 109 | if elementName not in G_UIElementUserDataArray[uiName]: 110 | G_UIElementUserDataArray[uiName][elementName] = [] 111 | G_UIElementUserDataArray[uiName][elementName].append( 112 | [dataName, datatype, datavalue, isMapToText] 113 | ) 114 | 115 | 116 | # 设置控件的用户数据值。 117 | def SetUserData(uiName, elementName, dataName, datavalue): 118 | global G_UIElementArray 119 | global G_UIElementUserDataArray 120 | if uiName in G_UIElementUserDataArray: 121 | if ( 122 | uiName in G_UIElementAlias.keys() 123 | and elementName in G_UIElementAlias[uiName].keys() 124 | ): 125 | elementName = G_UIElementAlias[uiName][elementName] 126 | if elementName in G_UIElementUserDataArray[uiName]: 127 | for EBData in G_UIElementUserDataArray[uiName][elementName]: 128 | if EBData[0] == dataName: 129 | EBData[2] = datavalue 130 | if EBData[3] == 1: 131 | SetText(uiName, elementName, datavalue) 132 | return 133 | 134 | 135 | # 取得控件的用户数据值。 136 | def GetUserData(uiName, elementName, dataName): 137 | global G_UIElementUserDataArray 138 | if uiName in G_UIElementUserDataArray: 139 | if ( 140 | uiName in G_UIElementAlias.keys() 141 | and elementName in G_UIElementAlias[uiName].keys() 142 | ): 143 | elementName = G_UIElementAlias[uiName][elementName] 144 | if elementName in G_UIElementUserDataArray[uiName]: 145 | for EBData in G_UIElementUserDataArray[uiName][elementName]: 146 | if EBData[0] == dataName: 147 | if EBData[1] == "int": 148 | return int(EBData[2]) 149 | elif EBData[1] == "float": 150 | return float(EBData[2]) 151 | else: 152 | return EBData[2] 153 | return None 154 | 155 | 156 | # 设置控件的tkinter属性值。 157 | def SetTKAttrib(uiName, elementName, AttribName, attribValue): 158 | global G_UIElementArray 159 | if uiName in G_UIElementArray: 160 | if ( 161 | uiName in G_UIElementAlias.keys() 162 | and elementName in G_UIElementAlias[uiName].keys() 163 | ): 164 | elementName = G_UIElementAlias[uiName][elementName] 165 | if AttribName in G_UIElementArray[uiName][elementName].configure().keys(): 166 | G_UIElementArray[uiName][elementName][AttribName] = attribValue 167 | 168 | 169 | # 获取控件的tkinter属性值。 170 | def GetTKAttrib(uiName, elementName, AttribName): 171 | global G_UIElementArray 172 | if uiName in G_UIElementArray: 173 | if ( 174 | uiName in G_UIElementAlias.keys() 175 | and elementName in G_UIElementAlias[uiName].keys() 176 | ): 177 | elementName = G_UIElementAlias[uiName][elementName] 178 | return G_UIElementArray[uiName][elementName].cget(AttribName) 179 | 180 | 181 | # 设置控件的文本(label, button, entry and text)。 182 | def SetText(uiName, elementName, textValue): 183 | global G_UIElementArray 184 | global G_UIElementVariableArray 185 | showtext = str("%s" % textValue) 186 | if ( 187 | uiName in G_UIElementAlias.keys() 188 | and elementName in G_UIElementAlias[uiName].keys() 189 | ): 190 | elementName = G_UIElementAlias[uiName][elementName] 191 | if uiName in G_UIElementVariableArray: 192 | if elementName in G_UIElementVariableArray[uiName]: 193 | G_UIElementVariableArray[uiName][elementName].set(showtext) 194 | return 195 | if uiName in G_UIElementArray: 196 | if elementName in G_UIElementArray[uiName]: 197 | if elementName.find("Text_") >= 0: 198 | G_UIElementArray[uiName][elementName].delete("0.0", tkinter.END) 199 | G_UIElementArray[uiName][elementName].insert(tkinter.END, showtext) 200 | else: 201 | G_UIElementArray[uiName][elementName].configure(text=showtext) 202 | 203 | 204 | # 获取控件的文本(label, button, entry and text)。 205 | def GetText(uiName, elementName): 206 | global G_UIElementArray 207 | global G_UIElementVariableArray 208 | if ( 209 | uiName in G_UIElementAlias.keys() 210 | and elementName in G_UIElementAlias[uiName].keys() 211 | ): 212 | elementName = G_UIElementAlias[uiName][elementName] 213 | if uiName in G_UIElementVariableArray: 214 | if elementName in G_UIElementVariableArray[uiName]: 215 | return G_UIElementVariableArray[uiName][elementName].get() 216 | if uiName in G_UIElementArray: 217 | if elementName in G_UIElementArray[uiName]: 218 | if elementName.find("Text_") >= 0: 219 | return G_UIElementArray[uiName][elementName].get("0.0", tkinter.END) 220 | elif elementName.find("Spinbox_") >= 0: 221 | return str(G_UIElementArray[uiName][elementName].get()) 222 | else: 223 | return G_UIElementArray[uiName][elementName].cget("text") 224 | return str("") 225 | 226 | 227 | # 设置控件的背景图片(Label,Button)。 228 | def SetImage(uiName, elementName, imagePath): 229 | global G_UIElementVariableArray 230 | if ( 231 | uiName in G_UIElementAlias.keys() 232 | and elementName in G_UIElementAlias[uiName].keys() 233 | ): 234 | elementName = G_UIElementAlias[uiName][elementName] 235 | if elementName.find("Label_") == 0 or elementName.find("Button_") == 0: 236 | Control = GetElement(uiName, elementName) 237 | if Control != None: 238 | if uiName in G_UIElementUserDataArray: 239 | if elementName in G_UIElementUserDataArray[uiName]: 240 | for EBData in G_UIElementUserDataArray[uiName][elementName]: 241 | if EBData[0] == "image": 242 | EBData[1] = imagePath 243 | from PIL import Image, ImageTk 244 | 245 | image = Image.open(imagePath).convert("RGBA") 246 | image_Resize = image.resize( 247 | (Control.winfo_width(), Control.winfo_height()), 248 | Image.ANTIALIAS, 249 | ) 250 | EBData[2] = ImageTk.PhotoImage(image_Resize) 251 | Control.configure(image=EBData[2]) 252 | return 253 | from PIL import Image, ImageTk 254 | 255 | image = Image.open(imagePath).convert("RGBA") 256 | image_Resize = image.resize( 257 | (Control.winfo_width(), Control.winfo_height()), Image.ANTIALIAS 258 | ) 259 | EBData2 = ImageTk.PhotoImage(image_Resize) 260 | AddUserData(uiName, elementName, "image", imagePath, EBData2, 0) 261 | Control.configure(image=EBData2) 262 | 263 | 264 | # 获取控件的背景图像文件(标签、按钮)。 265 | def GetImage(uiName, elementName): 266 | global G_UIElementVariableArray 267 | if ( 268 | uiName in G_UIElementAlias.keys() 269 | and elementName in G_UIElementAlias[uiName].keys() 270 | ): 271 | elementName = G_UIElementAlias[uiName][elementName] 272 | if elementName.find("Label_") == 0 or elementName.find("Button_") == 0: 273 | Control = GetElement(uiName, elementName) 274 | if Control != None: 275 | if uiName in G_UIElementUserDataArray: 276 | if elementName in G_UIElementUserDataArray[uiName]: 277 | for EBData in G_UIElementUserDataArray[uiName][elementName]: 278 | if EBData[0] == "image": 279 | return EBData[1] 280 | return str("") 281 | 282 | 283 | # 设置ListBox和ComboBox的选中项。 284 | def SetSelectIndex(uiName, elementName, index): 285 | if ( 286 | uiName in G_UIElementAlias.keys() 287 | and elementName in G_UIElementAlias[uiName].keys() 288 | ): 289 | elementName = G_UIElementAlias[uiName][elementName] 290 | Control = GetElement(uiName, elementName) 291 | if Control != None: 292 | if elementName.find("ComboBox_") == 0: 293 | Control.current(index) 294 | elif elementName.find("ListBox_") == 0: 295 | Control.select_set(index) 296 | 297 | 298 | # 取得ListBox和ComboBox的选中项。 299 | def GetSelectIndex(uiName, elementName): 300 | if ( 301 | uiName in G_UIElementAlias.keys() 302 | and elementName in G_UIElementAlias[uiName].keys() 303 | ): 304 | elementName = G_UIElementAlias[uiName][elementName] 305 | Control = GetElement(uiName, elementName) 306 | if Control != None: 307 | if elementName.find("ComboBox_") == 0: 308 | return Control.current() 309 | elif elementName.find("ListBox_") == 0: 310 | currIndex = Control.curselection() 311 | if len(currIndex) > 0 and currIndex[0] >= 0: 312 | return currIndex[0] 313 | return -1 314 | 315 | 316 | # 初始化界面各控件初始数。 317 | def InitElementData(uiName): 318 | global G_UIElementUserDataArray 319 | if uiName in G_UIElementUserDataArray: 320 | for elementName in G_UIElementUserDataArray[uiName].keys(): 321 | for EBData in G_UIElementUserDataArray[uiName][elementName]: 322 | if EBData[3] == 1: 323 | SetText(uiName, elementName, EBData[2]) 324 | SetText(uiName, elementName, EBData[2]) 325 | 326 | 327 | # 初始化界面各控件初始样式。 328 | def InitElementStyle(uiName, Style): 329 | StyleArray = ReadStyleFile(Style + ".py") 330 | global G_UIElementArray 331 | if uiName in G_UIElementArray: 332 | Root = GetElement(uiName, "root") 333 | TFormKey = ".TForm" 334 | if TFormKey in StyleArray: 335 | if "background" in StyleArray[TFormKey]: 336 | Root["background"] = StyleArray[TFormKey]["background"] 337 | for elementName in G_UIElementArray[uiName].keys(): 338 | Widget = G_UIElementArray[uiName][elementName] 339 | try: 340 | if Widget.winfo_exists() == 1: 341 | WinClass = Widget.winfo_class() 342 | StyleName = ".T" + WinClass 343 | for attribute in StyleArray[StyleName].keys(): 344 | Widget[attribute] = StyleArray[StyleName][attribute] 345 | except BaseException: 346 | continue 347 | 348 | 349 | # 取得界面的所有输入数据。 350 | def GetInputDataArray(uiName): 351 | global G_UIElementArray 352 | global G_UIInputDataArray 353 | global G_UIElementVariableArray 354 | G_UIInputDataArray.clear() 355 | if uiName in G_UIElementArray: 356 | for elementName in G_UIElementArray[uiName].keys(): 357 | G_UIInputDataArray[elementName] = [] 358 | Widget = G_UIElementArray[uiName][elementName] 359 | if elementName.find("Text_") >= 0: 360 | content = Widget.get("0.0", tkinter.END) 361 | G_UIInputDataArray[elementName].append(content) 362 | elif elementName.find("Entry_") >= 0: 363 | content = G_UIElementVariableArray[uiName][elementName].get() 364 | G_UIInputDataArray[elementName].append(content) 365 | if uiName in G_UIElementVariableArray: 366 | for elementName in G_UIElementVariableArray[uiName].keys(): 367 | if elementName.find("Group_") >= 0: 368 | ElementIntValue = G_UIElementVariableArray[uiName][elementName].get() 369 | G_UIInputDataArray[elementName] = [] 370 | G_UIInputDataArray[elementName].append(ElementIntValue) 371 | return G_UIInputDataArray 372 | 373 | 374 | # 将弹出界面对话框居中。 375 | def CenterDlg(uiName, popupDlg, dw=0, dh=0): 376 | if dw == 0: 377 | dw = popupDlg.winfo_width() 378 | if dh == 0: 379 | dh = popupDlg.winfo_height() 380 | root = GetElement(uiName, "root") 381 | if root != None: 382 | sw = root.winfo_width() 383 | sh = root.winfo_height() 384 | sx = root.winfo_x() 385 | sy = root.winfo_y() 386 | popupDlg.geometry( 387 | "%dx%d+%d+%d" % (dw, dh, sx + (sw - dw) / 2, sy + (sh - dh) / 2) 388 | ) 389 | else: 390 | import ctypes 391 | 392 | user32 = ctypes.windll.user32 393 | sw = user32.GetSystemMetrics(0) 394 | sh = user32.GetSystemMetrics(1) 395 | sx = 0 396 | sy = 0 397 | popupDlg.geometry( 398 | "%dx%d+%d+%d" % (dw, dh, sx + (sw - dw) / 2, sy + (sh - dh) / 2) 399 | ) 400 | 401 | 402 | # 在界面布局文件中调用设置控件的圆角属性,但由于尚未创建接口,因此有必要在两次之后调用ShowRoundedRectangle。注意:此功能不跨平台。 403 | def SetRoundedRectangle(control, WidthEllipse=20, HeightEllipse=20): 404 | if control != None: 405 | control.after( 406 | 10, lambda: ShowRoundedRectangle(control, WidthEllipse, HeightEllipse) 407 | ) 408 | 409 | 410 | # 立即设置控件的圆角属性。注意:此功能不跨平台。 411 | def ShowRoundedRectangle(control, WidthEllipse, HeightEllipse): 412 | import win32gui 413 | 414 | HRGN = win32gui.CreateRoundRectRgn( 415 | 0, 0, control.winfo_width(), control.winfo_height(), WidthEllipse, HeightEllipse 416 | ) 417 | win32gui.SetWindowRgn(control.winfo_id(), HRGN, 1) 418 | 419 | 420 | # 弹出一个信息对话框。 421 | def MessageBox(text): 422 | tkinter.messagebox.showwarning("info", text) 423 | 424 | 425 | # 弹出一个输入对话框。 426 | def InputBox(title, text): 427 | res = tkinter.simpledialog.askstring(title, "Input Box", initialvalue=text) 428 | return res 429 | 430 | 431 | # 弹出一个选择对话框,你需要选择YES或NO。 432 | def AskBox(title, text): 433 | res = tkinter.messagebox.askyesno(title, text) 434 | return res 435 | 436 | 437 | # 返回对应目录的所有指定类型文件。 438 | def WalkAllResFiles(parentPath, alldirs=True, extName=None): 439 | ResultFilesArray = [] 440 | if os.path.exists(parentPath) == True: 441 | for fileName in os.listdir(parentPath): 442 | if "__pycache__" not in fileName: 443 | if ".git" not in fileName: 444 | newPath = parentPath + "\\" + fileName 445 | if os.path.isdir(newPath): 446 | if extName == None: 447 | ResultFilesArray.append(newPath) 448 | if alldirs == True: 449 | ResultFilesArray.extend( 450 | WalkAllResFiles(newPath, alldirs, extName) 451 | ) 452 | else: 453 | if extName == None: 454 | ResultFilesArray.append(newPath) 455 | else: 456 | file_extension = os.path.splitext(fileName)[1].replace( 457 | ".", "" 458 | ) 459 | file_extension_lower = file_extension.lower().strip() 460 | file_extName_lower = extName.lower().strip() 461 | if file_extension_lower == file_extName_lower: 462 | ResultFilesArray.append(newPath) 463 | return ResultFilesArray 464 | 465 | 466 | # 重新定义消息映射函数,自定义参数。 467 | def EventFunction_Adaptor(fun, **params): 468 | return lambda event, fun=fun, params=params: fun(event, **params) 469 | 470 | 471 | # 设置控件的绝对或相对位置。 472 | def SetControlPlace(control, x, y, w, h): 473 | control.place(x=0, y=0, width=0, height=0) 474 | control.place(relx=0, rely=0, relwidth=0, relheight=0) 475 | if type(x) == type(1.0): 476 | if type(y) == type(1.0): 477 | if type(w) == type(1.0): 478 | if type(h) == type(1.0): 479 | control.place(relx=x, rely=y, relwidth=w, relheight=h) 480 | else: 481 | control.place(relx=x, rely=y, relwidth=w, height=h) 482 | else: 483 | if type(h) == type(1.0): 484 | control.place(relx=x, rely=y, width=w, relheight=h) 485 | else: 486 | control.place(relx=x, rely=y, width=w, height=h) 487 | else: 488 | if type(w) == type(1.0): 489 | if type(h) == type(1.0): 490 | control.place(relx=x, y=y, relwidth=w, relheight=h) 491 | else: 492 | control.place(relx=x, y=y, relwidth=w, height=h) 493 | else: 494 | if type(h) == type(1.0): 495 | control.place(relx=x, y=y, relwidth=w, relheight=h) 496 | else: 497 | control.place(relx=x, y=y, relwidth=w, height=h) 498 | else: 499 | if type(y) == type(1.0): 500 | if type(w) == type(1.0): 501 | if type(h) == type(1.0): 502 | control.place(x=x, rely=y, relwidth=w, relheight=h) 503 | else: 504 | control.place(x=x, rely=y, relwidth=w, height=h) 505 | else: 506 | if type(h) == type(1.0): 507 | control.place(x=x, rely=y, width=w, relheight=h) 508 | else: 509 | control.place(x=x, rely=y, width=w, height=h) 510 | else: 511 | if type(w) == type(1.0): 512 | if type(h) == type(1.0): 513 | control.place(x=x, y=y, relwidth=w, relheight=h) 514 | else: 515 | control.place(x=x, y=y, relwidth=w, height=h) 516 | else: 517 | if type(h) == type(1.0): 518 | control.place(x=x, y=y, width=w, relheight=h) 519 | else: 520 | control.place(x=x, y=y, width=w, height=h) 521 | 522 | 523 | # 定义一个可拖拽移动和拖拽边框大小的窗口类。 524 | class WindowDraggable: 525 | def __init__(self, widget, bordersize=6, bordercolor="#444444"): 526 | self.widget = widget 527 | widget.bind("", self.Enter) 528 | widget.bind("", self.Motion) 529 | widget.bind("", self.Leave) 530 | widget.bind("", self.StartDrag) 531 | widget.bind("", self.StopDrag) 532 | widget.bind("", self.MoveDragPos) 533 | self.bordersize = bordersize 534 | self.bordercolor = bordercolor 535 | self.top_drag = None 536 | self.left_drag = None 537 | self.right_drag = None 538 | self.bottom_drag = None 539 | self.topleft_drag = None 540 | self.bottomleft_drag = None 541 | self.topright_drag = None 542 | self.bottomright_drag = None 543 | widget.after(10, lambda: self.ShowWindowIcoToBar(widget)) 544 | 545 | def ShowWindowIcoToBar(self, widget): 546 | GWL_EXSTYLE = -20 547 | WS_EX_APPWINDOW = 0x00040000 548 | WS_EX_TOOLWINDOW = 0x00000080 549 | from ctypes import windll 550 | 551 | hwnd = windll.user32.GetParent(widget.winfo_id()) 552 | style = windll.user32.GetWindowLongPtrW(hwnd, GWL_EXSTYLE) 553 | style = style & ~WS_EX_TOOLWINDOW 554 | style = style | WS_EX_APPWINDOW 555 | res = windll.user32.SetWindowLongPtrW(hwnd, GWL_EXSTYLE, style) 556 | widget.wm_withdraw() 557 | widget.after(10, lambda: widget.wm_deiconify()) 558 | 559 | def Enter(self, event): 560 | if self.widget == event.widget or event.widget.winfo_class() == "Canvas": 561 | formx = self.widget.winfo_x() 562 | formy = self.widget.winfo_y() 563 | formw = self.widget.winfo_width() 564 | formh = self.widget.winfo_height() 565 | x = event.x_root - formx 566 | y = event.y_root - formy 567 | 568 | def Motion(self, event): 569 | if self.widget == event.widget or event.widget.winfo_class() == "Canvas": 570 | formx = self.widget.winfo_x() 571 | formy = self.widget.winfo_y() 572 | formw = self.widget.winfo_width() 573 | formh = self.widget.winfo_height() 574 | x = event.x_root - formx 575 | y = event.y_root - formy 576 | if ( 577 | (x >= 0) 578 | and (x <= self.bordersize) 579 | and (y >= 0) 580 | and (y <= self.bordersize) 581 | ): 582 | if self.top_drag == None: 583 | self.top_drag = tkinter.Label(self.widget) 584 | self.top_drag.bind("", self.StartDrag) 585 | self.top_drag.bind("", self.StopDrag) 586 | self.top_drag.bind("", self.MoveDragSize_TL) 587 | self.top_drag.bind("", self.LeaveDragBorder_TL) 588 | if self.left_drag == None: 589 | self.left_drag = tkinter.Label(self.widget) 590 | self.left_drag.bind("", self.StartDrag) 591 | self.left_drag.bind("", self.StopDrag) 592 | self.left_drag.bind("", self.MoveDragSize_TL) 593 | self.left_drag.bind("", self.LeaveDragBorder_TL) 594 | self.top_drag.place(x=0, y=0, width=formw, height=self.bordersize) 595 | self.top_drag.configure(bg=self.bordercolor) 596 | self.left_drag.place(x=0, y=0, width=self.bordersize, height=formh) 597 | self.left_drag.configure(bg=self.bordercolor) 598 | if (y >= 0) and (y <= self.bordersize): 599 | if self.top_drag == None: 600 | self.top_drag = tkinter.Label(self.widget) 601 | self.top_drag.bind("", self.StartDrag) 602 | self.top_drag.bind("", self.StopDrag) 603 | self.top_drag.bind("", self.MoveDragSize_V1) 604 | self.top_drag.bind("", self.MotionDragBorder) 605 | self.top_drag.bind("", self.LeaveDragBorder) 606 | self.top_drag.place(x=0, y=0, width=formw, height=self.bordersize) 607 | self.top_drag.configure(bg=self.bordercolor) 608 | if (y >= (formh - self.bordersize)) and (y <= formh): 609 | if self.bottom_drag == None: 610 | self.bottom_drag = tkinter.Label(self.widget) 611 | self.bottom_drag.bind("", self.StartDrag) 612 | self.bottom_drag.bind("", self.StopDrag) 613 | self.bottom_drag.bind("", self.MoveDragSize_V2) 614 | self.bottom_drag.bind("", self.MotionDragBorder) 615 | self.bottom_drag.bind("", self.LeaveDragBorder) 616 | self.bottom_drag.place( 617 | x=0, 618 | y=(formh - self.bordersize), 619 | width=formw, 620 | height=self.bordersize, 621 | ) 622 | self.bottom_drag.configure(bg=self.bordercolor) 623 | if (x >= 0) and (x <= self.bordersize): 624 | if self.left_drag == None: 625 | self.left_drag = tkinter.Label(self.widget) 626 | self.left_drag.bind("", self.StartDrag) 627 | self.left_drag.bind("", self.StopDrag) 628 | self.left_drag.bind("", self.MoveDragSize_H1) 629 | self.left_drag.bind("", self.MotionDragBorder) 630 | self.left_drag.bind("", self.LeaveDragBorder) 631 | self.left_drag.place(x=0, y=0, width=self.bordersize, height=formh) 632 | self.left_drag.configure(bg=self.bordercolor) 633 | if (x >= (formw - self.bordersize)) and (x <= formw): 634 | if self.right_drag == None: 635 | self.right_drag = tkinter.Label(self.widget) 636 | self.right_drag.bind("", self.StartDrag) 637 | self.right_drag.bind("", self.StopDrag) 638 | self.right_drag.bind("", self.MoveDragSize_H2) 639 | self.right_drag.bind("", self.MotionDragBorder) 640 | self.right_drag.bind("", self.LeaveDragBorder) 641 | self.right_drag.place( 642 | x=(formw - self.bordersize), 643 | y=0, 644 | width=self.bordersize, 645 | height=formh, 646 | ) 647 | self.right_drag.configure(bg=self.bordercolor) 648 | 649 | def Leave(self, event): 650 | if self.widget == event.widget or event.widget.winfo_class() == "Canvas": 651 | pass 652 | 653 | def StartDrag(self, event): 654 | self.x = event.x_root 655 | self.y = event.y_root 656 | 657 | def StopDrag(self, event): 658 | self.x = None 659 | self.y = None 660 | self.widget.configure(cursor="arrow") 661 | 662 | def MoveDragPos(self, event): 663 | if self.widget == event.widget or event.widget.winfo_class() == "Canvas": 664 | formx = self.widget.winfo_x() 665 | formy = self.widget.winfo_y() 666 | formw = self.widget.winfo_width() 667 | formh = self.widget.winfo_height() 668 | x = event.x_root - formx 669 | y = event.y_root - formy 670 | deltaX = event.x_root - self.x 671 | deltaY = event.y_root - self.y 672 | newX = self.widget.winfo_x() + deltaX 673 | newY = self.widget.winfo_y() + deltaY 674 | geoinfo = str( 675 | "%dx%d+%d+%d" 676 | % (self.widget.winfo_width(), self.widget.winfo_height(), newX, newY) 677 | ) 678 | self.widget.geometry(geoinfo) 679 | self.x = event.x_root 680 | self.y = event.y_root 681 | 682 | def MoveDragSize_H1(self, event): 683 | deltaX = event.x_root - self.x 684 | formx = self.widget.winfo_x() + deltaX 685 | newW = self.widget.winfo_width() - deltaX 686 | geoinfo = str( 687 | "%dx%d+%d+%d" 688 | % (newW, self.widget.winfo_height(), formx, self.widget.winfo_y()) 689 | ) 690 | self.widget.geometry(geoinfo) 691 | self.left_drag.place( 692 | x=0, y=0, width=self.bordersize, height=self.widget.winfo_height() 693 | ) 694 | self.x = event.x_root 695 | self.widget.configure(cursor="plus") 696 | 697 | def MoveDragSize_H2(self, event): 698 | deltaX = event.x_root - self.x 699 | formw = self.widget.winfo_width() 700 | formh = self.widget.winfo_height() 701 | newW = self.widget.winfo_width() + deltaX 702 | geoinfo = str( 703 | "%dx%d+%d+%d" 704 | % ( 705 | newW, 706 | self.widget.winfo_height(), 707 | self.widget.winfo_x(), 708 | self.widget.winfo_y(), 709 | ) 710 | ) 711 | self.widget.geometry(geoinfo) 712 | self.right_drag.place( 713 | x=newW - self.bordersize, y=0, width=self.bordersize, height=formh 714 | ) 715 | self.x = event.x_root 716 | self.widget.configure(cursor="plus") 717 | 718 | def MoveDragSize_V1(self, event): 719 | deltaY = event.y_root - self.y 720 | formy = self.widget.winfo_y() + deltaY 721 | newH = self.widget.winfo_height() - deltaY 722 | geoinfo = str( 723 | "%dx%d+%d+%d" 724 | % (self.widget.winfo_width(), newH, self.widget.winfo_x(), formy) 725 | ) 726 | self.widget.geometry(geoinfo) 727 | self.top_drag.place( 728 | x=0, y=0, width=self.widget.winfo_width(), height=self.bordersize 729 | ) 730 | self.y = event.y_root 731 | self.widget.configure(cursor="plus") 732 | 733 | def MoveDragSize_V2(self, event): 734 | deltaY = event.y_root - self.y 735 | newH = self.widget.winfo_height() + deltaY 736 | geoinfo = str( 737 | "%dx%d+%d+%d" 738 | % ( 739 | self.widget.winfo_width(), 740 | newH, 741 | self.widget.winfo_x(), 742 | self.widget.winfo_y(), 743 | ) 744 | ) 745 | self.widget.geometry(geoinfo) 746 | self.bottom_drag.place( 747 | x=0, 748 | y=(newH - self.bordersize), 749 | width=self.widget.winfo_width(), 750 | height=self.bordersize, 751 | ) 752 | self.y = event.y_root 753 | self.widget.configure(cursor="plus") 754 | 755 | def MotionDragBorder(self, event): 756 | formx = self.widget.winfo_x() 757 | formy = self.widget.winfo_y() 758 | formw = self.widget.winfo_width() 759 | formh = self.widget.winfo_height() 760 | x = event.x_root - formx 761 | y = event.y_root - formy 762 | if event.widget == self.left_drag: 763 | if y >= 0 and y <= self.bordersize: 764 | if self.top_drag == None: 765 | self.top_drag = tkinter.Label(self.widget) 766 | self.top_drag.place(x=0, y=0, width=formw, height=self.bordersize) 767 | self.top_drag.bind("", self.StartDrag) 768 | self.top_drag.bind("", self.StopDrag) 769 | self.top_drag.bind("", self.MoveDragSize_TL) 770 | self.top_drag.bind("", self.LeaveDragBorder_TL) 771 | if self.left_drag == None: 772 | self.left_drag = tkinter.Label(self.widget) 773 | self.left_drag.bind("", self.StartDrag) 774 | self.left_drag.bind("", self.StopDrag) 775 | self.left_drag.bind("", self.MoveDragSize_TL) 776 | self.left_drag.bind("", self.LeaveDragBorder_TL) 777 | if y >= (formh - self.bordersize) and y <= formh: 778 | if self.bottom_drag == None: 779 | self.bottom_drag = tkinter.Label(self.widget) 780 | self.bottom_drag.place( 781 | x=0, y=formh - self.bordersize, width=formw, height=self.bordersize 782 | ) 783 | self.bottom_drag.bind("", self.StartDrag) 784 | self.bottom_drag.bind("", self.StopDrag) 785 | self.bottom_drag.bind("", self.MoveDragSize_BL) 786 | self.bottom_drag.bind("", self.LeaveDragBorder_BL) 787 | if self.left_drag == None: 788 | self.left_drag = tkinter.Label(self.widget) 789 | self.left_drag.bind("", self.StartDrag) 790 | self.left_drag.bind("", self.StopDrag) 791 | self.left_drag.bind("", self.MoveDragSize_BL) 792 | self.left_drag.bind("", self.LeaveDragBorder_BL) 793 | if event.widget == self.right_drag: 794 | if y >= 0 and y <= self.bordersize: 795 | if self.top_drag == None: 796 | self.top_drag = tkinter.Label(self.widget) 797 | self.top_drag.place(x=0, y=0, width=formw, height=self.bordersize) 798 | self.top_drag.bind("", self.StartDrag) 799 | self.top_drag.bind("", self.StopDrag) 800 | self.top_drag.bind("", self.MoveDragSize_TR) 801 | self.top_drag.bind("", self.LeaveDragBorder_TR) 802 | if self.right_drag == None: 803 | self.right_drag = tkinter.Label(self.widget) 804 | self.right_drag.bind("", self.StartDrag) 805 | self.right_drag.bind("", self.StopDrag) 806 | self.right_drag.bind("", self.MoveDragSize_TR) 807 | self.right_drag.bind("", self.LeaveDragBorder_TR) 808 | if y >= (formh - self.bordersize) and y <= formh: 809 | if self.bottom_drag == None: 810 | self.bottom_drag = tkinter.Label(self.widget) 811 | self.bottom_drag.place( 812 | x=0, y=formh - self.bordersize, width=formw, height=self.bordersize 813 | ) 814 | self.bottom_drag.bind("", self.StartDrag) 815 | self.bottom_drag.bind("", self.StopDrag) 816 | self.bottom_drag.bind("", self.MoveDragSize_BR) 817 | self.bottom_drag.bind("", self.LeaveDragBorder_BR) 818 | if self.right_drag == None: 819 | self.right_drag = tkinter.Label(self.widget) 820 | self.right_drag.bind("", self.StartDrag) 821 | self.right_drag.bind("", self.StopDrag) 822 | self.right_drag.bind("", self.MoveDragSize_BR) 823 | self.right_drag.bind("", self.LeaveDragBorder_BR) 824 | if event.widget == self.top_drag: 825 | if x >= 0 and x <= self.bordersize: 826 | if self.top_drag == None: 827 | self.top_drag = tkinter.Label(self.widget) 828 | self.top_drag.bind("", self.StartDrag) 829 | self.top_drag.bind("", self.StopDrag) 830 | self.top_drag.bind("", self.MoveDragSize_TL) 831 | self.top_drag.bind("", self.LeaveDragBorder_TL) 832 | if self.left_drag == None: 833 | self.left_drag = tkinter.Label(self.widget) 834 | self.left_drag.place(x=0, y=0, width=self.bordersize, height=formh) 835 | self.left_drag.bind("", self.StartDrag) 836 | self.left_drag.bind("", self.StopDrag) 837 | self.left_drag.bind("", self.MoveDragSize_TL) 838 | self.left_drag.bind("", self.LeaveDragBorder_TL) 839 | if x >= (formw - self.bordersize) and x <= formw: 840 | if self.top_drag == None: 841 | self.top_drag = tkinter.Label(self.widget) 842 | self.top_drag.bind("", self.StartDrag) 843 | self.top_drag.bind("", self.StopDrag) 844 | self.top_drag.bind("", self.MoveDragSize_TR) 845 | self.top_drag.bind("", self.LeaveDragBorder_TR) 846 | if self.right_drag == None: 847 | self.right_drag = tkinter.Label(self.widget) 848 | self.right_drag.place( 849 | x=formw - self.bordersize, y=0, width=self.bordersize, height=formh 850 | ) 851 | self.right_drag.bind("", self.StartDrag) 852 | self.right_drag.bind("", self.StopDrag) 853 | self.right_drag.bind("", self.MoveDragSize_TR) 854 | self.right_drag.bind("", self.LeaveDragBorder_TR) 855 | if event.widget == self.bottom_drag: 856 | if x >= 0 and x <= self.bordersize: 857 | if self.bottom_drag == None: 858 | self.bottom_drag = tkinter.Label(self.widget) 859 | self.bottom_drag.bind("", self.StartDrag) 860 | self.bottom_drag.bind("", self.StopDrag) 861 | self.bottom_drag.bind("", self.MoveDragSize_BL) 862 | self.bottom_drag.bind("", self.LeaveDragBorder_BL) 863 | if self.left_drag == None: 864 | self.left_drag = tkinter.Label(self.widget) 865 | self.left_drag.place(x=0, y=0, width=self.bordersize, height=formh) 866 | self.left_drag.bind("", self.StartDrag) 867 | self.left_drag.bind("", self.StopDrag) 868 | self.left_drag.bind("", self.MoveDragSize_BL) 869 | self.left_drag.bind("", self.LeaveDragBorder_BL) 870 | if x >= (formw - self.bordersize) and x <= formw: 871 | if self.bottom_drag == None: 872 | self.bottom_drag = tkinter.Label(self.widget) 873 | self.bottom_drag.bind("", self.StartDrag) 874 | self.bottom_drag.bind("", self.StopDrag) 875 | self.bottom_drag.bind("", self.MoveDragSize_BR) 876 | self.bottom_drag.bind("", self.LeaveDragBorder_BR) 877 | if self.right_drag == None: 878 | self.right_drag = tkinter.Label(self.widget) 879 | self.right_drag.place( 880 | x=formw - self.bordersize, y=0, width=self.bordersize, height=formh 881 | ) 882 | self.right_drag.bind("", self.StartDrag) 883 | self.right_drag.bind("", self.StopDrag) 884 | self.right_drag.bind("", self.MoveDragSize_BR) 885 | self.right_drag.bind("", self.LeaveDragBorder_BR) 886 | 887 | def LeaveDragBorder(self, event): 888 | event.widget.place_forget() 889 | 890 | def MoveDragSize_TL(self, event): 891 | deltaX = event.x_root - self.x 892 | deltaY = event.y_root - self.y 893 | formx = self.widget.winfo_x() + deltaX 894 | newW = self.widget.winfo_width() - deltaX 895 | formy = self.widget.winfo_y() + deltaY 896 | newH = self.widget.winfo_height() - deltaY 897 | geoinfo = str("%dx%d+%d+%d" % (newW, newH, formx, formy)) 898 | self.widget.geometry(geoinfo) 899 | self.left_drag.place( 900 | x=0, y=0, width=self.bordersize, height=self.widget.winfo_height() 901 | ) 902 | self.top_drag.place( 903 | x=0, y=0, width=self.widget.winfo_width(), height=self.bordersize 904 | ) 905 | self.x = event.x_root 906 | self.y = event.y_root 907 | self.widget.configure(cursor="plus") 908 | 909 | def LeaveDragBorder_TL(self, event): 910 | self.left_drag.place_forget() 911 | self.top_drag.place_forget() 912 | self.widget.configure(cursor="arrow") 913 | 914 | def MoveDragSize_TR(self, event): 915 | deltaX = event.x_root - self.x 916 | deltaY = event.y_root - self.y 917 | formx = self.widget.winfo_x() 918 | newW = self.widget.winfo_width() + deltaX 919 | formy = self.widget.winfo_y() + deltaY 920 | newH = self.widget.winfo_height() - deltaY 921 | geoinfo = str("%dx%d+%d+%d" % (newW, newH, formx, formy)) 922 | self.widget.geometry(geoinfo) 923 | self.right_drag.place( 924 | x=newW - self.bordersize, 925 | y=0, 926 | width=self.bordersize, 927 | height=self.widget.winfo_height(), 928 | ) 929 | self.top_drag.place( 930 | x=0, y=0, width=self.widget.winfo_width(), height=self.bordersize 931 | ) 932 | self.x = event.x_root 933 | self.y = event.y_root 934 | self.widget.configure(cursor="plus") 935 | 936 | def LeaveDragBorder_TR(self, event): 937 | self.right_drag.place_forget() 938 | self.top_drag.place_forget() 939 | self.widget.configure(cursor="arrow") 940 | 941 | def MoveDragSize_BL(self, event): 942 | deltaX = event.x_root - self.x 943 | deltaY = event.y_root - self.y 944 | formx = self.widget.winfo_x() + deltaX 945 | newW = self.widget.winfo_width() - deltaX 946 | formy = self.widget.winfo_y() 947 | newH = self.widget.winfo_height() + deltaY 948 | geoinfo = str("%dx%d+%d+%d" % (newW, newH, formx, formy)) 949 | self.widget.geometry(geoinfo) 950 | self.left_drag.place( 951 | x=0, y=0, width=self.bordersize, height=self.widget.winfo_height() 952 | ) 953 | self.bottom_drag.place( 954 | x=0, 955 | y=newH - self.bordersize, 956 | width=self.widget.winfo_width(), 957 | height=self.bordersize, 958 | ) 959 | self.x = event.x_root 960 | self.y = event.y_root 961 | self.widget.configure(cursor="plus") 962 | 963 | def LeaveDragBorder_BL(self, event): 964 | self.left_drag.place_forget() 965 | self.bottom_drag.place_forget() 966 | self.widget.configure(cursor="arrow") 967 | 968 | def MoveDragSize_BR(self, event): 969 | deltaX = event.x_root - self.x 970 | deltaY = event.y_root - self.y 971 | formx = self.widget.winfo_x() 972 | newW = self.widget.winfo_width() + deltaX 973 | formy = self.widget.winfo_y() 974 | newH = self.widget.winfo_height() + deltaY 975 | geoinfo = str("%dx%d+%d+%d" % (newW, newH, formx, formy)) 976 | self.widget.geometry(geoinfo) 977 | self.right_drag.place( 978 | x=newW - self.bordersize, 979 | y=0, 980 | width=self.bordersize, 981 | height=self.widget.winfo_height(), 982 | ) 983 | self.bottom_drag.place( 984 | x=0, 985 | y=newH - self.bordersize, 986 | width=self.widget.winfo_width(), 987 | height=self.bordersize, 988 | ) 989 | self.x = event.x_root 990 | self.y = event.y_root 991 | self.widget.configure(cursor="plus") 992 | 993 | def LeaveDragBorder_BR(self, event): 994 | self.right_drag.place_forget() 995 | self.bottom_drag.place_forget() 996 | self.widget.configure(cursor="arrow") 997 | 998 | 999 | # 使用TKinter方式设置窗口圆角, 支持跨平台。 1000 | def SetRootRoundRectangle(canvas, x1, y1, x2, y2, radius=25, **kwargs): 1001 | points = [ 1002 | x1 + radius, 1003 | y1, 1004 | x1 + radius, 1005 | y1, 1006 | x2 - radius, 1007 | y1, 1008 | x2 - radius, 1009 | y1, 1010 | x2, 1011 | y1, 1012 | x2, 1013 | y1 + radius, 1014 | x2, 1015 | y1 + radius, 1016 | x2, 1017 | y2 - radius, 1018 | x2, 1019 | y2 - radius, 1020 | x2, 1021 | y2, 1022 | x2 - radius, 1023 | y2, 1024 | x2 - radius, 1025 | y2, 1026 | x1 + radius, 1027 | y2, 1028 | x1 + radius, 1029 | y2, 1030 | x1, 1031 | y2, 1032 | x1, 1033 | y2 - radius, 1034 | x1, 1035 | y2 - radius, 1036 | x1, 1037 | y1 + radius, 1038 | x1, 1039 | y1 + radius, 1040 | x1, 1041 | y1, 1042 | ] 1043 | return canvas.create_polygon(points, **kwargs, smooth=True) 1044 | 1045 | 1046 | # 从一个文件中读取内容。 1047 | def ReadFromFile(filePath): 1048 | content = None 1049 | if filePath != None: 1050 | if os.path.exists(filePath) == True: 1051 | f = open(filePath, mode="r", encoding="utf-8") 1052 | if f != None: 1053 | content = f.read() 1054 | f.close() 1055 | return content 1056 | 1057 | 1058 | # 将内容写入到一个文件中。 1059 | def WriteToFile(filePath, content): 1060 | if filePath != None: 1061 | f = open(filePath, mode="w", encoding="utf-8") 1062 | if f != None: 1063 | if content != None: 1064 | f.write(content) 1065 | f.close() 1066 | return True 1067 | return False 1068 | 1069 | 1070 | # 读取样式定义文件,返回样式列表。 1071 | def ReadStyleFile(filePath): 1072 | StyleArray = {} 1073 | if len(filePath) == 0: 1074 | return StyleArray 1075 | if os.path.exists(filePath) == False: 1076 | return StyleArray 1077 | f = open(filePath, encoding="utf-8") 1078 | line = "" 1079 | while True: 1080 | line = f.readline() 1081 | if not line: 1082 | break 1083 | text = line.strip() 1084 | if not text: 1085 | continue 1086 | if text.find("style = tkinter.ttk.Style()") >= 0: 1087 | continue 1088 | if text.find("style.configure(") >= 0: 1089 | splitarray1 = text.partition("style.configure(") 1090 | stylename = None 1091 | splitarray2 = None 1092 | if splitarray1[2].find(",") >= 0: 1093 | splitarray2 = splitarray1[2].partition(",") 1094 | stylename = splitarray2[0].replace('"', "") 1095 | else: 1096 | splitarray2 = splitarray1[2].partition(")") 1097 | stylename = splitarray2[0].replace('"', "") 1098 | sytleValueText = splitarray2[2] 1099 | fontindex_begin = sytleValueText.find("font=(") 1100 | fontindex_end = fontindex_begin 1101 | StyleArray[stylename] = {} 1102 | othertext = sytleValueText 1103 | if fontindex_begin >= 0: 1104 | fontindex_end = sytleValueText.find(")") 1105 | fonttext = sytleValueText[fontindex_begin + 6 : fontindex_end] 1106 | fontsplitarray = fonttext.split(",") 1107 | StyleArray[stylename]["font"] = tkinter.font.Font( 1108 | family=fontsplitarray[0].replace('"', "").strip(), 1109 | size=int(fontsplitarray[1].replace('"', "").strip()), 1110 | weight=fontsplitarray[2].replace('"', "").strip(), 1111 | ) 1112 | othertext = ( 1113 | sytleValueText[0:fontindex_begin] 1114 | + sytleValueText[fontindex_end + 1 : -1] 1115 | ) 1116 | else: 1117 | splitarray4 = sytleValueText.partition(")") 1118 | othertext = splitarray4[0] 1119 | splitarray3 = othertext.split(",") 1120 | for stylecfgtext in splitarray3: 1121 | if stylecfgtext.find("=") > 0: 1122 | splitarray4 = stylecfgtext.partition("=") 1123 | key = splitarray4[0].replace('"', "").strip() 1124 | value = splitarray4[2].replace('"', "").strip() 1125 | StyleArray[stylename][key] = value 1126 | continue 1127 | if text.find("style.map(") >= 0: 1128 | continue 1129 | f.close() 1130 | return StyleArray 1131 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | RemoteConnectionToolkit 2 | =================== 3 | [![Language](https://img.shields.io/badge/Python-3.10.0-blue?logo=python)](https://python.org) 4 | ![Language](https://img.shields.io/badge/RemoteConnectionToolkit-1.4.0-green) 5 | ![Plantform](https://img.shields.io/badge/Windows-blue) 6 | ![Plantform](https://img.shields.io/badge/Linux-blue) 7 | 8 | 9 | _A Development Kit for Remote Connection and Based on Python3._ 10 | 11 | ## Introduction 12 | Remote Connection Toolkit is a Python-based toolkit that simplifies the process of remote connection by encapsulating the Python network toolkit. It provides multiple operational tools for remote communication between computers. 13 | 14 | ## About This Project 15 | 16 | I was influenced by various remote desktop software(especially PowerToys), and developed this project using socket interface. It establishes a connection between two computers and controls them through instructions. This connection is bidirectional, which means that this project is useful for remote login, remote collaboration, and file transfer. 17 | 18 | ## Features 19 | - **Version Compatibility**: When communicating remotely, all digits except for the third digit of the version number must be the same to continue communication. 20 | - **Debugging GUI**: A GUI debugger is available to assist in debugging the remote connection process. 21 | - **Built-in Instruction Set**: It includes a set of built-in functions for common operations such as file transfer, screenshot capture, and remote screen monitoring. 22 | 23 | ## How did it work 24 | 25 | I use Python 3 to call the socket interface of the system, establishing one as a server and the other as a client. When the client initiates a connection to the server, they will send their tool version and network IP information to the other party to ensure the security and stability of remote transmission. Afterwards, they will wait for the user's command to be issued. The instructions and execution results will be transmitted to the corresponding computer through the TCP protocol. 26 | 27 | ## Requirements 28 | - Python 3.x 29 | - PIL (Python Imaging Library) 30 | - mss (Multiple ScreenShot) 31 | 32 | ## Installation 33 | 1. Clone the repository: 34 | ```bash 35 | git clone https://github.com/your-repo/RemoteConnectionToolkit.git 36 | ``` 37 | **👉 The tool versions of two computers must have the same digits except for the third digit! The project has strong scalability and there are many areas that need improvement and optimization.** 38 | 2. Install the required dependencies: 39 | ```bash 40 | pip install pillow mss 41 | ``` 42 | 43 | ## Details of The RemoteConnection Class 44 | 45 | The RemoteConnection class has the following member functions: 46 | 47 | ```python3 48 | class RemoteConnection: 49 | def __init__(self, remoteIP: str, port: int, debugGUI=False): ... 50 | def getLocalAddress(self) -> str: ... 51 | def send(self, msg) -> int: ... 52 | def sendString(self, msg: str) -> int: ... 53 | def passiveConnect(self, timeout=10): ... 54 | def initiativeConnect(self, timeout=10): ... 55 | def listen(self, funcList: dict): ... 56 | ``` 57 | 58 | #### RemoteConnection(remoteIP: str, port: int, debugGUI=False): 59 | 60 | This function takes three parameters. 61 | 62 | _remoteIP: str_ 63 | 64 | The first parameter is the IP address of the computer you want to connect to. \ 65 | 👉 When initiating a remote connection **in a passive manner**, a constant other than the IP address can be used: WRCD_ANY_IP_ADDRESS.It allows **any IP to connect the computer** and begin communication after compatibility and security checks. 66 | 67 | _port: int_ 68 | 69 | The port used when establishing a connection on a computer. 70 | 71 | _debugGUI=False_ 72 | 73 | If the parameter is True, the program will create a window for debugging. 74 | 75 | #### getLocalAddress(): 76 | 77 | Obtain the IP host name or IP address of the local machine. 78 | 79 | #### send(msg): 80 | 81 | The usage is the same as _socket.send_. 82 | 83 | #### sendString(msg: str): 84 | 85 | Function for sending string messages to remote computers. 86 | 87 | #### passiveConnect(timeout=0): 88 | 89 | Start in passive mode and wait for other computers to connect. Equivalent to establishing a server on the computer executing the code.\ 90 | The ‘timeout’ parameter specifies the maximum duration of waiting for a connection, measured in seconds. When timeout=0, the computer executing the code will wait until the process ends or another computer connects. 91 | 92 | #### initiativeConnect(timeout=0): 93 | 94 | Start in initiative mode and wait for other computers to connect. Equivalent to establishing a client on the computer executing the code.\ 95 | The ‘timeout’ parameter specifies the maximum duration of waiting for a connection, measured in seconds. When timeout=0, the computer executing the code will wait until the process ends or another computer connects. 96 | 97 | #### listen(funcList: dict): 98 | 99 | Start listening for requests from connected computers.\ 100 | 👉 This function will **block the process**. This means you need to **create a new thread** for this function.\ 101 | 🚨 **Please execute this function after completing PassiveConnect or InitiativeConnect**. Otherwise, you will receive a gift called Traceback... 102 | 103 | ## Built-in Functions 104 | The following is a list of built-in functions provided by the toolkit: 105 | 106 | | Function Name | Description | 107 | | --- | --- | 108 | | `Close` | Close the connection with the remote computer. | 109 | | `sendPathList` | Passively transfer the contents of a specified folder to the remote computer. | 110 | | `getPathList` | Proactively request the contents of a specified folder from the remote computer. | 111 | | `sendFile` | Proactively send a file to the remote computer. | 112 | | `reciveFile` | Passively receive a file from the remote computer. | 113 | | `getFile` | Proactively obtain a file from the remote computer. | 114 | | `catchScreenshot` | Capture the screenshot of the local computer. | 115 | | `sendScreenshot` | Send the screenshot of the local computer to the remote computer. | 116 | | `showScreenshot` | Get and display the screenshot of the remote computer. | 117 | | `getScreenshot` | Get the screenshot of the remote computer. | 118 | | `monitorRemoteScreen` | Continuously monitor the remote screen. | 119 | 120 | ### 3.Examples 121 | 122 | Here are some examples: 123 | 124 | ```python 125 | from RemoteConnectionToolkit import * 126 | 127 | 128 | if __name__ == "__main__": 129 | remote = RemoteConnection("192.168.0.102", 12345, True) 130 | remote.initiativeConnect(60) 131 | remote.listen(builtin_funcs) 132 | ``` 133 | 134 | ```python3 135 | from RemoteConnectionToolkit import * 136 | 137 | 138 | if __name__ == "__main__": 139 | remote = RemoteConnection(WRCT_ANY_IP_ADDRESS, 12345, True) 140 | remote.initiativeConnect(30) 141 | remote.listen(builtin_funcs) 142 | ``` 143 | 144 | ## Copyrights & Thanks 145 | 146 | ### Copyrights: 147 | 148 | Copyright(C) 2023-2025 [C14147](https://github.com/C14147/).\ 149 | Follow the Apache 2.0 license agreement.\ 150 | https://github.com/C14147/RemoteConnectionToolkit 151 | 152 | ### Thanks: 153 | 154 | [Honghaier-Game](https://github.com/honghaier-game/): GUI debugger design by his TKinterDesigner.\ 155 | TKinterDesigner is the predecessor of his software [PyMe](https://github.com/honghaier-game/PyMe). \ 156 | RemoteConnectionToolkit uses TKinterDesigner v1.5.1. 157 | -------------------------------------------------------------------------------- /RemoteCT-For-Java/RemoteCT.java: -------------------------------------------------------------------------------- 1 | import javax.swing.*; 2 | import java.awt.*; 3 | import java.io.*; 4 | import java.net.*; 5 | import java.util.*; 6 | import java.util.logging.*; 7 | import java.util.function.BiConsumer; 8 | import javax.imageio.ImageIO; 9 | import java.awt.image.BufferedImage; 10 | import java.util.Base64; 11 | import org.json.JSONArray; 12 | 13 | public class RemoteCT { 14 | private static final String VERSION = "1.4.0"; 15 | public static final String WRCT_ANY_IP_ADDRESS = "WRCT_ANY_IP_ADDRESS"; 16 | 17 | private Socket socket; 18 | private Socket clientSocket; 19 | private ServerSocket serverSocket; 20 | private boolean connected; 21 | private String connectMode; 22 | private String remoteIP; 23 | private String host; 24 | private int port; 25 | private PrintWriter out; 26 | private BufferedReader in; 27 | private Logger logger; 28 | private JTextArea debugTextArea; 29 | 30 | public RemoteCT(String remoteIP, int port, boolean debugGUI) throws Exception { 31 | this.remoteIP = remoteIP; 32 | this.port = port; 33 | this.connected = false; 34 | this.connectMode = "unconnect"; 35 | 36 | setupLogging(debugGUI); 37 | 38 | try { 39 | this.host = InetAddress.getLocalHost().getHostName(); 40 | } catch (UnknownHostException e) { 41 | throw new RemoteToolkitError("Failed to get local hostname"); 42 | } 43 | 44 | if (debugGUI) { 45 | createDebugWindow(); 46 | } 47 | 48 | logger.info("Complete initialization"); 49 | } 50 | 51 | private void setupLogging(boolean debugGUI) { 52 | logger = Logger.getLogger("RemoteCT"); 53 | logger.setLevel(Level.ALL); 54 | 55 | if (debugGUI) { 56 | // Debug GUI logging will be handled by the debug window 57 | } else { 58 | // File logging 59 | try { 60 | FileHandler fileHandler = new FileHandler("WRemoteConnection.logging.log"); 61 | fileHandler.setFormatter(new SimpleFormatter()); 62 | logger.addHandler(fileHandler); 63 | } catch (IOException e) { 64 | System.err.println("Failed to setup file logging: " + e.getMessage()); 65 | } 66 | } 67 | } 68 | 69 | private void createDebugWindow() { 70 | JFrame frame = new JFrame("Remote Connection Toolkit - Debug Helper"); 71 | frame.setSize(800, 600); 72 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 73 | 74 | debugTextArea = new JTextArea(); 75 | debugTextArea.setBackground(Color.BLACK); 76 | debugTextArea.setForeground(Color.WHITE); 77 | debugTextArea.setFont(new Font("Monospaced", Font.PLAIN, 12)); 78 | debugTextArea.setEditable(false); 79 | 80 | JScrollPane scrollPane = new JScrollPane(debugTextArea); 81 | frame.add(scrollPane); 82 | 83 | JTextField commandField = new JTextField(); 84 | commandField.addActionListener(e -> { 85 | String command = commandField.getText(); 86 | debugTextArea.append(">>>" + command + "\n"); 87 | try { 88 | // Execute command 89 | // This is simplified - you might want to add proper command handling 90 | commandField.setText(""); 91 | } catch (Exception ex) { 92 | debugTextArea.append("Error: " + ex.getMessage() + "\n"); 93 | } 94 | }); 95 | frame.add(commandField, BorderLayout.SOUTH); 96 | 97 | frame.setVisible(true); 98 | } 99 | 100 | public String getLocalAddress() { 101 | return host; 102 | } 103 | 104 | public void passiveConnect(int timeout) throws RemoteToolkitError { 105 | connectMode = "passiveConnect"; 106 | try { 107 | serverSocket = new ServerSocket(port); 108 | logger.info("Waiting for Client Connect..."); 109 | 110 | clientSocket = serverSocket.accept(); 111 | InetAddress clientAddress = clientSocket.getInetAddress(); 112 | 113 | if (!remoteIP.equals(WRCT_ANY_IP_ADDRESS) && !clientAddress.getHostAddress().equals(remoteIP)) { 114 | clientSocket.close(); 115 | throw new RemoteToolkitError("Connected IP " + clientAddress.getHostAddress() + 116 | " Does Not Match The Specified " + remoteIP); 117 | } 118 | 119 | setupStreams(); 120 | 121 | if (timeout > 0) { 122 | clientSocket.setSoTimeout(timeout * 1000); 123 | } 124 | 125 | // Version check 126 | sendString("Answer! Remote Connection Toolkit version " + VERSION + ",server ip: " + host); 127 | String response = receiveString(); 128 | if (!checkVersion(response)) { 129 | throw new RemoteToolkitError("Unsupported Client Interface"); 130 | } 131 | 132 | connected = true; 133 | logger.info("Client Connected: " + clientAddress.getHostAddress()); 134 | 135 | } catch (IOException e) { 136 | throw new RemoteToolkitError("Connection failed: " + e.getMessage()); 137 | } 138 | } 139 | 140 | public void initiativeConnect(int timeout) throws RemoteToolkitError { 141 | connectMode = "initiativeConnect"; 142 | try { 143 | socket = new Socket(remoteIP, port); 144 | if (timeout > 0) { 145 | socket.setSoTimeout(timeout * 1000); 146 | } 147 | 148 | setupStreams(); 149 | 150 | String response = receiveString(); 151 | sendString("Answer! Remote Connection Toolkit version " + VERSION + ",server ip: " + host); 152 | 153 | connected = true; 154 | logger.info("Connected to server: " + remoteIP); 155 | 156 | } catch (IOException e) { 157 | throw new RemoteToolkitError("Connection failed: " + e.getMessage()); 158 | } 159 | } 160 | 161 | private void setupStreams() throws IOException { 162 | Socket activeSocket = (connectMode.equals("passiveConnect")) ? clientSocket : socket; 163 | out = new PrintWriter(activeSocket.getOutputStream(), true); 164 | in = new BufferedReader(new InputStreamReader(activeSocket.getInputStream())); 165 | } 166 | 167 | public void listen(Map> funcList) { 168 | logger.info("Start ranging events..."); 169 | while (connected) { 170 | try { 171 | String message = receiveString(); 172 | String[] parts = message.split("\\|"); 173 | if (parts.length == 2) { 174 | String funcName = parts[0]; 175 | String[] args = parts[1].split(","); 176 | 177 | if (funcList.containsKey(funcName)) { 178 | try { 179 | funcList.get(funcName).accept(this, args); 180 | logger.info("Event " + funcName + " executed successfully"); 181 | } catch (Exception e) { 182 | logger.severe("Event " + funcName + " failed: " + e.getMessage()); 183 | sendError(e.getMessage()); 184 | } 185 | } 186 | } 187 | } catch (Exception e) { 188 | logger.severe("Connection error: " + e.getMessage()); 189 | break; 190 | } 191 | } 192 | } 193 | 194 | public void sendString(String message) { 195 | out.println(message); 196 | } 197 | 198 | public String receiveString() throws IOException { 199 | return in.readLine(); 200 | } 201 | 202 | private void sendError(String error) { 203 | try { 204 | String encodedError = Base64.getEncoder().encodeToString(error.getBytes()); 205 | sendString("showError|" + encodedError + ","); 206 | } catch (Exception e) { 207 | logger.severe("Failed to send error: " + e.getMessage()); 208 | } 209 | } 210 | 211 | private boolean checkVersion(String message) { 212 | // Version check implementation 213 | return message.contains("Answer! Remote Connection Toolkit version") && 214 | message.contains(VERSION.substring(0, VERSION.lastIndexOf("."))); 215 | } 216 | 217 | // Built-in command implementations follow... 218 | // Add the rest of the built-in commands here 219 | } 220 | -------------------------------------------------------------------------------- /RemoteCT-For-Java/RemoteCommands.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | import java.awt.*; 4 | import java.awt.image.BufferedImage; 5 | import javax.imageio.ImageIO; 6 | import org.json.JSONArray; 7 | import java.util.Base64; 8 | 9 | public class RemoteCommands { 10 | public static Map> getBuiltinCommands() { 11 | Map> commands = new HashMap<>(); 12 | 13 | commands.put("Close", RemoteCommands::closeRemote); 14 | commands.put("sendPathList", RemoteCommands::sendPathList); 15 | commands.put("getPathList", RemoteCommands::getPathList); 16 | commands.put("sendFile", RemoteCommands::sendFile); 17 | commands.put("receiveFile", RemoteCommands::receiveFile); 18 | commands.put("getFile", RemoteCommands::getFile); 19 | commands.put("catchScreenshot", RemoteCommands::catchScreenshot); 20 | commands.put("sendScreenshot", RemoteCommands::sendScreenshot); 21 | commands.put("showScreenshot", RemoteCommands::showScreenshot); 22 | commands.put("getScreenshot", RemoteCommands::getScreenshot); 23 | commands.put("monitorRemoteScreen", RemoteCommands::monitorRemoteScreen); 24 | 25 | return commands; 26 | } 27 | 28 | public static void closeRemote(RemoteCT remote, String[] args) { 29 | remote.sendString("Close|1,"); 30 | // Implementation for closing connection 31 | } 32 | 33 | public static void sendPathList(RemoteCT remote, String[] args) { 34 | File folder = new File(args[0]); 35 | String[] files = folder.list(); 36 | JSONArray jsonArray = new JSONArray(Arrays.asList(files)); 37 | remote.sendString(jsonArray.toString()); 38 | } 39 | 40 | public static void getPathList(RemoteCT remote, String[] args) { 41 | remote.sendString("sendPathList|" + args[0] + ","); 42 | // Implementation for receiving path list 43 | } 44 | 45 | public static void sendFile(RemoteCT remote, String[] args) { 46 | // Implementation for sending file 47 | } 48 | 49 | public static void receiveFile(RemoteCT remote, String[] args) { 50 | // Implementation for receiving file 51 | } 52 | 53 | public static void getFile(RemoteCT remote, String[] args) { 54 | remote.sendString("sendFile|" + args[0] + ","); 55 | } 56 | 57 | public static void catchScreenshot(RemoteCT remote, String[] args) { 58 | try { 59 | Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); 60 | BufferedImage capture = new Robot().createScreenCapture(screenRect); 61 | ImageIO.write(capture, "png", new File("tmp_screenshot_" + args[0] + ".png")); 62 | } catch (Exception e) { 63 | e.printStackTrace(); 64 | } 65 | } 66 | 67 | public static void sendScreenshot(RemoteCT remote, String[] args) { 68 | remote.sendString("sendFile|tmp_screenshot_" + args[0] + ".png"); 69 | } 70 | 71 | public static void showScreenshot(RemoteCT remote, String[] args) { 72 | // Implementation for showing screenshot 73 | } 74 | 75 | public static void getScreenshot(RemoteCT remote, String[] args) { 76 | remote.sendString("catchScreenshot|" + args[0]); 77 | remote.sendString("sendScreenshot|" + args[0]); 78 | if (args.length > 1 && args[1].equalsIgnoreCase("true")) { 79 | showScreenshot(remote, args); 80 | } 81 | } 82 | 83 | public static void monitorRemoteScreen(RemoteCT remote, String[] args) { 84 | int monitor = Integer.parseInt(args[0]); 85 | int interval = Integer.parseInt(args[1]); 86 | 87 | Thread monitorThread = new Thread(() -> { 88 | while (true) { 89 | remote.sendString("catchScreenshot|" + monitor); 90 | remote.sendString("sendScreenshot|" + monitor); 91 | try { 92 | Thread.sleep(interval * 1000); 93 | } catch (InterruptedException e) { 94 | break; 95 | } 96 | } 97 | }); 98 | monitorThread.start(); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /RemoteCT-For-Java/RemoteToolkitError.java: -------------------------------------------------------------------------------- 1 | public class RemoteToolkitError extends Exception { 2 | public RemoteToolkitError(String message) { 3 | super(message); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /RemoteConnectionToolkit.py: -------------------------------------------------------------------------------- 1 | """ 2 | Remote Connection Toolkit 3 | Copyright(C) 2023-2024 C14147. 4 | 5 | A remote connection toolkit that provides multiple operational tools by encapsulating 6 | the Python network toolkit, simplifying the process of remote connection. 7 | 8 | Declaration: 9 | Due to the strong scalability and fast version iteration of this project, when 10 | communicating remotely with a computer, all digits except for the third digit of the 11 | version number must be the same in order to continue communication. 12 | """ 13 | 14 | import os 15 | import re 16 | import sys 17 | import PIL.Image 18 | import mss 19 | import time 20 | import json 21 | import base64 22 | import socket 23 | import logging 24 | import tkinter 25 | import threading 26 | 27 | import Fun 28 | 29 | 30 | __version__ = "1.4.0" 31 | WRCT_ANY_IP_ADDRESS = "WRCT_ANY_IP_ADDRESS" 32 | 33 | 34 | class Redirector: 35 | """ 36 | Imitate the FileObject class, which redirects the message originally output 37 | to the terminal to the debug window when performing a write operation. 38 | """ 39 | 40 | def __init__(self, text_widget: tkinter.Text): 41 | self.text_widget = text_widget 42 | 43 | def write(self, message: str): 44 | self.text_widget.insert(tkinter.END, message) 45 | 46 | def flush(self): 47 | pass 48 | 49 | 50 | class DebugHelper: 51 | """GUI debugger for remote connection""" 52 | 53 | def __init__(self, root: tkinter.Tk, isTKroot=True): 54 | uiName = "DebugHelper" 55 | Fun.Register(uiName, "UIClass", self) 56 | self.root = root 57 | if isTKroot == True: 58 | root.title("Remote Connection Toolkit - Debug Helper") 59 | Fun.CenterDlg(uiName, root, 797, 600) 60 | root["background"] = "#000000" 61 | Form_1 = tkinter.Canvas(root, width=10, height=4) 62 | Form_1.place(x=0, y=0, width=797, height=600) 63 | Form_1.configure(bg="#000000", highlightthickness=0) 64 | Fun.Register(uiName, "root", root) 65 | Fun.Register(uiName, "Form_1", Form_1) 66 | # Create the elements of root 67 | self.Text_2 = tkinter.Text(root, bg="#000000", fg="#ffffff", relief="flat") 68 | Fun.Register(uiName, "Text_2", self.Text_2, "Text") 69 | self.Text_2.place(x=0, y=0, width=800, height=561) 70 | Entry_3_Variable = Fun.AddTKVariable(uiName, "Entry_3", "") 71 | self.Entry_3 = tkinter.Entry(root, textvariable=Entry_3_Variable, bg="#151515", fg="#ffffff", relief="flat") 72 | Fun.Register(uiName, "Entry_3", self.Entry_3) 73 | self.Entry_3.place(x=2, y=567, width=792, height=27) 74 | self.Entry_3.bind("", self.runEvent) 75 | # Inital all element's Data 76 | Fun.InitElementData(uiName) 77 | 78 | self.Text_2.config(font=("Microsoft YaHei UI", 12)) 79 | self.Entry_3.config(font=("Microsoft YaHei UI", 11)) 80 | self.Text_2.insert(tkinter.END, "========================================\n") 81 | self.Text_2.insert(tkinter.END, "Remote Connection Toolkit - Debug Window\n") 82 | self.Text_2.insert(tkinter.END, "========================================\n") 83 | self.Text_2.insert( 84 | tkinter.END, "We'll not save STDOUT and STDERR in debig mode.\n" 85 | ) 86 | sys.stdout = Redirector(self.Text_2) 87 | sys.stderr = Redirector(self.Text_2) 88 | 89 | def runEvent(self, evt): 90 | self.Text_2.insert(tkinter.END, f">>>{self.Entry_3.get()}\n") 91 | exec(str(self.Entry_3.get())) 92 | self.Entry_3.delete(0, tkinter.END) 93 | 94 | 95 | class TextboxHandler(logging.Handler): 96 | """Inheriting logging.Handler to output logs to the window""" 97 | 98 | def __init__(self, textbox): 99 | logging.Handler.__init__(self) 100 | self.textbox = textbox 101 | 102 | def emit(self, record): 103 | msg = self.format(record) 104 | self.textbox.insert(tkinter.END, msg + "\n") 105 | 106 | 107 | class RemoteToolkitError(Exception): 108 | """An Error Exception Class For Project""" 109 | 110 | def __init__(self, message: str): 111 | self.message = message 112 | 113 | def __str__(self): 114 | return self.message 115 | 116 | 117 | def _debugWindow(remote): 118 | global text2 119 | debugHelperWindow = tkinter.Tk() 120 | debugHelper = DebugHelper(debugHelperWindow) 121 | text2 = debugHelper.Text_2 122 | debugHelperWindow.mainloop() 123 | remote.socketObject.close() 124 | exit() 125 | 126 | 127 | def _split_version(version: str) -> list: 128 | vl = [] 129 | _tmp = version.split(".") 130 | logging.debug(f"Splited list: {_tmp}") 131 | for ver_iter in _tmp: 132 | vl.append(int(ver_iter)) 133 | return vl 134 | 135 | 136 | def _check_version(version: str): 137 | vi = _split_version(version) 138 | vc = _split_version(__version__) 139 | return (vi[0] == vc[0]) and (vi[1] == vc[1]) 140 | 141 | 142 | class RemoteConnection: 143 | def __init__(self, remoteIP: str, port=4469, debugGUI=False): 144 | if debugGUI: 145 | threading.Thread(target=_debugWindow, args=[self]).start() 146 | time.sleep(1) 147 | logging.basicConfig( 148 | handlers=[TextboxHandler(text2)], 149 | level=logging.DEBUG, 150 | format="(Remote Connection Toolkit: %(asctime)s) [%(levelname)s]: %(message)s", 151 | ) 152 | else: 153 | self.logger = logging.getLogger() 154 | format_str = logging.Formatter( 155 | "(Remote Connection: %(asctime)s) [%(levelname)s]: %(message)s" 156 | ) 157 | self.logger.setLevel(logging.DEBUG) 158 | sh = logging.StreamHandler() 159 | sh.setFormatter(format_str) 160 | th = logging.FileHandler( 161 | filename="WRemoteConnection.logging.log", encoding="utf-8" 162 | ) 163 | th.setFormatter(format_str) 164 | logging.basicConfig( 165 | level=logging.DEBUG, 166 | handlers=[sh, th], 167 | ) 168 | sys.stderr = open("WRemoteConnection.stderr.log", "a", encoding="utf-8") 169 | 170 | logging.info("Starting Remote Connection...") 171 | 172 | self.connect = True 173 | self.connectMode = "unconnect" 174 | self.socketObject = socket.socket() 175 | self.remoteIP = remoteIP 176 | self.host = socket.gethostname() 177 | self.port = port 178 | 179 | logging.info("Complete initialization") 180 | 181 | def getLocalAddress(self) -> str: 182 | return self.host 183 | 184 | def send(self, msg) -> int: 185 | if self.connectMode == "passiveConnect": 186 | return self.clientObject.send(msg) 187 | else: 188 | return self.socketObject.send(msg) 189 | 190 | def sendString(self, msg: str) -> int: 191 | return self.send(msg.encode()) 192 | 193 | def passiveConnect(self, timeout=0): 194 | self.connectMode = "passiveConnect" 195 | self.socketObject.bind((self.host, self.port)) 196 | self.socketObject.listen(3) 197 | logging.info("Waiting for Client Connect...") 198 | self.clientObject, addr = self.socketObject.accept() 199 | self.clientAddress, self.clientPort = addr 200 | logging.info(f"Client Connected: {self.clientAddress}:{self.clientPort}") 201 | if self.clientAddress != self.remoteIP and self.remoteIP != WRCT_ANY_IP_ADDRESS: 202 | self.clientObject.close() 203 | logging.error(f"Connected IP {self.clientAddress} Does Not Match The Specified {self.remoteIP}") 204 | raise RemoteToolkitError(f"Connected IP {self.clientAddress} Does Not Match The Specified {self.remoteIP}") 205 | 206 | # Check the client 207 | self.sendString(f"Answer! Remote Connection Toolkit version {__version__},server ip: {self.host}") 208 | if timeout: 209 | self.clientObject.settimeout(timeout) 210 | try: 211 | msg = self.clientObject.recv(1024).decode() 212 | except socket.timeout: 213 | logging.warning("Can't Connect Remote Computer: Time Out.") 214 | return 215 | ver = re.search(r"\d+\.\d+\.\d+", msg)[0] 216 | logging.debug(f"Received Version: {ver}") 217 | if msg and "Answer! Remote Connection Toolkit version" in msg and _check_version(ver): 218 | logging.info(f"Client Answered: {msg}") 219 | else: 220 | logging.error(f"Unsupported Client Interface (Client Answer: {msg})") 221 | raise RemoteToolkitError(f"Unsupported Client Interface (Client Answer: {msg})") 222 | 223 | def initiativeConnect(self, timeout=0): 224 | self.connectMode = "initiativeConnect" 225 | logging.info("Connecting Client...") 226 | self.socketObject.connect((self.remoteIP, self.port)) 227 | self.clientObject = self.socketObject 228 | self.clientAddress = self.remoteIP 229 | self.clientPort = self.port 230 | logging.info("Client Connected: {}".format(self.clientAddress)) 231 | 232 | # Check the client 233 | if timeout: 234 | self.clientObject.settimeout(timeout) 235 | try: 236 | msg = self.clientObject.recv(1024) 237 | except socket.timeout: 238 | logging.warning("Can't Connect Remote Computer: Time Out.") 239 | msg = msg.decode() 240 | 241 | self.sendString( 242 | "Answer! Remote Connection Toolkit version {},server ip: {}".format( 243 | __version__, self.host 244 | ) 245 | ) 246 | 247 | def listen(self, funcList: dict): 248 | logging.info("Start ranging events...") 249 | while self.connect: 250 | # Call event message must like this: "EventKeyWord|arg1,arg2,..." 251 | msg = self.clientObject.recv(4096).decode() 252 | cvk = msg.split("|") 253 | funcRE = cvk[0] 254 | if funcRE in funcList: 255 | event_args = cvk[1].split(",") 256 | logging.info(f"Event {funcRE} Started, Given Args: {event_args}") 257 | try: 258 | funcReturn = funcList[funcRE](self, event_args) 259 | logging.log( 260 | logging.INFO if funcReturn in (0, None) else logging.WARNING, 261 | f"Event {funcRE} Ended, Return Value: {funcReturn}", 262 | ) 263 | except Exception as e: 264 | logging.error(f"Event {funcRE} Crashed: {e}") 265 | self.sendString(f"showError|{base64.b64encode(str(e).encode('utf-8')).decode('utf-8')},") 266 | 267 | 268 | # Here is the implementation of the built-in instruction set: 269 | """ 270 | The following code is to implement the functions required for the funcList 271 | variable in remote computer communication. You can use them directly or refer 272 | to these functions to write your own functions to achieve the desired effect. 273 | 274 | Your custom function must like this: 275 | --> def func_name(remote: RemoteConnection, args: list) -> Any: 276 | ... 277 | The formal parameters of the function must have and only have the formal 278 | parameters of the above function. You can encapsulate other variables into 279 | the "args" parameter. 280 | """ 281 | 282 | 283 | def ArgsFormater(**kwargs): 284 | return {k: str(v) for k, v in kwargs.items()} 285 | 286 | 287 | def showError(remote: RemoteConnection, args: list): 288 | """Show the error message of remote computer""" 289 | # args[0]: Error Message 290 | logging.error( 291 | "Remote Computer Send An Error: {} .Please Check The Error And Feedback To Us.".format( 292 | base64.b64decode(args[0]).decode("utf-8") 293 | ) 294 | ) 295 | 296 | 297 | def closeRemote(remote: RemoteConnection, args: list): 298 | """Close Connection of The Remote""" 299 | # No arg used 300 | remote.sendString("Close|1,") 301 | remote.clientObject.close() 302 | logging.info("Connection Closed.") 303 | remote.connect = False 304 | remote.connectMode = "unconnect" 305 | 306 | 307 | def sendPathList(remote: RemoteConnection, args: list): 308 | """Passive transfer function, generally do not call directly.""" 309 | # args[0] : Folder Path(str) 310 | _tmp = json.dumps(list(os.listdir(os.path.abspath(args[0])))) 311 | remote.sendString(_tmp) 312 | 313 | 314 | def getPathList(remote: RemoteConnection, args: list): 315 | """Proactively request the contents of a specified folder from a remote computer.""" 316 | # args[0] : Folder Path(str) 317 | remote.sendString(f"sendPathList|{args[0]},") 318 | _tmp = remote.clientObject.recv(2048) 319 | print(_tmp.decode()) 320 | 321 | 322 | def sendFile(remote: RemoteConnection, args: list): 323 | """Proactively sending file to remote computer.""" 324 | # args[0] : File Path(str) 325 | remote.sendString(f"receiveFile|{args[0]},") 326 | msg = remote.clientObject.recv(1024).decode() 327 | if msg == "Ready": 328 | with open(os.path.abspath(args[0]), "rb") as file: 329 | while (f_data := file.read(1024)): 330 | remote.send(f_data) 331 | else: 332 | raise RemoteToolkitError( 333 | "The remote computer's response is incorrect when transferring files." 334 | ) 335 | 336 | 337 | def reciveFile(remote: RemoteConnection, args: list): 338 | """Passive file-receiving function, generally do not call directly.""" 339 | # args[0] : File Path(str) 340 | remote.sendString("Ready") 341 | filename = args[0] 342 | with open(filename, "wb") as file: 343 | while True: 344 | f_data = remote.clientObject.recv(1024) 345 | if f_data: 346 | file.write(f_data) 347 | else: 348 | break 349 | 350 | 351 | def getFile(remote: RemoteConnection, args: list): 352 | """Proactively obtain file from remote computer.""" 353 | # args[0] : File Path(str) 354 | remote.sendString(f"sendFile|{args[0]},") 355 | 356 | 357 | def catchScreenshot(remote: RemoteConnection, args: list): 358 | """Catch The Screenshot of This Computer""" 359 | # args[0] : Monitor Number(int) 360 | with mss.mss() as sct: 361 | monitors = sct.monitors[1:] 362 | monitor = int(args[0]) 363 | with mss.mss() as sct: 364 | screenshot = sct.grab(monitors[monitor]) 365 | mss.tools.to_png( 366 | screenshot.rgb, screenshot.size, output=f"tmp_screenshot_{monitor}.png" 367 | ) 368 | 369 | 370 | def sendScreenshot(remote: RemoteConnection, args: list): 371 | """Send The Screenshot of This Computer""" 372 | # args[0] : Monitor Number(int) 373 | monitor = int(args[0]) 374 | remote.sendString(f"sendFile|tmp_screenshot_{monitor}.png") 375 | 376 | 377 | def showScreenshot(remote: RemoteConnection, args: list): 378 | """Get Screenshot of Remote Computer""" 379 | # args[0] : Monitor Number(int) 380 | monitor = int(args[0]) 381 | img = PIL.Image.open(f"tmp_screenshot_{monitor}.png") 382 | img.show() 383 | 384 | 385 | def getScreenshot(remote: RemoteConnection, args: list): 386 | """Get Screenshot of Remote Computer""" 387 | # args[0] : Monitor Number(int) 388 | # args[1] : Is show image(bool) , default: false 389 | monitor = int(args[0]) 390 | if len(args) == 1: 391 | args[1] = "false" 392 | remote.sendString(f"catchScreenshot|{monitor}") 393 | remote.sendString(f"sendScreenshot|{monitor}") 394 | if args[1].lower() == "true": 395 | showScreenshot(remote, ArgsFormater(args[0])) 396 | 397 | 398 | def monitorRemoteScreen(remote: RemoteConnection, args: list): 399 | """Monitor the remote screen continuously.""" 400 | # args[0] : Monitor Number(int) 401 | # args[1] : Interval between screenshots in seconds (int) 402 | monitor = int(args[0]) 403 | interval = int(args[1]) 404 | while remote.connect: 405 | remote.sendString(f"catchScreenshot|{monitor}") 406 | remote.sendString(f"sendScreenshot|{monitor}") 407 | time.sleep(interval) 408 | 409 | 410 | builtin_funcs = { 411 | "Close": closeRemote, 412 | "sendPathList": sendPathList, 413 | "getPathList": getPathList, 414 | "sendFile": sendFile, 415 | "reciveFile": reciveFile, 416 | "getFile": getFile, 417 | "catchScreenshot": catchScreenshot, 418 | "sendScreenshot": sendScreenshot, 419 | "showScreenshot": showScreenshot, 420 | "getScreenshot": getScreenshot, 421 | "monitorRemoteScreen": monitorRemoteScreen, 422 | } 423 | 424 | if __name__ == "__main__": 425 | remote = RemoteConnection(WRCT_ANY_IP_ADDRESS, 12345, True) 426 | remote.initiativeConnect(30) 427 | remote.listen(builtin_funcs) 428 | -------------------------------------------------------------------------------- /ThanksList & Copyrights: -------------------------------------------------------------------------------- 1 | Copyrights: 2 | 3 | Copyright(C) 2023-2024 WorkFlow. 4 | Follow the Apache 2.0 license agreement. 5 | 6 | 7 | Thanks: 8 | 9 | Honghaier-Game: GUI debugger design by his TKinterDesigner. 10 | TKinterDesigner is the predecessor of his software PyMe( https://github.com/honghaier-game/PyMe ). 11 | RemoteConnectionToolkit uses TKinterDesigner v1.5.1. 12 | --------------------------------------------------------------------------------