Commit 85560daf authored by David Boddie's avatar David Boddie

Add the code for a resources tutorial

parent 0aaabbb3
#!/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')])
print('Updating desktop database...')
call(['update-desktop-database', '-q', path.join(datadir, 'applications')])
{
"app-id": "com.example.app_resources",
"runtime": "org.gnome.Platform",
"runtime-version": "3.30",
"sdk": "org.gnome.Sdk",
"command": "app-resources",
"finish-args": [
"--socket=wayland"
],
"modules": [
{
"name": "app_resources",
"buildsystem": "meson",
"builddir": true,
"sources": [
{
"type": "dir",
"path": "."
}
]
}
]
}
[Desktop Entry]
Name=App Resources
Icon=com.example.app_resources
Exec=app-resources
Terminal=false
Type=Application
Categories=
StartupNotify=false
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<svg xmlns="http://www.w3.org/2000/svg" height="64" version="1.1" width="64"
viewBox="0 0 100 100">
<path d="M 50,5 l 45,25 l -45,25 l -45,-25 z" stroke="black" fill="#c08040" />
<path d="M 95,30 l 0,40 l -45,25 l 0,-40 z" stroke="black" fill="#a06020" />
<path d="M 5,30 l 45,25 l 0,40 l -45,-25 z" stroke="black" fill="#804010" />
</svg>
configure_file(
input: 'com.example.app_resources.desktop',
output: 'com.example.app_resources.desktop',
copy: true,
install: true,
install_dir: join_paths(get_option('datadir'), 'applications')
)
install_data('com.example.app_resources.svg',
install_dir: join_paths(get_option('datadir'), 'icons', 'hicolor', 'scalable', 'apps'))
project('app_resources',
version: '0.1.0',
meson_version: '>= 0.48.0',
)
subdir('data')
subdir('src')
meson.add_install_script('build-aux/meson/postinstall.py')
#!@PYTHON@
# -*- coding: utf-8 -*-
# Copyright (C) 2019 Purism SPC
# SPDX-License-Identifier: GPL-3.0+
# Author: David Boddie <david.boddie@puri.sm>
import os
import signal
import sys
VERSION = '@VERSION@'
pkgdatadir = '@pkgdatadir@'
sys.path.insert(1, pkgdatadir)
signal.signal(signal.SIGINT, signal.SIG_DFL)
if __name__ == '__main__':
import gi
from gi.repository import Gio
res = Gio.Resource.load(os.path.join(pkgdatadir, 'app_resources.gresource'))
# Register the resource globally within the application.
res._register()
from app_resources import main
sys.exit(main.main(VERSION))
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/com/example/app_resources">
<file>images/picture.svg</file>
</gresource>
</gresources>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<svg xmlns="http://www.w3.org/2000/svg" height="600" version="1.1" width="600"
viewBox="0 0 600 600">
<defs>
<linearGradient id="background" x2="0%" y2="100%" spreadMethod="reflect">
<stop offset="0%" stop-color="#202040" opacity="0" />
<stop offset="100%" stop-color="#202020" />
</linearGradient>
<radialGradient id="sphere" fx="75%" fy="25%">
<stop offset="0%" stop-color="white" />
<stop offset="25%" stop-color="#a0ffa0" />
<stop offset="100%" stop-color="#002000" />
</radialGradient>
</defs>
<rect x="0" y="0" width="600" height="600" stroke="none" fill="url(#background)" />
<circle cx="300" cy="300" r="200" stroke="none" fill="url(#sphere)" />
</svg>
# -*- coding: utf-8 -*-
# Copyright (C) 2019 Purism SPC
# SPDX-License-Identifier: GPL-3.0+
# Author: David Boddie <david.boddie@puri.sm>
import sys
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio, GLib, Gtk
class Application(Gtk.Application):
def __init__(self):
super().__init__(application_id='com.example.app_resources')
GLib.set_application_name('App Resources')
def do_activate(self):
window = Gtk.ApplicationWindow(application=self)
window.set_icon_name('com.example.app_resources')
image = Gtk.Image.new_from_resource('/com/example/app_resources/images/picture.svg')
window.add(image)
window.show_all()
def main(version):
app = Application()
return app.run(sys.argv)
# Initialize local variables to hold installation paths.
pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
moduledir = join_paths(pkgdatadir, meson.project_name())
# Find the python3 program to help define the PYTHON configuration variable
# that will be used in the app-resources.in template.
python3 = find_program('python3')
conf = configuration_data()
conf.set('PYTHON', python3.path())
conf.set('VERSION', meson.project_version())
conf.set('pkgdatadir', pkgdatadir)
# Replace placeholders in templates with the configuration data defined above
# and create the versions of these files for installation in the build
# directory.
configure_file(
input: 'app-resources.in',
output: 'app-resources',
configuration: conf,
install: true,
install_dir: get_option('bindir')
)
# Declare the application's sources and their installation directory.
sources = [
'__init__.py',
'main.py'
]
install_data(sources, install_dir: moduledir)
# Import the gnome module and use a GNOME function to ensure that application
# resources will be compiled.
gnome = import('gnome')
gnome.compile_resources('app_resources',
'app_resources.gresource.xml',
gresource_bundle: true,
install: true,
install_dir: pkgdatadir,
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment