changeset 572:7f113f15300b

Include the Glade file in the main package on install.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 09 Jul 2014 23:44:53 +0200
parents e992927f07a8
children 4233c1c01d90
files pytouhou/menu.py setup.py
diffstat 2 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/menu.py	Thu Jul 10 14:35:02 2014 +0200
+++ b/pytouhou/menu.py	Wed Jul 09 23:44:53 2014 +0200
@@ -15,9 +15,10 @@
 from pytouhou.utils.helpers import get_logger
 logger = get_logger(__name__)
 
-from gi.repository import Gtk, Gdk
+from gi.repository import Gtk, Gdk, GLib
 
 import sys
+import os
 import re
 
 GL_VERSION_REGEX = re.compile(r'^\d\.\d$')
@@ -293,7 +294,10 @@
     handler = Handler(config, args)
 
     builder = Gtk.Builder()
-    builder.add_from_file('data/menu.glade')
+    try:
+        builder.add_from_file(os.path.join(os.path.dirname(__file__), 'data', 'menu.glade'))
+    except GLib.GError:
+        builder.add_from_file(os.path.join('data', 'menu.glade'))
     builder.connect_signals(handler)
 
     handler.init_gtk(builder)
--- a/setup.py	Thu Jul 10 14:35:02 2014 +0200
+++ b/setup.py	Wed Jul 09 23:44:53 2014 +0200
@@ -137,6 +137,13 @@
              'executables': [Executable(script='scripts/pytouhou', base=base)]}
 
 
+# Create a link to the data files (for packaging purposes)
+current_dir = os.path.dirname(os.path.realpath(__file__))
+temp_data_dir = os.path.join(current_dir, 'pytouhou', 'data')
+if not os.path.exists(temp_data_dir):
+    os.symlink(os.path.join(current_dir, 'data'), temp_data_dir)
+
+
 setup(name='PyTouhou',
       version='0.1',
       author='Thibaut Girka',
@@ -153,4 +160,10 @@
                                               'MAX_SOUNDS': 26,
                                               'USE_OPENGL': use_opengl}),
       scripts=['scripts/pytouhou'] + (['scripts/anmviewer'] if anmviewer else []),
+      package_data={'pytouhou': ['data/menu.glade']},
       **extra)
+
+
+# Remove the link afterwards
+if os.path.exists(temp_data_dir):
+    os.unlink(temp_data_dir)