Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sigmasd/deno-gtk-py
Deno wrapper+types over gtk using deno-python
https://github.com/sigmasd/deno-gtk-py
adwaita deno gtk python
Last synced: 8 days ago
JSON representation
Deno wrapper+types over gtk using deno-python
- Host: GitHub
- URL: https://github.com/sigmasd/deno-gtk-py
- Owner: sigmaSd
- License: mit
- Created: 2023-11-09T20:12:01.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-01-04T17:59:14.000Z (28 days ago)
- Last Synced: 2025-01-04T18:29:30.601Z (28 days ago)
- Topics: adwaita, deno, gtk, python
- Language: TypeScript
- Homepage: https://jsr.io/@sigma/gtk-py
- Size: 144 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Deno Gtk Py
Wrapper + types over Gtk using deno-python
## Usage
```ts
#!/usr/bin/env -S deno run --allow-ffi --allow-env=DENO_PYTHON_PATH --unstable-ffi
import {
type Adw1_ as Adw_,
type Gtk4_ as Gtk_,
kw,
NamedArgument,
python,
} from "jsr:@sigma/gtk-py"const gi = python.import("gi");
gi.require_version("Gtk", "4.0");
gi.require_version("Adw", "1");
const Gtk: Gtk_.Gtk = python.import("gi.repository.Gtk");
const Adw: Adw_.Adw = python.import("gi.repository.Adw");class MainWindow extends Gtk.ApplicationWindow {
#button;
constructor(kwArg: NamedArgument) {
super(kwArg);
this.set_title("Demo");
this.#button = Gtk.Button(kw`label=${"Click Me"}`);
this.#button.connect(
"clicked",
python.callback(() => {
Adw.MessageDialog(
//@ts-ignore it is a window
new NamedArgument("transient_for", this),
new NamedArgument("heading", "Deno GTK PY"),
new NamedArgument(
"body",
"Hello World",
),
).present();
}),
);
this.set_child(this.#button);
}
}class App extends Adw.Application {
#win: MainWindow | undefined;
constructor(kwArg: NamedArgument) {
super(kwArg);
this.connect("activate", this.onActivate);
}
onActivate = python.callback((_kwarg, app: Gtk_.Application) => {
this.#win = new MainWindow(new NamedArgument("application", app));
this.#win.present();
});
}const app = new App(kw`application_id=${"com.example.com"}`);
app.run(Deno.args);
```Check out the examples directory
![image](https://github.com/sigmaSd/0.4.10/22427111/cd8a4a23-4ef2-4185-b57a-94de1494cbdb)
## Tips
- Gtk have its own loop, somethings that you expect to work might not do to
this, for example `setTimeout` wont work in a python.callback after running
Gtk.Applicaiton. The solution is to use the primitives that GLib provides, for
example instead of `setTimeout`, use `GLib.add_timeout`
- For running async subprocess checkout `Gio.Subprocess`## Random apps made with it
- https://github.com/sigmaSd/Stimulator
- https://github.com/sigmaSd/chrono## References
- python gtk4 docs: http://lazka.github.io/pgi-docs/
- gtk4 docs: https://docs.gtk.org/gtk4/