termux-window 0.1.0__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.
@@ -0,0 +1,3 @@
1
+ from .main_mobile import show_x11
2
+
3
+ __all__ = ["show_x11"]
@@ -0,0 +1,59 @@
1
+ import os
2
+ import subprocess
3
+ import time
4
+ import matplotlib
5
+
6
+
7
+ os.environ["DISPLAY"] = ":1"
8
+ x11_proc = subprocess.Popen(["termux-x11", ":1"])
9
+
10
+ for tentativa in range(50):
11
+ teste = subprocess.run(
12
+ ["xdpyinfo", "-display", ":1"],
13
+ stdout=subprocess.DEVNULL,
14
+ stderr=subprocess.DEVNULL,
15
+ )
16
+ if teste.returncode == 0:
17
+ break
18
+ time.sleep(0.2)
19
+ else:
20
+ raise RuntimeError("O display :1 não ficou pronto")
21
+
22
+
23
+ subprocess.run(
24
+ [
25
+ "am", "start", "--user", "0",
26
+ "-n", "com.termux.x11/com.termux.x11.MainActivity",
27
+ ],
28
+ check=True,
29
+ )
30
+
31
+ matplotlib.use("TkAgg")
32
+
33
+
34
+ def show_x11():
35
+ import matplotlib.pyplot as plt
36
+
37
+ fig = plt.gcf()
38
+ janela = plt.get_current_fig_manager().window
39
+ janela.title("Aplicação")
40
+
41
+ janela.update_idletasks()
42
+ largura = janela.winfo_screenwidth()
43
+ altura = janela.winfo_screenheight()
44
+ janela.geometry(f"{largura}x{altura}+0+0")
45
+ janela.update()
46
+
47
+ fig.tight_layout()
48
+
49
+ def back_to_termux(evento=None):
50
+ janela.destroy()
51
+ x11_proc.terminate()
52
+ subprocess.run([
53
+ "am", "start", "--user", "0",
54
+ "-n", "com.termux/com.termux.app.TermuxActivity",
55
+ ])
56
+
57
+ janela.bind_all("<Home>", back_to_termux)
58
+
59
+ plt.show()
@@ -0,0 +1,98 @@
1
+ Metadata-Version: 2.4
2
+ Name: termux-window
3
+ Version: 0.1.0
4
+ Summary: Display matplotlib plots in a tkinter window inside Termux:X11
5
+ Author: João Coito
6
+ Requires-Python: >=3.9
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: matplotlib
9
+
10
+ # termux-window
11
+
12
+ Display `matplotlib` plots in a `tkinter` window inside Termux:X11 (`DISPLAY=:1` using the `TkAgg` backend) with minimal changes to standard plotting scripts.
13
+
14
+ ## Why Use `termux-window`?
15
+
16
+ On a desktop computer, running a Matplotlib script normally opens a graphical window automatically when you call `plt.show()`. On Android inside Termux, there is no desktop X11 session running by default, so plotting scripts often fail or lack a ready-to-use window workflow.
17
+
18
+ `termux-window` makes plotting on Termux feel much closer to working on a computer:
19
+
20
+ 1. Sets up `DISPLAY=:1` and starts `termux-x11` if needed.
21
+ 2. Waits until the `:1` display responds via `xdpyinfo`.
22
+ 3. Launches the **Termux:X11** activity and configures the `TkAgg` window.
23
+ 4. Lets you return to Termux cleanly (such as pressing `<Home>`).
24
+
25
+ You still write standard `matplotlib` code—whether using the implicit (`plt.*`) interface or the object-oriented (`fig, ax`) interface—and call `show_x11()` at the end.
26
+
27
+ ## Prerequisites
28
+
29
+ Because `termux-window` bridges Python, Tkinter, and Android/Termux X11 tools, make sure all of the following are installed and available:
30
+
31
+ * **Termux**: A working Termux installation on Android (avoid outdated app-store builds, if packages fail to install).
32
+ * **`x11-repo` enabled in Termux**: Required so X11 packages can be installed (`pkg install x11-repo`).
33
+ * **`termux-x11` (CLI and Android app)**: Both the `termux-x11` command-line package in Termux and the **Termux:X11** Android app must be installed; if the X11 app isn't installed or allowed to launch, `am start` will fail.
34
+ * **`xdpyinfo`**: Used to check whether display `:1` is ready (typically provided by `xorg-xdpyinfo`, install via pkg inside Termux).
35
+ * **`python-tkinter` / Tk libraries**: Required for `tkinter` and Matplotlib's `TkAgg` backend to create and manage the GUI window, install via pkg inside Termux.
36
+ * **`matplotlib`**: Installed in the Python environment you use to run your scripts.
37
+
38
+ ## Installation
39
+
40
+ Install from PyPI:
41
+
42
+ ```bash
43
+ pip install termux-window
44
+ ```
45
+
46
+ ## Usage Examples
47
+
48
+ Very similar to using `matplotlib` on a computer, that was my main goal in the development of this library, i also wanted to contribute something to the open-source comunity because thats how the comunity keeps growing.
49
+
50
+ ### Implicit Interface (`plt`)
51
+
52
+ ```python
53
+ from termux_window import show_x11
54
+ import matplotlib.pyplot as plt
55
+
56
+ months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
57
+ sales = [1200, 1550, 4400, 1900, 2250, 2100]
58
+
59
+ plt.figure()
60
+ plt.plot(
61
+ months, sales, marker="o", linewidth=2, color="#2563eb", label="Sales (€)"
62
+ )
63
+
64
+ plt.title("Monthly Sales (1st Half)")
65
+ plt.xlabel("Month")
66
+ plt.ylabel("Amount (€)")
67
+ plt.grid(True, linestyle="--", alpha=0.5)
68
+ plt.legend()
69
+
70
+ show_x11()
71
+ ```
72
+
73
+ ### Object-Oriented Interface (`fig, ax`)
74
+
75
+ ```python
76
+ from termux_window import show_x11
77
+ import matplotlib.pyplot as plt
78
+
79
+ months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
80
+ sales = [1200, 1550, 1400, 4900, 2250, 2100]
81
+
82
+ fig, ax = plt.subplots()
83
+ ax.plot(
84
+ months, sales, marker="o", linewidth=2, color="#2563eb", label="Sales (€)"
85
+ )
86
+
87
+ ax.set_title("Monthly Sales (1st Half)")
88
+ ax.set_xlabel("Month")
89
+ ax.set_ylabel("Amount (€)")
90
+ ax.grid(True, linestyle="--", alpha=0.5)
91
+ ax.legend()
92
+
93
+ show_x11()
94
+ ```
95
+
96
+ ## License
97
+
98
+ No license ahahah, you can do whatever you like with this code. Have fun!
@@ -0,0 +1,6 @@
1
+ termux_window/__init__.py,sha256=N18274KAnmTwnQiDVR0Pcf9P746q-x_rGjLgCAjNkrc,58
2
+ termux_window/main_mobile.py,sha256=PIuYEUt9jkCr1fUQ7llGgDY0rseXuDVQShk6sf1ZbKs,1267
3
+ termux_window-0.1.0.dist-info/METADATA,sha256=VduvttDtYDX0kotE10KgHyNaXZ3CotJ97eT77P0bock,3604
4
+ termux_window-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
5
+ termux_window-0.1.0.dist-info/top_level.txt,sha256=3j_vkGZGC-RZsbqEJy3mpRtxIO9HUgWc_PGumcsjnYA,14
6
+ termux_window-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ termux_window