SF.net SVN: fclient: [648] trunk/fclient/src/fclient/Ui_ViewLogger.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-15 23:58:25
|
Revision: 648
http://fclient.svn.sourceforge.net/fclient/?rev=648&view=rev
Author: jUrner
Date: 2008-07-15 16:58:09 -0700 (Tue, 15 Jul 2008)
Log Message:
-----------
what a diff pt II
Modified Paths:
--------------
trunk/fclient/src/fclient/Ui_ViewLogger.py
Modified: trunk/fclient/src/fclient/Ui_ViewLogger.py
===================================================================
--- trunk/fclient/src/fclient/Ui_ViewLogger.py 2008-07-15 23:57:40 UTC (rev 647)
+++ trunk/fclient/src/fclient/Ui_ViewLogger.py 2008-07-15 23:58:09 UTC (rev 648)
@@ -3,15 +3,15 @@
if __name__ == '__main__': # see --> http://bugs.python.org/issue1510172 . works only current dir and below
import os; __path__ = [os.path.dirname(__file__)]
+import sys
import logging
-import sys
-logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
from PyQt4 import QtCore, QtGui
-
from . import config
from . import Ui_View
+from .lib import fcp2
+from .lib.qt4ex.lib import actions
from .tpls.Ui_ViewLoggerWidgetTpl import Ui_ViewLoggerWidget
#**********************************************************************************
@@ -19,81 +19,134 @@
#**********************************************************************************
class Settings(config.SettingsBase):
+ PrefixVerbosityColorFg = 'ColorFgVerbosity'
+
_key_ = config.IdViewLoggerWidget
_settings_ = (
('MaxLines', 'UInt', 1000, config.SettingScopeUser),
+ ('Verbosity', 'PyString', 'Info', config.SettingScopePrivate),
+
+ #TODO: Chatty does not seem to work. check in fcp2.client
+ ('ColorFgVerbosityCRITICAL', 'QColor', QtGui.QColor('red'), config.SettingScopeUser),
+ ('ColorFgVerbosityERROR', 'QColor', QtGui.QColor('red'), config.SettingScopeUser),
+ ('ColorFgVerbosityWARNING', 'QColor', QtGui.QColor('red'), config.SettingScopeUser),
+ ('ColorFgVerbosityINFO', 'QColor', QtGui.QColor('black'), config.SettingScopeUser),
+ ('ColorFgVerbosityMESSAGE', 'QColor', QtGui.QColor('blue'), config.SettingScopeUser),
+ ('ColorFgVerbosityDEBUG', 'QColor', QtGui.QColor('slategray'), config.SettingScopeUser),
+ ('ColorFgVerbosityCHATTY', 'QColor', QtGui.QColor('lightslategray'), config.SettingScopeUser),
)
-#***********************************************************************
-#
-#***********************************************************************
-#TODO: more here...
-class TextEditActionClear(QtGui.QAction):
- def __init__(self, ed):
- QtGui.QAction.__init__(self, ed)
- self.setText(self.trUtf8('Clear'))
- ##self.setShortcut(self.trUtf8("del"))
- self.connect(self, QtCore.SIGNAL('triggered(bool)'), self.handleTriggered)
- self.connect(ed, QtCore.SIGNAL('textChanged()'), self.handleEdTextChanged)
+
+#TODO: for uniformity reasons (...) move ActionsBase to config, no?
+class Actions(actions.ActionsBase):
+
+ PrefixVerbosity = 'ActionVerbosity'
+
+ def __init__(self, parent):
+ actions.ActionsBase.__init__(self, parent)
- self.ed = ed
- self.handleEdTextChanged()
-
- def handleEdTextChanged(self):
- self.setEnabled(not self.ed.document().isEmpty())
-
- def handleTriggered(self, isChecked):
- self.ed.clear()
+ # for ease of use verbosities are mapped to verbosity actions like this: PrefixVerbosity + Verbosity
+ self.action(
+ name='ActionLoggerClear',
+ text=self.trUtf8('C&lear'),
+ trigger=parent.handleActionLoggerClear,
+ )
+
+ groupVerbosity = self.group(
+ name='GroupVerbosity',
+ trigger=parent.handleGroupVerbosityTriggered,
+ isExclusive=True,
+ )
+ self.action(
+ name='ActionVerbosityInfo',
+ text=self.trUtf8('Info'),
+ group=groupVerbosity,
+ trigger=None,
+ isCheckable=True,
+ userData=fcp2.ConstDebugVerbosity.Info,
+ )
+ self.action(
+ name='ActionVerbosityMessage',
+ text=self.trUtf8('Message'),
+ group=groupVerbosity,
+ trigger=None,
+ isCheckable=True,
+ userData=fcp2.ConstDebugVerbosity.Message,
+ )
+ self.action(
+ name='ActionVerbosityDebug',
+ text=self.trUtf8('Debug'),
+ group=groupVerbosity,
+ trigger=None,
+ isCheckable=True,
+ userData=fcp2.ConstDebugVerbosity.Debug,
+ )
+ self.action(
+ name='ActionVerbosityChatty',
+ text=self.trUtf8('Chatty'),
+ group=groupVerbosity,
+ trigger=None,
+ isCheckable=True,
+ userData=fcp2.ConstDebugVerbosity.Chatty,
+ )
#***********************************************************************
#
#***********************************************************************
class MyLoggingHandler(logging.Handler):
- def __init__(self, myLogf, *args, **kwargs):
+ def __init__(self, cb, *args, **kwargs):
logging.Handler.__init__(self, *args, **kwargs)
- self.myLogf = myLogf
+ self.cb = cb
def emit(self, record):
- self.myLogf(
- '%s:%s:%s' % (record.levelname, record.name, record.getMessage())
- )
+ self.cb(record)
#***********************************************************************
#
#***********************************************************************
class ViewLoggerWidget(QtGui.QWidget, Ui_ViewLoggerWidget):
- IdEddLogger = 'edLogger'
-
+ IdEdLogger = 'edLogger'
- def __init__(self, parent, level=logging.NOTSET):
+
+ def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
- self._acts = []
self._isCreated = False
- self._mainWindowMenus = []
+ self._mainWindowMenus = {} #TODO: wrap along with toolbars to a handy class MainWindowStuff
- self.settings = Settings()
-
self.setupUi(self)
config.ObjectRegistry.register(self)
- #NOTE: do not move to showEvent(). we want to be up and alive as soon as possible
- # to catch logs
- self.settings.restore()
- ed = self.controlById(self.IdEddLogger)
+ self.actions = Actions(self)
+ self.settings = Settings(self).restore()
+
+ # setup editbox
+ #NOTE: do not move to showEvent(). we want to be up and alive as soon as possible to catch logs
+ ed = self.controlById(self.IdEdLogger)
ed.document().setMaximumBlockCount(self.settings.value('MaxLines'))
- ed.contextMenuEvent = self.edLoggerContextMenuEvent
+ ed.contextMenuEvent = self.loggerContextMenuEvent
+ self.connect(ed, QtCore.SIGNAL('textChanged()'), self.handleLoggerTextChanged)
- self.loggingHandler = MyLoggingHandler(self.addMessage)
+ # setup logger
+ self.loggingHandler = MyLoggingHandler(self.addRecord)
logging.getLogger('').addHandler(self.loggingHandler)
+
+ # setup actions
+ verbosity = self.settings.value('Verbosity').title()
+ action = self.actions.get(self.actions.PrefixVerbosity + verbosity, None)
+ if action is None:
+ verbosity = self.settings.restoreDefaults('Verbosity')['Verbosity']
+ action = self.actions.get(self.actions.PrefixVerbosity + verbosity, None)
+ if action is None:
+ raise ValueError('default verbosity action "%s" not found. WTF?' % self.actions.PrefixVerbosity + verbosity)
+ action.trigger()
# atatch menus to main window if present. have to do it in __init__ to reserve order
menuBarWrap = config.ObjectRegistry.get(config.IdMainWindowMenuBarWrap, None)
if menuBarWrap is not None:
menu = QtGui.QMenu(self.viewDisplayName(), menuBarWrap.menuBar())
- for act in self.acts():
- menu.addAction(act)
+ self.populateMenu(menu)
self._mainWindowMenus = (
menuBarWrap.addViewMenu(menu),
)
@@ -101,22 +154,29 @@
#########################################
## methods
#########################################
- def acts(self):
- if not self._acts:
- self._acts = (
- TextEditActionClear(self.controlById(self.IdEddLogger)),
- )
- return self._acts
+ def addRecord(self, record):
+ """adds a logging record"""
+
+ ed = self.controlById(self.IdEdLogger)
+ fmt = ed.currentCharFormat()
+ colorFg = self.settings.value(self.settings.PrefixVerbosityColorFg + record.levelname)
+ fmt.setForeground(QtGui.QBrush(colorFg))
+ ed.setCurrentCharFormat(fmt)
+
+ text = '%s:%s:%s' % (record.levelname, record.name, record.getMessage())
+ ed.appendPlainText(text)
- def addMessage(self, text):
- ed = self.controlById(self.IdEddLogger)
- ed.append(text)
-
-
def controlById(self, idControl):
return getattr(self, idControl)
+
+ def populateMenu(self, menu):
+ menu.addAction(self.actions['ActionLoggerClear'])
+ subMenu = menu.addMenu(self.trUtf8('Verbosity'))
+ subMenu.addActions(self.actions['GroupVerbosity'].actions())
+ return menu
+
#########################################
##view methods
#########################################
@@ -140,20 +200,36 @@
#########################################
## overwritten events
#########################################
- def edLoggerContextMenuEvent(self, event):
+ def loggerContextMenuEvent(self, event):
"""customize context menu of the logger QTextEdit"""
- ed = self.controlById(self.IdEddLogger)
+ ed = self.controlById(self.IdEdLogger)
menu = ed.createStandardContextMenu()
- for act in self.acts():
- menu.addAction(act)
+ self.populateMenu(menu)
menu.exec_(event.globalPos())
+
def showEvent(self, event):
if self._isCreated:
return
self._isCreated = True
+
+ #########################################
+ ## event handlers
+ #########################################
+ def handleActionLoggerClear(self, action):
+ self.controlById(self.IdEdLogger).clear()
-
+
+ def handleGroupVerbosityTriggered(self, action):
+ nameVerbosity = action.objectName()[len(self.actions.PrefixVerbosity):]
+ self.settings.setValues(Verbosity=nameVerbosity)
+ logging.getLogger().setLevel(action.userData())
+
+
+ def handleLoggerTextChanged(self):
+ ed = self.controlById(self.IdEdLogger)
+ self.actions['ActionLoggerClear'].setEnabled(not ed.document().isEmpty())
+
#**********************************************************************************
#
#**********************************************************************************
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|