Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
def get_identity():
    if lin():
        platform = "X11"
    elif win():
        platform = "Windows"
    elif mac():
        platform = "Macintosh"
    else:
        platform = "Unknown"
    lang = glocale.lang[:5].replace('_','-')
    return "Mozilla/5.0 (%s; U; %s) Gramps/3.2" % ( platform, lang)
Exemple #4
0
def get_identity():
    if lin():
        platform = "X11"
    elif win():
        platform = "Windows"
    elif mac():
        platform = "Macintosh"
    else:
        platform = "Unknown"
    lang = glocale.lang[:5].replace('_', '-')
    return "Mozilla/5.0 (%s; U; %s) Gramps/3.2" % (platform, lang)
Exemple #5
0
 def make_tooltip_from_link(self, link_tag):
     """
     Return a string useful for a tooltip given a LinkTag object.
     """
     from gramps.gen.simple import SimpleAccess
     win_obj = find_parent_with_attr(self, attr="dbstate")
     display = link_tag.data
     if win_obj:
         simple_access = SimpleAccess(win_obj.dbstate.db)
         url = link_tag.data
         if url.startswith("gramps://"):
             obj_class, prop, value = url[9:].split("/")
             display = simple_access.display(obj_class, prop, value) or url
     return display + ((_("\nCommand-Click to follow link") if mac() else _(
         "\nCtrl-Click to follow link")) if self.get_editable() else '')
Exemple #6
0
def open_file_with_default_application(path, uistate):
    """
    Launch a program to open an arbitrary file. The file will be opened using
    whatever program is configured on the host as the default program for that
    type of file.

    :param file_path: The path to the file to be opened.
                      Example: "c:\\foo.txt"
    :type file_path: string
    :return: nothing
    """

    errstrings = None

    norm_path = os.path.normpath(path)
    if not os.path.exists(norm_path):
        display_error_dialog(0,
                             _("File %s does not exist") % norm_path, uistate)
        return

    if win():
        try:
            os.startfile(norm_path)
        except WindowsError as msg:
            display_error_dialog(0, str(msg), uistate)

        return

    if mac():
        utility = '/usr/bin/open'
    else:
        utility = 'xdg-open'
        errstrings = {
            1: 'Error in command line syntax.',
            2: 'One of the files passed on the command line did not exist.',
            3: ' A required tool could not be found.',
            4: 'The action failed.'
        }

    proc = subprocess.Popen([utility, norm_path], stderr=subprocess.STDOUT)

    from gi.repository import GLib
    GLib.timeout_add_seconds(1, poll_external, (proc, errstrings, uistate))
    return
Exemple #7
0
def open_file_with_default_application(path, uistate):
    """
    Launch a program to open an arbitrary file. The file will be opened using
    whatever program is configured on the host as the default program for that
    type of file.

    :param file_path: The path to the file to be opened.
                      Example: "c:\\foo.txt"
    :type file_path: string
    :return: nothing
    """

    errstrings = None

    norm_path = os.path.normpath(path)
    if not os.path.exists(norm_path):
        display_error_dialog(0, _("File %s does not exist") % norm_path,
                             uistate)
        return

    if win():
        try:
            os.startfile(norm_path)
        except WindowsError as msg:
            display_error_dialog(0, str(msg),
                             uistate)

        return

    if mac():
        utility = '/usr/bin/open'
    else:
        utility = 'xdg-open'
        errstrings = {1:'Error in command line syntax.',
                      2:'One of the files passed on the command line did not exist.',
                      3:' A required tool could not be found.',
                      4:'The action failed.'}

    proc = subprocess.Popen([utility, norm_path], stderr=subprocess.STDOUT)

    from gi.repository import GLib
    GLib.timeout_add_seconds(1, poll_external, (proc, errstrings, uistate))
    return
Exemple #8
0
TOOLKIT = NOWEB

# Attempting to import webkit gives an error dialog if webkit is not
# available so test first and log just a warning to the console instead.
repository = Repository.get_default()
if repository.enumerate_versions("WebKit"):
    try:
        from gi.repository import WebKit
        TOOLKIT = WEBKIT
    except:
        pass

from gramps.gen.config import config
if TOOLKIT == NOWEB and not config.get('interface.ignore-webkit'):
    from gramps.gen.constfunc import has_display, mac, win
    if win() or mac():  # WebKit is not put into either Windows or Mac bundles
        config.set('interface.ignore-webkit', True)
    if has_display() and not config.get('interface.ignore-webkit'):
        from gramps.gui.dialog import MessageHideDialog
        title = _("Webkit module not loaded.")
        msg = _("Webkit module not loaded. "
                "Embedded web page viewing will not be available. "
                "Use your package manager to install gir1.2-webkit-3.0")
        MessageHideDialog(title, msg, 'interface.ignore-webkit')

#no interfaces present, we do not register these plugins
if not (TOOLKIT == NOWEB):
    register(
        VIEW,
        id='htmlview',
        name=_("Html View"),