我如何在 Python 或 PyQt4 中捕获系统注销/关闭/锁定事件 [英] How do i catch system Logoff/ShutDown/Lock events in Python or PyQt4

查看:59
本文介绍了我如何在 Python 或 PyQt4 中捕获系统注销/关闭/锁定事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 .NET 中有一个应用程序,现在我正在使用 Python 和 PyQt 对其进行重新编码.在我的应用程序中,我需要知道系统事件(锁定、注销、重启和关机).我可以使用下面的代码段从 .NET Frame work 3.5 管理它

I have an application in .NET now i am recoding it using Python and PyQt. In my application i need to know system events (Lock,Logoff,Restart and Shutdown). I could able to manage it from .NET Frame work 3.5 using below snippit

AddHandler SystemEvents.SessionEnding, AddressOf ClosingApplication
AddHandler SystemEvents.SessionSwitch, AddressOf SessionSwitchEvent

根据系统,我需要做一些事情来更新我的数据库.

Depending on the system i need to do some stuff to update my Database.

谁能帮帮我...

推荐答案

您将需要使用 pywin32 库.它是 win32api 的包装类.然后您可以使用 SetConsoleCtrlHandler 来捕捉信号.

You are going to need to use the pywin32 library. It is a wrapper class for the win32api. You can then use the SetConsoleCtrlHandler to catch the signal.

要干净地捕获信号,您需要生成一个控制台窗口.为了让您的应用程序干净利落地运行,您可以在隐藏状态下运行控制台窗口.有关如何生成控制台窗口的更多信息,请参阅:Python - Windows 关机事件

To cleanly capture the signal you are going to need to spawn a console window. To make your application run cleanly, you can run the console window in a hidden state. For more information about how to spawn the console window see: Python - Windows Shutdown Events

这篇关于我如何在 Python 或 PyQt4 中捕获系统注销/关闭/锁定事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