2
# Gramps - a GTK+/GNOME based genealogy program
4
# Copyright (C) 2000-2006 Donald N. Allingham
5
# Copyright (C) 2009 Brian G. Matherly
6
# Copyright (C) 2009 Peter G. Landgren
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
Some independent constants/functions that can be safely imported
26
without any translation happening yet. Do _not_ add imports that will
27
perform a translation on import, eg Gtk.
30
#------------------------------------------------------------------------
34
#------------------------------------------------------------------------
38
#-------------------------------------------------------------------------
41
# Never test on LINUX, handle Linux in the else statement as default
43
#-------------------------------------------------------------------------
44
LINUX = ["Linux", "linux", "linux2"]
45
MACOS = ["Darwin", "darwin"]
46
WINDOWS = ["Windows", "win32"]
48
#-------------------------------------------------------------------------
52
#-------------------------------------------------------------------------
54
#python 2 and 3 support, use correct conversion to unicode
55
if sys.version_info[0] < 3:
56
conv_to_unicode = unicode
57
conv_to_unicode_direct = unicode
61
def conv_to_unicode(x, y):
62
if isinstance(x, str):
66
conv_to_unicode_direct = str
69
cuni = conv_to_unicode_direct
71
# handle in database is bytes, while internally Gramps wants unicode for py3
72
if sys.version_info[0] < 3:
73
handle2internal = lambda x: x
75
handle2internal = lambda x: conv_to_unicode(x, 'utf-8')
77
#-------------------------------------------------------------------------
79
# Platform determination functions
81
#-------------------------------------------------------------------------
85
Return True if a linux system
86
Note: Normally do as linux in else statement of a check !
88
if platform.system() in LINUX:
94
Return True if a Macintosh system
96
if platform.system() in MACOS:
102
Return True if a windows system
104
if platform.system() in WINDOWS:
108
## The following functions do import gtk, but only when called. They
109
## should only be called after translation system has been
114
Tests to see if Python is currently running with gtk and
115
windowing system is Mac OS-X's "quartz".
119
from gi.repository import Gtk
120
from gi.repository import Gdk
123
return Gdk.Display.get_default().__class__.__name__.endswith("QuartzDisplay")
128
Tests to see if Python is currently running with gtk
130
# FIXME: currently, Gtk.init_check() requires all strings
131
# in argv, and we might have unicode.
132
temp, sys.argv = sys.argv, sys.argv[:1]
134
from gi.repository import Gtk
135
from gi.repository import Gdk
140
test = Gtk.init_check(temp) and \
141
Gdk.Display.get_default()
148
# A couple of places add menu accelerators using <alt>, which doesn't
149
# work with Gtk-quartz. <Meta> is the usually correct replacement, but
150
# in one case the key is a number, and <meta>number is used by Spaces
151
# (a mac feature), so we'll use control instead.
155
Returns a string to pass to an accelerator map.