Printing to a "log screen" in a multi-module QT app

Anders Schneiderman schneida at seiu.org
Wed Feb 27 21:13:57 CET 2002


I'm writing an application using QT.  Right now when I want to use the
equivalent of "print", I call a method called "log" that's defined in
the main class in my main module:

def log(self, msg):
   try:
      self.logArea.insertline(msg, -1)
   except:
      self.logArea.insertline(str(msg), -1)

To call it in other classes that are in other modules of the app, I
pass "log" to the new class.  For ex:

class CodeEditor:
   def __init__ (self, log, ...)
       self.log = log

Is there a cleaner way to do this?  For example, is there a way to
redefine the "print" command?  Whatever solution I come up with, the
command to print has to be short;  "self.logObject.log('File
successfully updated')" is too much of a pain.  Any suggestions?

Thanks,
Anders Schneiderman
Information Manager
SEIU International



More information about the Python-list mailing list