gramps/gramps/gui/display.py
Paul Culley 44180b45e2
Help issues for bug 9042 (#738)
* Media Manager: add help button and remove '...'

Issue #9042

* Edit/Preferences: add Help button

Issue #9042

* Style Editor, Document Styles dialog: add help buttons

Issue #9042

* Fix Select Person dialog Help button URL

Issue #9042

* Fix Select Repository dialog Help button URL

Issue #9042

* Relationship Calculator: Add help button

Issue #9042

* Reorder Relationships dialog; add Help button

Issue #9042

* Generate Book Dialog; Fix Help URL

Issue #9042

* Manage Book dialog; add help button

Issue #9042

* Fix Detached Gramplets Help button URL when 'help_url' not in .gpr

Issue #9042

* Fix help URLs when they contain illegal characters and to match wiki
section targetID algorithm

Issue #9042
2018-12-20 09:10:58 -06:00

84 lines
2.7 KiB
Python

#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2002-2006 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
#-------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
import os
import webbrowser
import sys
from urllib.parse import quote
#------------------------------------------------------------------------
#
# Gramps modules
#
#------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale
from gramps.gen.const import URL_MANUAL_PAGE, URL_WIKISTRING
from gramps.gen.constfunc import is_quartz, mac
from gramps.gen.config import config
from .utils import open_file_with_default_application as run_file
#list of manuals on wiki, map locale code to wiki extension, add language codes
#completely, or first part, so pt_BR if Brazilian portugeze wiki manual, and
#nl for Dutch (nl_BE, nl_NL language code)
MANUALS = {
'nl' : '/nl',
'fr' : '/fr',
'sq' : '/sq',
'mk' : '/mk',
'de' : '/de',
'fi' : '/fi',
'ru' : '/ru',
'sk' : '/sk',
}
#first, determine language code, so nl_BE --> wiki /nl
lang = glocale.language[0]
if lang in MANUALS:
EXTENSION = MANUALS[lang]
else:
EXTENSION = ''
def display_help(webpage='', section=''):
"""
Display the specified webpage and section from the Gramps wiki.
"""
if not webpage:
link = URL_WIKISTRING + URL_MANUAL_PAGE + EXTENSION
else:
link = URL_WIKISTRING + quote(webpage) + EXTENSION
if section:
link += '#' + quote(section.replace(' ', '_')).replace('%', '.')
display_url(link)
def display_url(link, uistate=None):
"""
Open the specified URL in a browser.
"""
if (mac() and sys.version_info.major == 3 and sys.version_info.minor < 5):
import subprocess
proc = subprocess.call(['/usr/bin/open', link],
stderr=subprocess.STDOUT)
else:
webbrowser.open_new_tab(link)