framework-lib 0.1.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.
- framework_lib/__init__.py +0 -0
- framework_lib/data.py +156 -0
- framework_lib/framework.py +139 -0
- framework_lib/models.py +1470 -0
- framework_lib/program.py +126 -0
- framework_lib/setup.py +12 -0
- framework_lib-0.1.2.dist-info/METADATA +54 -0
- framework_lib-0.1.2.dist-info/RECORD +11 -0
- framework_lib-0.1.2.dist-info/WHEEL +5 -0
- framework_lib-0.1.2.dist-info/licenses/LICENSE +0 -0
- framework_lib-0.1.2.dist-info/top_level.txt +1 -0
framework_lib/program.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import data
|
|
2
|
+
import time
|
|
3
|
+
import builtins
|
|
4
|
+
from models import RedirectField, ErrorForm, ErrorHelper, PygameEmbedding, pygame
|
|
5
|
+
from inspect import signature as s
|
|
6
|
+
|
|
7
|
+
class DummyPage:
|
|
8
|
+
name="dummy"
|
|
9
|
+
def call(self, ctx={}):
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
class Singleton(type):
|
|
13
|
+
_instances = {}
|
|
14
|
+
def __call__(cls, *args, **kwargs):
|
|
15
|
+
if cls not in cls._instances:
|
|
16
|
+
inst = super().__call__(*args, **kwargs)
|
|
17
|
+
cls._instances[cls] = inst
|
|
18
|
+
try:
|
|
19
|
+
si=s(inst.on_begin)
|
|
20
|
+
args=list(si.parameters)
|
|
21
|
+
if len(args)>0:
|
|
22
|
+
ErrorForm(f"on_begin of Game cannot accept any arguments", "INITIALIZATION", type="304 GAME ERROR").call()
|
|
23
|
+
else:
|
|
24
|
+
inst.on_begin()
|
|
25
|
+
for k, v in inst.__dict__.items():
|
|
26
|
+
setattr(builtins, k, v)
|
|
27
|
+
except AttributeError:
|
|
28
|
+
pass
|
|
29
|
+
return cls._instances[cls]
|
|
30
|
+
|
|
31
|
+
class Game(metaclass=Singleton):
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
class Program:
|
|
35
|
+
def __init__(self, ps, pctx, pcs, vpgs, game, pps=25, gfile="g.json", globals={}):
|
|
36
|
+
asr=["page", "page context", "file", "globals", "valid pages","pages per second", "game"]
|
|
37
|
+
args=[ps, pctx, gfile, globals, vpgs, pps, game]
|
|
38
|
+
types=[str, dict, str, dict, list, int, Game]
|
|
39
|
+
self.c=ErrorHelper(asr, args, types)
|
|
40
|
+
self.db=data.Database(gfile, ps, globals)
|
|
41
|
+
self.vpgs=vpgs
|
|
42
|
+
self.g=game
|
|
43
|
+
if not self.c:
|
|
44
|
+
self.vpgs.append("dummy")
|
|
45
|
+
if self.db.retrieve("", total=True)=="ERR" or self.db.retrieve("", total=True)=={}:
|
|
46
|
+
self.db.new()
|
|
47
|
+
self.page_ctx=pctx
|
|
48
|
+
self.exit_now=False
|
|
49
|
+
self.page_class=pcs
|
|
50
|
+
self.history=[]
|
|
51
|
+
self.PPS=pps
|
|
52
|
+
self.gfile=gfile
|
|
53
|
+
result=1
|
|
54
|
+
if not self.c:
|
|
55
|
+
result=RedirectField(pcs, DummyPage, self, pctx).call()
|
|
56
|
+
self.globals=globals
|
|
57
|
+
self.st=globals
|
|
58
|
+
self.sv=globals
|
|
59
|
+
self.gload()
|
|
60
|
+
if result==1:
|
|
61
|
+
self.c=True
|
|
62
|
+
def run(self):
|
|
63
|
+
if not self.c:
|
|
64
|
+
cl=None
|
|
65
|
+
try:
|
|
66
|
+
while True:
|
|
67
|
+
time.sleep(1/self.PPS)
|
|
68
|
+
if not isinstance(cl,self.page_class):
|
|
69
|
+
self.cl, cl=self.page_class(), self.page_class()
|
|
70
|
+
config=None
|
|
71
|
+
try:
|
|
72
|
+
config=self.page_class.config
|
|
73
|
+
except:
|
|
74
|
+
pass
|
|
75
|
+
if config=="pgwin":
|
|
76
|
+
cl.call()
|
|
77
|
+
elif type(config) == tuple:
|
|
78
|
+
if isinstance(config[1], PygameEmbedding):
|
|
79
|
+
if config[0]=="scene":
|
|
80
|
+
self.gload()
|
|
81
|
+
config[1].ebf=cl.call
|
|
82
|
+
config[1].call()
|
|
83
|
+
if config[1].exit:
|
|
84
|
+
pygame.quit()
|
|
85
|
+
self.exit_now=True
|
|
86
|
+
self.write_history(cl.name)
|
|
87
|
+
self.gstore()
|
|
88
|
+
else:
|
|
89
|
+
ErrorForm(f"Invalid config for a page: {config}", self.page_class.name, "100 INTERNAL ERROR").call()
|
|
90
|
+
else:
|
|
91
|
+
self.gload()
|
|
92
|
+
if self.page_ctx=={}:
|
|
93
|
+
cl.call()
|
|
94
|
+
else:
|
|
95
|
+
cl.call(self.page_ctx)
|
|
96
|
+
self.write_history(cl.name)
|
|
97
|
+
self.gstore()
|
|
98
|
+
if self.exit_now:
|
|
99
|
+
break
|
|
100
|
+
return 0
|
|
101
|
+
except KeyboardInterrupt:
|
|
102
|
+
ErrorForm("Warning: KeyboardInterrupt used to exit the framework program. Some data may have not been saved.", self.page_class.name, "400 EXIT WARNING").call()
|
|
103
|
+
else:
|
|
104
|
+
return 1
|
|
105
|
+
def gstore(self):
|
|
106
|
+
self.db.change("",self.globals, total=True)
|
|
107
|
+
def gload(self):
|
|
108
|
+
globals=self.db.retrieve("", total=True)
|
|
109
|
+
if globals=="ERR":
|
|
110
|
+
self.globals=self.st
|
|
111
|
+
else:
|
|
112
|
+
self.globals=globals
|
|
113
|
+
def write_history(self, page):
|
|
114
|
+
c=ErrorHelper(["page"], [page], [str])
|
|
115
|
+
if not c:
|
|
116
|
+
self.history.append({"page": page, "context": self.page_ctx, "class": self.page_class})
|
|
117
|
+
else:
|
|
118
|
+
return "ERR"
|
|
119
|
+
def read_history(self, block_err=False):
|
|
120
|
+
if len(self.history)==0 and not block_err:
|
|
121
|
+
ErrorForm("Accessing unknown value in history is not possible", self.control, "302 HISTORY ERROR")
|
|
122
|
+
if len(self.history)==0:
|
|
123
|
+
return "ERR"
|
|
124
|
+
package=self.history.pop()
|
|
125
|
+
self.page_class=package["class"]
|
|
126
|
+
self.page_ctx=package["context"]
|
framework_lib/setup.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: framework-lib
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Python Framework Library, expandable, provides support for Console, Tkinter and Pygame.
|
|
5
|
+
Author-email: Ad1Ad1 <help91922@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Ad1Ad1/game-framework
|
|
8
|
+
Project-URL: Issues, https://github.com/Ad1Ad1/game-framework/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.13
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# Quick Start and PyPI guide for Page Framework(v1.0)
|
|
17
|
+
|
|
18
|
+
## Useful Links
|
|
19
|
+
|
|
20
|
+
[View official API documentation](https://github.com/Ad1Ad1/game-framework/blob/main/README.md)
|
|
21
|
+
|
|
22
|
+
[View official examples page](https://github.com/Ad1Ad1/game-framework/blob/main/EXAMPLES.md)
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
First, install the framework with this command
|
|
26
|
+
|
|
27
|
+
```shell
|
|
28
|
+
pip install framework-lib
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Project creation
|
|
32
|
+
Now, create a new project(maybe in a separate folder) with this command
|
|
33
|
+
```shell
|
|
34
|
+
framework-lib project create {name}
|
|
35
|
+
```
|
|
36
|
+
Open created folder. List contents with this command:
|
|
37
|
+
```shell
|
|
38
|
+
ls
|
|
39
|
+
```
|
|
40
|
+
You should see something like this
|
|
41
|
+
|
|
42
|
+
```plaintext
|
|
43
|
+
Mode LastWriteTime Length Name
|
|
44
|
+
---- ------------- ------ ----
|
|
45
|
+
-a---- 10.07.2026 19:53 4294 data.py
|
|
46
|
+
-a---- 10.07.2026 19:53 72680 models.py
|
|
47
|
+
-a---- 10.07.2026 19:53 2 models_requirements.json
|
|
48
|
+
-a---- 10.07.2026 19:53 6578 program.py
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Now create your file there.
|
|
52
|
+
|
|
53
|
+
## What to use?
|
|
54
|
+
Choose one from our examples or create your own
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
framework_lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
framework_lib/data.py,sha256=g56bxejhs8wLOHwKDyE7tN0pKYfqwlQi_7tDxKf1YsI,4293
|
|
3
|
+
framework_lib/framework.py,sha256=mod5xdOnGWVfWnEZw2mpHzN8itBe-S1w1eQXgPBuI1E,7205
|
|
4
|
+
framework_lib/models.py,sha256=Tf90-J41iNSneH4X0bG2jsYVPqIqmYs6_2ytk8LIkOk,72842
|
|
5
|
+
framework_lib/program.py,sha256=_wptDdtdKTDoUzE2YiWxO230egNqFPlGRNpFCWNKmMc,6578
|
|
6
|
+
framework_lib/setup.py,sha256=RZR74vPPI7gJa4WC31QcJ9ox76BOVyZK9oYG5FCTvIY,257
|
|
7
|
+
framework_lib-0.1.2.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
framework_lib-0.1.2.dist-info/METADATA,sha256=TlC-vqqPPgXD_xbztoCgZXEOsAqGKZ890fmo6ji06ac,1703
|
|
9
|
+
framework_lib-0.1.2.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
10
|
+
framework_lib-0.1.2.dist-info/top_level.txt,sha256=rKbRZtVN2huyCl-EYLEFC9eczt3lxUvJxltdN75jFuA,14
|
|
11
|
+
framework_lib-0.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
framework_lib
|