webgui-py 0.1.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 gordoprime00
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,93 @@
1
+ Metadata-Version: 2.4
2
+ Name: webgui-py
3
+ Version: 0.1.0
4
+ Summary: A simple Python GUI framework that uses HTML as the interface
5
+ License-Expression: MIT
6
+ Requires-Python: >=3.9
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: flask
10
+ Dynamic: license-file
11
+
12
+ # WebGUI
13
+
14
+ A simple Python GUI framework that uses HTML as the interface.
15
+
16
+ WebGUI lets you make Python applications with a web browser as the GUI without needing to write JavaScript.
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ pip install webgui
22
+ ```
23
+
24
+ ## Basic Example
25
+
26
+
27
+ ```python
28
+ import webgui
29
+ import time
30
+
31
+ webgui.init()
32
+
33
+ webgui.send("index.html")
34
+
35
+ while webgui.running():
36
+
37
+ if webgui.button("say hello").clicked:
38
+ print("Hello!")
39
+
40
+ time.sleep(0.05)
41
+ ```
42
+
43
+
44
+ ```html
45
+ <!DOCTYPE html>
46
+ <html>
47
+
48
+ <body>
49
+
50
+ <h1>My App</h1>
51
+
52
+ <p>Hello!</p>
53
+
54
+ <button name="say hello">Say Hello</button>
55
+
56
+ </body>
57
+
58
+ </html>
59
+ ```
60
+
61
+ ## Getting Input
62
+
63
+ You can also ask the user for text:
64
+
65
+ ```python
66
+ name = webgui.get_input("What's your name?")
67
+
68
+ print(name)
69
+ ```
70
+
71
+ The browser displays an input box and returns what the user entered.
72
+
73
+ ## Why WebGUI?
74
+
75
+ WebGUI is designed to be simple.
76
+
77
+ You write your interface using HTML and control your application using Python.
78
+
79
+ You don't need to write JavaScript or deal directly with HTTP communication.
80
+
81
+ ## Features
82
+
83
+ * HTML-based GUI
84
+ * Python controls the application
85
+ * Automatic browser opening
86
+ * Simple button handling
87
+ * Text input
88
+ * Multiple HTML pages
89
+ * No JavaScript required in your application
90
+
91
+ ## License
92
+
93
+ See the LICENSE file.
@@ -0,0 +1,82 @@
1
+ # WebGUI
2
+
3
+ A simple Python GUI framework that uses HTML as the interface.
4
+
5
+ WebGUI lets you make Python applications with a web browser as the GUI without needing to write JavaScript.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install webgui
11
+ ```
12
+
13
+ ## Basic Example
14
+
15
+
16
+ ```python
17
+ import webgui
18
+ import time
19
+
20
+ webgui.init()
21
+
22
+ webgui.send("index.html")
23
+
24
+ while webgui.running():
25
+
26
+ if webgui.button("say hello").clicked:
27
+ print("Hello!")
28
+
29
+ time.sleep(0.05)
30
+ ```
31
+
32
+
33
+ ```html
34
+ <!DOCTYPE html>
35
+ <html>
36
+
37
+ <body>
38
+
39
+ <h1>My App</h1>
40
+
41
+ <p>Hello!</p>
42
+
43
+ <button name="say hello">Say Hello</button>
44
+
45
+ </body>
46
+
47
+ </html>
48
+ ```
49
+
50
+ ## Getting Input
51
+
52
+ You can also ask the user for text:
53
+
54
+ ```python
55
+ name = webgui.get_input("What's your name?")
56
+
57
+ print(name)
58
+ ```
59
+
60
+ The browser displays an input box and returns what the user entered.
61
+
62
+ ## Why WebGUI?
63
+
64
+ WebGUI is designed to be simple.
65
+
66
+ You write your interface using HTML and control your application using Python.
67
+
68
+ You don't need to write JavaScript or deal directly with HTTP communication.
69
+
70
+ ## Features
71
+
72
+ * HTML-based GUI
73
+ * Python controls the application
74
+ * Automatic browser opening
75
+ * Simple button handling
76
+ * Text input
77
+ * Multiple HTML pages
78
+ * No JavaScript required in your application
79
+
80
+ ## License
81
+
82
+ See the LICENSE file.
@@ -0,0 +1,19 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "webgui-py"
7
+ version = "0.1.0"
8
+ description = "A simple Python GUI framework that uses HTML as the interface"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+
14
+ dependencies = [
15
+ "flask"
16
+ ]
17
+
18
+ [tool.setuptools.packages.find]
19
+ where = ["."]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ from .gui import *
@@ -0,0 +1,251 @@
1
+ from flask import Flask, request, Response
2
+ import threading
3
+ import time
4
+ import webbrowser
5
+ import os
6
+ import re
7
+ import urllib.parse
8
+
9
+ app = Flask(__name__)
10
+
11
+ _current_page = ""
12
+ _buttons_clicked = []
13
+ _running = False
14
+ _server_thread = None
15
+ _port = 5000
16
+
17
+ _input_value = None
18
+ _input_waiting = False
19
+ _input_question = ""
20
+
21
+
22
+ # ============================================================
23
+ # INTERNAL HTML PROCESSING
24
+ # ============================================================
25
+
26
+ def _process_html(html):
27
+
28
+ pattern = r'<button([^>]*)name=["\']([^"\']+)["\']([^>]*)>'
29
+
30
+ def replace_button(match):
31
+
32
+ before = match.group(1)
33
+ name = match.group(2)
34
+ after = match.group(3)
35
+
36
+ encoded_name = urllib.parse.quote(name)
37
+
38
+ return (
39
+ f'<button{before}name="{name}"{after} '
40
+ f'onclick="fetch(\'/__gui_button?name={encoded_name}\', '
41
+ f'{{method: \'POST\'}}); return false;">'
42
+ )
43
+
44
+ return re.sub(pattern, replace_button, html)
45
+
46
+
47
+ def _read_page():
48
+
49
+ if not _current_page:
50
+ return "<h1>No page has been sent.</h1>"
51
+
52
+ if not os.path.isfile(_current_page):
53
+ return f"<h1>File not found: {_current_page}</h1>"
54
+
55
+ try:
56
+
57
+ with open(_current_page, "r", encoding="utf-8") as file:
58
+ html = file.read()
59
+
60
+ except Exception as error:
61
+
62
+ return f"<h1>Could not read page</h1><p>{error}</p>"
63
+
64
+ return _process_html(html)
65
+
66
+
67
+ # ============================================================
68
+ # WEB SERVER
69
+ # ============================================================
70
+
71
+ @app.route("/")
72
+ def _page():
73
+
74
+ if _input_waiting:
75
+
76
+ question = _input_question
77
+
78
+ return f"""
79
+ <!DOCTYPE html>
80
+ <html>
81
+
82
+ <head>
83
+ <title>Input</title>
84
+ </head>
85
+
86
+ <body>
87
+
88
+ <h1>Input</h1>
89
+
90
+ <p>{question}</p>
91
+
92
+ <form method="post" action="/__gui_input">
93
+
94
+ <input
95
+ type="text"
96
+ name="value"
97
+ autofocus
98
+ >
99
+
100
+ <button type="submit">
101
+ Submit
102
+ </button>
103
+
104
+ </form>
105
+
106
+ </body>
107
+
108
+ </html>
109
+ """
110
+
111
+ return Response(
112
+ _read_page(),
113
+ content_type="text/html"
114
+ )
115
+
116
+
117
+ @app.route("/__gui_button", methods=["POST"])
118
+ def _button_clicked():
119
+
120
+ name = request.args.get("name")
121
+
122
+ if name:
123
+ _buttons_clicked.append(name)
124
+
125
+ return "", 204
126
+
127
+
128
+ @app.route("/__gui_input", methods=["POST"])
129
+ def _input_submitted():
130
+
131
+ global _input_value
132
+ global _input_waiting
133
+
134
+ _input_value = request.form.get("value", "")
135
+ _input_waiting = False
136
+
137
+ return Response(
138
+ _read_page(),
139
+ content_type="text/html"
140
+ )
141
+
142
+
143
+ # ============================================================
144
+ # GUI FUNCTIONS
145
+ # ============================================================
146
+
147
+ def init(port=5000, open_browser=True):
148
+
149
+ global _running
150
+ global _server_thread
151
+ global _port
152
+
153
+ if _running:
154
+ return
155
+
156
+ _port = port
157
+ _running = True
158
+
159
+ def run_server():
160
+
161
+ app.run(
162
+ host="127.0.0.1",
163
+ port=_port,
164
+ debug=False,
165
+ use_reloader=False
166
+ )
167
+
168
+ _server_thread = threading.Thread(
169
+ target=run_server,
170
+ daemon=True
171
+ )
172
+
173
+ _server_thread.start()
174
+
175
+ time.sleep(1)
176
+
177
+ if open_browser:
178
+
179
+ webbrowser.open(
180
+ f"http://127.0.0.1:{_port}"
181
+ )
182
+
183
+
184
+ def send(filename):
185
+
186
+ global _current_page
187
+
188
+ _current_page = filename
189
+
190
+
191
+ def button(name):
192
+
193
+ return Button(name)
194
+
195
+
196
+ def running():
197
+
198
+ return _running
199
+
200
+
201
+ def close():
202
+
203
+ global _running
204
+
205
+ _running = False
206
+
207
+
208
+ def get_input(question):
209
+
210
+ global _input_value
211
+ global _input_waiting
212
+ global _input_question
213
+
214
+ _input_value = None
215
+ _input_question = question
216
+ _input_waiting = True
217
+
218
+ while _input_value is None:
219
+
220
+ if not _running:
221
+ return ""
222
+
223
+ time.sleep(0.05)
224
+
225
+ value = _input_value
226
+
227
+ _input_value = None
228
+
229
+ return value
230
+
231
+
232
+ # ============================================================
233
+ # BUTTON
234
+ # ============================================================
235
+
236
+ class Button:
237
+
238
+ def __init__(self, name):
239
+
240
+ self.name = name
241
+
242
+ @property
243
+ def clicked(self):
244
+
245
+ if self.name in _buttons_clicked:
246
+
247
+ _buttons_clicked.remove(self.name)
248
+
249
+ return True
250
+
251
+ return False
@@ -0,0 +1,93 @@
1
+ Metadata-Version: 2.4
2
+ Name: webgui-py
3
+ Version: 0.1.0
4
+ Summary: A simple Python GUI framework that uses HTML as the interface
5
+ License-Expression: MIT
6
+ Requires-Python: >=3.9
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: flask
10
+ Dynamic: license-file
11
+
12
+ # WebGUI
13
+
14
+ A simple Python GUI framework that uses HTML as the interface.
15
+
16
+ WebGUI lets you make Python applications with a web browser as the GUI without needing to write JavaScript.
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ pip install webgui
22
+ ```
23
+
24
+ ## Basic Example
25
+
26
+
27
+ ```python
28
+ import webgui
29
+ import time
30
+
31
+ webgui.init()
32
+
33
+ webgui.send("index.html")
34
+
35
+ while webgui.running():
36
+
37
+ if webgui.button("say hello").clicked:
38
+ print("Hello!")
39
+
40
+ time.sleep(0.05)
41
+ ```
42
+
43
+
44
+ ```html
45
+ <!DOCTYPE html>
46
+ <html>
47
+
48
+ <body>
49
+
50
+ <h1>My App</h1>
51
+
52
+ <p>Hello!</p>
53
+
54
+ <button name="say hello">Say Hello</button>
55
+
56
+ </body>
57
+
58
+ </html>
59
+ ```
60
+
61
+ ## Getting Input
62
+
63
+ You can also ask the user for text:
64
+
65
+ ```python
66
+ name = webgui.get_input("What's your name?")
67
+
68
+ print(name)
69
+ ```
70
+
71
+ The browser displays an input box and returns what the user entered.
72
+
73
+ ## Why WebGUI?
74
+
75
+ WebGUI is designed to be simple.
76
+
77
+ You write your interface using HTML and control your application using Python.
78
+
79
+ You don't need to write JavaScript or deal directly with HTTP communication.
80
+
81
+ ## Features
82
+
83
+ * HTML-based GUI
84
+ * Python controls the application
85
+ * Automatic browser opening
86
+ * Simple button handling
87
+ * Text input
88
+ * Multiple HTML pages
89
+ * No JavaScript required in your application
90
+
91
+ ## License
92
+
93
+ See the LICENSE file.
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ webgui/__init__.py
5
+ webgui/gui.py
6
+ webgui_py.egg-info/PKG-INFO
7
+ webgui_py.egg-info/SOURCES.txt
8
+ webgui_py.egg-info/dependency_links.txt
9
+ webgui_py.egg-info/requires.txt
10
+ webgui_py.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ flask
@@ -0,0 +1,2 @@
1
+ dist
2
+ webgui