This commit is contained in:
Aliberk Sandıkçı 2024-06-21 20:39:24 +03:00
parent e84de621c2
commit 08619b2ef2
Signed by: asandikci
GPG key ID: 25C67A03B5666BC1
7 changed files with 175 additions and 30 deletions

2
.gitignore vendored
View file

@ -54,7 +54,7 @@ cover/
# Translations
*.mo
*.pot
# *.pot
# Django stuff:
*.log

1
po/compile_translations.sh Executable file
View file

@ -0,0 +1 @@
msgfmt en_US.po -o en_US.mo

68
po/en_US.po Normal file
View file

@ -0,0 +1,68 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
# FULL NAME <EMAIL@ADDRESS>, 2024.
# rstrstrstrst <rstrstr@arstarst.rstrst>, 2024.
#
msgid ""
msgstr ""
"Project-Id-Version: 1.0.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-21 19:25+0300\n"
"PO-Revision-Date: 2024-06-21 19:33+0300\n"
"Last-Translator: rstrstrstrst <rstrstr@arstarst.rstrst>\n"
"Language-Team: LANGUAGE <a@aaaaaa.carstrtarstarstarst>\n"
"Language: en_US\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Gtranslator 46.1\n"
#: ../src/MainWindow.py:54
msgid "Metin Editörü"
msgstr "Text Editor"
#: ../src/MainWindow.py:61
msgid "Yeni Doküman"
msgstr "New Document"
#: ../src/MainWindow.py:67 ../src/MainWindow.py:135
msgid "Dosya Aç"
msgstr "Open File"
#: ../src/MainWindow.py:73
msgid "Kaydet"
msgstr "Save"
#: ../src/MainWindow.py:79
msgid "Farklı Kaydet"
msgstr "Save As"
#: ../src/MainWindow.py:94
msgid "Seçenekler"
msgstr "Preferences"
#: ../src/MainWindow.py:130
msgid "Yeni Dosya"
msgstr "New File"
#: ../src/MainWindow.py:138
msgid "_Aç"
msgstr "_Open"
#: ../src/MainWindow.py:139
msgid "_İptal"
msgstr "_Cancel"
#: ../src/MainWindow.py:172
msgid "Dosyayı Kaydet"
msgstr "Save File"
#: ../src/MainWindow.py:175
msgid "_Save"
msgstr "_Save"
#: ../src/MainWindow.py:176
msgid "_Cancel"
msgstr "_Cancels"

1
po/files Normal file
View file

@ -0,0 +1 @@
../src/MainWindow.py

2
po/generate_pot_file.sh Executable file
View file

@ -0,0 +1,2 @@
cd $(dirname "$0")
xgettext --files-from=files --language=Python -o gtk4py.pot

66
po/gtk4py.pot Normal file
View file

@ -0,0 +1,66 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-21 19:25+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: ../src/MainWindow.py:54
msgid "Metin Editörü"
msgstr ""
#: ../src/MainWindow.py:61
msgid "Yeni Doküman"
msgstr ""
#: ../src/MainWindow.py:67 ../src/MainWindow.py:135
msgid "Dosya Aç"
msgstr ""
#: ../src/MainWindow.py:73
msgid "Kaydet"
msgstr ""
#: ../src/MainWindow.py:79
msgid "Farklı Kaydet"
msgstr ""
#: ../src/MainWindow.py:94
msgid "Seçenekler"
msgstr ""
#: ../src/MainWindow.py:130
msgid "Yeni Dosya"
msgstr ""
#: ../src/MainWindow.py:138
msgid "_Aç"
msgstr ""
#: ../src/MainWindow.py:139
msgid "_İptal"
msgstr ""
#: ../src/MainWindow.py:172
msgid "Dosyayı Kaydet"
msgstr ""
#: ../src/MainWindow.py:175
msgid "_Save"
msgstr ""
#: ../src/MainWindow.py:176
msgid "_Cancel"
msgstr ""

View file

