e3sertools 0.0.1__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.
- e3sertools-0.0.1/PKG-INFO +18 -0
- e3sertools-0.0.1/e3sertools/__init__.py +99 -0
- e3sertools-0.0.1/e3sertools/job.py +38 -0
- e3sertools-0.0.1/e3sertools/py.typed +0 -0
- e3sertools-0.0.1/e3sertools.egg-info/PKG-INFO +18 -0
- e3sertools-0.0.1/e3sertools.egg-info/SOURCES.txt +10 -0
- e3sertools-0.0.1/e3sertools.egg-info/dependency_links.txt +1 -0
- e3sertools-0.0.1/e3sertools.egg-info/top_level.txt +1 -0
- e3sertools-0.0.1/pyproject.toml +20 -0
- e3sertools-0.0.1/readme.md +3 -0
- e3sertools-0.0.1/setup.cfg +4 -0
- e3sertools-0.0.1/unlicense +24 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: e3sertools
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Tools for interacting with e3series
|
|
5
|
+
Author-email: kham@tuta.io
|
|
6
|
+
Maintainer-email: kham@tuta.io
|
|
7
|
+
License-Expression: Unlicense
|
|
8
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Typing :: Typed
|
|
11
|
+
Requires-Python: >=3.14
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: unlicense
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# Python package `e3sertools`
|
|
17
|
+
|
|
18
|
+
Handy tools for working with Zuken E3.series API using e3series package.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
from contextvars import ContextVar
|
|
4
|
+
|
|
5
|
+
import psutil
|
|
6
|
+
from e3series import Application
|
|
7
|
+
|
|
8
|
+
active_app: ContextVar[Application | None] = ContextVar("active_app", default=None)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def show(*values: object) -> None:
|
|
12
|
+
message = " ".join(map(str, values))
|
|
13
|
+
print(message)
|
|
14
|
+
if app := active_app.get():
|
|
15
|
+
app.PutMessageEx(0, message, 0, 100, 50, 255)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def warn(*values: object) -> None:
|
|
19
|
+
message = " ".join(map(str, values))
|
|
20
|
+
print("W:", message, file=sys.stderr)
|
|
21
|
+
if app := active_app.get():
|
|
22
|
+
app.PutWarning(0, message)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def alert(*values: object) -> None:
|
|
26
|
+
message = " ".join(map(str, values))
|
|
27
|
+
print("E:", message, file=sys.stderr)
|
|
28
|
+
if app := active_app.get():
|
|
29
|
+
app.PutError(0, message)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _set_active_e3(app: Application) -> int:
|
|
33
|
+
active_app.set(app)
|
|
34
|
+
return app.GetId()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def resolve_e3() -> int:
|
|
38
|
+
if pid := int(os.environ.get("E3_SERIES_PID", 0)):
|
|
39
|
+
return _set_active_e3(Application(pid))
|
|
40
|
+
ppid = os.getpid()
|
|
41
|
+
while ppid:
|
|
42
|
+
try:
|
|
43
|
+
process = psutil.Process(ppid)
|
|
44
|
+
except psutil.NoSuchProcess:
|
|
45
|
+
break
|
|
46
|
+
if process.exe().endswith("\\E3.series"):
|
|
47
|
+
pid = ppid
|
|
48
|
+
break
|
|
49
|
+
ppid = process.ppid()
|
|
50
|
+
if not pid:
|
|
51
|
+
pids = get_running_e3s()
|
|
52
|
+
pid = pids[0] if len(pids) == 1 else prompt_user_to_select_e3(pids)
|
|
53
|
+
os.environ["E3_SERIES_PID"] = str(pid)
|
|
54
|
+
return _set_active_e3(Application(pid))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def prompt_user_to_select_e3(pids: list[int] | None = None) -> int:
|
|
58
|
+
import tkinter as tk
|
|
59
|
+
|
|
60
|
+
if pids is None:
|
|
61
|
+
pids = get_running_e3s()
|
|
62
|
+
if not pids:
|
|
63
|
+
# raise UserError("Running process missing")
|
|
64
|
+
raise ProcessLookupError("No process running")
|
|
65
|
+
name: str = ""
|
|
66
|
+
options: dict[int, str] = {}
|
|
67
|
+
for pid in pids:
|
|
68
|
+
app = Application(pid)
|
|
69
|
+
name = app.GetName()
|
|
70
|
+
path = app.GetProjectInformation("")[1]
|
|
71
|
+
description = f"{name} [{pid}] {path}"
|
|
72
|
+
options[pid] = description
|
|
73
|
+
pid = 0
|
|
74
|
+
|
|
75
|
+
def submit() -> None:
|
|
76
|
+
nonlocal pid
|
|
77
|
+
if pid := user_selection.get():
|
|
78
|
+
win.quit()
|
|
79
|
+
|
|
80
|
+
win = tk.Tk()
|
|
81
|
+
win.title(name)
|
|
82
|
+
user_selection = tk.IntVar(value=pid)
|
|
83
|
+
for pid, description in options.items():
|
|
84
|
+
tk.Radiobutton(win, variable=user_selection, value=pid, text=description).pack(anchor=tk.W)
|
|
85
|
+
tk.Button(win, text="OK".center(10), command=submit).pack(pady=2)
|
|
86
|
+
win.mainloop()
|
|
87
|
+
if not pid:
|
|
88
|
+
raise KeyboardInterrupt("User canceled connection")
|
|
89
|
+
return pid
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def get_running_e3s() -> list[int]:
|
|
93
|
+
import e3series.tools
|
|
94
|
+
|
|
95
|
+
return e3series.tools.get_running_e3s()
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class UserError(Exception):
|
|
99
|
+
pass
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import gc
|
|
2
|
+
from collections.abc import Generator
|
|
3
|
+
from contextlib import contextmanager
|
|
4
|
+
from contextvars import ContextVar
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from e3series import Application, Job
|
|
8
|
+
|
|
9
|
+
from . import active_app, resolve_e3
|
|
10
|
+
|
|
11
|
+
active_job: ContextVar[Job | None] = ContextVar("active_job", default=None)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@contextmanager
|
|
15
|
+
def use(job: Job) -> Generator[None]:
|
|
16
|
+
try:
|
|
17
|
+
with active_job.set(job):
|
|
18
|
+
yield None
|
|
19
|
+
finally:
|
|
20
|
+
del job
|
|
21
|
+
gc.collect()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@contextmanager
|
|
25
|
+
def connect_to_application(app: Application | int | None = None) -> Generator[None]:
|
|
26
|
+
if app is None:
|
|
27
|
+
app = Application(resolve_e3())
|
|
28
|
+
elif isinstance(app, int):
|
|
29
|
+
app = Application(app)
|
|
30
|
+
with active_app.set(app):
|
|
31
|
+
with use(app.CreateJobObject()):
|
|
32
|
+
yield None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def __getattr__(name: str) -> Any:
|
|
36
|
+
if job := active_job.get():
|
|
37
|
+
return getattr(job, name)
|
|
38
|
+
raise ValueError("Missing active job")
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: e3sertools
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Tools for interacting with e3series
|
|
5
|
+
Author-email: kham@tuta.io
|
|
6
|
+
Maintainer-email: kham@tuta.io
|
|
7
|
+
License-Expression: Unlicense
|
|
8
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Typing :: Typed
|
|
11
|
+
Requires-Python: >=3.14
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: unlicense
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# Python package `e3sertools`
|
|
17
|
+
|
|
18
|
+
Handy tools for working with Zuken E3.series API using e3series package.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
e3sertools
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "e3sertools"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "Tools for interacting with e3series"
|
|
5
|
+
readme = "readme.md"
|
|
6
|
+
requires-python = ">=3.14"
|
|
7
|
+
license = "Unlicense"
|
|
8
|
+
license-files = ["unlicense"]
|
|
9
|
+
authors = [{ email = "kham@tuta.io" }]
|
|
10
|
+
maintainers = [{ email = "kham@tuta.io" }]
|
|
11
|
+
keywords = []
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Operating System :: Microsoft :: Windows",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Typing :: Typed",
|
|
16
|
+
]
|
|
17
|
+
dependencies = []
|
|
18
|
+
|
|
19
|
+
# [project.scripts]
|
|
20
|
+
# e3tools = "e3tools:main"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
|
2
|
+
|
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
+
distribute this software, either in source code form or as a compiled
|
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
+
means.
|
|
7
|
+
|
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
+
of this software dedicate any and all copyright interest in the
|
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
|
11
|
+
of the public at large and to the detriment of our heirs and
|
|
12
|
+
successors. We intend this dedication to be an overt act of
|
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
|
14
|
+
software under copyright law.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
For more information, please refer to <https://unlicense.org/>
|