本文整理匯總了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
示例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