def instance_running(self):
'''
Use CreateEvent to make sure there is only one instance running
'''
if self.SICHECK_EVENT is None:
self.SICHECK_EVENT = win32event.CreateEvent(
None, 1, 0, self.GUID
)
# An instance is already running, quit
if win32api.GetLastError() == winerror.ERROR_ALREADY_EXISTS:
win32gui.MessageBox(
self.HWND,
'You can only run one instance at a time',
'Seems like KeyCounter is already running',
win32con.MB_OK
)
return self.stop()
python类MessageBox()的实例源码
def CopyCallBack(self, hwnd, func, flags,
srcName, srcAttr, destName, destAttr):
# This function should return:
# IDYES Allows the operation.
# IDNO Prevents the operation on this folder but continues with any other operations that have been approved (for example, a batch copy operation).
# IDCANCEL Prevents the current operation and cancels any pending operations.
print "CopyCallBack", hwnd, func, flags, srcName, srcAttr, destName, destAttr
return win32gui.MessageBox(hwnd, "Allow operation?", "CopyHook",
win32con.MB_YESNO)
def InvokeCommand(self, ci):
mask, hwnd, verb, params, dir, nShow, hotkey, hicon = ci
win32gui.MessageBox(hwnd, "Hello", "Wow", win32con.MB_OK)
def CopyCallBack(self, hwnd, func, flags,
srcName, srcAttr, destName, destAttr):
# This function should return:
# IDYES Allows the operation.
# IDNO Prevents the operation on this folder but continues with any other operations that have been approved (for example, a batch copy operation).
# IDCANCEL Prevents the current operation and cancels any pending operations.
print "CopyCallBack", hwnd, func, flags, srcName, srcAttr, destName, destAttr
return win32gui.MessageBox(hwnd, "Allow operation?", "CopyHook",
win32con.MB_YESNO)
def InvokeCommand(self, ci):
mask, hwnd, verb, params, dir, nShow, hotkey, hicon = ci
win32gui.MessageBox(hwnd, "Hello", "Wow", win32con.MB_OK)
def CopyCallBack(self, hwnd, func, flags,
srcName, srcAttr, destName, destAttr):
# This function should return:
# IDYES Allows the operation.
# IDNO Prevents the operation on this folder but continues with any other operations that have been approved (for example, a batch copy operation).
# IDCANCEL Prevents the current operation and cancels any pending operations.
print("CopyCallBack", hwnd, func, flags, srcName, srcAttr, destName, destAttr)
return win32gui.MessageBox(hwnd, "Allow operation?", "CopyHook",
win32con.MB_YESNO)
def InvokeCommand(self, ci):
mask, hwnd, verb, params, dir, nShow, hotkey, hicon = ci
win32gui.MessageBox(hwnd, "Hello", "Wow", win32con.MB_OK)
def pause(self, string = "Click to Continue test"):
""" Wait for the user to click a button to continue testing.
parameters:
[string] = Message to display to user
returns:
None
"""
self._wait()
try:
win32gui.MessageBox(0, string, "Pausing test...", 0)
except:
(ErrorType,ErrorValue,ErrorTB)=sys.exc_info()
print sys.exc_info()
traceback.print_exc(ErrorTB)
else: return True
def pause(self, string = "Click to Continue test"):
""" Wait for the user to click a button to continue testing.
parameters:
[string] = Message to display to user
returns:
None
"""
self._wait()
try:
win32gui.MessageBox(0, string, "Pausing test...", 0)
except:
(ErrorType,ErrorValue,ErrorTB)=sys.exc_info()
print (sys.exc_info())
traceback.print_exc(ErrorTB)
else: return True