Ejemplo n.º 1
0
def friendly_app_name(prog_id=None, exe=None):
    try:
        from win32com.shell import shell, shellcon
        a = shell.AssocCreate()
        a.Init((shellcon.ASSOCF_INIT_BYEXENAME if exe else 0), exe or prog_id)
        return a.GetString(shellcon.ASSOCF_REMAPRUNDLL, shellcon.ASSOCSTR_FRIENDLYAPPNAME)
    except Exception:
        import traceback
        traceback.print_exc()
Ejemplo n.º 2
0
def launchApplicationByUrl(url, mimeType):
    """Launches an application in the background for
    displaying a url which is of a specific mimeType
    @param url: the url to display
    @param mimeType: the mime type of the content
    """
    try:
        import gnomevfs
    except ImportError:
        gnomevfs = None

    try:
        from win32com.shell import shell as win32shell
    except ImportError:
        win32shell = None

    try:
        import gio
    except ImportError:
        gio = None

    if gio:
        app = gio.app_info_get_default_for_type(mimeType, True)
        if not app:
            return
        args = '%s %s' % (app.get_executable(), url)
        executable = None
        shell = True
    elif gnomevfs:
        app = gnomevfs.mime_get_default_application(mimeType)
        if not app:
            return
        args = '%s %s' % (app[2], url)
        executable = None
        shell = True
    elif win32shell:
        assoc = win32shell.AssocCreate()
        ext = _EXTENSIONS.get(mimeType)
        if ext is None:
            return
        assoc.Init(0, '.' + ext)
        args = assoc.GetString(0, _ASSOCSTR_COMMAND)
        executable = assoc.GetString(0, _ASSOCSTR_EXECUTABLE)
        args = args.replace("%1", url)
        args = args.replace("%L", url)
        shell = False
    else:
        return

    import subprocess
    subprocess.Popen(args, executable=executable, shell=shell)
Ejemplo n.º 3
0
def file_assoc_windows(ft):
    # See the IQueryAssociations::GetString method documentation on MSDN
    from win32com.shell import shell, shellcon
    a = shell.AssocCreate()
    a.Init(0, '.' + ft.lower())
    return a.GetString(0, shellcon.ASSOCSTR_EXECUTABLE)