From 30698d7dd1bf1bd68f08f7b2621931976a7e6019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aliberk=20Sand=C4=B1k=C3=A7=C4=B1?= Date: Thu, 20 Jun 2024 17:38:51 +0300 Subject: [PATCH] update --- README.md | 7 ++++-- shell.nix | 21 ++++++++++++++++ src/MainWindow.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++ src/main.py | 24 +++++++++++++++++++ 4 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 shell.nix create mode 100644 src/MainWindow.py create mode 100755 src/main.py diff --git a/README.md b/README.md index 5872d8d..2a7c360 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # gtk4py -GTK4 test -https://uzem.pardus.org.tr/enrol/index.php?id=23 \ No newline at end of file +GTK4 test +https://uzem.pardus.org.tr/enrol/index.php?id=23 + +### 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..3732830 --- /dev/null +++ b/shell.nix @@ -0,0 +1,21 @@ +# 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.gtk4 + pkgs.gobject-introspection + pkgs.pkg-config + pkgs.libnotify + # pkgs.libadwaita + (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..dfae02b --- /dev/null +++ b/src/MainWindow.py @@ -0,0 +1,61 @@ +import gi, sys +gi.require_version('Gtk', '4.0') +from gi.repository import Gtk, Gio + +class MainWindow(Gtk.ApplicationWindow): + def __init__(self, app): + super().__init__(application=app) + + self.setup_actions() + + self.setup_window() + + self.setup_headerbar() + + self.setup_ui() + + # == SETUPS == + def setup_actions(self): + pass + + def setup_window(self): + self.set_default_size(600, 400) + self.set_title("Metin Editörü") + + def setup_headerbar(self): + btn_new = Gtk.Button(label="New", icon_name="document-new-symbolic", tooltip_text="Yeni Doküman") + btn_open = Gtk.Button(label="Open", icon_name="document-open-symbolic", tooltip_text="Dosya Aç") + btn_save = Gtk.Button(label="Save", icon_name="document-save-symbolic", tooltip_text="Kaydet") + btn_save_as = Gtk.Button(label="Save As", icon_name="document-save-as-symbolic", tooltip_text="Farklı Kaydet") + + box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) + box.append(btn_new) + box.append(btn_open) + box.append(btn_save) + box.append(btn_save_as) + + headerbar = Gtk.HeaderBar() + headerbar.pack_start(box) + + btn_preferences = Gtk.Button(label="Preferences", icon_name="preferences-system-symbolic", tooltip_text="Seçenekler") + box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) + box.append(btn_preferences) + headerbar.pack_end(box) + + self.set_titlebar(headerbar) + + def setup_ui(self): + self.text_view = Gtk.TextView ( + monospace=True, + left_margin=5, + right_margin=5, + top_margin=5 + ) + scrolled_window = Gtk.ScrolledWindow(child=self.text_view) + + self.set_child(scrolled_window) + + # == FUNCTIONS == + # == CALLBACKS == + def on_btn_button_clicked(self, btn): + print("Merhaba, evet bu bir buton") \ No newline at end of file diff --git a/src/main.py b/src/main.py new file mode 100755 index 0000000..44cd21b --- /dev/null +++ b/src/main.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + +import gi, sys +gi.require_version('Gtk', '4.0') +from gi.repository import Gtk + +from MainWindow import MainWindow + +win = None +def on_activate(app): + global win + + if not win: + win = MainWindow(app) + win.present() + +app = Gtk.Application(application_id='com.asandikci.gtk4py') +app.connect('activate', on_activate) + +app.set_accels_for_action('win.open', ['o']) +app.set_accels_for_action('win.save', ['s']) +app.set_accels_for_action('win.save-as', ['s']) + +app.run(sys.argv) \ No newline at end of file