@ -1,9 +1,19 @@
import gi, sys
gi.require_version('Gtk', '4.0')
gi.require_version("Gtk", "4.0")
from gi.repository import Gtk, Gio
import FileOperations
import locale
from locale import gettext as _
APPNAME = "gtk4py"
TRANSLATIONS_PATH = "/usr/share/locale"
locale.bindtextdomain(APPNAME, TRANSLATIONS_PATH)
locale.textdomain(APPNAME)
class MainWindow(Gtk.ApplicationWindow):
def __init__(self, app):
super().__init__(application=app)
@ -22,7 +32,6 @@ class MainWindow(Gtk.ApplicationWindow):
def setup_variables(self):
self._current_working_file = None
def setup_actions(self):
new_action = Gio.SimpleAction(name="new")
new_action.connect("activate", self.on_action_win_new_activated)
@ -33,43 +42,41 @@ class MainWindow(Gtk.ApplicationWindow):
self.add_action(open_action)
save_action = Gio.SimpleAction(name="save")
save_action.connect("activate" , self.on_action_win_save_activated)
save_action.connect("activate", self.on_action_win_save_activated)
self.add_action(save_action)
save_as_action = Gio.SimpleAction(name="save-as")
save_as_action.connect("activate", self.on_action_win_save_as_activated)
self.add_action(save_as_action)
def setup_window(self):
self.set_default_size(600, 400)
self.set_title("Metin Editörü")
self.set_title(_("Metin Editörü"))
def setup_headerbar(self):
btn_new = Gtk.Button(
label="New",
action_name="win.new",
icon_name="document-new-symbolic",
tooltip_text="Yeni Doküman"
tooltip_text=_("Yeni Doküman"),
)
btn_open = Gtk.Button(
label="Open",
action_name="win.open",
icon_name="document-open-symbolic",
tooltip_text="Dosya Aç"
tooltip_text=_("Dosya Aç"),
)
btn_save = Gtk.Button(
label="Save",
action_name="win.save",
icon_name="document-save-symbolic",
tooltip_text="Kaydet"
tooltip_text=_("Kaydet"),
)
btn_save_as = Gtk.Button(
label="Save As",
action_name="win.save-as",
icon_name="document-save-as-symbolic",
tooltip_text="Farklı Kaydet"
tooltip_text=_("Farklı Kaydet"),
)
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
@ -81,7 +88,11 @@ class MainWindow(Gtk.ApplicationWindow):
headerbar = Gtk.HeaderBar()
headerbar.pack_start(box)
btn_preferences = Gtk.Button(label="Preferences", icon_name="open-menu-symbolic", tooltip_text="Seçenekler")
btn_preferences = Gtk.Button(
label="Preferences",
icon_name="open-menu-symbolic",
tooltip_text=_("Seçenekler"),
)
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
box.append(btn_preferences)
headerbar.pack_end(box)
@ -89,11 +100,8 @@ class MainWindow(Gtk.ApplicationWindow):
self.set_titlebar(headerbar)
def setup_ui(self):
self.text_view = Gtk.TextView (
monospace=True,
left_margin=5,
right_margin=5,
top_margin=5
self.text_view = Gtk.TextView(
monospace=True, left_margin=5, right_margin=5, top_margin=5
)
scrolled_window = Gtk.ScrolledWindow(child=self.text_view)
@ -116,20 +124,19 @@ class MainWindow(Gtk.ApplicationWindow):
start = buffer.get_start_iter()
buffer.place_cursor(start)
# == CALLBACKS ==
def on_action_win_new_activated(self, action, params):
self.set_textview_text("")
self.set_title("New File")
self.set_title(_("Yeni Dosya"))
self._current_working_file = None
def on_action_win_open_activated(self, action, params):
self._open_file_chooser = Gtk.FileChooserNative (
title="Open File",
self._open_file_chooser = Gtk.FileChooserNative(
title=_("Dosya Aç"),
transient_for=self,
action=Gtk.FileChooserAction.OPEN,
accept_label="_Open",
cancel_label="_Cancel"
accept_label=_("_Aç"),
cancel_label=_("_İptal"),
)
self._open_file_chooser.connect("response", self.on_open_dialog_response)
@ -154,17 +161,19 @@ class MainWindow(Gtk.ApplicationWindow):
def on_action_win_save_activated(self, action, params):
if self._current_working_file:
text = self.get_textview_text()
FileOperations.save_file(self._current_working_file, text, self.on_file_saved)
FileOperations.save_file(
self._current_working_file, text, self.on_file_saved
)
else:
self.activate_action("win.save-as")
def on_action_win_save_as_activated(self, action, params):
self._save_file_chooser = Gtk.FileChooserNative (
title="Save File",
self._save_file_chooser = Gtk.FileChooserNative(
title=_("Dosyayı Kaydet"),
transient_for=self,
action=Gtk.FileChooserAction.SAVE,
accept_label="_Save",
cancel_label="_Cancel"
accept_label=_("_Save"),
cancel_label=_("_Cancel"),
)
self._save_file_chooser.connect("response", self.on_save_dialog_response)
@ -183,5 +192,3 @@ class MainWindow(Gtk.ApplicationWindow):
filename = FileOperations.get_name(file)
self.set_title(filename)
self._current_working_file = file