• PySide 模块
  • PySide.QtGui
  • 内容表

    上一话题

    QUndoCommand

    下一话题

    QTextTableCell

    QDesktopServices

    概要

    静态函数

    详细描述

    PySide.QtGui.QDesktopServices class provides methods for accessing common desktop services.

    Many desktop environments provide services that can be used by applications to perform common tasks, such as opening a web page, in a way that is both consistent and takes into account the user's application preferences.

    This class contains functions that provide simple interfaces to these services that indicate whether they succeeded or failed.

    PySide.QtGui.QDesktopServices.openUrl() function is used to open files located at arbitrary URLs in external applications. For URLs that correspond to resources on the local filing system (where the URL scheme is “file”), a suitable application will be used to open the file; otherwise, a web browser will be used to fetch and display the file.

    The user's desktop settings control whether certain executable file types are opened for browsing, or if they are executed instead. Some desktop environments are configured to prevent users from executing files obtained from non-local URLs, or to ask the user's permission before doing so.

    URL 处理程序

    The behavior of the PySide.QtGui.QDesktopServices.openUrl() function can be customized for individual URL schemes to allow applications to override the default handling behavior for certain types of URLs.

    The dispatch mechanism allows only one custom handler to be used for each URL scheme; this is set using the PySide.QtGui.QDesktopServices.setUrlHandler() function. Each handler is implemented as a slot which accepts only a single PySide.QtCore.QUrl 自变量。

    The existing handlers for each scheme can be removed with the PySide.QtGui.QDesktopServices.unsetUrlHandler() function. This returns the handling behavior for the given scheme to the default behavior.

    This system makes it easy to implement a help system, for example. Help could be provided in labels and text browsers using help://myapplication/mytopic URLs, and by registering a handler it becomes possible to display the help text inside the application:

    def showHelp(url):
        # ...
        pass
    QDesktopServices.setUrlHandler("help", showHelp);
    											

    If inside the handler you decide that you can't open the requested URL, you can just call QDesktopServices.openUrl() again with the same argument, and it will try to open the URL using the appropriate mechanism for the user's desktop environment.

    class PySide.QtGui. QDesktopServices
    PySide.QtGui.QDesktopServices. StandardLocation

    This enum describes the different locations that can be queried by QDesktopServices::storageLocation and QDesktopServices::displayName.

    常量 描述
    QDesktopServices.DesktopLocation Returns the user's desktop directory.
    QDesktopServices.DocumentsLocation Returns the user's document.
    QDesktopServices.FontsLocation Returns the user's fonts.
    QDesktopServices.ApplicationsLocation Returns the user's applications.
    QDesktopServices.MusicLocation Returns the users music.
    QDesktopServices.MoviesLocation Returns the user's movies.
    QDesktopServices.PicturesLocation Returns the user's pictures.
    QDesktopServices.TempLocation Returns the system's temporary directory.
    QDesktopServices.HomeLocation Returns the user's home directory.
    QDesktopServices.DataLocation Returns a directory location where persistent application data can be stored. QCoreApplication.applicationName and QCoreApplication.organizationName should work on all platforms.
    QDesktopServices.CacheLocation Returns a directory location where user-specific non-essential (cached) data should be written.
    static PySide.QtGui.QDesktopServices. displayName ( type )
    参数: type PySide.QtGui.QDesktopServices.StandardLocation
    返回类型: unicode

    Returns a localized display name for the given location type or an empty PySide.QtCore.QString if no relevant location can be found.

    static PySide.QtGui.QDesktopServices. openUrl ( url )
    参数: url PySide.QtCore.QUrl
    返回类型: PySide.QtCore.bool

    Opens the given url in the appropriate Web browser for the user's desktop environment, and returns true if successful; otherwise returns false.

    If the URL is a reference to a local file (i.e., the URL scheme is “file”) then it will be opened with a suitable application instead of a Web browser.

    The following example opens a file on the Windows file system residing on a path that contains spaces:

    QDesktopServices.openUrl(QUrl("file:///C:/Documents and Settings/All Users/Desktop", QUrl.TolerantMode))
    												

    mailto URL is specified, the user's e-mail client will be used to open a composer window containing the options specified in the URL, similar to the way mailto links are handled by a Web browser.

    For example, the following URL contains a recipient ( user@foo.com ), a subject ( 测试 ), and a message body ( Just a test ):

    mailto:user@foo.com?subject=Test&body=Just a test
    											

    警告

    Although many e-mail clients can send attachments and are Unicode-aware, the user may have configured their client without these features. Also, certain e-mail clients (e.g., Lotus Notes) have problems with long URLs.

    注意

    On Symbian OS, SwEvent capability is required to open the given url if the Web browser is already running.

    static PySide.QtGui.QDesktopServices. setUrlHandler ( scheme , receiver , 方法 )
    参数:

    设置处理程序为给定 scheme to be the handler 方法 provided by the receiver 对象。

    This function provides a way to customize the behavior of PySide.QtGui.QDesktopServices.openUrl() 。若 PySide.QtGui.QDesktopServices.openUrl() is called with a URL with the specified scheme then the given 方法 receiver object is called instead of PySide.QtGui.QDesktopServices 启动外部应用程序。

    提供方法必须被实现成槽,且其只接受单 PySide.QtCore.QUrl 自变量。

    PySide.QtGui.QDesktopServices.setUrlHandler() is used to set a new handler for a scheme which already has a handler, the existing handler is simply replaced with the new one. Since PySide.QtGui.QDesktopServices 不拥有处理程序的所有权,因此,当替换处理程序时没有对象会被删除。

    注意:总是在其内调用处理程序的线程,也会调用 QDesktopServices.openUrl() .

    static PySide.QtGui.QDesktopServices. storageLocation ( type )
    参数: type PySide.QtGui.QDesktopServices.StandardLocation
    返回类型: unicode

    Returns the default system directory where files of type belong, or an empty string if the location cannot be determined.

    注意

    The storage location returned can be a directory that does not exist; i.e., it may need to be created by the system or the user.

    注意

    On Symbian OS, ApplicationsLocation always point /sys/bin folder on the same drive with executable. FontsLocation always points to folder on ROM drive. Symbian OS does not have desktop concept, DesktopLocation returns same path as DocumentsLocation . Rest of the standard locations point to folder on same drive with executable, except that if executable is in ROM the folder from C drive is returned.

    static PySide.QtGui.QDesktopServices. unsetUrlHandler ( scheme )
    参数: scheme – unicode

    移除先前设置的 URL 处理程序,为指定的 scheme .