rouwan-gui 0.2.2__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.
rouwan_gui/Button.py ADDED
@@ -0,0 +1,29 @@
1
+ import rouwan_gui as rwg
2
+
3
+ class Button:
4
+
5
+ def __init__(self, x, y, width, height,text,window, color,command=None,font_size=1):
6
+ self.frame= rwg.Frame(x, y, width, height, window, color)
7
+ self.frame_text= rwg.Text(x, y, text, window, font_size=font_size)
8
+ self.window=window
9
+ self.command=command
10
+
11
+ def draw(self):
12
+ self.frame.draw()
13
+ self.frame_text.draw()
14
+
15
+ def is_clicked(self):
16
+ if self.window.last_mouse is not None:
17
+ pos=self.window.last_mouse[0]
18
+ con_x=pos[0]>=self.frame.left and pos[0]<=self.frame.right
19
+ con_y=pos[1]>=self.frame.bottom and pos[1]<=self.frame.top
20
+ if con_x and con_y:
21
+ return True
22
+ return False
23
+
24
+ def update(self):
25
+ if (self.command is not None) and self.is_clicked():
26
+ self.command()
27
+
28
+ def create_Button(name,x,y,width,height,text,window,color,command=None,font_size=1):
29
+ window.role_dict[name]=Button(x,y,width,height,text,window,color,command=command,font_size=font_size)
rouwan_gui/Entry.py ADDED
@@ -0,0 +1,36 @@
1
+ import pyglet as pg
2
+ import rouwan_gui as rwg
3
+
4
+ class Entry:
5
+
6
+ def __init__(self,x, y, width, height, window, color,init_text="",font_size=1):
7
+ self.size=font_size
8
+ self.button= rwg.Button(x, y, width, height, init_text, window, color, font_size=font_size)
9
+ self.result=""
10
+ self.window=window
11
+ self.state=False
12
+
13
+ def draw(self):
14
+ self.button.draw()
15
+
16
+ def update(self):
17
+ try:
18
+ if self.button.is_clicked():
19
+ self.state=not self.state
20
+ inputs=self.window.last_text
21
+ symbol=self.window.last_key[0]
22
+ if self.state and (symbol is not None):
23
+ if symbol==pg.window.key.RETURN or symbol==pg.window.key.ENTER:
24
+ self.state=False
25
+ elif symbol==pg.window.key.BACKSPACE:
26
+ self.result=self.result[:-1]
27
+ else:
28
+ self.result+=inputs
29
+ self.button.frame_text.change_text(self.result,self.size)
30
+
31
+ except:
32
+ pass
33
+
34
+ def create_Entry(name,x,y,width,height,window,color,init_text="",font_size=1):
35
+ window.role_dict[name]=Entry(x,y,width,height,window,color,init_text=init_text,font_size=font_size)
36
+
rouwan_gui/Frame.py ADDED
@@ -0,0 +1,34 @@
1
+ import pyglet as pg
2
+
3
+ class Frame:
4
+ def __init__(self,x,y,width,height,window,color):
5
+ self.width=window.w_to_num(width)
6
+ self.height=window.h_to_num(height)
7
+ self.top=window.y_to_num(height/2+y)
8
+ self.bottom=window.y_to_num(y-height/2)
9
+ self.left=window.x_to_num(x-width/2)
10
+ self.right=window.x_to_num(x+width/2)
11
+ self.x=window.x_to_num(x)
12
+ self.y=window.y_to_num(y)
13
+ self.window=window
14
+ self.color=color
15
+ self.core=pg.shapes.Rectangle(
16
+ self.left,
17
+ self.bottom,
18
+ self.width,
19
+ self.height,
20
+ color=color
21
+ )
22
+
23
+ def draw(self):
24
+ self.core.draw()
25
+
26
+ def create_Frame(name,x,y,width,height,window,color):
27
+ window.role_dict[name]=Frame(x,y,width,height,window,color)
28
+
29
+
30
+
31
+
32
+
33
+
34
+
rouwan_gui/STSONG.TTF ADDED
Binary file
rouwan_gui/Table.py ADDED
@@ -0,0 +1,16 @@
1
+ import rouwan_gui as rwg
2
+
3
+ class Table:
4
+ def __init__(self,x,y,width,height,text,window,frame_color=rwg.Color_V,font_size=1):
5
+ self.frame= rwg.Frame(x, y, width, height, window,frame_color)
6
+ self.text= rwg.Text(x, y, text, window, font_size=font_size)
7
+
8
+ def draw(self):
9
+ self.frame.draw()
10
+ self.text.draw()
11
+
12
+ def change_text(self,new_text):
13
+ self.text.change_text(new_text,self.text.font_size)
14
+
15
+ def create_Table(name,x,y,width,height,text,window,frame_color=rwg.Color_V,font_size=1):
16
+ window.role_dict[name]=Table(x,y,width,height,text,window,frame_color=frame_color,font_size=font_size)
rouwan_gui/Text.py ADDED
@@ -0,0 +1,40 @@
1
+ import pyglet as pg
2
+
3
+ FONT="STSONG.TTF"
4
+
5
+ class Text:
6
+ def __init__(self,x,y,text,window,font_size=1):
7
+ global FONT
8
+ self.x=window.x_to_num(x)
9
+ self.y=window.y_to_num(y)
10
+ self.text=text
11
+ self.window=window
12
+ self.font_size=font_size
13
+ self.core=pg.text.Label(
14
+ self.text,
15
+ font_name=FONT,
16
+ font_size=font_size,
17
+ x=self.x,
18
+ y=self.y,
19
+ anchor_x="center",
20
+ anchor_y="center"
21
+ )
22
+
23
+ def draw(self):
24
+ self.core.draw()
25
+
26
+ def change_text(self,new_text,new_size):
27
+ self.text=new_text
28
+ self.font_size=new_size
29
+ self.core=pg.text.Label(
30
+ self.text,
31
+ font_name=FONT,
32
+ font_size=self.font_size,
33
+ x=self.x,
34
+ y=self.y,
35
+ anchor_x="center",
36
+ anchor_y="center"
37
+ )
38
+
39
+ def create_Text(name,x,y,text,window,font_size=1):
40
+ window.role_dict[name]=Text(x,y,text,window,font_size=font_size)
rouwan_gui/Window.py ADDED
@@ -0,0 +1,56 @@
1
+ import pyglet as pg
2
+
3
+ class Window:
4
+ #坐标标准:中心点为(0,0),横向±960,纵向±540,右上正,左下负
5
+ def __init__(self,width,height,name,fps,update_command):
6
+ self.core=pg.window.Window(width,height,name)
7
+ self.width=width
8
+ self.height=height
9
+ self.name=name
10
+ self.fps=fps
11
+ self.role_dict={}
12
+ self.update_command=update_command
13
+ self.last_text=""
14
+ self.last_key=None
15
+ self.last_mouse=None
16
+ self.core.push_handlers(
17
+ on_text=self._get_text,
18
+ on_key_press=self._get_key,
19
+ on_mouse_press=self._get_mouse,
20
+ on_draw=self._draw
21
+ )
22
+ pg.clock.schedule_interval(self.update,1/self.fps)
23
+
24
+ def w_to_num(self,width):
25
+ return (width/1920)*self.width
26
+
27
+ def h_to_num(self,height):
28
+ return (height/1080)*self.height
29
+
30
+ def x_to_num(self,x):
31
+ return ((x+960)/1920)*self.width
32
+
33
+ def y_to_num(self,y):
34
+ return ((y+540)/1080)*self.height
35
+
36
+ def _get_text(self,text):
37
+ self.last_text=text
38
+
39
+ def _get_key(self,symbol,modifiers):
40
+ self.last_key=(symbol,modifiers)
41
+
42
+ def _get_mouse(self,x,y,button,modifiers):
43
+ self.last_mouse=((x,y),(button,modifiers))
44
+
45
+ def _draw(self):
46
+ for obj in self.role_dict.values():
47
+ obj.draw()
48
+
49
+ def update(self,dt):
50
+ self.update_command(self, dt)
51
+ self.last_text=""
52
+ self.last_key=None
53
+ self.last_mouse=None
54
+
55
+ def run(self):
56
+ pg.app.run()
rouwan_gui/__init__.py ADDED
@@ -0,0 +1,11 @@
1
+ Color_V=(255,255,255,255)
2
+
3
+ from rouwan_gui.Button import *
4
+ from rouwan_gui.Entry import *
5
+ from rouwan_gui.Frame import *
6
+ from rouwan_gui.Table import *
7
+ from rouwan_gui.Text import *
8
+ from rouwan_gui.Window import *
9
+
10
+ __version__="0.2.2"
11
+ #该库的输入均为将屏幕逻辑分辨率定为(1920,1080),且屏幕中间点为(0,0),且任意控件均是以中心点作为位置参考点
@@ -0,0 +1,232 @@
1
+ Metadata-Version: 2.4
2
+ Name: rouwan-gui
3
+ Version: 0.2.2
4
+ Summary: 这是一个Python的GUI库。
5
+ Author-email: 肥美入类 <ydx20140606@qq.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/you/pygui
8
+ Project-URL: Repository, https://github.com/you/pygui
9
+ Keywords: gui,demo
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: pyglet>=2.0
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest; extra == "dev"
17
+ Requires-Dist: build; extra == "dev"
18
+
19
+ # rouwan-gui
20
+
21
+ 一个基于 [pyglet](https://pyglet.org/) 的轻量级 Python GUI 库。
22
+
23
+ ## 简介
24
+
25
+ `rouwan-gui` 提供窗口、按钮、输入框、文本、容器、表格等常用控件,采用固定的逻辑坐标系,纯 Python 实现,跨平台运行。
26
+
27
+ ## 坐标约定
28
+
29
+ - 逻辑分辨率固定为 `1920 x 1080`
30
+ - 屏幕中心为 `(0, 0)`
31
+ - 横向范围 `-960 ~ +960`,纵向范围 `-540 ~ +540`
32
+ - 右上为正方向,左下为负方向
33
+ - **所有控件以自身中心点作为位置参考点**
34
+
35
+ 实际像素位置会按窗口真实尺寸自动换算,无需手动处理。
36
+
37
+ ## 安装
38
+
39
+ 从 whl 安装:
40
+
41
+ ```bash
42
+ pip install E:\PycharmProject\rouwan_gui-0.2.2-py3-none-any.whl
43
+ ```
44
+
45
+ 从源码可编辑安装(开发用):
46
+
47
+ ```bash
48
+ cd PyUI
49
+ pip install -e .
50
+ ```
51
+
52
+ 依赖 `pyglet`,安装时会自动拉取。
53
+
54
+ ## 快速开始
55
+
56
+ ```python
57
+ import rouwan_gui as rwg
58
+
59
+
60
+ def update(window, dt):
61
+ """每帧调用一次。"""
62
+ pass
63
+
64
+
65
+ # 创建窗口:宽、高、标题、帧率、每帧回调
66
+ win = rwg.Window(800, 600, "我的应用", 60, update)
67
+
68
+ # 创建按钮:名称, x, y, 宽, 高, 文本, 窗口, 颜色, 回调, 字号
69
+ rwg.create_Button(
70
+ "btn1", 0, 0, 200, 60, "点我", win, (0, 255, 0, 255),
71
+ command=lambda: print("clicked"),
72
+ )
73
+
74
+ # 创建输入框:名称, x, y, 宽, 高, 窗口, 颜色, 初始文本, 字号
75
+ rwg.create_Entry(
76
+ "input1", 0, -100, 300, 40, win, (60, 60, 60, 255),
77
+ )
78
+
79
+ # 创建文本:名称, x, y, 文本, 窗口, 字号
80
+ rwg.create_Text("title", 0, 200, "标题", win, font_size=24)
81
+
82
+ # 启动主循环
83
+ win.run()
84
+ ```
85
+
86
+ ## API
87
+
88
+ ### Window
89
+
90
+ ```python
91
+ Window(width, height, name, fps, update_command)
92
+ ```
93
+
94
+ | 参数 | 说明 |
95
+ |------|------|
96
+ | `width` / `height` | 窗口像素尺寸 |
97
+ | `name` | 窗口标题 |
98
+ | `fps` | 每帧更新频率 |
99
+ | `update_command` | 每帧回调,签名 `func(window, dt)` |
100
+
101
+ 内部状态:
102
+
103
+ - `role_dict`:所有控件,按名字索引
104
+ - `last_text` / `last_key` / `last_mouse`:当前帧输入状态
105
+
106
+ 方法:
107
+
108
+ - `run()`:启动主循环
109
+
110
+ ### Button
111
+
112
+ ```python
113
+ create_Button(name, x, y, width, height, text, window, color,
114
+ command=None, font_size=1)
115
+ ```
116
+
117
+ | 参数 | 说明 |
118
+ |------|------|
119
+ | `name` | 控件名,用于 `role_dict` 索引 |
120
+ | `x`, `y` | 中心点逻辑坐标 |
121
+ | `width`, `height` | 逻辑尺寸 |
122
+ | `text` | 按钮文字 |
123
+ | `window` | 所属窗口 |
124
+ | `color` | 背景色 `(r, g, b, a)`,取值 `0~255` |
125
+ | `command` | 点击回调,无参函数 |
126
+ | `font_size` | 字号 |
127
+
128
+ ### Entry
129
+
130
+ ```python
131
+ create_Entry(name, x, y, width, height, window, color,
132
+ init_text="", font_size=1)
133
+ ```
134
+
135
+ 点击切换输入状态,回车结束输入,退格删除字符。当前内容存于 `entry.result`。
136
+
137
+ ### Text
138
+
139
+ ```python
140
+ create_Text(name, x, y, text, window, font_size=1)
141
+ ```
142
+
143
+ 显示文本,使用内置字体 `STSONG.TTF`,居中锚点。
144
+
145
+ ### Frame
146
+
147
+ ```python
148
+ create_Frame(name, x, y, width, height, window, color)
149
+ ```
150
+
151
+ 纯色矩形区域。
152
+
153
+ ### Table
154
+
155
+ ```python
156
+ create_Table(name, x, y, width, height, text, window,
157
+ frame_color=Color_V, font_size=1)
158
+ ```
159
+
160
+ 带背景的文字块。`Color_V` 默认为不透明白 `(255, 255, 255, 255)`。
161
+
162
+ ## 颜色
163
+
164
+ 所有颜色均为 `(R, G, B, A)` 四元组,取值范围 `0 ~ 255`。
165
+
166
+ - `A = 0`:完全透明
167
+ - `A = 255`:完全不透明
168
+
169
+ 示例:
170
+
171
+ ```python
172
+ (255, 0, 0, 255) # 不透明红
173
+ (0, 255, 0, 128) # 半透明绿
174
+ (0, 0, 0, 0) # 全透明
175
+ ```
176
+
177
+ `rouwan_gui.Color_V` 是默认颜色常量。
178
+
179
+ ## 项目结构
180
+
181
+ ```
182
+ PyUI/
183
+ ├── src/
184
+ │ └── rouwan_gui/
185
+ │ ├── __init__.py
186
+ │ ├── Window.py
187
+ │ ├── Frame.py
188
+ │ ├── Button.py
189
+ │ ├── Entry.py
190
+ │ ├── Text.py
191
+ │ ├── Table.py
192
+ │ └── STSONG.TTF
193
+ ├── tests/
194
+ ├── pyproject.toml
195
+ └── README.md
196
+ ```
197
+
198
+ ## 开发
199
+
200
+ 安装开发依赖:
201
+
202
+ ```bash
203
+ pip install -e ".[dev]"
204
+ ```
205
+
206
+ 运行测试:
207
+
208
+ ```bash
209
+ python -m pytest
210
+ ```
211
+
212
+ 打包:
213
+
214
+ ```bash
215
+ python -m build
216
+ ```
217
+
218
+ 生成的文件位于 `dist/` 目录下。
219
+
220
+ ## 字体说明
221
+
222
+ 本库自带 `STSONG.TTF` 字体文件,随代码一起打包。若需替换字体,修改 `Text.py` 中的 `FONT` 常量即可。
223
+
224
+ ## 版本历史
225
+
226
+ - **0.2.2** — 当前版本,修复各种bug,统一风格
227
+ - **0.2.1** — 修复打包时文件名改动的遗留问题
228
+ - **0.2.0** — 首个可打包版本
229
+
230
+ ## License
231
+
232
+ MIT
@@ -0,0 +1,12 @@
1
+ rouwan_gui/Button.py,sha256=sfjkKBx9936F3EFYmDR3HRpdyj3ROLc5ixrpcmGnoUg,1074
2
+ rouwan_gui/Entry.py,sha256=v7mDNarDI1_QAaWv0_pEnvaPTizxFKbU7EqReszJhyo,1261
3
+ rouwan_gui/Frame.py,sha256=g6WAzuxLkj8s4jCCn3SirsmBmvttkdbqWKZ7c8xDufY,854
4
+ rouwan_gui/STSONG.TTF,sha256=xcwu1eLA5jhQE_6C2VDu5pYNgFvWArhsU_9FR4PzgsQ,11697600
5
+ rouwan_gui/Table.py,sha256=ndAJf7CuCBX9koDA0IzpmeZ2xmeep5MoAaIp3KgTDMA,650
6
+ rouwan_gui/Text.py,sha256=GumzKS6V9cicxUJmYOeQ4Y1QRKDL8PMQuJV9DvON264,1056
7
+ rouwan_gui/Window.py,sha256=NSOlK1Dtwrfq4704kzo0UpJiAgNzHCl7wQjrBX8BPqo,1595
8
+ rouwan_gui/__init__.py,sha256=lWgvHkV2Iq2QWbbxVzq680YJhRyLCfr9COxRXM4nBBs,394
9
+ rouwan_gui-0.2.2.dist-info/METADATA,sha256=mjRbAKwQkgXHtQwr67BzHVzI6h34-ikvjyK8uW9J08c,5230
10
+ rouwan_gui-0.2.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
11
+ rouwan_gui-0.2.2.dist-info/top_level.txt,sha256=j_e5ToppV2d6c92l8iOumhxFhBuRXjYHmgnNF5ZFoKY,11
12
+ rouwan_gui-0.2.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ rouwan_gui