From 4ac51cf84f6da441aef4ad1de6e240a4f7ed2762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=8A=E6=99=9A=E6=89=93=E8=80=81=E8=99=8E?= Date: Wed, 18 Mar 2026 23:12:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[=E6=8A=95=E7=A8=BF]=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=84=9A=E6=9C=AC:=20=E8=AE=A1=E7=AE=97=E5=99=A8=20=E2=80=94?= =?UTF-8?q?=20by=20=E4=BB=8A=E6=99=9A=E6=89=93=E8=80=81=E8=99=8E?= =?UTF-8?q?=F0=9F=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script_library/scripts/ui/script_mmw6k09q.py | 144 +++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 script_library/scripts/ui/script_mmw6k09q.py diff --git a/script_library/scripts/ui/script_mmw6k09q.py b/script_library/scripts/ui/script_mmw6k09q.py new file mode 100644 index 0000000..c2ec5f3 --- /dev/null +++ b/script_library/scripts/ui/script_mmw6k09q.py @@ -0,0 +1,144 @@ +import ui +import re + +# 只允许安全的计算表达式 +_allowed_pattern = re.compile(r'^[0-9+\-*/().\s]+$') + +def safe_eval(expr: str): + expr = expr.strip() + if not expr: + return '' + if not _allowed_pattern.match(expr): + return 'Error' + try: + result = eval(expr, {"__builtins__": None}, {}) + if isinstance(result, float): + return str(int(result)) if result.is_integer() else str(result) + return str(result) + except Exception: + return 'Error' + + +class SimpleCalculator(ui.View): + def __init__(self, *args, **kwargs): + # 模拟“正常用户”:给一个典型根尺寸 320x480 + super().__init__(frame=(0, 0, 320, 480), *args, **kwargs) + + self.background_color = 'white' + self.name = '计算器(测试UI居中)' + self.expr = '0' + + # 顶部显示区域 —— 占一点高度,不压得太高,也不太低 + self.display = ui.Label() + self.display.frame = (16, 40, self.width - 32, 60) + self.display.alignment = ui.ALIGN_RIGHT + self.display.font = ('', 32) + self.display.text = '0' + self.display.text_color = 'black' + self.display.background_color = None + self.add_subview(self.display) + + # 按钮布局:整体放在中部偏下,但不是挤到最下面 + buttons = [ + ['C', '+/-', '%', '/'], + ['7', '8', '9', '*'], + ['4', '5', '6', '-'], + ['1', '2', '3', '+'], + ['0', '', '.', '='], + ] + + margin = 10 + btn_w = (self.width - margin * 5) / 4.0 + btn_h = 60 + # 比你之前的 140 再往上提一点,整体更居中 + start_y = 120 + + for row_index, row in enumerate(buttons): + for col_index, title in enumerate(row): + if title == '': + continue + + x = margin + col_index * (btn_w + margin) + y = start_y + row_index * (btn_h + margin) + + # 0 键双倍宽度 + if title == '0' and row_index == 4 and col_index == 0: + width = btn_w * 2 + margin + else: + width = btn_w + + btn = ui.Button(title=title) + btn.frame = (x, y, width, btn_h) + btn.font = ('', 24) + btn.corner_radius = 12 + + if title in ['C', '+/-', '%']: + btn.background_color = '#a5a5a5' + btn.tint_color = 'black' + elif title in ['/', '*', '-', '+', '=']: + btn.background_color = '#ff9f0a' + btn.tint_color = 'white' + else: + btn.background_color = '#333333' + btn.tint_color = 'white' + + btn.action = self.button_tapped + self.add_subview(btn) + + # 更新显示 + def update_display(self): + self.display.text = self.expr + + # 按钮事件 + def button_tapped(self, sender): + text = sender.title + + if text == 'C': + self.expr = '0' + self.update_display() + return + + if text == '+/-': + if self.expr.startswith('-'): + self.expr = self.expr[1:] + else: + if self.expr != '0': + self.expr = '-' + self.expr + self.update_display() + return + + if text == '%': + val = safe_eval(self.expr) + if val not in ('Error', ''): + try: + num = float(val) / 100.0 + self.expr = str(int(num)) if num.is_integer() else str(num) + except Exception: + self.expr = 'Error' + else: + self.expr = 'Error' + self.update_display() + return + + if text == '=': + result = safe_eval(self.expr) + self.expr = result if result != '' else '0' + self.update_display() + return + + # 普通数字/符号输入 + if self.expr == '0' and text in '0123456789': + self.expr = text + else: + self.expr += text + + self.update_display() + + +def main(): + v = SimpleCalculator() + v.present('sheet') + + +if __name__ == '__main__': + main() \ No newline at end of file From ed45ded310282ef1c5cdc6baad1410ce720a25df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=8A=E6=99=9A=E6=89=93=E8=80=81=E8=99=8E?= Date: Wed, 18 Mar 2026 23:12:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[=E6=8A=95=E7=A8=BF]=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20index.json:=20=E6=B7=BB=E5=8A=A0=20=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script_library/index.json | 81 ++++++++++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 9 deletions(-) diff --git a/script_library/index.json b/script_library/index.json index ac49940..3360cb6 100644 --- a/script_library/index.json +++ b/script_library/index.json @@ -1,7 +1,7 @@ { "format_version": 1, - "data_version": 1, - "updated": "2026-03-18T12:00:00Z", + "data_version": 2, + "updated": "2026-03-18T15:12:33.180Z", "announcement": null, "categories": [ { @@ -55,7 +55,11 @@ "color": "#9B59B6" } ], - "featured": ["space_shooter", "neon_snake", "brick_breaker"], + "featured": [ + "space_shooter", + "neon_snake", + "brick_breaker" + ], "scripts": [ { "id": "brick_breaker", @@ -70,7 +74,13 @@ "file_type": "py", "author": "官方", "author_en": "Official", - "tags": ["scene", "touch", "particle", "game", "brick"], + "tags": [ + "scene", + "touch", + "particle", + "game", + "brick" + ], "requires": [], "min_app_version": "1.5.0", "added": "2026-03-18", @@ -91,7 +101,13 @@ "file_type": "py", "author": "官方", "author_en": "Official", - "tags": ["scene", "touch", "particle", "game", "shooter"], + "tags": [ + "scene", + "touch", + "particle", + "game", + "shooter" + ], "requires": [], "min_app_version": "1.5.0", "added": "2026-03-18", @@ -112,7 +128,13 @@ "file_type": "py", "author": "官方", "author_en": "Official", - "tags": ["scene", "gravity", "accelerometer", "game", "maze"], + "tags": [ + "scene", + "gravity", + "accelerometer", + "game", + "maze" + ], "requires": [], "min_app_version": "1.5.0", "added": "2026-03-18", @@ -133,7 +155,13 @@ "file_type": "py", "author": "官方", "author_en": "Official", - "tags": ["scene", "touch", "game", "snake", "dpad"], + "tags": [ + "scene", + "touch", + "game", + "snake", + "dpad" + ], "requires": [], "min_app_version": "1.5.0", "added": "2026-03-18", @@ -154,7 +182,13 @@ "file_type": "py", "author": "官方", "author_en": "Official", - "tags": ["scene", "touch", "game", "jump", "endless"], + "tags": [ + "scene", + "touch", + "game", + "jump", + "endless" + ], "requires": [], "min_app_version": "1.5.0", "added": "2026-03-18", @@ -175,13 +209,42 @@ "file_type": "py", "author": "官方", "author_en": "Official", - "tags": ["scene", "touch", "game", "whack", "timer"], + "tags": [ + "scene", + "touch", + "game", + "whack", + "timer" + ], "requires": [], "min_app_version": "1.5.0", "added": "2026-03-18", "updated": null, "status": "active", "lines": 427 + }, + { + "id": "script_mmw6k09q", + "name": "计算器", + "name_en": "计算器", + "desc": "计算器脚本iOS原生风格", + "desc_en": "计算器脚本iOS原生风格", + "category": "ui", + "file": "scripts/ui/script_mmw6k09q.py", + "thumbnail": null, + "version": 1, + "file_type": "py", + "author": "今晚打老虎🐯", + "author_en": "今晚打老虎🐯", + "tags": [ + "community" + ], + "requires": [], + "min_app_version": "1.5.0", + "added": "2026-03-18", + "updated": null, + "status": "active", + "lines": 144 } ] }