Skip to content

Commit

Permalink
Use correct root directory when searching for data files
Browse files Browse the repository at this point in the history
  • Loading branch information
innir committed Dec 30, 2016
1 parent 8143a90 commit 0d11280
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 4 additions & 3 deletions bin/gtranscribe
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class gTranscribeWindow:
def __init__(self):
builder = Gtk.Builder()
builder.set_translation_domain('gTranscribe')
builder.add_from_file(get_data_file('ui', 'gTranscribe.glade'))
builder.add_from_file(get_data_file(PROJECT_ROOT_DIRECTORY, 'ui',
'gTranscribe.glade'))
builder.connect_signals(self)
self.window = builder.get_object("gtranscribe_window")

Expand All @@ -71,8 +72,8 @@ class gTranscribeWindow:
icon = icon_theme.load_icon('gtranscribe', 128, 0)
else:
icon = GdkPixbuf.Pixbuf.new_from_file_at_scale(
get_data_file('icons', 'scalable', 'apps', 'gtranscribe.svg'),
128, 128, 0)
get_data_file(PROJECT_ROOT_DIRECTORY, 'icons', 'scalable',
'apps', 'gtranscribe.svg'), 128, 128, 0)
self.window.set_default_icon(icon)

self.text_view = builder.get_object("text_view")
Expand Down
8 changes: 3 additions & 5 deletions gtranscribe/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,14 @@ def md5_of_file(fname):
return md5.hexdigest()


def get_data_file(*path_segments):
def get_data_file(root_dir, *path_segments):
"""Return the absolute path of the given data file."""
# Where to look for data (ui and image files). By default,
# this is ../data, relative your trunk layout
data_directory = os.path.abspath(
os.path.join(os.path.dirname(__file__), '../data/'))
data_directory = os.path.join(root_dir, 'data/')

# If this path does not exist fall back to system wide directory
if not os.path.exists(data_directory):
data_directory = os.path.abspath(
os.path.join(os.path.dirname(__file__), '../share/gTranscribe/'))
data_directory = os.path.join(root_dir, 'share/gTranscribe/')

return os.path.join(data_directory, *path_segments)

0 comments on commit 0d11280

Please sign in to comment.