[Spambayes-checkins] spambayes/windows pop3proxy_tray.py,1.1,1.2

Adam Walker xenogeist at users.sourceforge.net
Mon Sep 1 15:46:28 EDT 2003


Update of /cvsroot/spambayes/spambayes/windows
In directory sc8-pr-cvs1:/tmp/cvs-serv8836/windows

Modified Files:
	pop3proxy_tray.py 
Log Message:
Fixed Tony's tray program to work around Python 2.3. Added code to run the proxy in a seperate thread (I'll leave interacting with a service for another day). Includes the icon voted most likely change.

Index: pop3proxy_tray.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/windows/pop3proxy_tray.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** pop3proxy_tray.py	1 Sep 2003 10:04:58 -0000	1.1
--- pop3proxy_tray.py	1 Sep 2003 21:46:26 -0000	1.2
***************
*** 9,13 ****
  # Foundation license.
  
! __author__ = "Tony Meyer <ta-meyer at ihug.co.nz>"
  __credits__ = "Mark Hammond, all the Spambayes folk."
  
--- 9,13 ----
  # Foundation license.
  
! __author__ = "Tony Meyer <ta-meyer at ihug.co.nz>, Adam Walker"
  __credits__ = "Mark Hammond, all the Spambayes folk."
  
***************
*** 24,27 ****
--- 24,28 ----
  import sys
  import webbrowser
+ import thread
  
  import win32con
***************
*** 37,40 ****
--- 38,43 ----
  from spambayes.Options import options
  
+ WM_TASKBAR_NOTIFY = win32con.WM_USER + 20
+ 
  class MainWindow(object):
      def __init__(self):
***************
*** 53,80 ****
              win32con.WM_DESTROY: self.OnDestroy,
              win32con.WM_COMMAND: self.OnCommand,
!             win32con.WM_USER+20 : self.OnTaskbarNotify,
          }
  
-         # Register the Window class.
-         wc = WNDCLASS()
-         hinst = wc.hInstance = GetModuleHandle(None)
-         wc.lpszClassName = "SpambayesTaskbar"
-         wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;
-         wc.hCursor = LoadCursor( 0, win32con.IDC_ARROW )
-         wc.hbrBackground = win32con.COLOR_WINDOW
-         wc.lpfnWndProc = message_map
-         classAtom = RegisterClass(wc)
- 
          # Create the Window.
!         style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
!         self.hwnd = CreateWindow(classAtom, "SpamBayes", style,
!                                  0, 0, win32con.CW_USEDEFAULT,
!                                  win32con.CW_USEDEFAULT, 0, 0, hinst, None)
!         UpdateWindow(self.hwnd)
  
          # Try and find a custom icon
          # XXX This needs to be done, but first someone needs to make a wee
          # XXX spambayes icon
!         iconPathName = os.path.abspath(os.path.join( os.path.split(sys.executable)[0], "pyc.ico" ))
          if not os.path.isfile(iconPathName):
              # Look in the source tree.
--- 56,74 ----
              win32con.WM_DESTROY: self.OnDestroy,
              win32con.WM_COMMAND: self.OnCommand,
!             WM_TASKBAR_NOTIFY : self.OnTaskbarNotify,
          }
  
          # Create the Window.
!         hinst = GetModuleHandle(None)
!         # this will replaced with a real configure dialog later
!         # this is mainly to work around not being able to register a window class
!         # with python 2.3
!         dialogTemplate = [['SpamBayes', (14, 10, 246, 187), -1865809852 & ~win32con.WS_VISIBLE, None, (8, 'Tahoma')],]
!         self.hwnd = CreateDialogIndirect(hinst, dialogTemplate, 0, message_map)
  
          # Try and find a custom icon
          # XXX This needs to be done, but first someone needs to make a wee
          # XXX spambayes icon
!         iconPathName = os.path.abspath( "resources\\sbicon.ico" )
          if not os.path.isfile(iconPathName):
              # Look in the source tree.
***************
*** 88,93 ****
  
          flags = NIF_ICON | NIF_MESSAGE | NIF_TIP
!         nid = (self.hwnd, 0, flags, win32con.WM_USER+20, hicon, "SpamBayes")
          Shell_NotifyIcon(NIM_ADD, nid)
  
          # Start up pop3proxy
--- 82,88 ----
  
          flags = NIF_ICON | NIF_MESSAGE | NIF_TIP
!         nid = (self.hwnd, 0, flags, WM_TASKBAR_NOTIFY, hicon, "SpamBayes")
          Shell_NotifyIcon(NIM_ADD, nid)
+         self.started = False
  
          # Start up pop3proxy
***************
*** 95,106 ****
          # XXX This should determine if we are using the service, and if so
          # XXX start that, and if not kick pop3proxy off in a separate thread.
!         #pop3proxy.prepare(state=pop3proxy.state)
!         #pop3proxy.start(pop3proxy.state)
!         #self.started = True
  
      def OnDestroy(self, hwnd, msg, wparam, lparam):
! 		nid = (self.hwnd, 0)
! 		Shell_NotifyIcon(NIM_DELETE, nid)
! 		PostQuitMessage(0)
  
      def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):
--- 90,100 ----
          # XXX This should determine if we are using the service, and if so
          # XXX start that, and if not kick pop3proxy off in a separate thread.
!         pop3proxy.prepare(state=pop3proxy.state)
!         self.StartProxyThread()
  
      def OnDestroy(self, hwnd, msg, wparam, lparam):
!         nid = (self.hwnd, 0)
!         Shell_NotifyIcon(NIM_DELETE, nid)
!         PostQuitMessage(0)
  
      def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):
***************
*** 142,145 ****
--- 136,144 ----
          DestroyWindow(self.hwnd)
          sys.exit()
+         
+     def StartProxyThread(self):
+         args = (pop3proxy.state,)
+         thread.start_new_thread(pop3proxy.start, args)
+         self.started = True
  
      def StartStop(self):
***************
*** 152,157 ****
              self.started = False
          else:
!             pop3proxy.start(pop3proxy.state)
!             self.started = True
  
      def OpenInterface(self):
--- 151,155 ----
              self.started = False
          else:
!             self.StartProxyThread()
  
      def OpenInterface(self):





More information about the Spambayes-checkins mailing list