miumapp


Namemiumapp JSON
Version 1.0.9 PyPI version JSON
download
home_pageNone
Summary一个使用 Python + HTML 开发桌面 GUI 应用的框架,支持 Windows、Mac、Linux 平台。
upload_time2024-03-12 12:24:54
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseNone
keywords electron flutter uniapp pyqt5 miumapp
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 项目描述

一个使用 Python + HTML 开发桌面 GUI 应用的框架,支持 Windows、Mac、Linux 平台。

功能:

* 可在 HTML 中调用后端的 Python 函数。
* 可在 Python 上下文中调用窗口内的 JavaScript 对象。
* 可在 Python 上下文中对窗口发送操纵指令,执行包括但不限于:URL跳转、关闭窗口、JS注入、最大化等操作。
* 可开启多个窗口。
* 由于每个窗口可与 Python 双向调用,因此不同窗口之间可通过【窗口A → Python → 窗口B】的途径相互调用。
* 可指定窗口标题。
* 可指定窗口图标。
* 可通过传递 URL 或 HTML 文本这两种数据之一来决定窗口内容。
* 可通过 Nuitka 打包成可移植二进制文件。

我们所采用的技术栈组合是经过深思熟虑的,通过结合 **Python** 与  **HTML** 这两种高效、灵活、易用的技术栈,意味着您正在选择一个能够大大减少开发时间、简化开发流程、拥有丰富的第三方扩展的解决方案。与其它工具相比,我们的优势在于对新技术的快速适应、更为强大的社区支持,以及持续的更新和改进。

# 作者

[江南雨上](mailto:lcctoor@outlook.com)

