Use PREFIX in install rule.
[SysBars.git] / compat.py
blob9d0e8d4fa5295ac9995fd40e18e25191a6d5e896
1 """ Stuff that works a bit differently depending on whether we're running in
2 a ROX or GNOME environment.
3 """
5 import os
7 import gtk as g
9 _app_info = None
11 def init_rox():
12 global get_app_info, get_logo, quit, load_first_config, save_config_path
13 get_app_info = get_app_info_rox
14 get_logo = get_logo_rox
15 quit = quit_rox
16 load_first_config = load_first_config_rox
17 save_config_path = save_config_path_rox
20 def init_gnome():
21 global get_app_info, get_logo, quit, load_first_config, save_config_path
22 get_app_info = get_app_info_gnome
23 get_logo = get_logo_gnome
24 quit = quit_gnome
25 load_first_config = load_first_config_gnome
26 save_config_path = save_config_path_gnome
29 def get_app_info_rox():
30 import rox
31 from rox import AppInfo
32 global _app_info
33 if not _app_info:
34 app_info = AppInfo.AppInfo(os.path.join(rox.app_dir, 'AppInfo.xml'))
35 _app_info = (app_info.getAuthors(),
36 app_info.findElements('Version')[0].firstChild.nodeValue.split()[0])
37 return _app_info
40 def get_logo_rox(size = 64):
41 import rox
42 return g.gdk.pixbuf_new_from_file_at_size( \
43 os.path.join(rox.app_dir, '.DirIcon'), size, size)
46 def quit_rox():
47 import rox
48 rox.toplevel_unref()
49 g.main_quit()
52 def load_first_config_rox(uri, appname, leafname):
53 from rox import basedir
54 return basedir.load_first_config(uri, appname, leafname)
57 def save_config_path_rox(uri, appname):
58 from rox import basedir
59 return basedir.save_config_path(uri, appname)
62 def get_app_info_gnome():
63 import prefix
64 global _app_info
65 if not _app_info:
66 version = None
67 authors = None
68 fp = open(os.path.join(prefix.share_dir, 'AppInfo.xml'))
69 for l in fp.readlines():
70 if '<Version>' in l:
71 version = l.split('>', 1)[1].split(' ', 1)[0]
72 if authors:
73 break
74 elif '<Authors>' in l:
75 authors = l.split('>', 1)[1].split('<', 1)[0]
76 if version:
77 break
78 fp.close()
79 _app_info = (authors, version)
80 return _app_info
83 def get_logo_gnome(size = 64):
84 import prefix
85 return g.gdk.pixbuf_new_from_file_at_size( \
86 os.path.join(prefix.icons_dir, 'sysbars.svg'),
87 size, size)
90 def quit_gnome():
91 g.main_quit()
94 def _xdg_config_home():
95 return os.path.expanduser(os.environ.get('XDG_CONFIG_HOME', '~/.config'))
98 def load_first_config_gnome(uri, appname, leafname):
99 for d in [_xdg_config_home()] + \
100 os.environ.get('XDG_CONFIG_DIRS', '/etc/xdg').split(':'):
101 f = os.path.join(d, uri, appname, leafname)
102 if os.path.exists(f):
103 return f
104 return None
107 def save_config_path_gnome(uri, appname):
108 d = os.path.join(_xdg_config_home(), uri, appname)
109 if not os.path.isdir(d):
110 os.makedirs(d, 0755)
111 return d