1#
2# Gramps - a GTK+/GNOME based genealogy program
3#
4# Copyright (C) 2002-2006  Donald N. Allingham
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19#
20
21#-------------------------------------------------------------------------
22#
23# Python modules
24#
25#-------------------------------------------------------------------------
26import os
27import webbrowser
28import sys
29from urllib.parse import quote
30#------------------------------------------------------------------------
31#
32# Gramps modules
33#
34#------------------------------------------------------------------------
35from gramps.gen.const import GRAMPS_LOCALE as glocale
36from gramps.gen.const import URL_MANUAL_PAGE, URL_WIKISTRING
37from gramps.gen.constfunc import is_quartz, mac
38from gramps.gen.config import config
39from .utils import open_file_with_default_application as run_file
40
41#list of manuals on wiki, map locale code to wiki extension, add language codes
42#completely, or first part, so pt_BR if Brazilian portugeze wiki manual, and
43#nl for Dutch (nl_BE, nl_NL language code)
44MANUALS = {
45    'nl' : '/nl',
46    'fr' : '/fr',
47    'sq' : '/sq',
48    'mk' : '/mk',
49    'de' : '/de',
50    'fi' : '/fi',
51    'ru' : '/ru',
52    'sk' : '/sk',
53}
54
55#first, determine language code, so nl_BE --> wiki /nl
56lang = glocale.language[0]
57if lang in MANUALS:
58    EXTENSION = MANUALS[lang]
59else:
60    EXTENSION = ''
61
62def display_help(webpage='', section=''):
63    """
64    Display the specified webpage and section from the Gramps wiki.
65    """
66    if not webpage:
67        link = URL_WIKISTRING + URL_MANUAL_PAGE + EXTENSION
68    else:
69        link = URL_WIKISTRING + quote(webpage) + EXTENSION
70        if section:
71            link += '#' + quote(section.replace(' ', '_')).replace('%', '.')
72    display_url(link)
73
74def display_url(link, uistate=None):
75    """
76    Open the specified URL in a browser.
77    """
78    if (mac() and sys.version_info.major == 3 and sys.version_info.minor < 5):
79        import subprocess
80        proc = subprocess.call(['/usr/bin/open', link],
81                               stderr=subprocess.STDOUT)
82    else:
83        webbrowser.open_new_tab(link)
84