Commit 56106435 authored by David Boddie's avatar David Boddie

Moved the images out of the application resources, even though they are very

small.
Moved the UI and CSS files into the src directory to comply with conventions
that other applications tend to follow.
Updated the meson.build files to install the images in the pkgdatadir.
Added a template Python module to hold configuration values, following the
convention used by Vala applications. This makes it easier for the
application to find installation information at run-time.
parent f5d1ee78
pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
gnome = import('gnome')
gnome.compile_resources('treasure',
'treasure.gresource.xml',
gresource_bundle: true,
install: true,
install_dir: pkgdatadir,
)
desktop_file = i18n.merge_file(
input: 'sm.puri.treasure.desktop.in',
output: 'sm.puri.treasure.desktop',
......@@ -50,3 +41,14 @@ if compile_schemas.found()
args: ['--strict', '--dry-run', meson.current_source_dir()]
)
endif
# Install icons to the appropriate locations for their themes:
install_data (join_paths('icons', 'hicolor', 'scalable', 'apps', 'treasure.svg'),
install_dir: join_paths(get_option('datadir'), 'icons', 'hicolor', 'scalable', 'apps'))
# Install images to application-specific locations:
install_subdir('images',
install_dir: pkgdatadir
)
......@@ -28,6 +28,8 @@ directory. This typically contains files that are generated by an IDE (such
as GNOME Builder) when the project is created and those that the developer
creates.
In this example
Data Files (data)
-----------------
VERSION = '@VERSION@'
pkgdatadir = '@pkgdatadir@'
localedir = '@localedir@'
......@@ -5,18 +5,22 @@
# SPDX-License-Identifier: GPL-3.0+
# Author: David Boddie <david.boddie@puri.sm>
import random
import sys
import os, random, sys
from . import config
import gi
gi.require_version('GdkPixbuf', '2.0')
gi.require_version('Gtk', '3.0')
from gi.repository import Gio, GLib, Gtk
from gi.repository import GdkPixbuf, Gio, GLib, Gtk
gi.require_version('Handy', '0.0')
from gi.repository import Handy
Handy.init()
class Application(Gtk.Application):
_images = ['dug1.svg', 'dug2.svg', 'ground.svg', 'treasure.svg']
def __init__(self):
super().__init__(application_id='sm.puri.treasure')
GLib.set_application_name(_('Treasure'))
......@@ -35,6 +39,14 @@ class Application(Gtk.Application):
self.css = Gtk.CssProvider()
self.css.load_from_resource('/sm/puri/treasure/ui/style.css')
# Load images from the application's data directory and store them
# as pixbufs.
self.pixbufs = {}
for image in self._images:
self.pixbufs[image] = GdkPixbuf.Pixbuf.new_from_file(
os.path.join(config.pkgdatadir, 'images', image))
# Get the window from the builder.
self.window = builder.get_object('window')
self.window.set_property('application', self)
......@@ -97,7 +109,7 @@ class Application(Gtk.Application):
# Create a widget for each tile.
for row in range(self.rows):
for column in range(self.columns):
image = Gtk.Image(resource='/sm/puri/treasure/images/ground.svg')
image = Gtk.Image.new_from_pixbuf(self.pixbufs['ground.svg'])
button = Gtk.Button(image=image, relief=Gtk.ReliefStyle.NONE)
# Apply a style defined in the style sheet to the button,
......@@ -135,23 +147,23 @@ class Application(Gtk.Application):
pos = self.cells[widget]
if widget.get_image().props.resource != '/sm/puri/treasure/images/ground.svg':
if widget.get_image().get_pixbuf() != self.pixbufs['ground.svg']:
return
self.turns += 1
self.update_turns_label()
if pos == self.treasure_pos:
widget.set_image(Gtk.Image(resource='/sm/puri/treasure/images/treasure.svg'))
widget.set_image(Gtk.Image.new_from_pixbuf(self.pixbufs['treasure.svg']))
self.turns_label.set_text(_('Well done! You found the treasure in {0} turns.').format(self.turns))
self.won = True
else:
if random.randint(0, 1) == 0:
res = '/sm/puri/treasure/images/dug1.svg'
pixbuf = self.pixbufs['dug1.svg']
else:
res = '/sm/puri/treasure/images/dug2.svg'
pixbuf = self.pixbufs['dug2.svg']
widget.set_image(Gtk.Image(resource=res))
widget.set_image(Gtk.Image.new_from_pixbuf(pixbuf))
def main(version):
......
pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
moduledir = join_paths(pkgdatadir, 'treasure')
gnome = import('gnome')
gnome.compile_resources('treasure',
'treasure.gresource.xml',
gresource_bundle: true,
install: true,
install_dir: pkgdatadir,
)
python3 = import('python3')
......@@ -17,6 +25,14 @@ configure_file(
install_dir: get_option('bindir')
)
configure_file(
input: 'config.py.in',
output: 'config.py',
configuration: conf,
install: true,
install_dir: moduledir
)
treasure_sources = [
'__init__.py',
'main.py',
......
......@@ -4,9 +4,5 @@
<file>ui/menus.ui</file>
<file>ui/window.ui</file>
<file>ui/style.css</file>
<file>images/dug1.svg</file>
<file>images/dug2.svg</file>
<file>images/ground.svg</file>
<file>images/treasure.svg</file>
</gresource>
</gresources>
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