[Zope-CVS] CVS: Packages/FunctionalTests/FunctionalTests - TkLoggingProxy.py:1.2

Tres Seaver tseaver@zope.com
Tue, 20 May 2003 08:18:10 -0400


Update of /cvs-repository/Packages/FunctionalTests/FunctionalTests
In directory cvs.zope.org:/tmp/cvs-serv18601/FunctionalTests

Modified Files:
	TkLoggingProxy.py 
Log Message:
 - Still broken stab at making the Tk version work.

=== Packages/FunctionalTests/FunctionalTests/TkLoggingProxy.py 1.1 => 1.2 ===
--- Packages/FunctionalTests/FunctionalTests/TkLoggingProxy.py:1.1	Thu Apr 24 17:39:51 2003
+++ Packages/FunctionalTests/FunctionalTests/TkLoggingProxy.py	Tue May 20 08:18:09 2003
@@ -1,5 +1,8 @@
 from Tkinter import *
 
+from LoggingProxy import LoggingServer
+from LoggingProxy import LoggingFilter
+
 class FormDialog( Frame ):
     """
     """
@@ -81,6 +84,8 @@
 
 class TkLoggingProxy( Frame ):
 
+    _logging_proxy = None
+
     def __init__( self, parent=None ):
 
         Frame.__init__( self, parent )
@@ -144,6 +149,10 @@
                               )
                             )
 
+        self._showLogMessage( 'Logging server args: \n%s'
+                            % self._makeServerArgs()
+                            )
+
     def _optionsDialog( self, labels_and_vars ):
 
         top = Toplevel()
@@ -166,12 +175,63 @@
                              )
                            )
 
+    def _startLogging( self ):
+
+        if self._logging_proxy is not None:
+            self._logging_proxy.server_close()
+            del self._logging_proxy
+
+        self._logging_proxy = LoggingServer( self._makeServerArgs()
+                                           , LoggingFilter )
+        
+        self._showLogMessage( 'Logging started' )
+
+    def _stopLogging( self ):
+
+        if self._logging_proxy is not None:
+            self._logging_proxy.server_close()
+            del self._logging_proxy
+
+        self._showLogMessage( 'Logging stopped' )
+
+    def _makeServerArgs( self ):
+
+        args = []
+
+        verbosity = self._verbosity.get()
+
+        if verbosity < 1:
+            args.append( '-q' )
+
+        for v in range( 1, verbosity ):
+            args.append( '-v' )
+
+        if self._record_inbound.get():
+            args.append( '-i' )
+        else:
+            args.append( '-I' )
+
+        args.extend( ( '-h', self._listen_host.get() ) )
+        args.extend( ( '-p', str( self._listen_port.get() ) ) )
+        args.extend( ( '-l', self._logfile_directory.get() ) )
+        args.extend( ( '-f', self._logfile_prefix.get() ) )
+
+        return args
+
+    def _handleRequest( self ):
+        if self._logging_proxy:
+            self._logging_proxy.handle_request()
+            after_idle( self._handleRequest )
+
     def _showLogMessage( self, message ):
+
         self._text.configure( state=NORMAL )
+
         try:
             self._text.insert( END, '%s\n' % message )
         finally:
             self._text.configure( state=DISABLED )
+
         self._text.see( END )
 
     def _makeWidgets( self ):
@@ -182,6 +242,8 @@
         self._makeButton( bar, "Server Options", self._serverOptions )
         self._makeButton( bar, "Logging Options", self._loggingOptions )
         self._makeButton( bar, "Check", self._showOptions )
+        self._makeButton( bar, "Start", self._startLogging )
+        self._makeButton( bar, "Stop", self._stopLogging )
 
         bar.pack( side=TOP )