From 065649aaada16f4d2c8d25f5562cd96be4f9e080 Mon Sep 17 00:00:00 2001 From: David Boddie Date: Fri, 5 Apr 2019 17:19:09 +0200 Subject: [PATCH] Add most of the first tutorial Signed-off-by: David Boddie --- build-aux/meson/postinstall.py | 13 ++++++++ com.example.first_application.json | 38 ++++++++++++++++++++++ data/com.example.first_application.desktop | 8 +++++ data/com.example.first_application.svg | 8 +++++ data/meson.build | 10 ++++++ meson.build | 9 +++++ src/main.py | 34 +++++++++++++++++++ src/meson.build | 7 ++++ 8 files changed, 127 insertions(+) create mode 100755 build-aux/meson/postinstall.py create mode 100644 com.example.first_application.json create mode 100644 data/com.example.first_application.desktop create mode 100644 data/com.example.first_application.svg create mode 100644 data/meson.build create mode 100644 meson.build create mode 100755 src/main.py create mode 100644 src/meson.build diff --git a/build-aux/meson/postinstall.py b/build-aux/meson/postinstall.py new file mode 100755 index 0000000..f39c172 --- /dev/null +++ b/build-aux/meson/postinstall.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 + +from os import environ, path +from subprocess import call + +prefix = environ.get('MESON_INSTALL_PREFIX', '/usr/local') +datadir = path.join(prefix, 'share') +destdir = environ.get('DESTDIR', '') + +# Package managers set this so we don't need to run +if not destdir: + print('Updating icon cache...') + call(['gtk-update-icon-cache', '-qtf', path.join(datadir, 'icons', 'hicolor')]) diff --git a/com.example.first_application.json b/com.example.first_application.json new file mode 100644 index 0000000..a1adb68 --- /dev/null +++ b/com.example.first_application.json @@ -0,0 +1,38 @@ +{ + "app-id": "com.example.first_application", + "runtime": "org.gnome.Platform", + "runtime-version": "master", + "sdk": "org.gnome.Sdk", + "command": "your-first-application", + "finish-args": [ + "--socket=wayland" + ], + "build-options": { + "env": { + "V": "1" + } + }, + "cleanup": [ + "/lib/pkgconfig", + "/man", + "/share/doc", + "/share/gtk-doc", + "/share/man", + "/share/pkgconfig" + ], + "modules": [ + { + "name": "first-application", + "buildsystem": "meson", + "builddir": true, + "subdir": "First_Application", + "sources": [ + { + "branch": "master", + "type": "git", + "url": "https://source.puri.sm/david.boddie/tutorials.git" + } + ] + } + ] +} diff --git a/data/com.example.first_application.desktop b/data/com.example.first_application.desktop new file mode 100644 index 0000000..1a79679 --- /dev/null +++ b/data/com.example.first_application.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Name=Your First Application +Icon=com.example.first_application +Exec=your-first-application +Terminal=false +Type=Application +Categories= +StartupNotify=false diff --git a/data/com.example.first_application.svg b/data/com.example.first_application.svg new file mode 100644 index 0000000..5a9e6e3 --- /dev/null +++ b/data/com.example.first_application.svg @@ -0,0 +1,8 @@ + + + + + + + diff --git a/data/meson.build b/data/meson.build new file mode 100644 index 0000000..a4fab63 --- /dev/null +++ b/data/meson.build @@ -0,0 +1,10 @@ +configure_file( + input: 'com.example.first_application.desktop', + output: 'com.example.first_application.desktop', + copy: true, + install: true, + install_dir: join_paths(get_option('datadir'), 'applications') +) + +install_data('com.example.first_application.svg', + install_dir: join_paths(get_option('datadir'), 'icons', 'hicolor', 'scalable', 'apps')) diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..d2d2b8e --- /dev/null +++ b/meson.build @@ -0,0 +1,9 @@ +project('first-application', + version: '0.1.0', + meson_version: '>= 0.40.0', +) + +subdir('data') +subdir('src') + +meson.add_install_script('build-aux/meson/postinstall.py') diff --git a/src/main.py b/src/main.py new file mode 100755 index 0000000..61eb17b --- /dev/null +++ b/src/main.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Copyright (C) 2018 Purism SPC +# SPDX-License-Identifier: GPL-3.0+ +# Author: David Boddie + +import sys +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import GLib, Gtk + + +class Application(Gtk.Application): + + def __init__(self): + super().__init__(application_id='com.example.first_application') + GLib.set_application_name('Your First Application') + + def do_activate(self): + window = Gtk.ApplicationWindow(application=self) + window.set_icon_name('com.example.first_application') + + label = Gtk.Label() + label.set_markup('Hello World!') + window.add(label) + window.show_all() + + +if __name__ == "__main__": + + app = Application() + result = app.run(sys.argv) + sys.exit(result) diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..cf70c27 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,7 @@ +configure_file( + input: 'main.py', + output: 'your-first-application', + copy: true, + install: true, + install_dir: get_option('bindir') +)