SF.net SVN: fclient: [626] trunk/fclient/src/fclient/Ui_ViewLogger.py
Status: Pre-Alpha
Brought to you by:
jurner
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. |