dabo Commit
Revision 4459
Date: 2008-08-27 09:01:24 -0700 (Wed, 27 Aug 2008)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/4459
Changed:
U trunk/dabo/dApp.py
U trunk/dabo/ui/uiwx/dBaseMenuBar.py
U trunk/dabo/ui/uiwx/uiApp.py
Log:
Implemented a basic debugging output window. It's fairly simple now, but can be
customized further based on feedback.
There is a new menu item in the base menubar class "Debug Output Window". It's
designed to be a checked menu item, but the check always appears to be out of
sync with the debug window. Selecting that menu shows/hides the debug output
window.
To add debug output, add this line to your app where you want to record
information:
debugout("Some stuff")
You can add multiple items, much like the print command, and they will be
output with a space separator
debugout("Status", self.status)
You don't have to do anything to enable debugging; just issue debugout()
statements.
Diff:
Modified: trunk/dabo/dApp.py
===================================================================
--- trunk/dabo/dApp.py 2008-08-27 01:47:01 UTC (rev 4458)
+++ trunk/dabo/dApp.py 2008-08-27 16:01:24 UTC (rev 4459)
@@ -10,6 +10,7 @@
import datetime
import urllib2
import shutil
+import logging
import dabo
import dabo.ui
import dabo.db
@@ -999,14 +1000,24 @@
self.uiApp.showCommandWindow(context)
+ def toggleDebugWindow(self, context=None):
+ """Shows/hodes a debug output window. It will
+ display the output of the debugging commands
+ from your program.
+ """
+ self.uiApp.toggleDebugWindow(context)
+
+
def fontZoomIn(self, evt=None):
"""Increase the font size on the active form."""
self.uiApp.fontZoomIn()
+
def fontZoomOut(self, evt=None):
"""Decrease the font size on the active form."""
self.uiApp.fontZoomOut()
+
def fontZoomNormal(self, evt=None):
"""Reset the font size to normal on the active form."""
self.uiApp.fontZoomNormal()
@@ -1017,6 +1028,8 @@
# layer to be handled there.
def onCmdWin(self, evt):
self.uiApp.onCmdWin(evt)
+ def onDebugWin(self, evt):
+ self.uiApp.onDebugWin(evt)
def onWinClose(self, evt):
self.uiApp.onWinClose(evt)
def onFileExit(self, evt):
Modified: trunk/dabo/ui/uiwx/dBaseMenuBar.py
===================================================================
--- trunk/dabo/ui/uiwx/dBaseMenuBar.py 2008-08-27 01:47:01 UTC (rev 4458)
+++ trunk/dabo/ui/uiwx/dBaseMenuBar.py 2008-08-27 16:01:24 UTC (rev 4459)
@@ -32,10 +32,14 @@
self.Caption = _("&File")
if self.Application.ShowCommandWindowMenu:
- self.append(_("Command Win&dow"), HotKey="Ctrl+D",
OnHit=app.onCmdWin,
- bmp="%s/apps/utilities-terminal.png" %
iconPath,
+ self.commandWinMenuItem = self.append(_("Command
Win&dow"), HotKey="Ctrl+D",
+ OnHit=app.onCmdWin,
bmp="%s/apps/utilities-terminal.png" % iconPath,
help=_("Open up a command window for
debugging") )
-
+
+ self.debugMenuItem = self.append(_("De&bug Output
Window"), HotKey="Ctrl+B",
+ OnHit=app.onDebugWin,
bmp="%s/apps/utilities-terminal.png" % iconPath,
+ menutype="check", help=_("Open up a
debug output window") )
+
prmpt = _("Close Windo&w")
self.append(prmpt, HotKey="Ctrl+W", OnHit=app.onWinClose,
help=_("Close the current window") )
@@ -155,6 +159,18 @@
self.appendMenu(ViewMenu(self))
self.appendMenu(HelpMenu(self))
+
+# Trying to expose menu atts as menubar atts. Not sure if this is a good idea
yet...
+# def __getattr__(self, att):
+# ret = None
+# for menu in self.Children:
+# ret = getattr(menu, att)
+# if ret:
+# break
+# if not ret:
+# raise AttributeError
+# return ret
+
if __name__ == "__main__":
app = dabo.dApp()
app.setup()
Modified: trunk/dabo/ui/uiwx/uiApp.py
===================================================================
--- trunk/dabo/ui/uiwx/uiApp.py 2008-08-27 01:47:01 UTC (rev 4458)
+++ trunk/dabo/ui/uiwx/uiApp.py 2008-08-27 16:01:24 UTC (rev 4459)
@@ -2,6 +2,7 @@
import sys
import os
import time
+import logging
import wx
import dabo
import dabo.ui as ui
@@ -153,6 +154,30 @@
self._mruMenuLinks = {}
self._mruMaxItems = 12
wx.InitAllImageHandlers()
+ # Set up the debug logging
+ self.debugWindow = None
+ log = logging.getLogger("Debug")
+ class DebugLogHandler(logging.Handler):
+ def emit(self, record):
+ msg = record.getMessage()
+ try:
+ self.messages.append(msg)
+ except AttributeError:
+ self.messages = [msg]
+ self.updateTarget()
+ def updateTarget(self):
+ try:
+ self.target
+ self.messages
+ except AttributeError:
+ return
+ if self.target:
+ self.target.Value =
"\n".join(self.messages)
+ hnd = self._debugHandler = DebugLogHandler()
+ fmt = logging.Formatter("%(message)s")
+ hnd.setFormatter(fmt)
+ log.setLevel(logging.DEBUG)
+ log.addHandler(hnd)
def OnInit(self):
@@ -345,6 +370,10 @@
self.showCommandWindow()
+ def onDebugWin(self, evt):
+ self.toggleDebugWindow()
+
+
def showCommandWindow(self, context=None):
"""Display a command window for debugging."""
if context is None:
@@ -353,6 +382,36 @@
dlg.show()
+ def toggleDebugWindow(self, context=None):
+ """Display a debug output window."""
+ class DebugWindow(dabo.ui.dToolForm):
+ def afterInit(self):
+ self.Caption = _("Debug Output")
+ self.out = dabo.ui.dEditBox(self, ReadOnly=True)
+ self.out.bindEvent(dEvents.ContextMenu,
self.onContext)
+ self.Sizer.append1x(self.out)
+ def onContext(self, evt):
+ self.out.Value = ""
+
+ if not self.debugWindow:
+ if context is None:
+ context = self.ActiveForm
+ self.debugWindow = DebugWindow(context)
+ # Set the handler action
+ self._debugHandler.target = self.debugWindow.out
+ if self.debugWindow.Visible:
+ self.debugWindow.hide()
+ else:
+ self._debugHandler.updateTarget()
+ self.debugWindow.show()
+# # Having issues with the check mark on the menu being out of
sync.
+# try:
+# context.MenuBar.debugMenuItem.Checked =
self.debugWindow.Visible
+# except AttributeError:
+# # No such item
+# pass
+
+
def onWinClose(self, evt):
"""Close the topmost window, if any."""
if self.ActiveForm:
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]