Initial Commit

This commit is contained in:
Aliberk Sandıkçı 2024-06-20 10:56:29 +03:00
parent 3f5e93993c
commit 675320dbf3
Signed by: asandikci
GPG key ID: 25C67A03B5666BC1
6 changed files with 452 additions and 3 deletions

View file

@ -1,4 +1,7 @@
# gtk3py # gtk3py
GTK3 Test GTK3 Test
https://gonullu.pardus.org.tr/pardusa-uygulama-gelistirme-rehberi-gtk3/ 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

20
shell.nix Normal file
View file

@ -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 <nixpkgs> {};
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
]))
];
}

46
src/MainWindow.py Normal file
View file

@ -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))

22
src/main.py Executable file
View file

@ -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)

149
ui/MainWindow.glade Normal file
View file

@ -0,0 +1,149 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkApplicationWindow" id="window">
<property name="can-focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">8</property>
<property name="margin-end">8</property>
<property name="margin-top">8</property>
<property name="margin-bottom">8</property>
<property name="orientation">vertical</property>
<property name="spacing">8</property>
<child>
<!-- n-columns=2 n-rows=2 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="row-spacing">7</property>
<property name="column-spacing">7</property>
<child>
<object class="GtkButton" id="btn_whoami">
<property name="label" translatable="yes">Who am I</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="on_btn_whoami_clicked" swapped="no"/>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn_displayserver">
<property name="label" translatable="yes">Display Server</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="on_btn_displayserver_clicked" swapped="no"/>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn_listdir">
<property name="label" translatable="yes">List Directory*</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="on_btn_listdir_clicked" swapped="no"/>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn_de">
<property name="label" translatable="yes">Desktop Environment</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="on_btn_de_clicked" swapped="no"/>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="spacing">13</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Arguments*: </property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry_args">
<property name="width-request">300</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="halign">end</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="lbl_output">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">[output]</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

209
ui/MainWindow.glade~ Normal file
View file

@ -0,0 +1,209 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkApplicationWindow" id="window">
<property name="can-focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">8</property>
<property name="margin-end">8</property>
<property name="margin-top">8</property>
<property name="margin-bottom">8</property>
<property name="orientation">vertical</property>
<property name="spacing">8</property>
<child>
<!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="row-spacing">2</property>
<property name="column-spacing">7</property>
<child>
<object class="GtkButton" id="btn_whoami">
<property name="label" translatable="yes">Who am I</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="on_btn_whoami_clicked" swapped="no"/>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn_displaymanager">
<property name="label" translatable="yes">Display Manager</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="on_btn_displaymanager_clicked" swapped="no"/>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn_displayserver">
<property name="label" translatable="yes">Display Server</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="on_btn_displayserver_clicked" swapped="no"/>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn_listdir">
<property name="label" translatable="yes">List Directory*</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn_de">
<property name="label" translatable="yes">Desktop Environment</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="on_btn_de_clicked" swapped="no"/>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button_B">
<property name="label" translatable="yes">button_B</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button_C">
<property name="label" translatable="yes">button_C</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button_D">
<property name="label" translatable="yes">button_D</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button_E">
<property name="label" translatable="yes">button</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="spacing">13</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Arguments*: </property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry_args">
<property name="width-request">300</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="halign">end</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="lbl_output">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">[output]</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>