Update of /cvsroot/pywin32/pywin32/win32/Demos
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4045
Modified Files:
eventLogDemo.py win32gui_taskbar.py
Log Message:
remove use of 'import *'
Index: win32gui_taskbar.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/Demos/win32gui_taskbar.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** win32gui_taskbar.py 3 Oct 2008 01:03:56 -0000 1.10
--- win32gui_taskbar.py 4 Dec 2008 07:22:19 -0000 1.11
***************
*** 1,12 ****
# Creates a task-bar icon. Run from Python.exe to see the
# messages printed.
! from win32api import *
! from win32gui import *
! import win32con
import sys, os
class MainWindow:
def __init__(self):
! msg_TaskbarRestart = RegisterWindowMessage("TaskbarCreated");
message_map = {
msg_TaskbarRestart: self.OnRestart,
--- 1,11 ----
# Creates a task-bar icon. Run from Python.exe to see the
# messages printed.
! import win32api, win32gui
! import win32con, winerror
import sys, os
class MainWindow:
def __init__(self):
! msg_TaskbarRestart = win32gui.RegisterWindowMessage("TaskbarCreated");
message_map = {
msg_TaskbarRestart: self.OnRestart,
***************
*** 16,24 ****
}
# Register the Window class.
! wc = WNDCLASS()
! hinst = wc.hInstance = GetModuleHandle(None)
wc.lpszClassName = "PythonTaskbarDemo"
wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;
! wc.hCursor = LoadCursor( 0, win32con.IDC_ARROW )
wc.hbrBackground = win32con.COLOR_WINDOW
wc.lpfnWndProc = message_map # could also specify a wndproc.
--- 15,23 ----
}
# Register the Window class.
! wc = win32gui.WNDCLASS()
! hinst = wc.hInstance = win32api.GetModuleHandle(None)
wc.lpszClassName = "PythonTaskbarDemo"
wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;
! wc.hCursor = win32api.LoadCursor( 0, win32con.IDC_ARROW )
wc.hbrBackground = win32con.COLOR_WINDOW
wc.lpfnWndProc = message_map # could also specify a wndproc.
***************
*** 33,44 ****
# Create the Window.
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
! self.hwnd = CreateWindow( classAtom, "Taskbar Demo", style, \
0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
0, 0, hinst, None)
! UpdateWindow(self.hwnd)
self._DoCreateIcons()
def _DoCreateIcons(self):
# Try and find a custom icon
! hinst = GetModuleHandle(None)
iconPathName = os.path.abspath(os.path.join( os.path.split(sys.executable)[0], "pyc.ico" ))
if not os.path.isfile(iconPathName):
--- 32,43 ----
# Create the Window.
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
! self.hwnd = win32gui.CreateWindow( wc.lpszClassName, "Taskbar Demo", style, \
0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
0, 0, hinst, None)
! win32gui.UpdateWindow(self.hwnd)
self._DoCreateIcons()
def _DoCreateIcons(self):
# Try and find a custom icon
! hinst = win32api.GetModuleHandle(None)
iconPathName = os.path.abspath(os.path.join( os.path.split(sys.executable)[0], "pyc.ico" ))
if not os.path.isfile(iconPathName):
***************
*** 50,63 ****
if os.path.isfile(iconPathName):
icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
! hicon = LoadImage(hinst, iconPathName, win32con.IMAGE_ICON, 0, 0, icon_flags)
else:
print "Can't find a Python icon file - using default"
! hicon = LoadIcon(0, win32con.IDI_APPLICATION)
! flags = NIF_ICON | NIF_MESSAGE | NIF_TIP
nid = (self.hwnd, 0, flags, win32con.WM_USER+20, hicon, "Python Demo")
try:
! Shell_NotifyIcon(NIM_ADD, nid)
! except error:
# This is common when windows is starting, and this code is hit
# before the taskbar has been created.
--- 49,62 ----
if os.path.isfile(iconPathName):
icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
! hicon = win32gui.LoadImage(hinst, iconPathName, win32con.IMAGE_ICON, 0, 0, icon_flags)
else:
print "Can't find a Python icon file - using default"
! hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
! flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
nid = (self.hwnd, 0, flags, win32con.WM_USER+20, hicon, "Python Demo")
try:
! win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
! except win32gui.error:
# This is common when windows is starting, and this code is hit
# before the taskbar has been created.
***************
*** 71,76 ****
def OnDestroy(self, hwnd, msg, wparam, lparam):
nid = (self.hwnd, 0)
! Shell_NotifyIcon(NIM_DELETE, nid)
! PostQuitMessage(0) # Terminate the app.
def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):
--- 70,75 ----
def OnDestroy(self, hwnd, msg, wparam, lparam):
nid = (self.hwnd, 0)
! win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, nid)
! win32gui.PostQuitMessage(0) # Terminate the app.
def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):
***************
*** 79,98 ****
elif lparam==win32con.WM_LBUTTONDBLCLK:
print "You double-clicked me - goodbye"
! DestroyWindow(self.hwnd)
elif lparam==win32con.WM_RBUTTONUP:
print "You right clicked me."
! menu = CreatePopupMenu()
! AppendMenu( menu, win32con.MF_STRING, 1023, "Display Dialog")
! AppendMenu( menu, win32con.MF_STRING, 1024, "Say Hello")
! AppendMenu( menu, win32con.MF_STRING, 1025, "Exit program" )
! pos = GetCursorPos()
# See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
! SetForegroundWindow(self.hwnd)
! TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None)
! PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
return 1
def OnCommand(self, hwnd, msg, wparam, lparam):
! id = LOWORD(wparam)
if id == 1023:
import win32gui_dialog
--- 78,97 ----
elif lparam==win32con.WM_LBUTTONDBLCLK:
print "You double-clicked me - goodbye"
! win32gui.DestroyWindow(self.hwnd)
elif lparam==win32con.WM_RBUTTONUP:
print "You right clicked me."
! menu = win32gui.CreatePopupMenu()
! win32gui.AppendMenu( menu, win32con.MF_STRING, 1023, "Display Dialog")
! win32gui.AppendMenu( menu, win32con.MF_STRING, 1024, "Say Hello")
! win32gui.AppendMenu( menu, win32con.MF_STRING, 1025, "Exit program" )
! pos = win32gui.GetCursorPos()
# See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
! win32gui.SetForegroundWindow(self.hwnd)
! win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None)
! win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
return 1
def OnCommand(self, hwnd, msg, wparam, lparam):
! id = win32api.LOWORD(wparam)
if id == 1023:
import win32gui_dialog
***************
*** 102,106 ****
elif id == 1025:
print "Goodbye"
! DestroyWindow(self.hwnd)
else:
print "Unknown command -", id
--- 101,105 ----
elif id == 1025:
print "Goodbye"
! win32gui.DestroyWindow(self.hwnd)
else:
print "Unknown command -", id
***************
*** 108,112 ****
def main():
w=MainWindow()
! PumpMessages()
if __name__=='__main__':
--- 107,111 ----
def main():
w=MainWindow()
! win32gui.PumpMessages()
if __name__=='__main__':
Index: eventLogDemo.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/Demos/eventLogDemo.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** eventLogDemo.py 7 Jun 2003 02:08:45 -0000 1.5
--- eventLogDemo.py 4 Dec 2008 07:22:19 -0000 1.6
***************
*** 1,7 ****
! import win32evtlog, traceback
! import win32api, win32con
import win32security # To translate NT Sids to account names.
! from win32evtlogutil import *
def ReadLog(computer, logType="Application", dumpEachRecord = 0):
--- 1,7 ----
! import win32evtlog
! import win32api
import win32security # To translate NT Sids to account names.
! import win32evtlogutil
def ReadLog(computer, logType="Application", dumpEachRecord = 0):
***************
*** 18,22 ****
for object in objects:
# get it for testing purposes, but dont print it.
! msg = SafeFormatMessage(object, logType).encode("mbcs")
if object.Sid is not None:
try:
--- 18,22 ----
for object in objects:
# get it for testing purposes, but dont print it.
! msg = win32evtlogutil.SafeFormatMessage(object, logType)
if object.Sid is not None:
try:
***************
*** 41,45 ****
win32evtlog.CloseEventLog(h)
! def Usage():
print "Writes an event to the event log."
print "-w : Dont write any test records."
--- 41,45 ----
win32evtlog.CloseEventLog(h)
! def usage():
print "Writes an event to the event log."
print "-w : Dont write any test records."
***************
*** 74,78 ****
computer = val
if opt in ['-h', '-?']:
! Usage()
return
if opt=='-r':
--- 74,78 ----
computer = val
if opt in ['-h', '-?']:
! usage()
return
if opt=='-r':
***************
*** 83,89 ****
verbose = verbose + 1
if do_write:
! ReportEvent(logType, 2, strings=["The message text for event 2"], data = "Raw\0Data")
! ReportEvent(logType, 1, eventType=win32evtlog.EVENTLOG_WARNING_TYPE, strings=["A warning"], data = "Raw\0Data")
! ReportEvent(logType, 1, eventType=win32evtlog.EVENTLOG_INFORMATION_TYPE, strings=["An info"], data = "Raw\0Data")
print "Successfully wrote 3 records to the log"
--- 83,89 ----
verbose = verbose + 1
if do_write:
! win32evtlogutil.ReportEvent(logType, 2, strings=["The message text for event 2"], data = "Raw\0Data")
! win32evtlogutil.ReportEvent(logType, 1, eventType=win32evtlog.EVENTLOG_WARNING_TYPE, strings=["A warning"], data = "Raw\0Data")
! win32evtlogutil.ReportEvent(logType, 1, eventType=win32evtlog.EVENTLOG_INFORMATION_TYPE, strings=["An info"], data = "Raw\0Data")
print "Successfully wrote 3 records to the log"
|