pyxllib 0.0.43__py3-none-any.whl → 0.3.197__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. pyxllib/__init__.py +9 -2
  2. pyxllib/algo/__init__.py +8 -0
  3. pyxllib/algo/disjoint.py +54 -0
  4. pyxllib/algo/geo.py +541 -0
  5. pyxllib/{util/mathlib.py → algo/intervals.py} +172 -36
  6. pyxllib/algo/matcher.py +389 -0
  7. pyxllib/algo/newbie.py +166 -0
  8. pyxllib/algo/pupil.py +629 -0
  9. pyxllib/algo/shapelylib.py +67 -0
  10. pyxllib/algo/specialist.py +241 -0
  11. pyxllib/algo/stat.py +494 -0
  12. pyxllib/algo/treelib.py +149 -0
  13. pyxllib/algo/unitlib.py +66 -0
  14. pyxllib/autogui/__init__.py +5 -0
  15. pyxllib/autogui/activewin.py +246 -0
  16. pyxllib/autogui/all.py +9 -0
  17. pyxllib/autogui/autogui.py +852 -0
  18. pyxllib/autogui/uiautolib.py +362 -0
  19. pyxllib/autogui/virtualkey.py +102 -0
  20. pyxllib/autogui/wechat.py +827 -0
  21. pyxllib/autogui/wechat_msg.py +421 -0
  22. pyxllib/autogui/wxautolib.py +84 -0
  23. pyxllib/cv/__init__.py +1 -11
  24. pyxllib/cv/expert.py +267 -0
  25. pyxllib/cv/{imlib.py → imfile.py} +18 -83
  26. pyxllib/cv/imhash.py +39 -0
  27. pyxllib/cv/pupil.py +9 -0
  28. pyxllib/cv/rgbfmt.py +1525 -0
  29. pyxllib/cv/slidercaptcha.py +137 -0
  30. pyxllib/cv/trackbartools.py +163 -49
  31. pyxllib/cv/xlcvlib.py +1040 -0
  32. pyxllib/cv/xlpillib.py +423 -0
  33. pyxllib/data/__init__.py +0 -0
  34. pyxllib/data/echarts.py +240 -0
  35. pyxllib/data/jsonlib.py +89 -0
  36. pyxllib/{util/oss2_.py → data/oss.py} +11 -9
  37. pyxllib/data/pglib.py +1127 -0
  38. pyxllib/data/sqlite.py +568 -0
  39. pyxllib/{util → data}/sqllib.py +13 -31
  40. pyxllib/ext/JLineViewer.py +505 -0
  41. pyxllib/ext/__init__.py +6 -0
  42. pyxllib/{util → ext}/demolib.py +119 -35
  43. pyxllib/ext/drissionlib.py +277 -0
  44. pyxllib/ext/kq5034lib.py +12 -0
  45. pyxllib/{util/main.py → ext/old.py} +122 -284
  46. pyxllib/ext/qt.py +449 -0
  47. pyxllib/ext/robustprocfile.py +497 -0
  48. pyxllib/ext/seleniumlib.py +76 -0
  49. pyxllib/{util/tklib.py → ext/tk.py} +10 -11
  50. pyxllib/ext/unixlib.py +827 -0
  51. pyxllib/ext/utools.py +351 -0
  52. pyxllib/{util/webhooklib.py → ext/webhook.py} +45 -17
  53. pyxllib/ext/win32lib.py +40 -0
  54. pyxllib/ext/wjxlib.py +88 -0
  55. pyxllib/ext/wpsapi.py +124 -0
  56. pyxllib/ext/xlwork.py +9 -0
  57. pyxllib/ext/yuquelib.py +1105 -0
  58. pyxllib/file/__init__.py +17 -0
  59. pyxllib/file/docxlib.py +761 -0
  60. pyxllib/{util → file}/gitlib.py +40 -27
  61. pyxllib/file/libreoffice.py +165 -0
  62. pyxllib/file/movielib.py +148 -0
  63. pyxllib/file/newbie.py +10 -0
  64. pyxllib/file/onenotelib.py +1469 -0
  65. pyxllib/file/packlib/__init__.py +330 -0
  66. pyxllib/{util → file/packlib}/zipfile.py +598 -195
  67. pyxllib/file/pdflib.py +426 -0
  68. pyxllib/file/pupil.py +185 -0
  69. pyxllib/file/specialist/__init__.py +685 -0
  70. pyxllib/{basic/_5_dirlib.py → file/specialist/dirlib.py} +364 -93
  71. pyxllib/file/specialist/download.py +193 -0
  72. pyxllib/file/specialist/filelib.py +2829 -0
  73. pyxllib/file/xlsxlib.py +3131 -0
  74. pyxllib/file/xlsyncfile.py +341 -0
  75. pyxllib/prog/__init__.py +5 -0
  76. pyxllib/prog/cachetools.py +64 -0
  77. pyxllib/prog/deprecatedlib.py +233 -0
  78. pyxllib/prog/filelock.py +42 -0
  79. pyxllib/prog/ipyexec.py +253 -0
  80. pyxllib/prog/multiprogs.py +940 -0
  81. pyxllib/prog/newbie.py +451 -0
  82. pyxllib/prog/pupil.py +1197 -0
  83. pyxllib/{sitepackages.py → prog/sitepackages.py} +5 -3
  84. pyxllib/prog/specialist/__init__.py +391 -0
  85. pyxllib/prog/specialist/bc.py +203 -0
  86. pyxllib/prog/specialist/browser.py +497 -0
  87. pyxllib/prog/specialist/common.py +347 -0
  88. pyxllib/prog/specialist/datetime.py +199 -0
  89. pyxllib/prog/specialist/tictoc.py +240 -0
  90. pyxllib/prog/specialist/xllog.py +180 -0
  91. pyxllib/prog/xlosenv.py +108 -0
  92. pyxllib/stdlib/__init__.py +17 -0
  93. pyxllib/{util → stdlib}/tablepyxl/__init__.py +1 -3
  94. pyxllib/{util → stdlib}/tablepyxl/style.py +1 -1
  95. pyxllib/{util → stdlib}/tablepyxl/tablepyxl.py +2 -4
  96. pyxllib/text/__init__.py +8 -0
  97. pyxllib/text/ahocorasick.py +39 -0
  98. pyxllib/text/airscript.js +744 -0
  99. pyxllib/text/charclasslib.py +121 -0
  100. pyxllib/text/jiebalib.py +267 -0
  101. pyxllib/text/jinjalib.py +32 -0
  102. pyxllib/text/jsa_ai_prompt.md +271 -0
  103. pyxllib/text/jscode.py +922 -0
  104. pyxllib/text/latex/__init__.py +158 -0
  105. pyxllib/text/levenshtein.py +303 -0
  106. pyxllib/text/nestenv.py +1215 -0
  107. pyxllib/text/newbie.py +300 -0
  108. pyxllib/text/pupil/__init__.py +8 -0
  109. pyxllib/text/pupil/common.py +1121 -0
  110. pyxllib/text/pupil/xlalign.py +326 -0
  111. pyxllib/text/pycode.py +47 -0
  112. pyxllib/text/specialist/__init__.py +8 -0
  113. pyxllib/text/specialist/common.py +112 -0
  114. pyxllib/text/specialist/ptag.py +186 -0
  115. pyxllib/text/spellchecker.py +172 -0
  116. pyxllib/text/templates/echart_base.html +11 -0
  117. pyxllib/text/templates/highlight_code.html +17 -0
  118. pyxllib/text/templates/latex_editor.html +103 -0
  119. pyxllib/text/vbacode.py +17 -0
  120. pyxllib/text/xmllib.py +747 -0
  121. pyxllib/xl.py +39 -0
  122. pyxllib/xlcv.py +17 -0
  123. pyxllib-0.3.197.dist-info/METADATA +48 -0
  124. pyxllib-0.3.197.dist-info/RECORD +126 -0
  125. {pyxllib-0.0.43.dist-info → pyxllib-0.3.197.dist-info}/WHEEL +4 -5
  126. pyxllib/basic/_1_strlib.py +0 -945
  127. pyxllib/basic/_2_timelib.py +0 -488
  128. pyxllib/basic/_3_pathlib.py +0 -916
  129. pyxllib/basic/_4_loglib.py +0 -419
  130. pyxllib/basic/__init__.py +0 -54
  131. pyxllib/basic/arrow_.py +0 -250
  132. pyxllib/basic/chardet_.py +0 -66
  133. pyxllib/basic/dirlib.py +0 -529
  134. pyxllib/basic/dprint.py +0 -202
  135. pyxllib/basic/extension.py +0 -12
  136. pyxllib/basic/judge.py +0 -31
  137. pyxllib/basic/log.py +0 -204
  138. pyxllib/basic/pathlib_.py +0 -705
  139. pyxllib/basic/pytictoc.py +0 -102
  140. pyxllib/basic/qiniu_.py +0 -61
  141. pyxllib/basic/strlib.py +0 -761
  142. pyxllib/basic/timer.py +0 -132
  143. pyxllib/cv/cv.py +0 -834
  144. pyxllib/cv/cvlib/_1_geo.py +0 -543
  145. pyxllib/cv/cvlib/_2_cvprcs.py +0 -309
  146. pyxllib/cv/cvlib/_2_imgproc.py +0 -594
  147. pyxllib/cv/cvlib/_3_pilprcs.py +0 -80
  148. pyxllib/cv/cvlib/_4_cvimg.py +0 -211
  149. pyxllib/cv/cvlib/__init__.py +0 -10
  150. pyxllib/cv/debugtools.py +0 -82
  151. pyxllib/cv/fitz_.py +0 -300
  152. pyxllib/cv/installer.py +0 -42
  153. pyxllib/debug/_0_installer.py +0 -38
  154. pyxllib/debug/_1_typelib.py +0 -277
  155. pyxllib/debug/_2_chrome.py +0 -198
  156. pyxllib/debug/_3_showdir.py +0 -161
  157. pyxllib/debug/_4_bcompare.py +0 -140
  158. pyxllib/debug/__init__.py +0 -49
  159. pyxllib/debug/bcompare.py +0 -132
  160. pyxllib/debug/chrome.py +0 -198
  161. pyxllib/debug/installer.py +0 -38
  162. pyxllib/debug/showdir.py +0 -158
  163. pyxllib/debug/typelib.py +0 -278
  164. pyxllib/image/__init__.py +0 -12
  165. pyxllib/torch/__init__.py +0 -20
  166. pyxllib/torch/modellib.py +0 -37
  167. pyxllib/torch/trainlib.py +0 -344
  168. pyxllib/util/__init__.py +0 -20
  169. pyxllib/util/aip_.py +0 -141
  170. pyxllib/util/casiadb.py +0 -59
  171. pyxllib/util/excellib.py +0 -495
  172. pyxllib/util/filelib.py +0 -612
  173. pyxllib/util/jsondata.py +0 -27
  174. pyxllib/util/jsondata2.py +0 -92
  175. pyxllib/util/labelmelib.py +0 -139
  176. pyxllib/util/onepy/__init__.py +0 -29
  177. pyxllib/util/onepy/onepy.py +0 -574
  178. pyxllib/util/onepy/onmanager.py +0 -170
  179. pyxllib/util/pyautogui_.py +0 -219
  180. pyxllib/util/textlib.py +0 -1305
  181. pyxllib/util/unorder.py +0 -22
  182. pyxllib/util/xmllib.py +0 -639
  183. pyxllib-0.0.43.dist-info/METADATA +0 -39
  184. pyxllib-0.0.43.dist-info/RECORD +0 -80
  185. pyxllib-0.0.43.dist-info/top_level.txt +0 -1
  186. {pyxllib-0.0.43.dist-info → pyxllib-0.3.197.dist-info/licenses}/LICENSE +0 -0
