~ubuntu-branches/ubuntu/trusty/gramps/trusty-proposed

« back to all changes in this revision

Viewing changes to gramps/gen/constfunc.py

  • Committer: Package Import Robot
  • Author(s): Ross Gammon
  • Date: 2014-02-03 17:28:04 UTC
  • mfrom: (39.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20140203172804-76y7nwxiw92zhlnj
Tags: 4.0.3+dfsg-1
* New upstream release (Closes: #720858)
* To-do notes improved and made persistent (Closes: #680692)
* Applied patch to setup.py to fix resource path problem
* Applied patch to disable the optional HTML View & prevent a crash
* Remove sourceless javascript files (Closes: #736436)
* Gramps uses Bat Mitzva internally (Closes: #502532)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Gramps - a GTK+/GNOME based genealogy program
 
3
#
 
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.
 
11
#
 
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.
 
16
#
 
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
 
20
#
 
21
 
 
22
# $Id$
 
23
 
 
24
"""
 
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.
 
28
"""
 
29
 
 
30
#------------------------------------------------------------------------
 
31
#
 
32
# python modules
 
33
#
 
34
#------------------------------------------------------------------------
 
35
import platform
 
36
import sys
 
37
 
 
38
#-------------------------------------------------------------------------
 
39
#
 
40
# Platforms
 
41
# Never test on LINUX, handle Linux in the else statement as default
 
42
#
 
43
#-------------------------------------------------------------------------
 
44
LINUX = ["Linux", "linux", "linux2"]
 
45
MACOS = ["Darwin", "darwin"]
 
46
WINDOWS = ["Windows", "win32"]
 
47
 
 
48
#-------------------------------------------------------------------------
 
49
#
 
50
# Public Functions
 
51
#
 
52
#-------------------------------------------------------------------------
 
53
 
 
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
 
58
    STRTYPE = basestring
 
59
    UNITYPE = unicode
 
60
else:
 
61
    def conv_to_unicode(x, y):
 
62
        if isinstance(x, str):
 
63
            return x
 
64
        else:
 
65
            return x.decode(y)
 
66
    conv_to_unicode_direct = str
 
67
    STRTYPE = str
 
68
    UNITYPE = str
 
69
cuni = conv_to_unicode_direct
 
70
 
 
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
 
74
else:
 
75
    handle2internal = lambda x: conv_to_unicode(x, 'utf-8')
 
76
 
 
77
#-------------------------------------------------------------------------
 
78
#
 
79
# Platform determination functions
 
80
#
 
81
#-------------------------------------------------------------------------
 
82
 
 
83
def lin():
 
84
    """
 
85
    Return True if a linux system
 
86
    Note: Normally do as linux in else statement of a check !
 
87
    """
 
88
    if platform.system() in LINUX:
 
89
        return True
 
90
    return False
 
91
    
 
92
def mac():
 
93
    """
 
94
    Return True if a Macintosh system
 
95
    """
 
96
    if platform.system() in MACOS:
 
97
        return True
 
98
    return False
 
99
 
 
100
def win():
 
101
    """
 
102
    Return True if a windows system
 
103
    """
 
104
    if platform.system() in WINDOWS:
 
105
        return True
 
106
    return False
 
107
 
 
108
## The following functions do import gtk, but only when called. They
 
109
## should only be called after translation system has been
 
110
## initialized!
 
111
 
 
112
def is_quartz():
 
113
    """
 
114
    Tests to see if Python is currently running with gtk and 
 
115
    windowing system is Mac OS-X's "quartz".
 
116
    """
 
117
    if mac():
 
118
        try:
 
119
            from gi.repository import Gtk
 
120
            from gi.repository import Gdk
 
121
        except:
 
122
            return False
 
123
        return Gdk.Display.get_default().__class__.__name__.endswith("QuartzDisplay")
 
124
    return False
 
125
 
 
126
def has_display():
 
127
    """
 
128
    Tests to see if Python is currently running with gtk 
 
129
    """
 
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]
 
133
    try:
 
134
        from gi.repository import Gtk
 
135
        from gi.repository import Gdk
 
136
    except:
 
137
        return False
 
138
 
 
139
    try:
 
140
        test = Gtk.init_check(temp) and \
 
141
            Gdk.Display.get_default()
 
142
        sys.argv = temp
 
143
        return bool(test)
 
144
    except:
 
145
        sys.argv = temp
 
146
        return False
 
147
 
 
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.
 
152
 
 
153
def mod_key():
 
154
    """
 
155
    Returns a string to pass to an accelerator map.
 
156
    """
 
157
 
 
158
    if is_quartz():
 
159
        return "<ctrl>"
 
160
 
 
161
    return "<alt>"