1
# -*- coding: utf-8; -*-
3
Copyright (C) 2007-2013 Guake authors
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as
7
published by the Free Software Foundation; either version 2 of the
8
License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
General Public License for more details.
15
You should have received a copy of the GNU General Public
16
License along with this program; if not, write to the
17
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
Boston, MA 02110-1301 USA
20
from __future__ import absolute_import
29
# Internationalization purposes.
32
__all__ = ['_', 'ShowableError', 'test_gconf',
33
'pixmapfile', 'gladefile', 'hexify_color',
34
'get_binaries_from_path']
37
class ShowableError(Exception):
39
def __init__(self, title, msg, exit_code=1):
40
d = gtk.MessageDialog(type=gtk.MESSAGE_ERROR,
41
buttons=gtk.BUTTONS_CLOSE)
42
d.set_markup('<b><big>%s</big></b>' % title)
43
d.format_secondary_markup(msg)
51
c = gconf.client_get_default()
52
return c.dir_exists('/apps/guake')
56
f = os.path.join(guake.globals.IMAGE_DIR, x)
57
if not os.path.exists(f):
58
raise IOError('No such file or directory: %s' % f)
59
return os.path.abspath(f)
63
f = os.path.join(guake.globals.GLADE_DIR, x)
64
if not os.path.exists(f):
65
raise IOError('No such file or directory: %s' % f)
66
return os.path.abspath(f)
70
h = lambda x: hex(x).replace('0x', '').zfill(4)
71
return '#%s%s%s' % (h(c.red), h(c.green), h(c.blue))
74
def get_binaries_from_path(compiled_re):
76
for i in os.environ.get('PATH', '').split(os.pathsep):
78
for j in os.listdir(i):
79
if compiled_re.match(j):
80
ret.append(os.path.join(i, j))
84
def shell_quote(text):
85
""" quote text (filename) for inserting into a shell """
86
return r"\'".join("'%s'" % p for p in text.split("'"))
89
def clamp(value, lower, upper):
90
return max(min(value, upper), lower)