Thread: SF.net SVN: fclient: [548] trunk/fclient/src/fclient/Ui_ViewLogger.py
Status: Pre-Alpha
Brought to you by:
jurner
From: <jU...@us...> - 2008-07-08 10:50:24
|
Revision: 548 http://fclient.svn.sourceforge.net/fclient/?rev=548&view=rev Author: jUrner Date: 2008-07-08 03:49:27 -0700 (Tue, 08 Jul 2008) Log Message: ----------- started implementing logger Added Paths: ----------- trunk/fclient/src/fclient/Ui_ViewLogger.py Added: trunk/fclient/src/fclient/Ui_ViewLogger.py =================================================================== --- trunk/fclient/src/fclient/Ui_ViewLogger.py (rev 0) +++ trunk/fclient/src/fclient/Ui_ViewLogger.py 2008-07-08 10:49:27 UTC (rev 548) @@ -0,0 +1,39 @@ + +from __future__ import absolute_import +if __name__ == '__main__': # see --> http://bugs.python.org/issue1510172 . works only current dir and below + import os; __path__ = [os.path.dirname(__file__)] + + +from PyQt4 import QtGui + + +from . import config +from .tpls.Ui_ViewLoggerTpl import Ui_ViewLoggerTpl +#********************************************************************************** +# +#********************************************************************************** +#*********************************************************************** +# +#*********************************************************************** +class ViewWidgetLogger(QtGui.QWidget, Ui_ViewLoggerTpl): + + def __init__(self, parent, cfg=None): + QtGui.QWidget.__init__(self, parent) + + + self.cfg = config.Config(self) if cfg is None else cfg + + + self.setupUi(self) + +#********************************************************************************** +# +#********************************************************************************** +if __name__ == '__main__': + import sys + + app = QtGui.QApplication(sys.argv) + w = ViewWidgetLogger(None) + w.show() + res = app.exec_() + sys.exit(res) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-07-11 16:33:31
|
Revision: 575 http://fclient.svn.sourceforge.net/fclient/?rev=575&view=rev Author: jUrner Date: 2008-07-11 09:33:36 -0700 (Fri, 11 Jul 2008) Log Message: ----------- too many changes to list 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-11 16:33:29 UTC (rev 574) +++ trunk/fclient/src/fclient/Ui_ViewLogger.py 2008-07-11 16:33:36 UTC (rev 575) @@ -3,6 +3,9 @@ if __name__ == '__main__': # see --> http://bugs.python.org/issue1510172 . works only current dir and below import os; __path__ = [os.path.dirname(__file__)] +import logging +import sys +logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) from PyQt4 import QtGui @@ -14,21 +17,56 @@ #********************************************************************************** # #********************************************************************************** +class Settings(config.SettingsBase): + + _key_ = config.IdViewLoggerWidget + _settings_ = ( + ('MaxLines', 'UInt', 1000), + ) + #*********************************************************************** # #*********************************************************************** class ViewLoggerWidget(QtGui.QWidget, Ui_ViewLoggerWidget): - def __init__(self, parent, cfg=None): - QtGui.QWidget.__init__(self, parent) + IdEddLogger = 'edLogger' + + class MyLoggingHandler(logging.Handler): + def __init__(self, myLogf, *args, **kwargs): + logging.Handler.__init__(self, *args, **kwargs) + self.myLogf = myLogf - self.cfg = config.Config(self) if cfg is None else cfg + def emit(self, record): + self.myLogf( + '%s:%s:%s' % (record.levelname, record.name, record.getMessage()) + ) + + + def __init__(self, parent, cfg=None, level=logging.NOTSET): + QtGui.QWidget.__init__(self, parent) + self.settings = Settings() - self.setupUi(self) config.ObjectRegistry.register(self) - + + self.settings.restore() + ed = self.controlById(self.IdEddLogger) + ed.document().setMaximumBlockCount(self.settings.value('MaxLines')) + + self.loggingHandler = self.MyLoggingHandler(self.addMessage) + logging.getLogger('').addHandler(self.loggingHandler) + + + def controlById(self, idControl): + return getattr(self, idControl) + + def addMessage(self, text): + print text, type(text) + + ed = self.controlById(self.IdEddLogger) + ed.append(text) + #********************************************************************************** # #********************************************************************************** @@ -36,7 +74,7 @@ def __init__(self): self._widget = None - + def displayName(self): return QtGui.QApplication.translate("ViewLogger", "Logger", None, QtGui.QApplication.UnicodeUTF8) @@ -51,7 +89,9 @@ if self._widget is None: self._widget = ViewLoggerWidget(parent) return self._widget - + + def close(self): + pass #********************************************************************************** # This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-07-12 11:08:10
|
Revision: 585 http://fclient.svn.sourceforge.net/fclient/?rev=585&view=rev Author: jUrner Date: 2008-07-12 04:08:08 -0700 (Sat, 12 Jul 2008) Log Message: ----------- left over print statement 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-12 11:07:35 UTC (rev 584) +++ trunk/fclient/src/fclient/Ui_ViewLogger.py 2008-07-12 11:08:08 UTC (rev 585) @@ -62,8 +62,6 @@ return getattr(self, idControl) def addMessage(self, text): - print text, type(text) - ed = self.controlById(self.IdEddLogger) ed.append(text) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-07-12 20:00:05
|
Revision: 601 http://fclient.svn.sourceforge.net/fclient/?rev=601&view=rev Author: jUrner Date: 2008-07-12 13:00:08 -0700 (Sat, 12 Jul 2008) Log Message: ----------- customize context menu 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-12 19:59:24 UTC (rev 600) +++ trunk/fclient/src/fclient/Ui_ViewLogger.py 2008-07-12 20:00:08 UTC (rev 601) @@ -7,7 +7,7 @@ import sys logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) -from PyQt4 import QtGui +from PyQt4 import QtCore, QtGui from . import config @@ -21,9 +21,31 @@ _key_ = config.IdViewLoggerWidget _settings_ = ( - ('MaxLines', 'UInt', 1000), + ('MaxLines', 'UInt', 1000, config.SettingScopeUser), ) +#*********************************************************************** +# +#*********************************************************************** +#TODO: more here... +class TextEditActionClear(QtGui.QAction): + + def __init__(self, menu, 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(menu, QtCore.SIGNAL('aboutToShow()'), self.handleMenuAboutToShow) + + self.ed = ed + + def handleMenuAboutToShow(self): + self.setEnabled(not self.ed.document().isEmpty()) + + def handleTriggered(self, isChecked): + self.ed.clear() + + #*********************************************************************** # #*********************************************************************** @@ -53,6 +75,7 @@ self.settings.restore() ed = self.controlById(self.IdEddLogger) ed.document().setMaximumBlockCount(self.settings.value('MaxLines')) + ed.contextMenuEvent = self.edLoggerContextMenuEvent self.loggingHandler = self.MyLoggingHandler(self.addMessage) logging.getLogger('').addHandler(self.loggingHandler) @@ -65,6 +88,22 @@ ed = self.controlById(self.IdEddLogger) ed.append(text) + +######################################### + ## overwritten events + ######################################### + def edLoggerContextMenuEvent(self, event): + """customize context menu of the logger QTextEdit""" + ed = self.controlById(self.IdEddLogger) + menu = ed.createStandardContextMenu() + + act = TextEditActionClear(menu, ed) + menu.addAction(act) + + menu.exec_(event.globalPos()) + + + #********************************************************************************** # #********************************************************************************** @@ -91,14 +130,4 @@ def close(self): pass -#********************************************************************************** -# -#********************************************************************************** -if __name__ == '__main__': - import sys - - app = QtGui.QApplication(sys.argv) - w = ViewLoggerWidget(None) - w.show() - res = app.exec_() - sys.exit(res) + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-07-13 14:20:24
|
Revision: 626 http://fclient.svn.sourceforge.net/fclient/?rev=626&view=rev Author: jUrner Date: 2008-07-13 07:20:33 -0700 (Sun, 13 Jul 2008) Log Message: ----------- continued impl widget 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-13 14:20:28 UTC (rev 625) +++ trunk/fclient/src/fclient/Ui_ViewLogger.py 2008-07-13 14:20:33 UTC (rev 626) @@ -29,105 +29,144 @@ #TODO: more here... class TextEditActionClear(QtGui.QAction): - def __init__(self, menu, ed): + 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(menu, QtCore.SIGNAL('aboutToShow()'), self.handleMenuAboutToShow) + self.connect(ed, QtCore.SIGNAL('textChanged()'), self.handleEdTextChanged) self.ed = ed + self.handleEdTextChanged() - def handleMenuAboutToShow(self): + def handleEdTextChanged(self): self.setEnabled(not self.ed.document().isEmpty()) def handleTriggered(self, isChecked): self.ed.clear() + +#*********************************************************************** +# +#*********************************************************************** +class MyLoggingHandler(logging.Handler): + def __init__(self, myLogf, *args, **kwargs): + logging.Handler.__init__(self, *args, **kwargs) + self.myLogf = myLogf + + def emit(self, record): + self.myLogf( + '%s:%s:%s' % (record.levelname, record.name, record.getMessage()) + ) - #*********************************************************************** # #*********************************************************************** class ViewLoggerWidget(QtGui.QWidget, Ui_ViewLoggerWidget): IdEddLogger = 'edLogger' - - class MyLoggingHandler(logging.Handler): - - def __init__(self, myLogf, *args, **kwargs): - logging.Handler.__init__(self, *args, **kwargs) - self.myLogf = myLogf - - def emit(self, record): - self.myLogf( - '%s:%s:%s' % (record.levelname, record.name, record.getMessage()) - ) - def __init__(self, parent, cfg=None, level=logging.NOTSET): + def __init__(self, parent, level=logging.NOTSET): QtGui.QWidget.__init__(self, parent) + self._acts = [] + self._isCreated = False + self._mainWindowMenus = [] + 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) ed.document().setMaximumBlockCount(self.settings.value('MaxLines')) ed.contextMenuEvent = self.edLoggerContextMenuEvent - self.loggingHandler = self.MyLoggingHandler(self.addMessage) + self.loggingHandler = MyLoggingHandler(self.addMessage) logging.getLogger('').addHandler(self.loggingHandler) + # 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._mainWindowMenus = ( + menuBarWrap.addViewMenu(menu), + ) + + ######################################### + ## methods + ######################################### + def acts(self): + if not self._acts: + self._acts = ( + TextEditActionClear(self.controlById(self.IdEddLogger)), + ) + return self._acts - def controlById(self, idControl): - return getattr(self, idControl) - + def addMessage(self, text): ed = self.controlById(self.IdEddLogger) ed.append(text) - -######################################### + + def controlById(self, idControl): + return getattr(self, idControl) + + ######################################### + ##view methods + ######################################### + def viewClose(self): + pass + + def viewDisplayName(self): + return self.trUtf8('Logger') + + def viewHandleCurrentChanged(self, isCurrent): + pass + #for menu in self._mainWindowMenus: + # menu.setVisible(isCurrent) + + def viewIcon(self): + return QtGui.QIcon() + + def viewName(self): + return self.objectName() + + ######################################### ## overwritten events ######################################### def edLoggerContextMenuEvent(self, event): """customize context menu of the logger QTextEdit""" ed = self.controlById(self.IdEddLogger) menu = ed.createStandardContextMenu() + for act in self.acts(): + menu.addAction(act) + menu.exec_(event.globalPos()) - act = TextEditActionClear(menu, ed) - menu.addAction(act) + def showEvent(self, event): + if self._isCreated: + return + self._isCreated = True - menu.exec_(event.globalPos()) - - #********************************************************************************** # #********************************************************************************** -class ViewLogger(Ui_View.View): +if __name__ == '__main__': + import sys + from . import Ui_ViewLogger - def __init__(self): - self._widget = None + app = QtGui.QApplication(sys.argv) + w = ViewLoggerWidget(None) - def displayName(self): - return QtGui.QApplication.translate("ViewLogger", "Logger", None, QtGui.QApplication.UnicodeUTF8) - - def icon(self): - return QtGui.QIcon() - - def objectName(self): - return 'ViewLogger' - - - def widget(self, parent): - if self._widget is None: - self._widget = ViewLoggerWidget(parent) - return self._widget - - def close(self): - pass + w.show() + res = app.exec_() + sys.exit(res) + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |