def spawn(self, args, callback=None): if callback: logger.warn('os.startfile does not support a callback') for arg in args: if isinstance(arg, (zim.fs.File, zim.fs.Dir)): path = os.path.normpath(arg.path) elif is_uri_re.match(arg) and not is_win32_path_re.match(arg): # URL or e.g. mailto: or outlook: URI path = unicode(arg) else: # must be file path = os.path.normpath(unicode(arg)) logger.info('Opening with os.startfile: %s', path) os.startfile(path)
def open_url(widget, url): '''Open an URL (or URI) in the web browser or other relevant program. The application is determined based on the URL / URI scheme. Unkown schemes and "file://" URIs are opened with the webbrowser. @param widget: parent for new dialogs, C{Gtk.Widget} or C{None} @param url: an URL or URI as string ''' logger.debug('open_url(%s)', url) assert isinstance(url, str) if is_win32_share_re.match(url): url = normalize_win32_share(url) if os.name == 'nt': return _open_with_filebrowser(widget, url) # else consider as a x-scheme-handler/smb type URI below elif is_www_link_re.match(url): url = 'http://' + url elif not is_uri_re.match(url): raise ValueError('Not an URL: %s' % url) else: pass if url.startswith('file:/'): # Special case, force to browser (and not use open_file()) # even though the result may be the same if the browser is # dispatched through xdg-open, gnome-open, ...) _open_with_webbrowser(widget, url) elif url.startswith('outlook:') and hasattr(os, 'startfile'): # Special case for outlook folder paths on windows os.startfile(url) else: from zim.gui.applications import get_mimetype manager = ApplicationManager() type = get_mimetype( url) # Supports "x-scheme-handler/... for URL schemes" logger.debug('Got type "%s" for "%s"', type, url) entry = manager.get_default_application(type) if entry: _open_with(widget, entry, url) elif url.startswith('mailto:'): _open_with_emailclient(widget, url) else: _open_with_webbrowser(widget, url)
def spawn(self, args, callback=None): if callback: logger.warn('os.startfile does not support a callback') for arg in args: if isinstance(arg, (zim.fs.File, zim.fs.Dir)): path = os.path.normpath(arg.path) elif is_uri_re.match(arg) and not is_win32_path_re.match(arg): # URL or e.g. mailto: or outlook: URI path = str(arg) else: # must be file path = os.path.normpath(str(arg)) logger.info('Opening with os.startfile: %s', path) if TEST_MODE: TEST_MODE_RUN_CB((self.__class__.__name__, url)) else: os.startfile(path)
def spawn(self, args, callback=None): if callback: raise NotImplementedError( 'os.startfile does not support a callback') for arg in args: if isinstance(arg, (zim.fs.File, zim.fs.Dir)): path = os.path.normpath(arg.path).replace( '/', SEP) # msys can use '/' instead of '\\' elif is_uri_re.match(arg) and not is_win32_path_re.match(arg): # URL or e.g. mailto: or outlook: URI path = str(arg) else: # must be file path = os.path.normpath(str(arg)).replace( '/', SEP) # msys can use '/' instead of '\\' logger.info('Opening with os.startfile: %s', path) if TEST_MODE: TEST_MODE_RUN_CB((self.__class__.__name__, path)) else: os.startfile(path)