GTC-Pygame-Runtime-Support


NameGTC-Pygame-Runtime-Support JSON
Version 0.0.15 PyPI version JSON
download
home_pagehttps://github.com/GTC-Software-Studio/GTC-Pygame-Runtime-Support/
SummaryIntegrated Pygame application development support.
upload_time2025-03-18 10:33:02
maintainerNone
docs_urlNone
authorGTC Byzantine
requires_pythonNone
licenseGNU GPLv3
keywords software pygame button input page drag popup
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # GTC Pygame Runtime Support
集成 Pygame 应用开发支持

Finding an English version? [click here](https://github.com/GTC-Software-Studio/GTC-Pygame-Runtime-Support)

нашли русскую версию? [кликните сюда](https://github.com/GTC-Software-Studio/GTC-Pygame-Runtime-Support/blob/main/README-ru.md)

此软件包可用于 Pygame 应用开发,包括但不限于游戏、窗体应用,应于版本大于 3.4.0 的 Python 环境中运行。

## 软件包安装
向绝大多数软件包一样,本软件包也可使用 pip 下载并安装

```plain
pip install GTC_Pygame_Runtime_Support
```

如果 pip 不慎爆炸,您可以从 [Github](https://github.com/GTC-Byzantine/GTC-Pygame-Runtime-Support/) 处直接复制源码

## 使用示例
### 按钮
PRS 提供三种按钮类型,全部位于`button.py`文件内,此处以其中的`FeedbackButton`为例进行展示

```python
import pygame
import GTC_Pygame_Runtime_Support as gPRS
screen = pygame.display.set_mode((200, 200))
button = gPRS.button.FeedbackButton([40, 40], [20, 20], '114', 15, screen, bg_color=[0, 145, 220], 
                                    border_color=[209, 240, 255], text_color=[255, 255, 255],
                                    change_color=((0, 145, 220), (0, 225, 0))) # 生成按钮
running = 1
clock = pygame.time.Clock()
while running: # 主循环
    screen.fill((255, 255, 255))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = 0
    button.operate(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3)) # 按钮贴图处
    if button.on_click:
        print("clicked")
    pygame.display.flip()
    clock.tick(60)
```

运行如上代码,你将能够创建一个显示文字为 114 的按钮,并且点击这个按钮后,控制台会输出"clicked",并且根据用户的动作,按钮将会有不同的反馈。

### 页面
PRS 提供的页面类型位于`page.py`内,此处以`PlainPage`为例进行展示

```python
import sys
import pygame
import GTC_Pygame_Runtime_Support as gPRS

screen = pygame.display.set_mode((500, 500))
bp = gPRS.page.PlainPage([300, 300], [300, 1000], [100, 100], screen, 1.4, True)

if __name__ == '__main__':
    clock = pygame.time.Clock()
    bp.surface.fill((255, 255, 255))
    for i in range(100):
        pygame.draw.line(bp.surface, [0, 0, 0], [0, 10 * i], [300, 10 * i])
    bp.set_as_background()

    mw = [False, False]
    while True:
        mw = [False, False]
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 4:
                    mw[1] = True
                elif event.button == 5:
                    mw[0] = True
        bp.operate(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3), mw, True)
        pygame.display.flip()
        clock.tick(60)
```

运行上述代码,你将能够创建一个可由鼠标滚轮滚动和鼠标左键拖动的页面,你可以自行更换其背景,只要你在主循环前调用函数`bp.set_as_background()`

### PRS 中的嵌套操作
在 PRS 中,一切展示型组件都可通过托管 (trusteeship) 的方式进行嵌套。

#### 在页面中嵌套按钮
PRS 中所有组件托管按钮的方式均相同,就像下面展示的:

```python
import sys
import pygame
import GTC_Pygame_Runtime_Support as gPRS

screen = pygame.display.set_mode((500, 500))
bp = gPRS.page.PlainPage([300, 300], [300, 1000], [100, 100], screen, 1.4, True)

if __name__ == '__main__':
    clock = pygame.time.Clock()
    bp.surface.fill((255, 255, 255))
    for i in range(100):
        pygame.draw.line(bp.surface, [0, 0, 0], [0, 10 * i], [300, 10 * i])
    bp.set_as_background()
    bt = gPRS.button.FeedbackButton([40, 40], [20, 20], '114', 10, bp.surface)
    bp.add_button_trusteeship(bt)

    mw = [False, False]
    while True:
        mw = [False, False]
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 4:
                    mw[1] = True
                elif event.button == 5:
                    mw[0] = True
        bp.operate(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3), mw, True)
        if bt.on_click:
            print('clicked')
        pygame.display.flip()
        clock.tick(60)
```

PRS 通常通过`item.add_button_trusteeship(button)`的形式添加嵌套按钮,同时按钮声明时的目标 surface 应指向被嵌套对象的 surface,通常是`item.surface`。

#### 在页面中嵌套页面
原理基本同上。

```python
import sys
import pygame
import GTC_Pygame_Runtime_Support as gPRS

screen = pygame.display.set_mode((500, 500))
bp = gPRS.page.PlainPage([300, 300], [300, 1000], [100, 100], screen, 1.4, True)

if __name__ == '__main__':
    clock = pygame.time.Clock()
    bp.surface.fill((255, 255, 255))
    for i in range(100):
        pygame.draw.line(bp.surface, [0, 0, 0], [0, 10 * i], [300, 10 * i])
    bp.set_as_background()
    inner_p = gPRS.page.PlainPage([100, 100], [100, 300], [50, 200], bp.surface, wheel_support=True)
    inner_p.surface.fill((255, 255, 255))
    for i in range(100):
        pygame.draw.line(inner_p.surface, [0, 0, 255], [0, 9 * i], [300, 9 * i])
    inner_p.set_as_background()
    bp.add_page_trusteeship(inner_p)

    mw = [False, False]
    while True:
        mw = [False, False]
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 4:
                    mw[1] = True
                elif event.button == 5:
                    mw[0] = True
        bp.operate(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3), mw, True)
        pygame.display.flip()
        clock.tick(60)
```

通过以上介绍,您应该能对 PRS 的使用特点有大概的了解。

想要获取完整文档?点击前往[语雀文档](https://www.yuque.com/tdkjzx/gtc_prs)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/GTC-Software-Studio/GTC-Pygame-Runtime-Support/",
    "name": "GTC-Pygame-Runtime-Support",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "software pygame button input page drag popup",
    "author": "GTC Byzantine",
    "author_email": "w1127inline@outlook.com",
    "download_url": null,
    "platform": null,
    "description": "# GTC Pygame Runtime Support\r\n\u96c6\u6210 Pygame \u5e94\u7528\u5f00\u53d1\u652f\u6301\r\n\r\nFinding an English version? [click here](https://github.com/GTC-Software-Studio/GTC-Pygame-Runtime-Support)\r\n\r\n\u043d\u0430\u0448\u043b\u0438 \u0440\u0443\u0441\u0441\u043a\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e? [\u043a\u043b\u0438\u043a\u043d\u0438\u0442\u0435 \u0441\u044e\u0434\u0430](https://github.com/GTC-Software-Studio/GTC-Pygame-Runtime-Support/blob/main/README-ru.md)\r\n\r\n\u6b64\u8f6f\u4ef6\u5305\u53ef\u7528\u4e8e Pygame \u5e94\u7528\u5f00\u53d1\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\u6e38\u620f\u3001\u7a97\u4f53\u5e94\u7528\uff0c\u5e94\u4e8e\u7248\u672c\u5927\u4e8e 3.4.0 \u7684 Python \u73af\u5883\u4e2d\u8fd0\u884c\u3002\r\n\r\n## \u8f6f\u4ef6\u5305\u5b89\u88c5\r\n\u5411\u7edd\u5927\u591a\u6570\u8f6f\u4ef6\u5305\u4e00\u6837\uff0c\u672c\u8f6f\u4ef6\u5305\u4e5f\u53ef\u4f7f\u7528 pip \u4e0b\u8f7d\u5e76\u5b89\u88c5\r\n\r\n```plain\r\npip install GTC_Pygame_Runtime_Support\r\n```\r\n\r\n\u5982\u679c pip \u4e0d\u614e\u7206\u70b8\uff0c\u60a8\u53ef\u4ee5\u4ece [Github](https://github.com/GTC-Byzantine/GTC-Pygame-Runtime-Support/) \u5904\u76f4\u63a5\u590d\u5236\u6e90\u7801\r\n\r\n## \u4f7f\u7528\u793a\u4f8b\r\n### \u6309\u94ae\r\nPRS \u63d0\u4f9b\u4e09\u79cd\u6309\u94ae\u7c7b\u578b\uff0c\u5168\u90e8\u4f4d\u4e8e`button.py`\u6587\u4ef6\u5185\uff0c\u6b64\u5904\u4ee5\u5176\u4e2d\u7684`FeedbackButton`\u4e3a\u4f8b\u8fdb\u884c\u5c55\u793a\r\n\r\n```python\r\nimport pygame\r\nimport GTC_Pygame_Runtime_Support as gPRS\r\nscreen = pygame.display.set_mode((200, 200))\r\nbutton = gPRS.button.FeedbackButton([40, 40], [20, 20], '114', 15, screen, bg_color=[0, 145, 220], \r\n                                    border_color=[209, 240, 255], text_color=[255, 255, 255],\r\n                                    change_color=((0, 145, 220), (0, 225, 0))) # \u751f\u6210\u6309\u94ae\r\nrunning = 1\r\nclock = pygame.time.Clock()\r\nwhile running: # \u4e3b\u5faa\u73af\r\n    screen.fill((255, 255, 255))\r\n    for event in pygame.event.get():\r\n        if event.type == pygame.QUIT:\r\n            running = 0\r\n    button.operate(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3)) # \u6309\u94ae\u8d34\u56fe\u5904\r\n    if button.on_click:\r\n        print(\"clicked\")\r\n    pygame.display.flip()\r\n    clock.tick(60)\r\n```\r\n\r\n\u8fd0\u884c\u5982\u4e0a\u4ee3\u7801\uff0c\u4f60\u5c06\u80fd\u591f\u521b\u5efa\u4e00\u4e2a\u663e\u793a\u6587\u5b57\u4e3a 114 \u7684\u6309\u94ae\uff0c\u5e76\u4e14\u70b9\u51fb\u8fd9\u4e2a\u6309\u94ae\u540e\uff0c\u63a7\u5236\u53f0\u4f1a\u8f93\u51fa\"clicked\"\uff0c\u5e76\u4e14\u6839\u636e\u7528\u6237\u7684\u52a8\u4f5c\uff0c\u6309\u94ae\u5c06\u4f1a\u6709\u4e0d\u540c\u7684\u53cd\u9988\u3002\r\n\r\n### \u9875\u9762\r\nPRS \u63d0\u4f9b\u7684\u9875\u9762\u7c7b\u578b\u4f4d\u4e8e`page.py`\u5185\uff0c\u6b64\u5904\u4ee5`PlainPage`\u4e3a\u4f8b\u8fdb\u884c\u5c55\u793a\r\n\r\n```python\r\nimport sys\r\nimport pygame\r\nimport GTC_Pygame_Runtime_Support as gPRS\r\n\r\nscreen = pygame.display.set_mode((500, 500))\r\nbp = gPRS.page.PlainPage([300, 300], [300, 1000], [100, 100], screen, 1.4, True)\r\n\r\nif __name__ == '__main__':\r\n    clock = pygame.time.Clock()\r\n    bp.surface.fill((255, 255, 255))\r\n    for i in range(100):\r\n        pygame.draw.line(bp.surface, [0, 0, 0], [0, 10 * i], [300, 10 * i])\r\n    bp.set_as_background()\r\n\r\n    mw = [False, False]\r\n    while True:\r\n        mw = [False, False]\r\n        for event in pygame.event.get():\r\n            if event.type == pygame.QUIT:\r\n                sys.exit()\r\n            elif event.type == pygame.MOUSEBUTTONDOWN:\r\n                if event.button == 4:\r\n                    mw[1] = True\r\n                elif event.button == 5:\r\n                    mw[0] = True\r\n        bp.operate(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3), mw, True)\r\n        pygame.display.flip()\r\n        clock.tick(60)\r\n```\r\n\r\n\u8fd0\u884c\u4e0a\u8ff0\u4ee3\u7801\uff0c\u4f60\u5c06\u80fd\u591f\u521b\u5efa\u4e00\u4e2a\u53ef\u7531\u9f20\u6807\u6eda\u8f6e\u6eda\u52a8\u548c\u9f20\u6807\u5de6\u952e\u62d6\u52a8\u7684\u9875\u9762\uff0c\u4f60\u53ef\u4ee5\u81ea\u884c\u66f4\u6362\u5176\u80cc\u666f\uff0c\u53ea\u8981\u4f60\u5728\u4e3b\u5faa\u73af\u524d\u8c03\u7528\u51fd\u6570`bp.set_as_background()`\r\n\r\n### PRS \u4e2d\u7684\u5d4c\u5957\u64cd\u4f5c\r\n\u5728 PRS \u4e2d\uff0c\u4e00\u5207\u5c55\u793a\u578b\u7ec4\u4ef6\u90fd\u53ef\u901a\u8fc7\u6258\u7ba1 (trusteeship) \u7684\u65b9\u5f0f\u8fdb\u884c\u5d4c\u5957\u3002\r\n\r\n#### \u5728\u9875\u9762\u4e2d\u5d4c\u5957\u6309\u94ae\r\nPRS \u4e2d\u6240\u6709\u7ec4\u4ef6\u6258\u7ba1\u6309\u94ae\u7684\u65b9\u5f0f\u5747\u76f8\u540c\uff0c\u5c31\u50cf\u4e0b\u9762\u5c55\u793a\u7684\uff1a\r\n\r\n```python\r\nimport sys\r\nimport pygame\r\nimport GTC_Pygame_Runtime_Support as gPRS\r\n\r\nscreen = pygame.display.set_mode((500, 500))\r\nbp = gPRS.page.PlainPage([300, 300], [300, 1000], [100, 100], screen, 1.4, True)\r\n\r\nif __name__ == '__main__':\r\n    clock = pygame.time.Clock()\r\n    bp.surface.fill((255, 255, 255))\r\n    for i in range(100):\r\n        pygame.draw.line(bp.surface, [0, 0, 0], [0, 10 * i], [300, 10 * i])\r\n    bp.set_as_background()\r\n    bt = gPRS.button.FeedbackButton([40, 40], [20, 20], '114', 10, bp.surface)\r\n    bp.add_button_trusteeship(bt)\r\n\r\n    mw = [False, False]\r\n    while True:\r\n        mw = [False, False]\r\n        for event in pygame.event.get():\r\n            if event.type == pygame.QUIT:\r\n                sys.exit()\r\n            elif event.type == pygame.MOUSEBUTTONDOWN:\r\n                if event.button == 4:\r\n                    mw[1] = True\r\n                elif event.button == 5:\r\n                    mw[0] = True\r\n        bp.operate(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3), mw, True)\r\n        if bt.on_click:\r\n            print('clicked')\r\n        pygame.display.flip()\r\n        clock.tick(60)\r\n```\r\n\r\nPRS \u901a\u5e38\u901a\u8fc7`item.add_button_trusteeship(button)`\u7684\u5f62\u5f0f\u6dfb\u52a0\u5d4c\u5957\u6309\u94ae\uff0c\u540c\u65f6\u6309\u94ae\u58f0\u660e\u65f6\u7684\u76ee\u6807 surface \u5e94\u6307\u5411\u88ab\u5d4c\u5957\u5bf9\u8c61\u7684 surface\uff0c\u901a\u5e38\u662f`item.surface`\u3002\r\n\r\n#### \u5728\u9875\u9762\u4e2d\u5d4c\u5957\u9875\u9762\r\n\u539f\u7406\u57fa\u672c\u540c\u4e0a\u3002\r\n\r\n```python\r\nimport sys\r\nimport pygame\r\nimport GTC_Pygame_Runtime_Support as gPRS\r\n\r\nscreen = pygame.display.set_mode((500, 500))\r\nbp = gPRS.page.PlainPage([300, 300], [300, 1000], [100, 100], screen, 1.4, True)\r\n\r\nif __name__ == '__main__':\r\n    clock = pygame.time.Clock()\r\n    bp.surface.fill((255, 255, 255))\r\n    for i in range(100):\r\n        pygame.draw.line(bp.surface, [0, 0, 0], [0, 10 * i], [300, 10 * i])\r\n    bp.set_as_background()\r\n    inner_p = gPRS.page.PlainPage([100, 100], [100, 300], [50, 200], bp.surface, wheel_support=True)\r\n    inner_p.surface.fill((255, 255, 255))\r\n    for i in range(100):\r\n        pygame.draw.line(inner_p.surface, [0, 0, 255], [0, 9 * i], [300, 9 * i])\r\n    inner_p.set_as_background()\r\n    bp.add_page_trusteeship(inner_p)\r\n\r\n    mw = [False, False]\r\n    while True:\r\n        mw = [False, False]\r\n        for event in pygame.event.get():\r\n            if event.type == pygame.QUIT:\r\n                sys.exit()\r\n            elif event.type == pygame.MOUSEBUTTONDOWN:\r\n                if event.button == 4:\r\n                    mw[1] = True\r\n                elif event.button == 5:\r\n                    mw[0] = True\r\n        bp.operate(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3), mw, True)\r\n        pygame.display.flip()\r\n        clock.tick(60)\r\n```\r\n\r\n\u901a\u8fc7\u4ee5\u4e0a\u4ecb\u7ecd\uff0c\u60a8\u5e94\u8be5\u80fd\u5bf9 PRS \u7684\u4f7f\u7528\u7279\u70b9\u6709\u5927\u6982\u7684\u4e86\u89e3\u3002\r\n\r\n\u60f3\u8981\u83b7\u53d6\u5b8c\u6574\u6587\u6863\uff1f\u70b9\u51fb\u524d\u5f80[\u8bed\u96c0\u6587\u6863](https://www.yuque.com/tdkjzx/gtc_prs)\r\n",
    "bugtrack_url": null,
    "license": "GNU GPLv3",
    "summary": "Integrated Pygame application development support.",
    "version": "0.0.15",
    "project_urls": {
        "Homepage": "https://github.com/GTC-Software-Studio/GTC-Pygame-Runtime-Support/"
    },
    "split_keywords": [
        "software",
        "pygame",
        "button",
        "input",
        "page",
        "drag",
        "popup"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d4cc8ab7a419b92fb3f3438105bca7c62b6d9e9ca2fdb71916a7d23de9e9e4eb",
                "md5": "acbf078b3ceffa39b48f61d00849e685",
                "sha256": "0bd2ecb2fd87ec6d8cb6b11075dbbe103bebfc8d41f81488cb46c330d22d0879"
            },
            "downloads": -1,
            "filename": "GTC_Pygame_Runtime_Support-0.0.15-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "acbf078b3ceffa39b48f61d00849e685",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 42625,
            "upload_time": "2025-03-18T10:33:02",
            "upload_time_iso_8601": "2025-03-18T10:33:02.534830Z",
            "url": "https://files.pythonhosted.org/packages/d4/cc/8ab7a419b92fb3f3438105bca7c62b6d9e9ca2fdb71916a7d23de9e9e4eb/GTC_Pygame_Runtime_Support-0.0.15-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-03-18 10:33:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "GTC-Software-Studio",
    "github_project": "GTC-Pygame-Runtime-Support",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "gtc-pygame-runtime-support"
}
        
Elapsed time: 1.03810s