@@ -1,170 +0,0 @@
1
- import win32com.client
2
-
3
- if win32com.client.gencache.is_readonly:
4
- win32com.client.gencache.is_readonly = False
5
- win32com.client.gencache.Rebuild()
6
-
7
- """
8
- OnePy
9
- Provides pythonic wrappers around OneNote COM interfaces
10
- """
11
-
12
- ON15_APP_ID = 'OneNote.Application.15'
13
- ON15_SCHEMA = "{http://schemas.microsoft.com/office/onenote/2013/onenote}"
14
- ON14_APP_ID = 'OneNote.Application.14'
15
- ON14_SCHEMA = "{http://schemas.microsoft.com/office/onenote/2010/onenote}"
16
-
17
-
18
- class ONProcess:
19
-
20
- def __init__(self, version=15):
21
-
22
- try:
23
- if version == 15:
24
- self.process = win32com.client.gencache.EnsureDispatch(ON15_APP_ID)
25
- self.namespace = ON15_SCHEMA
26
- if version == 14:
27
- self.process = win32com.client.gencache.EnsureDispatch(ON14_APP_ID)
28
- self.namespace = ON14_SCHEMA
29
- except Exception as e:
30
- print(e)
31
- print("error starting onenote {}".format(version))
32
-
33
- def get_hierarchy(self, start_node_id="", hierarchy_scope=4):
34
- """
35
- HierarchyScope
36
- 0 - Gets just the start node specified and no descendants.
37
- 1 - Gets the immediate child nodes of the start node, and no descendants in higher or lower subsection groups.
38
- 2 - Gets all notebooks below the start node, or root.
39
- 3 - Gets all sections below the start node, including sections in section groups and subsection groups.
40
- 4 - Gets all pages below the start node, including all pages in section groups and subsection groups.
41
- """
42
- return self.process.GetHierarchy(start_node_id, hierarchy_scope)
43
-
44
- def update_hierarchy(self, changes_xml_in):
45
- try:
46
- self.process.UpdateHierarchy(changes_xml_in)
47
- except Exception as e:
48
- print("Could not Update Hierarchy")
49
-
50
- def open_hierarchy(self, path, relative_to_object_id, object_id, create_file_type=0):
51
- """
52
- CreateFileType
53
- 0 - Creates no new object.
54
- 1 - Creates a notebook with the specified name at the specified location.
55
- 2 - Creates a section group with the specified name at the specified location.
56
- 3 - Creates a section with the specified name at the specified location.
57
- """
58
- try:
59
- return self.process.OpenHierarchy(path, relative_to_object_id, "", create_file_type)
60
- except Exception as e:
61
- print("Could not Open Hierarchy")
62
-
63
- def delete_hierarchy(self, object_id, excpect_last_modified=""):
64
- try:
65
- self.process.DeleteHierarchy(object_id, excpect_last_modified)
66
- except Exception as e:
67
- print("Could not Delete Hierarchy")
68
-
69
- def create_new_page(self, section_id, new_page_style=0):
70
- """
71
- NewPageStyle
72
- 0 - Create a Page that has Default Page Style
73
- 1 - Create a blank page with no title
74
- 2 - Createa blank page that has no title
75
- """
76
- try:
77
- self.process.CreateNewPage(section_id, "", new_page_style)
78
- except Exception as e:
79
- print("Unable to create the page")
80
-
81
- def close_notebook(self, notebook_id):
82
- try:
83
- self.process.CloseNotebook(notebook_id)
84
- except Exception as e:
85
- print("Could not Close Notebook")
86
-
87
- def get_page_content(self, page_id, page_info=0):
88
- """
89
- PageInfo
90
- 0 - Returns only basic page content, without selection markup and binary data objects. This is the standard value to pass.
91
- 1 - Returns page content with no selection markup, but with all binary data.
92
- 2 - Returns page content with selection markup, but no binary data.
93
- 3 - Returns page content with selection markup and all binary data.
94
- """
95
- try:
96
- return self.process.GetPageContent(page_id, "", page_info)
97
- except Exception as e:
98
- print("Could not get Page Content")
99
-
100
- def update_page_content(self, page_changes_xml_in, excpect_last_modified=0):
101
- try:
102
- self.process.UpdatePageContent(page_changes_xml_in, excpect_last_modified)
103
- except Exception as e:
104
- print("Could not Update Page Content")
105
-
106
- def get_binary_page_content(self, page_id, callback_id):
107
- try:
108
- return self.process.GetBinaryPageContent(page_id, callback_id)
109
- except Exception as e:
110
- print("Could not Get Binary Page Content")
111
-
112
- def delete_page_content(self, page_id, object_id, excpect_last_modified=0):
113
- try:
114
- self.process.DeletePageContent(page_id, object_id, excpect_last_modified)
115
- except Exception as e:
116
- print("Could not Delete Page Content")
117
-
118
- # Actions
119
-
120
- def navigate_to(self, object_id, new_window=False):
121
- try:
122
- self.process.NavigateTo(object_id, "", new_window)
123
- except Exception as e:
124
- print("Could not Navigate To")
125
-
126
- def publish(self, hierarchy_id, target_file_path, publish_format, clsid_of_exporter=""):
127
- """
128
- PublishFormat
129
- 0 - Published page is in .one format.
130
- 1 - Published page is in .onea format.
131
- 2 - Published page is in .mht format.
132
- 3 - Published page is in .pdf format.
133
- 4 - Published page is in .xps format.
134
- 5 - Published page is in .doc or .docx format.
135
- 6 - Published page is in enhanced metafile (.emf) format.
136
- """
137
- try:
138
- self.process.Publish(hierarchy_id, target_file_path, publish_format, clsid_of_exporter)
139
- except Exception as e:
140
- print("Could not Publish")
141
-
142
- def open_package(self, path_package, path_dest):
143
- try:
144
- return self.process.OpenPackage(path_package, path_dest)
145
- except Exception as e:
146
- print("Could not Open Package")
147
-
148
- def get_hyperlink_to_object(self, hierarchy_id, target_file_path=""):
149
- try:
150
- return self.process.GetHyperlinkToObject(hierarchy_id, target_file_path)
151
- except Exception as e:
152
- print("Could not Get Hyperlink")
153
-
154
- def find_pages(self, start_node_id, search_string, display):
155
- try:
156
- return self.process.FindPages(start_node_id, search_string, "", False, display)
157
- except Exception as e:
158
- print("Could not Find Pages")
159
-
160
- def get_special_location(self, special_location=0):
161
- """
162
- SpecialLocation
163
- 0 - Gets the path to the Backup Folders folder location.
164
- 1 - Gets the path to the Unfiled Notes folder location.
165
- 2 - Gets the path to the Default Notebook folder location.
166
- """
167
- try:
168
- return self.process.GetSpecialLocation(special_location)
169
- except Exception as e:
170
- print("Could not retreive special location")
@@ -1,219 +0,0 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- # @Author : 陈坤泽
4
- # @Email : 877362867@qq.com
5
- # @Data : 2020/06/06
6
-
7
-
8
- import os
9
- import re
10
- import subprocess
11
- import time
12
-
13
- try:
14
- import pyautogui
15
- except ModuleNotFoundError:
16
- subprocess.run(['pip', 'install', 'pyautogui'])
17
- import pyautogui
18
-
19
- try:
20
- import keyboard
21
- except ModuleNotFoundError:
22
- subprocess.run(['pip', 'install', 'keyboard'])
23
- import keyboard
24
-
25
- import pyscreeze
26
-
27
- from pyxllib.basic import get_etag, Path, dprint
28
-
29
-
30
- class AutoGui:
31
- """ 跟GUI有关的操作自动化功能
32
-
33
- 每帧处理要0.15秒左右,仅适用于一般的办公、回合制手游,不适合fps类游戏外挂
34
- """
35
-
36
- def __init__(self, figspath, grayscale=False, confidence=0.999):
37
- """
38
- :param figspath: 图片素材所在目录
39
- :param grayscalse: 匹配时是否仅考虑灰度图
40
- :param confidence: 匹配时允许的误差,使用该功能需要OpenCV库的支持
41
- confidence参数暂未实装
42
- """
43
- self.figspath = str(figspath)
44
- self.grayscale = grayscale
45
- self.confidence = confidence
46
- self.use_opencv = pyscreeze.useOpenCV
47
-
48
- def find(self, name, grayscale=None, confidence=None):
49
- """
50
- :param name: 判断当前屏幕中,是否存在图库中名为name的图
51
- :param grayscale: 这里如果设置了,会覆盖类中的默认设置
52
- :return: 如果存在,返回其中心坐标,否则返回None
53
- """
54
- grayscale = self.grayscale if grayscale is None else grayscale
55
- confidence = self.confidence if confidence is None else confidence
56
- file_path = os.path.join(self.figspath, name)
57
- # 如果使用了cv2,是不能直接处理含中文的路径的;有的话,就要先拷贝到一个英文路径来处理
58
- # 出现这种情况,均速会由0.168秒变慢18%到0.198秒。
59
- if self.use_opencv and re.search(r'[\u4e00-\u9fa5,。;?()【】、①-⑨]', file_path):
60
- # TODO 除了拷贝图片的方法,应该有其他更好的策略
61
- p1 = Path(file_path)
62
- p2 = Path(get_etag(file_path), p1.suffix, root=Path.TEMP)
63
- p1.copy(p2, if_exists='ignore') # 使用etag去重,出现相同etag则不用拷贝了
64
- file_path = p2.fullpath
65
- # print(file_path)
66
- pos = pyautogui.locateCenterOnScreen(file_path, grayscale=grayscale, confidence=confidence)
67
- # pyautogui.screenshot().save('debug.jpg')
68
- # dprint(name, pos)
69
- return pos
70
-
71
- def move_to(self, name, grayscale=None):
72
- """找到则返回坐标,否则返回None"""
73
- pos = self.find(name, grayscale)
74
- if pos: pyautogui.moveTo(*pos)
75
- return pos
76
-
77
- def click(self, name, grayscale=None, confidence=None, wait=True, back=False):
78
- """找到则返回坐标,否则返回None
79
- :param wait: 是否等待图标出现运行成功后再继续
80
- """
81
- pos0 = pyautogui.position()
82
- while True:
83
- if isinstance(name, (tuple, list)) and len(name) == 2: # 直接输入坐标
84
- pos = name
85
- else:
86
- pos = self.find(name, grayscale, confidence)
87
- if pos: pyautogui.click(*pos)
88
- if pos or not wait: break
89
- if back: pyautogui.moveTo(*pos0) # 恢复鼠标原位置
90
- return pos
91
-
92
- def try_click(self, name, grayscale=None, confidence=None, back=False):
93
- return self.click(name, grayscale=grayscale, confidence=confidence, wait=False, back=back)
94
-
95
-
96
- class PosTran:
97
- """ 坐标位置变换
98
-
99
- 应用场景: 原来在A窗口下的点p和区域r,
100
- 在窗口位置、大小改成B后,p和r的坐标
101
- """
102
-
103
- def __init__(self, w1, w2):
104
- """
105
- :param w1: 原窗口位置 (x, y, w, h)
106
- :param w2: 新窗口位置
107
- """
108
- self.w1 = w1
109
- self.w2 = w2
110
-
111
- @classmethod
112
- def point2point(cls, w1, p1, w2):
113
- """ 窗口w1切到w2,原点p1变换到坐标p2
114
- """
115
- x1, y1, w1, h1 = w1
116
- x2, y2, w2, h2 = w2
117
- x = x2 + (p1[0] - x1) * w2 / w1
118
- y = y2 + (p1[1] - y1) * h2 / h1
119
- return round(x), round(y)
120
-
121
- def w1point(self, w2point):
122
- return self.point2point(self.w2, w2point, self.w1)
123
-
124
- def w2point(self, w1point):
125
- """旧窗口中的点坐标转回新窗口点坐标"""
126
- return self.point2point(self.w1, w1point, self.w2)
127
-
128
- @classmethod
129
- def dx2dx(cls, w1, dx1, w2):
130
- """ 宽度偏移量的变化
131
- """
132
- return round(dx1 * w2[2] / w1[2])
133
-
134
- def w1dx(self, dx2):
135
- return self.dx2dx(self.w2, dx2, self.w1)
136
-
137
- def w2dx(self, dx1):
138
- return self.dx2dx(self.w1, dx1, self.w2)
139
-
140
- @classmethod
141
- def dy2dy(cls, w1, dy1, w2):
142
- return round(dy1 * w2[3] / w1[3])
143
-
144
- def w1dy(self, dy2):
145
- return self.dy2dy(self.w2, dy2, self.w1)
146
-
147
- def w2dy(self, dy1):
148
- return self.dy2dy(self.w1, dy1, self.w2)
149
-
150
- @classmethod
151
- def region2region(cls, w1, r1, w2):
152
- """ 窗口w1切到w2,原区域r1变换到坐标r2
153
- """
154
- x, y = cls.point2point(w1, r1[:2], w2)
155
- w = round(r1[2] * w2[2] / w1[2])
156
- h = round(r1[3] * w2[3] / w1[3])
157
- return x, y, w, h
158
-
159
- def w1region(self, w2region):
160
- return self.region2region(self.w2, w2region, self.w1)
161
-
162
- def w2region(self, w1region):
163
- return self.region2region(self.w1, w1region, self.w2)
164
-
165
-
166
- def lookup_mouse_position():
167
- """查看鼠标位置的工具
168
- """
169
- from keyboard import read_key
170
-
171
- left_top_point = None
172
- while True:
173
- k = read_key()
174
- if k == 'ctrl':
175
- # 定位当前鼠标坐标位置
176
- # 也可以用来定位区域时,先确定区域的左上角点
177
- left_top_point = pyautogui.position()
178
- print('坐标:', *left_top_point)
179
- elif k == 'alt':
180
- # 定位区域的右下角点,并输出区域
181
- p = pyautogui.position()
182
- print('区域(x y w h):', left_top_point.x, left_top_point.y, p.x - left_top_point.x, p.y - left_top_point.y)
183
- elif k == 'esc':
184
- break
185
- # keyboard的监控太快了,需要暂停一下
186
- time.sleep(0.4)
187
-
188
-
189
- def lookup_mouse_position2(w1, w2, reverse=False):
190
- """ 涉及到窗口位置、大小调整时的坐标计算
191
- 当前在窗口w1的坐标,切换到w2时的坐标
192
- :param reverse: 当前窗口实际是变换后的w2,输出的时候需要按照 w1 -> w2 的格式展示
193
- 代码实现的时候,其实只要把输出的内容对调即可
194
-
195
- 该函数是lookup_mouse_postion的进阶版,两个函数还是先不做合并,便于理解维护
196
- """
197
- import keyboard
198
- postran = PosTran(w1, w2)
199
-
200
- left_top_point = None
201
- while True:
202
- k = keyboard.read_key()
203
- if k == 'ctrl':
204
- # 定位当前鼠标坐标位置
205
- # 也可以用来定位区域时,先确定区域的左上角点
206
- left_top_point = pyautogui.position()
207
- p1, p2 = left_top_point, postran.w2point(left_top_point)
208
- if reverse: p1, p2 = p2, p1
209
- print('坐标:', *p1, '-->', *p2)
210
- elif k == 'alt':
211
- # 定位区域的右下角点,并输出区域
212
- p = pyautogui.position()
213
- r1 = [left_top_point.x, left_top_point.y, p.x - left_top_point.x, p.y - left_top_point.y]
214
- r2 = postran.w2region(r1)
215
- if reverse: r1, r2 = r2, r1
216
- print('区域(x y w h):', *r1, '-->', *r2)
217
- elif k == 'esc':
218
- break
219
- time.sleep(0.4)