diff --git a/README.md b/README.md index d3f210c..ce973e3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ -# gtk3py - +# gtk3py + GTK3 Test -https://gonullu.pardus.org.tr/pardusa-uygulama-gelistirme-rehberi-gtk3/ \ No newline at end of file +https://gonullu.pardus.org.tr/pardusa-uygulama-gelistirme-rehberi-gtk3/ + +### Development Environment +run `nix develop -f shell.nix` command in NixOS to get into development environment diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..c75744e --- /dev/null +++ b/shell.nix @@ -0,0 +1,20 @@ +# shell.nix +let + # We pin to a specific nixpkgs commit for reproducibility. + # Last updated: 2024-04-29. Check for new commits at https://status.nixos.org. + # pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/cf8cc1201be8bc71b7cbbbdaf349b22f4f99c7ae.tar.gz") {}; + pkgs = import {}; +in pkgs.mkShell { + packages = [ + pkgs.gtk3 + pkgs.gobject-introspection + pkgs.pkg-config + pkgs.libnotify + (pkgs.python3.withPackages (python-pkgs: [ + # select Python packages here + # python-pkgs.gi + python-pkgs.pycairo + python-pkgs.pygobject3 + ])) + ]; +} diff --git a/src/MainWindow.py b/src/MainWindow.py new file mode 100644 index 0000000..fd1b019 --- /dev/null +++ b/src/MainWindow.py @@ -0,0 +1,46 @@ +import gi, os, subprocess +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk, GLib, Gio + + +class MainWindow: + def __init__(self, application): + self.builder = Gtk.Builder() + self.builder.add_from_file(os.path.dirname(os.path.abspath(__file__)) + "/../ui/MainWindow.glade") + self.builder.connect_signals(self) + self.window = self.builder.get_object("window") + self.window.set_application(application) + self.application = application + + self.defineComponents() + self.window.show_all() + + def defineComponents(self): + self.lbl_output = self.builder.get_object("lbl_output") + + def label_output(self, *args): + output = args[1].stdout.decode("utf-8") + print(args[1].stderr.decode("utf-8")) + # print("DEBUG:", args) + self.lbl_output.set_label(output) + + def on_btn_whoami_clicked(self, btn): + self.label_output(self, subprocess.run(["whoami"], capture_output=True)) + + def on_btn_displaymanager_clicked(self, btn): + self.label_output(self, subprocess.run(["echo", "ERROR"], capture_output=True)) + + def on_btn_displayserver_clicked(self, btn): + self.label_output(self, subprocess.run(["echo", os.environ['XDG_SESSION_TYPE']], capture_output=True)) + + def on_btn_listdir_clicked(self, btn): + self.label_output(self, subprocess.run(["ls"] + self.builder.get_object("entry_args").get_text().split(), capture_output=True)) + + def on_btn_de_clicked(self, btn): + self.label_output(self, subprocess.run(["echo", os.environ['XDG_SESSION_DESKTOP']], capture_output=True)) + + + + + + \ No newline at end of file diff --git a/src/main.py b/src/main.py new file mode 100755 index 0000000..ae7e6d0 --- /dev/null +++ b/src/main.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +import sys + +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk, GLib, Gio + +from MainWindow import MainWindow + +class Application(Gtk.Application): + def __init__(self, *args, **kwargs): + super().__init__(*args, application_id="com.asandikci.gtk3py", flags=Gio.ApplicationFlags.NON_UNIQUE, **kwargs) + + self.window = None + GLib.set_prgname("com.asandikci.gtk3py") + + def do_activate(self): + self.window = MainWindow(self) + +app = Application() +app.run(sys.argv) \ No newline at end of file diff --git a/ui/MainWindow.glade b/ui/MainWindow.glade new file mode 100644 index 0000000..2230053 --- /dev/null +++ b/ui/MainWindow.glade @@ -0,0 +1,149 @@ + + + + + + False + + + True + False + 8 + 8 + 8 + 8 + vertical + 8 + + + + True + False + center + 7 + 7 + + + Who am I + True + True + True + + + + 0 + 0 + + + + + Display Server + True + True + True + + + + 1 + 0 + + + + + List Directory* + True + True + True + + + + 0 + 1 + + + + + Desktop Environment + True + True + True + + + + 1 + 1 + + + + + False + True + 0 + + + + + True + False + vertical + + + True + False + 13 + + + True + False + Arguments*: + + + False + True + 0 + + + + + 300 + True + True + end + True + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + [output] + + + False + True + 1 + + + + + False + True + 1 + + + + + + diff --git a/ui/MainWindow.glade~ b/ui/MainWindow.glade~ new file mode 100644 index 0000000..884fab1 --- /dev/null +++ b/ui/MainWindow.glade~ @@ -0,0 +1,209 @@ + + + + + + False + + + True + False + 8 + 8 + 8 + 8 + vertical + 8 + + + + True + False + center + 2 + 7 + + + Who am I + True + True + True + + + + 0 + 0 + + + + + Display Manager + True + True + True + + + + 1 + 0 + + + + + Display Server + True + True + True + + + + 2 + 0 + + + + + List Directory* + True + True + True + + + 0 + 1 + + + + + Desktop Environment + True + True + True + + + + 1 + 1 + + + + + button_B + True + True + True + + + 2 + 1 + + + + + button_C + True + True + True + + + 0 + 2 + + + + + button_D + True + True + True + + + 1 + 2 + + + + + button + True + True + True + + + 2 + 2 + + + + + False + True + 0 + + + + + True + False + vertical + + + True + False + 13 + + + True + False + Arguments*: + + + False + True + 0 + + + + + 300 + True + True + end + True + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + [output] + + + False + True + 1 + + + + + False + True + 1 + + + + + +