XMWAI 0.4.12__py3-none-any.whl → 0.4.23__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.
Potentially problematic release.
This version of XMWAI might be problematic. Click here for more details.
- XMWAI/__init__.py +2 -2
- XMWAI/trial_class.py +53 -49
- {xmwai-0.4.12.dist-info → xmwai-0.4.23.dist-info}/METADATA +1 -1
- {xmwai-0.4.12.dist-info → xmwai-0.4.23.dist-info}/RECORD +7 -7
- {xmwai-0.4.12.dist-info → xmwai-0.4.23.dist-info}/WHEEL +0 -0
- {xmwai-0.4.12.dist-info → xmwai-0.4.23.dist-info}/licenses/LICENSE.txt +0 -0
- {xmwai-0.4.12.dist-info → xmwai-0.4.23.dist-info}/top_level.txt +0 -0
XMWAI/__init__.py
CHANGED
|
@@ -2,10 +2,10 @@ from .core import story, photo, reply, poem, crack, show # 从子模块导入
|
|
|
2
2
|
from .magic_core import birthday # 从子模块导入函数到顶层
|
|
3
3
|
from .bomb_core import bomb # 从子模块导入函数到顶层
|
|
4
4
|
from .idiom_core import idiom, searchIdiom, get_json_path # 从子模块导入函数到顶层
|
|
5
|
-
from .trial_class import make, get_file_content_as_base64, save_pic,
|
|
5
|
+
from .trial_class import make, get_file_content_as_base64, save_pic, detect_scale, open_image, get_file_content_as_base64_2, cartoon # 从子模块导入函数到顶层
|
|
6
6
|
from .web_core import burger, cookbook # 从子模块导入函数到顶层
|
|
7
7
|
|
|
8
8
|
__all__ = ["story", "photo", "reply", "poem", 'birthday', 'bomb',
|
|
9
9
|
"idiom", "searchIdiom", "get_json_path", "crack", "show",
|
|
10
|
-
"make", "get_file_content_as_base64", "save_pic", "
|
|
10
|
+
"make", "get_file_content_as_base64", "save_pic", "detect_scale", "open_image",
|
|
11
11
|
"get_file_content_as_base64_2", "cartoon", "burger", "cookbook"] # 可选:明确导出的内容
|
XMWAI/trial_class.py
CHANGED
|
@@ -13,6 +13,9 @@ import cv2
|
|
|
13
13
|
import numpy as np
|
|
14
14
|
|
|
15
15
|
'''-----------体验课1-----------'''
|
|
16
|
+
import urllib.parse
|
|
17
|
+
import platform
|
|
18
|
+
from io import BytesIO
|
|
16
19
|
|
|
17
20
|
|
|
18
21
|
def make(screen):
|
|
@@ -57,9 +60,8 @@ def make(screen):
|
|
|
57
60
|
# 发送创建任务请求
|
|
58
61
|
response = requests.post(create_url, headers=headers,
|
|
59
62
|
data=create_payload.encode("utf-8"))
|
|
60
|
-
response.raise_for_status()
|
|
63
|
+
response.raise_for_status()
|
|
61
64
|
task_id = response.json()["data"]["task_id"]
|
|
62
|
-
# print(f"任务已创建,ID: {task_id}")
|
|
63
65
|
|
|
64
66
|
# 轮询检查任务状态
|
|
65
67
|
query_payload = json.dumps({"task_id": task_id}, ensure_ascii=False)
|
|
@@ -71,16 +73,15 @@ def make(screen):
|
|
|
71
73
|
query_url, headers=headers, data=query_payload.encode("utf-8"))
|
|
72
74
|
response.raise_for_status()
|
|
73
75
|
task_status = response.json()["data"]["task_status"]
|
|
74
|
-
# print(f"任务状态: {task_status}")
|
|
75
76
|
|
|
76
77
|
# 处理任务结果
|
|
77
78
|
if task_status == "SUCCESS":
|
|
78
79
|
picture = requests.get(response.json()[
|
|
79
|
-
|
|
80
|
+
"data"]["sub_task_result_list"][0]["final_image_list"][0]["img_url"])
|
|
80
81
|
image_data = BytesIO(picture.content)
|
|
81
82
|
image = Image.open(image_data)
|
|
82
83
|
image.save('image.gif')
|
|
83
|
-
|
|
84
|
+
open_image("image.gif")
|
|
84
85
|
else:
|
|
85
86
|
print(f"任务失败,状态: {task_status}")
|
|
86
87
|
|
|
@@ -99,14 +100,31 @@ def get_file_content_as_base64(path, urlencoded=False):
|
|
|
99
100
|
return content
|
|
100
101
|
|
|
101
102
|
|
|
103
|
+
def detect_scale():
|
|
104
|
+
"""
|
|
105
|
+
跨平台缩放比例检测
|
|
106
|
+
- Windows: 检测实际 DPI
|
|
107
|
+
- macOS/Linux: 默认返回 1.0
|
|
108
|
+
"""
|
|
109
|
+
if platform.system() == "Windows":
|
|
110
|
+
try:
|
|
111
|
+
user32 = ctypes.windll.user32
|
|
112
|
+
user32.SetProcessDPIAware()
|
|
113
|
+
if hasattr(user32, 'GetDpiForSystem'):
|
|
114
|
+
dpi = user32.GetDpiForSystem()
|
|
115
|
+
return dpi / 96.0
|
|
116
|
+
screen_width = user32.GetSystemMetrics(0)
|
|
117
|
+
return screen_width / 1920.0
|
|
118
|
+
except Exception:
|
|
119
|
+
return 1.0
|
|
120
|
+
else:
|
|
121
|
+
return 1.0
|
|
122
|
+
|
|
123
|
+
|
|
102
124
|
def save_pic(screen, output_file="pic.png"):
|
|
103
125
|
"""
|
|
104
126
|
精准截取turtle绘图区域,不包含窗口边框和标题栏
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
参数:
|
|
108
|
-
screen: turtle的Screen对象
|
|
109
|
-
output_file: 输出文件名
|
|
127
|
+
跨平台支持 (Windows/macOS/Linux)
|
|
110
128
|
"""
|
|
111
129
|
canvas = screen.getcanvas()
|
|
112
130
|
screen.update()
|
|
@@ -118,62 +136,48 @@ def save_pic(screen, output_file="pic.png"):
|
|
|
118
136
|
width = canvas.winfo_width()
|
|
119
137
|
height = canvas.winfo_height()
|
|
120
138
|
|
|
121
|
-
#
|
|
122
|
-
scale_factor =
|
|
123
|
-
# print(f"检测到屏幕缩放比例: {scale_factor}x")
|
|
139
|
+
# 检测屏幕缩放比例
|
|
140
|
+
scale_factor = detect_scale()
|
|
124
141
|
|
|
125
|
-
#
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
title_height = int(
|
|
142
|
+
# Windows 上要扣除边框和标题栏
|
|
143
|
+
border_width = int(
|
|
144
|
+
8 * scale_factor) if platform.system() == "Windows" else 0
|
|
145
|
+
title_height = int(
|
|
146
|
+
30 * scale_factor) if platform.system() == "Windows" else 0
|
|
129
147
|
|
|
130
148
|
# 计算实际绘图区域
|
|
131
149
|
img = ImageGrab.grab(
|
|
132
150
|
bbox=(
|
|
133
|
-
x + border_width,
|
|
134
|
-
y + title_height,
|
|
135
|
-
x + width - border_width,
|
|
136
|
-
y + height - border_width
|
|
151
|
+
x + border_width,
|
|
152
|
+
y + title_height,
|
|
153
|
+
x + width - border_width,
|
|
154
|
+
y + height - border_width
|
|
137
155
|
)
|
|
138
156
|
)
|
|
139
157
|
|
|
140
|
-
# 保存为PNG
|
|
141
158
|
img.save(output_file)
|
|
142
|
-
# print(f"已保存图形到 {output_file} (尺寸: {img.size})")
|
|
143
159
|
except Exception as e:
|
|
144
160
|
print(f"截图时出错: {e}")
|
|
145
|
-
print("提示:
|
|
161
|
+
print("提示: 可以尝试手动截图或使用其他方法")
|
|
146
162
|
|
|
147
163
|
|
|
148
|
-
def
|
|
164
|
+
def open_image(file_path):
|
|
149
165
|
"""
|
|
150
|
-
|
|
151
|
-
|
|
166
|
+
跨平台打开图片
|
|
167
|
+
- Windows: os.startfile
|
|
168
|
+
- macOS: open
|
|
169
|
+
- Linux: xdg-open
|
|
152
170
|
"""
|
|
171
|
+
system = platform.system()
|
|
153
172
|
try:
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
#
|
|
159
|
-
|
|
160
|
-
dpi = user32.GetDpiForSystem()
|
|
161
|
-
return dpi / 96.0 # Windows标准DPI是96
|
|
162
|
-
|
|
163
|
-
# 尝试获取显示器DPI (Windows 10及以上)
|
|
164
|
-
if hasattr(user32, 'GetDpiForWindow'):
|
|
165
|
-
root = tk.Tk()
|
|
166
|
-
dpi = user32.GetDpiForWindow(root.winfo_id())
|
|
167
|
-
root.destroy()
|
|
168
|
-
return dpi / 96.0
|
|
169
|
-
|
|
170
|
-
# 兼容方法:获取屏幕尺寸并与标准尺寸比较
|
|
171
|
-
screen_width = user32.GetSystemMetrics(0)
|
|
172
|
-
return screen_width / 1920.0 # 假设标准分辨率为1920x1080
|
|
173
|
+
if system == "Windows":
|
|
174
|
+
os.startfile(file_path)
|
|
175
|
+
elif system == "Darwin": # macOS
|
|
176
|
+
os.system(f"open {file_path}")
|
|
177
|
+
else: # Linux / 其他
|
|
178
|
+
os.system(f"xdg-open {file_path}")
|
|
173
179
|
except Exception as e:
|
|
174
|
-
print(f"
|
|
175
|
-
print("使用默认缩放比例1.0")
|
|
176
|
-
return 1.0
|
|
180
|
+
print(f"打开图片失败: {e}")
|
|
177
181
|
|
|
178
182
|
|
|
179
183
|
'''-----------体验课2-----------'''
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
XMWAI/__init__.py,sha256
|
|
1
|
+
XMWAI/__init__.py,sha256=pQEXlJlAbe4PvWoWDJb0NW1C4Z0pQve3FT1SB6epSEI,918
|
|
2
2
|
XMWAI/bomb_core.py,sha256=h2ZPH3SuoG2L_XOf1dcK8p3lhw5QzhneWl2yMLj1RiU,1819
|
|
3
3
|
XMWAI/core.py,sha256=rOXj7FnewSdnzBcFLjpnBtrOTCsvMfiycIcdPDagxho,10012
|
|
4
4
|
XMWAI/idiom_core.py,sha256=yU-VHhqqoutVm6GVikcjL3m9yuB1hUsFBpPYvwY4n5g,1689
|
|
5
5
|
XMWAI/magic_core.py,sha256=Ms4b12PJ8rjsmceg1VUqWCWx2ebvdhLp4sIF6K_Vaok,3491
|
|
6
|
-
XMWAI/trial_class.py,sha256=
|
|
6
|
+
XMWAI/trial_class.py,sha256=fPsl7BZvhzch2FOIG4azr999kjtoly53Acm3LqL8f98,9724
|
|
7
7
|
XMWAI/web_core.py,sha256=7awPg1kYW3lYrbgylqJvUF3g050bn6H21PgmQ7Kv1wA,10927
|
|
8
8
|
XMWAI/file/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
XMWAI/file/idiom.json,sha256=HUtPRUzhxBbWoasjadbmbA_5ngQ5AXLu9weQSZ4hzhk,10319857
|
|
@@ -107,8 +107,8 @@ XMWAI/static/images/tomato.png,sha256=FEOEAOdUhW_BDFgTpxOkYc0I5Iu29_gtHb3RIPEej0
|
|
|
107
107
|
XMWAI/templates/burger.html,sha256=vDnxpSW8phetyScySsalScZnFKl3LNpy5lJjKxGXgbI,3320
|
|
108
108
|
XMWAI/templates/nutrition_pie.html,sha256=yJVXI28i-UfvF0xOXGSNLMb8oCJNhh2J3zoRDr5_7DM,5567
|
|
109
109
|
XMWAI/templates/创意菜谱.html,sha256=RcDgH58QLyUJ9A59wobu3wvchGBY1snVsXcZQZam5M0,4805
|
|
110
|
-
xmwai-0.4.
|
|
111
|
-
xmwai-0.4.
|
|
112
|
-
xmwai-0.4.
|
|
113
|
-
xmwai-0.4.
|
|
114
|
-
xmwai-0.4.
|
|
110
|
+
xmwai-0.4.23.dist-info/licenses/LICENSE.txt,sha256=bcaIQMrIhdQ3O-PoZlexjmW6h-wLGvHxh5Oksl4ohtc,1066
|
|
111
|
+
xmwai-0.4.23.dist-info/METADATA,sha256=RzOFoDRfC_5-Oe_cX_-fQ8qRLoJzJ5RhqI1-8E2OtRA,1198
|
|
112
|
+
xmwai-0.4.23.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
113
|
+
xmwai-0.4.23.dist-info/top_level.txt,sha256=yvGcDI-sggK5jqd9wz0saipZvk3oIE3hNGHlqUjxf0c,6
|
|
114
|
+
xmwai-0.4.23.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|