diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..666ed97 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.flatpak-builder/ \ No newline at end of file diff --git a/data/de.privacynerd.colorcodes.desktop.in b/data/de.privacynerd.colorcodes.desktop.in new file mode 100644 index 0000000..8356eba --- /dev/null +++ b/data/de.privacynerd.colorcodes.desktop.in @@ -0,0 +1,8 @@ +[Desktop Entry] +Name=colorcodes +Exec=colorcodes +Icon=de.privacynerd.colorcodes +Terminal=false +Type=Application +Categories=GTK; +StartupNotify=true diff --git a/data/de.privacynerd.colorcodes.gschema.xml b/data/de.privacynerd.colorcodes.gschema.xml new file mode 100644 index 0000000..75a0b21 --- /dev/null +++ b/data/de.privacynerd.colorcodes.gschema.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/data/de.privacynerd.colorcodes.metainfo.xml.in b/data/de.privacynerd.colorcodes.metainfo.xml.in new file mode 100644 index 0000000..e0f2c58 --- /dev/null +++ b/data/de.privacynerd.colorcodes.metainfo.xml.in @@ -0,0 +1,9 @@ + + + de.privacynerd.colorcodes.desktop + CC0-1.0 + GPL-3.0-or-later + +

No description

+
+
diff --git a/data/icons/hicolor/scalable/apps/de.privacynerd.colorcodes.svg b/data/icons/hicolor/scalable/apps/de.privacynerd.colorcodes.svg new file mode 100644 index 0000000..a74c4df --- /dev/null +++ b/data/icons/hicolor/scalable/apps/de.privacynerd.colorcodes.svg @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + image/svg+xml + + + + + + + + application-x-executable + + + + + + + + + + + + + + + + diff --git a/data/icons/hicolor/symbolic/apps/de.privacynerd.colorcodes-symbolic.svg b/data/icons/hicolor/symbolic/apps/de.privacynerd.colorcodes-symbolic.svg new file mode 100644 index 0000000..0444828 --- /dev/null +++ b/data/icons/hicolor/symbolic/apps/de.privacynerd.colorcodes-symbolic.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/data/icons/meson.build b/data/icons/meson.build new file mode 100644 index 0000000..64161b3 --- /dev/null +++ b/data/icons/meson.build @@ -0,0 +1,13 @@ +application_id = 'de.privacynerd.colorcodes' + +scalable_dir = 'hicolor' / 'scalable' / 'apps' +install_data( + scalable_dir / ('@0@.svg').format(application_id), + install_dir: get_option('datadir') / 'icons' / scalable_dir +) + +symbolic_dir = 'hicolor' / 'symbolic' / 'apps' +install_data( + symbolic_dir / ('@0@-symbolic.svg').format(application_id), + install_dir: get_option('datadir') / 'icons' / symbolic_dir +) diff --git a/data/meson.build b/data/meson.build new file mode 100644 index 0000000..aee2321 --- /dev/null +++ b/data/meson.build @@ -0,0 +1,36 @@ +desktop_file = i18n.merge_file( + input: 'de.privacynerd.colorcodes.desktop.in', + output: 'de.privacynerd.colorcodes.desktop', + type: 'desktop', + po_dir: '../po', + install: true, + install_dir: get_option('datadir') / 'applications' +) + +desktop_utils = find_program('desktop-file-validate', required: false) +if desktop_utils.found() + test('Validate desktop file', desktop_utils, args: [desktop_file]) +endif + +appstream_file = i18n.merge_file( + input: 'de.privacynerd.colorcodes.metainfo.xml.in', + output: 'de.privacynerd.colorcodes.metainfo.xml', + po_dir: '../po', + install: true, + install_dir: get_option('datadir') / 'metainfo' +) + +appstreamcli = find_program('appstreamcli', required: false, disabler: true) +test('Validate appstream file', appstreamcli, + args: ['validate', '--no-net', '--explain', appstream_file]) + +install_data('de.privacynerd.colorcodes.gschema.xml', + install_dir: get_option('datadir') / 'glib-2.0' / 'schemas' +) + +compile_schemas = find_program('glib-compile-schemas', required: false, disabler: true) +test('Validate schema file', + compile_schemas, + args: ['--strict', '--dry-run', meson.current_source_dir()]) + +subdir('icons') diff --git a/de.privacynerd.colorcodes.json b/de.privacynerd.colorcodes.json new file mode 100644 index 0000000..3b44174 --- /dev/null +++ b/de.privacynerd.colorcodes.json @@ -0,0 +1,38 @@ +{ + "app-id" : "de.privacynerd.colorcodes", + "runtime" : "org.gnome.Platform", + "runtime-version" : "45", + "sdk" : "org.gnome.Sdk", + "command" : "colorcodes", + "finish-args" : [ + "--share=network", + "--share=ipc", + "--socket=fallback-x11", + "--device=dri", + "--socket=wayland" + ], + "cleanup" : [ + "/include", + "/lib/pkgconfig", + "/man", + "/share/doc", + "/share/gtk-doc", + "/share/man", + "/share/pkgconfig", + "*.la", + "*.a" + ], + "modules" : [ + { + "name" : "colorcodes", + "builddir" : true, + "buildsystem" : "meson", + "sources" : [ + { + "type" : "git", + "url" : "https://git.privacynerd.de/BlueFox/ColorCodes.git" + } + ] + } + ] +} diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..4151030 --- /dev/null +++ b/meson.build @@ -0,0 +1,20 @@ +project('colorcodes', + version: '0.1.0', + meson_version: '>= 0.62.0', + default_options: [ 'warning_level=2', 'werror=false', ], +) + +i18n = import('i18n') +gnome = import('gnome') + + + +subdir('data') +subdir('src') +subdir('po') + +gnome.post_install( + glib_compile_schemas: true, + gtk_update_icon_cache: true, + update_desktop_database: true, +) diff --git a/po/LINGUAS b/po/LINGUAS new file mode 100644 index 0000000..e69de29 diff --git a/po/POTFILES b/po/POTFILES new file mode 100644 index 0000000..0321f1f --- /dev/null +++ b/po/POTFILES @@ -0,0 +1,6 @@ +data/de.privacynerd.colorcodes.desktop.in +data/de.privacynerd.colorcodes.metainfo.xml.in +data/de.privacynerd.colorcodes.gschema.xml +src/main.py +src/window.py +src/window.ui diff --git a/po/meson.build b/po/meson.build new file mode 100644 index 0000000..78fd765 --- /dev/null +++ b/po/meson.build @@ -0,0 +1 @@ +i18n.gettext('colorcodes', preset: 'glib') diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/colorcodes.gresource.xml b/src/colorcodes.gresource.xml new file mode 100644 index 0000000..b95cd02 --- /dev/null +++ b/src/colorcodes.gresource.xml @@ -0,0 +1,7 @@ + + + + window.ui + gtk/help-overlay.ui + + diff --git a/src/colorcodes.in b/src/colorcodes.in new file mode 100755 index 0000000..e4b1e58 --- /dev/null +++ b/src/colorcodes.in @@ -0,0 +1,46 @@ +#!@PYTHON@ + +# colorcodes.in +# +# Copyright 2024 Benjamin Burkhardt +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# SPDX-License-Identifier: GPL-3.0-or-later + +import os +import sys +import signal +import locale +import gettext + +VERSION = '@VERSION@' +pkgdatadir = '@pkgdatadir@' +localedir = '@localedir@' + +sys.path.insert(1, pkgdatadir) +signal.signal(signal.SIGINT, signal.SIG_DFL) +locale.bindtextdomain('colorcodes', localedir) +locale.textdomain('colorcodes') +gettext.install('colorcodes', localedir) + +if __name__ == '__main__': + import gi + + from gi.repository import Gio + resource = Gio.Resource.load(os.path.join(pkgdatadir, 'colorcodes.gresource')) + resource._register() + + from colorcodes import main + sys.exit(main.main(VERSION)) diff --git a/src/gtk/help-overlay.ui b/src/gtk/help-overlay.ui new file mode 100644 index 0000000..ef12f02 --- /dev/null +++ b/src/gtk/help-overlay.ui @@ -0,0 +1,29 @@ + + + + True + + + shortcuts + 10 + + + General + + + Show Shortcuts + win.show-help-overlay + + + + + Quit + app.quit + + + + + + + + diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..b4f474b --- /dev/null +++ b/src/main.py @@ -0,0 +1,85 @@ +# main.py +# +# Copyright 2024 Benjamin Burkhardt +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# SPDX-License-Identifier: GPL-3.0-or-later + +import sys +import gi + +gi.require_version('Gtk', '4.0') +gi.require_version('Adw', '1') + +from gi.repository import Gtk, Gio, Adw +from .window import ColorcodesWindow + + +class ColorcodesApplication(Adw.Application): + """The main application singleton class.""" + + def __init__(self): + super().__init__(application_id='de.privacynerd.colorcodes', + flags=Gio.ApplicationFlags.DEFAULT_FLAGS) + self.create_action('quit', lambda *_: self.quit(), ['q']) + self.create_action('about', self.on_about_action) + self.create_action('preferences', self.on_preferences_action) + + def do_activate(self): + """Called when the application is activated. + + We raise the application's main window, creating it if + necessary. + """ + win = self.props.active_window + if not win: + win = ColorcodesWindow(application=self) + win.present() + + def on_about_action(self, widget, _): + """Callback for the app.about action.""" + about = Adw.AboutWindow(transient_for=self.props.active_window, + application_name='colorcodes', + application_icon='de.privacynerd.colorcodes', + developer_name='Benjamin Burkhardt', + version='0.1.0', + developers=['Benjamin Burkhardt'], + copyright='© 2024 Benjamin Burkhardt') + about.present() + + def on_preferences_action(self, widget, _): + """Callback for the app.preferences action.""" + print('app.preferences action activated') + + def create_action(self, name, callback, shortcuts=None): + """Helper funciton to add an application action. + + Args: + name: the name of the action + callback: the function to be called when the action is + activated + shortcuts: an optional list of accelerators + """ + action = Gio.SimpleAction.new(name, None) + action.connect("activate", callback) + self.add_action(action) + if shortcuts: + self.set_accels_for_action(f"app.{name}", shortcuts) + + +def main(version): + """The application's entry point.""" + app = ColorcodesApplication() + return app.run(sys.argv) diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..fad9e5b --- /dev/null +++ b/src/meson.build @@ -0,0 +1,35 @@ +pkgdatadir = get_option('prefix') / get_option('datadir') / meson.project_name() +moduledir = pkgdatadir / 'colorcodes' +gnome = import('gnome') + +gnome.compile_resources('colorcodes', + 'colorcodes.gresource.xml', + gresource_bundle: true, + install: true, + install_dir: pkgdatadir, +) + +python = import('python') + +conf = configuration_data() +conf.set('PYTHON', python.find_installation('python3').path()) +conf.set('VERSION', meson.project_version()) +conf.set('localedir', get_option('prefix') / get_option('localedir')) +conf.set('pkgdatadir', pkgdatadir) + +configure_file( + input: 'colorcodes.in', + output: 'colorcodes', + configuration: conf, + install: true, + install_dir: get_option('bindir'), + install_mode: 'r-xr--r--' +) + +colorcodes_sources = [ + '__init__.py', + 'main.py', + 'window.py', +] + +install_data(colorcodes_sources, install_dir: moduledir) diff --git a/src/window.py b/src/window.py new file mode 100644 index 0000000..4866fb4 --- /dev/null +++ b/src/window.py @@ -0,0 +1,30 @@ +# window.py +# +# Copyright 2024 Benjamin Burkhardt +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# SPDX-License-Identifier: GPL-3.0-or-later + +from gi.repository import Adw +from gi.repository import Gtk + +@Gtk.Template(resource_path='/de/privacynerd/colorcodes/window.ui') +class ColorcodesWindow(Adw.ApplicationWindow): + __gtype_name__ = 'ColorcodesWindow' + + label = Gtk.Template.Child() + + def __init__(self, **kwargs): + super().__init__(**kwargs) diff --git a/src/window.ui b/src/window.ui new file mode 100644 index 0000000..117ade8 --- /dev/null +++ b/src/window.ui @@ -0,0 +1,49 @@ + + + + + + +
+ + _Preferences + app.preferences + + + _Keyboard Shortcuts + win.show-help-overlay + + + _About Colorcodes + app.about + +
+
+