當前位置: 首頁>>代碼示例>>Python>>正文


Python winreg.KEY_QUERY_VALUE屬性代碼示例

本文整理匯總了Python中winreg.KEY_QUERY_VALUE屬性的典型用法代碼示例。如果您正苦於以下問題:Python winreg.KEY_QUERY_VALUE屬性的具體用法?Python winreg.KEY_QUERY_VALUE怎麽用?Python winreg.KEY_QUERY_VALUE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在winreg的用法示例。


在下文中一共展示了winreg.KEY_QUERY_VALUE屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _init_from_registry

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_QUERY_VALUE [as 別名]
def _init_from_registry(cls):
        if sys.platform != 'win32' or rcParams[cls.exec_key] != 'convert':
            return
        import winreg
        for flag in (0, winreg.KEY_WOW64_32KEY, winreg.KEY_WOW64_64KEY):
            try:
                hkey = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE,
                                        r'Software\Imagemagick\Current',
                                        0, winreg.KEY_QUERY_VALUE | flag)
                binpath = winreg.QueryValueEx(hkey, 'BinPath')[0]
                winreg.CloseKey(hkey)
                break
            except Exception:
                binpath = ''
        if binpath:
            for exe in ('convert.exe', 'magick.exe'):
                path = os.path.join(binpath, exe)
                if os.path.exists(path):
                    binpath = path
                    break
            else:
                binpath = ''
        rcParams[cls.exec_key] = rcParamsDefault[cls.exec_key] = binpath 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:25,代碼來源:animation.py

示例2: set_screensaver

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_QUERY_VALUE [as 別名]
def set_screensaver(must_disable, window):
    """ Enable or disable the screensaver.

    Args:
        must_disable (`bool`):  if `True`, indicates that the screensaver must be disabled; otherwise it will be enabled
        window (:class:`~Gdk.Window`): The window on the screen where the screensaver is to be suspended.
    """
    if IS_MAC_OS:
        # On Mac OS X we can use caffeinate to prevent the display from sleeping
        if must_disable:
            if set_screensaver.dpms_was_enabled is None or set_screensaver.dpms_was_enabled.poll():
                set_screensaver.dpms_was_enabled = subprocess.Popen(['caffeinate', '-d', '-w', str(os.getpid())])
        else:
            if set_screensaver.dpms_was_enabled and not set_screensaver.dpms_was_enabled.poll():
                set_screensaver.dpms_was_enabled.kill()
                set_screensaver.dpms_was_enabled.poll()
                set_screensaver.dpms_was_enabled = None

    elif IS_POSIX:
        # Import here because util should be imported without depending on gi
        from gi.repository import Gio

        # On Linux and Wayland we can use a dbus interface to tell the screensaver
        # to not lock the screen, should work on all freedesktop compliant desktops
        # eg. Gnome, KDE,...
        bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
        iface = Gio.DBusProxy.new_sync(bus, Gio.DBusProxyFlags.NONE, None,
                                       'org.freedesktop.ScreenSaver',
                                       '/org/freedesktop/ScreenSaver',
                                       'org.freedesktop.ScreenSaver', None)

        if must_disable and not set_screensaver.dpms_was_enabled:
            set_screensaver.dbus_cookie = iface.Inhibit("(ss)", "pympress", _("Fullscreen Presentation running"))
            set_screensaver.dpms_was_enabled = True
        if not must_disable and set_screensaver.dpms_was_enabled:
            iface.UnInhibit("(u)", set_screensaver.dbus_cookie)
            set_screensaver.dbus_cookie = None
            set_screensaver.dpms_was_enabled = False

    elif IS_WINDOWS:
        try:
            with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Control Panel\Desktop', 0,
                                winreg.KEY_QUERY_VALUE | winreg.KEY_SET_VALUE) as key:
                if must_disable:
                    value, regtype = winreg.QueryValueEx(key, "ScreenSaveActive")
                    assert(regtype == winreg.REG_SZ)
                    set_screensaver.dpms_was_enabled = (value == "1")
                    if set_screensaver.dpms_was_enabled:
                        winreg.SetValueEx(key, "ScreenSaveActive", 0, winreg.REG_SZ, "0")
                elif set_screensaver.dpms_was_enabled:
                    winreg.SetValueEx(key, "ScreenSaveActive", 0, winreg.REG_SZ, "1")
        except (OSError, PermissionError):
            logger.exception(_("access denied when trying to access screen saver settings in registry!"))

    else:
        logger.warning(_("Unsupported OS: can't enable/disable screensaver"))


#: remember DPMS setting before we change it 
開發者ID:Cimbali,項目名稱:pympress,代碼行數:61,代碼來源:util.py


注:本文中的winreg.KEY_QUERY_VALUE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。