[主页](https://lcctoor.github.io/arts/) \| [Github](https://github.com/lcctoor) \| [PyPi](https://pypi.org/user/lcctoor) \| [微信](https://lcctoor.github.io/arts/arts/ip_static/WeChatQRC.jpg) \| [邮箱](mailto:lcctoor@outlook.com) \| [捐赠](https://lcctoor.github.io/arts/arts/ip_static/DonationQRC-0rmb.jpg)

# Bug提交、功能提议

您可以通过 [Github-Issues](https://github.com/lcctoor/arts/issues)、[微信](https://lcctoor.github.io/arts/arts/ip_static/WeChatQRC.jpg) 与我联系。

# 安装

```
pip install miumapp
```

# 检查是否安装成功

运行内置Demo:

```python
import asyncio
from miumapp.demo import Introduce

asyncio.run( Introduce().start() )
```

运行后,若显示出与图片 [效果图](https://lcctoor.github.io/arts/arts/miumapp/ip_static/DemoUI.png) 所示一致的效果,则说明安装成功。

# 教程 ([查看美化版](https://lcctoor.github.io/arts/arts/miumapp) 👈)

本文将以最简洁的方式向你介绍核心知识,而不会让你被繁琐的术语所淹没。

## 导入

```python
import asyncio
from miumapp import App, allow_callpy
```

## 创建 APP

```python
class my_app(App):
    async def main(self):
        ...

asyncio.run( my_app().start() )
```

由于我们在主任务 main 中未定义任何代码,因此这个 APP 是一个空 APP,运行后看不到任何效果。

## 创建窗口

```python
class my_app(App):
  
    async def main(self):
        html = 'Hello, miumapp !'
        await self.create_window(html=html)

asyncio.run( my_app().start() )
```

此时,我们将能看到屏幕上打开了一个窗口,其内容为“Hello, miumapp !”。

### 指定窗口内容源

可通过传递 HTML 文本或 URL 链接这两种数据之一来决定窗口内容,示例:

```python
await self.create_window(html='你好!')
```

```python
await self.create_window(url='https://www.baidu.com/')
```

### 指定窗口标题

```python
await self.create_window(html='你好!', title='第一个窗口')
```

## 关闭窗口

可通过对窗口对象执行 `await window.close()` 或者点击窗口右上角的 `×` 图标来关闭窗口。

## 在 HTML 中调用 Python 函数

使用 allow_callpy 装饰的 Python 异步函数将能够在 HTML 中被调用,例如:

```python
class my_app(App):
  
    async def main(self):
        html = 'Hello, miumapp !'
        await self.create_window(html=html)

    @allow_callpy
    async def addition(self, a, b):
        return a + b

    async def sub(self, a, b):
        return a - b

asyncio.run( my_app().start() )
```

在这个例子中,方法 sub 只能在 Python 层面被调用,而方法 addition 既能在 Python 层面被调用,也能在 HTML 中被调用。

在 HTML 中调用 addition 方法:

```JavaScript
async function sum() {
    let a = parseInt( document.getElementById('a').value )  // 30
    let b = parseInt( document.getElementById('b').value )  // 50
    let kwargs = {a:a, b:b}
    let result = await miumapp.callpy(method='addition', kwargs=kwargs)
    console.log(result)  // {"code":0, "msg":"", "data":80}
}
```

## 在 Python 中调用 JavaScript 对象

### 一些示例

执行 JavaScript 代码:

```python
await window.evaluate("document.title = '第一个APP'", force_expr=True)
```

```python
await window.evaluate("alert(1)", force_expr=True)
```

获取变量值:

```python
CityName = await window.evaluate("CityName")  # 假设窗口中有一个叫 CityName 的变量
print(CityName)  # >>> '北京市'
```

调用函数并获取返回值:

```python
city_name = await window.evaluate("get_city_name()", force_expr=True)  # 假设窗口中有一个叫 get_city_name 的函数
print(city_name)  # >>> '上海市'
```

由于 window 对象继承自 pyppeteer.page.Page,因此 window.evaluate 支持 pyppeteer.page.Page.evaluate 的所有用法。关于 window.evaluate 的更多用法,请参考 [pyppeteer.page.Page.evaluate](https://pyppeteer.github.io/pyppeteer/reference.html#pyppeteer.page.Page.evaluate) 。

## window 对象的更多方法

由于 window 对象继承自 pyppeteer.page.Page,因此 window 支持 pyppeteer.page.Page 的所有方法,例如页面跳转、点击按钮、输入等。关于 window 的更多方法,请参考 [pyppeteer.page.Page](https://pyppeteer.github.io/pyppeteer/reference.html#pyppeteer.page.Page) 。

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "miumapp",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "electron,flutter,uniapp,pyqt5,miumapp",
    "author": null,
    "author_email": "\u6c5f\u5357\u96e8\u4e0a <lcctoor@outlook.com>",
    "download_url": "https://files.pythonhosted.org/packages/bb/37/bbe812c0bfe92f181f38282ab7c149500d8d26610bfb9ab82a751ebe4477/miumapp-1.0.9.tar.gz",
    "platform": null,
    "description": "# \u9879\u76ee\u63cf\u8ff0\n\n\u4e00\u4e2a\u4f7f\u7528 Python + HTML \u5f00\u53d1\u684c\u9762 GUI \u5e94\u7528\u7684\u6846\u67b6\uff0c\u652f\u6301 Windows\u3001Mac\u3001Linux \u5e73\u53f0\u3002\n\n\u529f\u80fd\uff1a\n\n* \u53ef\u5728 HTML \u4e2d\u8c03\u7528\u540e\u7aef\u7684 Python \u51fd\u6570\u3002\n* \u53ef\u5728 Python \u4e0a\u4e0b\u6587\u4e2d\u8c03\u7528\u7a97\u53e3\u5185\u7684 JavaScript \u5bf9\u8c61\u3002\n* \u53ef\u5728 Python \u4e0a\u4e0b\u6587\u4e2d\u5bf9\u7a97\u53e3\u53d1\u9001\u64cd\u7eb5\u6307\u4ee4\uff0c\u6267\u884c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\uff1aURL\u8df3\u8f6c\u3001\u5173\u95ed\u7a97\u53e3\u3001JS\u6ce8\u5165\u3001\u6700\u5927\u5316\u7b49\u64cd\u4f5c\u3002\n* \u53ef\u5f00\u542f\u591a\u4e2a\u7a97\u53e3\u3002\n* \u7531\u4e8e\u6bcf\u4e2a\u7a97\u53e3\u53ef\u4e0e Python \u53cc\u5411\u8c03\u7528\uff0c\u56e0\u6b64\u4e0d\u540c\u7a97\u53e3\u4e4b\u95f4\u53ef\u901a\u8fc7\u3010\u7a97\u53e3A \u2192 Python \u2192 \u7a97\u53e3B\u3011\u7684\u9014\u5f84\u76f8\u4e92\u8c03\u7528\u3002\n* \u53ef\u6307\u5b9a\u7a97\u53e3\u6807\u9898\u3002\n* \u53ef\u6307\u5b9a\u7a97\u53e3\u56fe\u6807\u3002\n* \u53ef\u901a\u8fc7\u4f20\u9012 URL \u6216 HTML \u6587\u672c\u8fd9\u4e24\u79cd\u6570\u636e\u4e4b\u4e00\u6765\u51b3\u5b9a\u7a97\u53e3\u5185\u5bb9\u3002\n* \u53ef\u901a\u8fc7 Nuitka \u6253\u5305\u6210\u53ef\u79fb\u690d\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002\n\n\u6211\u4eec\u6240\u91c7\u7528\u7684\u6280\u672f\u6808\u7ec4\u5408\u662f\u7ecf\u8fc7\u6df1\u601d\u719f\u8651\u7684\uff0c\u901a\u8fc7\u7ed3\u5408 **Python** \u4e0e  **HTML** \u8fd9\u4e24\u79cd\u9ad8\u6548\u3001\u7075\u6d3b\u3001\u6613\u7528\u7684\u6280\u672f\u6808\uff0c\u610f\u5473\u7740\u60a8\u6b63\u5728\u9009\u62e9\u4e00\u4e2a\u80fd\u591f\u5927\u5927\u51cf\u5c11\u5f00\u53d1\u65f6\u95f4\u3001\u7b80\u5316\u5f00\u53d1\u6d41\u7a0b\u3001\u62e5\u6709\u4e30\u5bcc\u7684\u7b2c\u4e09\u65b9\u6269\u5c55\u7684\u89e3\u51b3\u65b9\u6848\u3002\u4e0e\u5176\u5b83\u5de5\u5177\u76f8\u6bd4\uff0c\u6211\u4eec\u7684\u4f18\u52bf\u5728\u4e8e\u5bf9\u65b0\u6280\u672f\u7684\u5feb\u901f\u9002\u5e94\u3001\u66f4\u4e3a\u5f3a\u5927\u7684\u793e\u533a\u652f\u6301\uff0c\u4ee5\u53ca\u6301\u7eed\u7684\u66f4\u65b0\u548c\u6539\u8fdb\u3002\n\n# \u4f5c\u8005\n\n[\u6c5f\u5357\u96e8\u4e0a](mailto:lcctoor@outlook.com)\n\n[\u4e3b\u9875](https://lcctoor.github.io/arts/) \\| [Github](https://github.com/lcctoor) \\| [PyPi](https://pypi.org/user/lcctoor) \\| [\u5fae\u4fe1](https://lcctoor.github.io/arts/arts/ip_static/WeChatQRC.jpg) \\| [\u90ae\u7bb1](mailto:lcctoor@outlook.com) \\| [\u6350\u8d60](https://lcctoor.github.io/arts/arts/ip_static/DonationQRC-0rmb.jpg)\n\n# Bug\u63d0\u4ea4\u3001\u529f\u80fd\u63d0\u8bae\n\n\u60a8\u53ef\u4ee5\u901a\u8fc7 [Github-Issues](https://github.com/lcctoor/arts/issues)\u3001[\u5fae\u4fe1](https://lcctoor.github.io/arts/arts/ip_static/WeChatQRC.jpg) \u4e0e\u6211\u8054\u7cfb\u3002\n\n# \u5b89\u88c5\n\n```\npip install miumapp\n```\n\n# \u68c0\u67e5\u662f\u5426\u5b89\u88c5\u6210\u529f\n\n\u8fd0\u884c\u5185\u7f6eDemo\uff1a\n\n```python\nimport asyncio\nfrom miumapp.demo import Introduce\n\nasyncio.run( Introduce().start() )\n```\n\n\u8fd0\u884c\u540e\uff0c\u82e5\u663e\u793a\u51fa\u4e0e\u56fe\u7247 [\u6548\u679c\u56fe](https://lcctoor.github.io/arts/arts/miumapp/ip_static/DemoUI.png) \u6240\u793a\u4e00\u81f4\u7684\u6548\u679c\uff0c\u5219\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002\n\n# \u6559\u7a0b ([\u67e5\u770b\u7f8e\u5316\u7248](https://lcctoor.github.io/arts/arts/miumapp) \ud83d\udc48)\n\n\u672c\u6587\u5c06\u4ee5\u6700\u7b80\u6d01\u7684\u65b9\u5f0f\u5411\u4f60\u4ecb\u7ecd\u6838\u5fc3\u77e5\u8bc6\uff0c\u800c\u4e0d\u4f1a\u8ba9\u4f60\u88ab\u7e41\u7410\u7684\u672f\u8bed\u6240\u6df9\u6ca1\u3002\n\n## \u5bfc\u5165\n\n```python\nimport asyncio\nfrom miumapp import App, allow_callpy\n```\n\n## \u521b\u5efa APP\n\n```python\nclass my_app(App):\n    async def main(self):\n        ...\n\nasyncio.run( my_app().start() )\n```\n\n\u7531\u4e8e\u6211\u4eec\u5728\u4e3b\u4efb\u52a1 main \u4e2d\u672a\u5b9a\u4e49\u4efb\u4f55\u4ee3\u7801\uff0c\u56e0\u6b64\u8fd9\u4e2a APP \u662f\u4e00\u4e2a\u7a7a APP\uff0c\u8fd0\u884c\u540e\u770b\u4e0d\u5230\u4efb\u4f55\u6548\u679c\u3002\n\n## \u521b\u5efa\u7a97\u53e3\n\n```python\nclass my_app(App):\n  \n    async def main(self):\n        html = 'Hello, miumapp !'\n        await self.create_window(html=html)\n\nasyncio.run( my_app().start() )\n```\n\n\u6b64\u65f6\uff0c\u6211\u4eec\u5c06\u80fd\u770b\u5230\u5c4f\u5e55\u4e0a\u6253\u5f00\u4e86\u4e00\u4e2a\u7a97\u53e3\uff0c\u5176\u5185\u5bb9\u4e3a\u201cHello, miumapp !\u201d\u3002\n\n### \u6307\u5b9a\u7a97\u53e3\u5185\u5bb9\u6e90\n\n\u53ef\u901a\u8fc7\u4f20\u9012 HTML \u6587\u672c\u6216 URL \u94fe\u63a5\u8fd9\u4e24\u79cd\u6570\u636e\u4e4b\u4e00\u6765\u51b3\u5b9a\u7a97\u53e3\u5185\u5bb9\uff0c\u793a\u4f8b\uff1a\n\n```python\nawait self.create_window(html='\u4f60\u597d!')\n```\n\n```python\nawait self.create_window(url='https://www.baidu.com/')\n```\n\n### \u6307\u5b9a\u7a97\u53e3\u6807\u9898\n\n```python\nawait self.create_window(html='\u4f60\u597d!', title='\u7b2c\u4e00\u4e2a\u7a97\u53e3')\n```\n\n## \u5173\u95ed\u7a97\u53e3\n\n\u53ef\u901a\u8fc7\u5bf9\u7a97\u53e3\u5bf9\u8c61\u6267\u884c `await window.close()` \u6216\u8005\u70b9\u51fb\u7a97\u53e3\u53f3\u4e0a\u89d2\u7684 `\u00d7` \u56fe\u6807\u6765\u5173\u95ed\u7a97\u53e3\u3002\n\n## \u5728 HTML \u4e2d\u8c03\u7528 Python \u51fd\u6570\n\n\u4f7f\u7528 allow_callpy \u88c5\u9970\u7684 Python \u5f02\u6b65\u51fd\u6570\u5c06\u80fd\u591f\u5728 HTML \u4e2d\u88ab\u8c03\u7528\uff0c\u4f8b\u5982\uff1a\n\n```python\nclass my_app(App):\n  \n    async def main(self):\n        html = 'Hello, miumapp !'\n        await self.create_window(html=html)\n\n    @allow_callpy\n    async def addition(self, a, b):\n        return a + b\n\n    async def sub(self, a, b):\n        return a - b\n\nasyncio.run( my_app().start() )\n```\n\n\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u65b9\u6cd5 sub \u53ea\u80fd\u5728 Python \u5c42\u9762\u88ab\u8c03\u7528\uff0c\u800c\u65b9\u6cd5 addition \u65e2\u80fd\u5728 Python \u5c42\u9762\u88ab\u8c03\u7528\uff0c\u4e5f\u80fd\u5728 HTML \u4e2d\u88ab\u8c03\u7528\u3002\n\n\u5728 HTML \u4e2d\u8c03\u7528 addition \u65b9\u6cd5\uff1a\n\n```JavaScript\nasync function sum() {\n    let a = parseInt( document.getElementById('a').value )  // 30\n    let b = parseInt( document.getElementById('b').value )  // 50\n    let kwargs = {a:a, b:b}\n    let result = await miumapp.callpy(method='addition', kwargs=kwargs)\n    console.log(result)  // {\"code\":0, \"msg\":\"\", \"data\":80}\n}\n```\n\n## \u5728 Python \u4e2d\u8c03\u7528 JavaScript \u5bf9\u8c61\n\n### \u4e00\u4e9b\u793a\u4f8b\n\n\u6267\u884c JavaScript \u4ee3\u7801\uff1a\n\n```python\nawait window.evaluate(\"document.title = '\u7b2c\u4e00\u4e2aAPP'\", force_expr=True)\n```\n\n```python\nawait window.evaluate(\"alert(1)\", force_expr=True)\n```\n\n\u83b7\u53d6\u53d8\u91cf\u503c\uff1a\n\n```python\nCityName = await window.evaluate(\"CityName\")  # \u5047\u8bbe\u7a97\u53e3\u4e2d\u6709\u4e00\u4e2a\u53eb CityName \u7684\u53d8\u91cf\nprint(CityName)  # >>> '\u5317\u4eac\u5e02'\n```\n\n\u8c03\u7528\u51fd\u6570\u5e76\u83b7\u53d6\u8fd4\u56de\u503c\uff1a\n\n```python\ncity_name = await window.evaluate(\"get_city_name()\", force_expr=True)  # \u5047\u8bbe\u7a97\u53e3\u4e2d\u6709\u4e00\u4e2a\u53eb get_city_name \u7684\u51fd\u6570\nprint(city_name)  # >>> '\u4e0a\u6d77\u5e02'\n```\n\n\u7531\u4e8e window \u5bf9\u8c61\u7ee7\u627f\u81ea pyppeteer.page.Page\uff0c\u56e0\u6b64 window.evaluate \u652f\u6301 pyppeteer.page.Page.evaluate \u7684\u6240\u6709\u7528\u6cd5\u3002\u5173\u4e8e window.evaluate \u7684\u66f4\u591a\u7528\u6cd5\uff0c\u8bf7\u53c2\u8003 [pyppeteer.page.Page.evaluate](https://pyppeteer.github.io/pyppeteer/reference.html#pyppeteer.page.Page.evaluate) \u3002\n\n## window \u5bf9\u8c61\u7684\u66f4\u591a\u65b9\u6cd5\n\n\u7531\u4e8e window \u5bf9\u8c61\u7ee7\u627f\u81ea pyppeteer.page.Page\uff0c\u56e0\u6b64 window \u652f\u6301 pyppeteer.page.Page \u7684\u6240\u6709\u65b9\u6cd5\uff0c\u4f8b\u5982\u9875\u9762\u8df3\u8f6c\u3001\u70b9\u51fb\u6309\u94ae\u3001\u8f93\u5165\u7b49\u3002\u5173\u4e8e window \u7684\u66f4\u591a\u65b9\u6cd5\uff0c\u8bf7\u53c2\u8003 [pyppeteer.page.Page](https://pyppeteer.github.io/pyppeteer/reference.html#pyppeteer.page.Page) \u3002\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "\u4e00\u4e2a\u4f7f\u7528 Python + HTML \u5f00\u53d1\u684c\u9762 GUI \u5e94\u7528\u7684\u6846\u67b6\uff0c\u652f\u6301 Windows\u3001Mac\u3001Linux \u5e73\u53f0\u3002",
    "version": "1.0.9",
    "project_urls": {
        "HomePage": "https://github.com/lcctoor/arts/tree/main/arts/miumapp"
    },
    "split_keywords": [
        "electron",
        "flutter",
        "uniapp",
        "pyqt5",
        "miumapp"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "2ecc6a205379ad6b97479665e7de48fa00e28c3295c30b3c6c6300d2f13df445",
                "md5": "01f759685f1c754bb0ab6d32893369b0",
                "sha256": "25c5bb8fe126f4b4e03a56dc71d392c7a94a3d278face217b545d92bb32548df"
            },
            "downloads": -1,
            "filename": "miumapp-1.0.9-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "01f759685f1c754bb0ab6d32893369b0",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 10465,
            "upload_time": "2024-03-12T12:24:51",
            "upload_time_iso_8601": "2024-03-12T12:24:51.895725Z",
            "url": "https://files.pythonhosted.org/packages/2e/cc/6a205379ad6b97479665e7de48fa00e28c3295c30b3c6c6300d2f13df445/miumapp-1.0.9-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "bb37bbe812c0bfe92f181f38282ab7c149500d8d26610bfb9ab82a751ebe4477",
                "md5": "efd3e863f263961754b52e59b84b0753",
                "sha256": "26d8c1a3d899781d76d03771ce31d1afe5f1fa348d333be319fb1ba0673561d6"
            },
            "downloads": -1,
            "filename": "miumapp-1.0.9.tar.gz",
            "has_sig": false,
            "md5_digest": "efd3e863f263961754b52e59b84b0753",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 19608,
            "upload_time": "2024-03-12T12:24:54",
            "upload_time_iso_8601": "2024-03-12T12:24:54.732224Z",
            "url": "https://files.pythonhosted.org/packages/bb/37/bbe812c0bfe92f181f38282ab7c149500d8d26610bfb9ab82a751ebe4477/miumapp-1.0.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-12 12:24:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lcctoor",
    "github_project": "arts",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "miumapp"
}
        
Elapsed time: 0.30470s