LoggerWidget.py :  » Network » Luma » luma-2.4 » lib » luma » base » utils » gui » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » Luma 
Luma » luma 2.4 » lib » luma » base » utils » gui » LoggerWidget.py
# -*- coding: utf-8 -*-

###########################################################################
#    Copyright (C) 2005 by Wido Depping                                      
#    <widod@users.sourceforge.net>                                                             
#
# Copyright: See COPYING file that comes with this distribution
#
###########################################################################

from qt import *
from ConfigParser import *
import os.path

from base.utils.gui.LoggerWidgetDesign import LoggerWidgetDesign
from base.utils.backend.LogObject import LogObject
import environment


class LoggerWidget(LoggerWidgetDesign):

    def __init__(self,parent = None,name = None,fl = 0):
        LoggerWidgetDesign.__init__(self,parent,name,fl)
        
        self.parent = parent
        self.configFile = os.path.join(environment.userHomeDir, ".luma", "luma")
        self.readSettings()
        
        self.logObjectList = []
        
        self.connect(self.errorBox, SIGNAL("stateChanged(int)"), self.displayMessages)
        self.connect(self.debugBox, SIGNAL("stateChanged(int)"), self.displayMessages)
        self.connect(self.infoBox, SIGNAL("stateChanged(int)"), self.displayMessages)
        

###############################################################################

    def displayMessages(self):
        self.messageEdit.clear()
        
        for x in self.logObjectList:
            self.appendMessage(x)
            
        self.saveSettings()
            
###############################################################################

    def appendMessage(self, messageObject):
        if (messageObject.getLogType() == "Debug") and self.debugBox.isOn():
            self.messageEdit.append(messageObject.getLogMessage())
            self.messageEdit.append("\n")
            return
            
        if (messageObject.getLogType() == "Error") and self.errorBox.isOn():
            self.messageEdit.append(messageObject.getLogMessage())
            self.messageEdit.append("\n")
            return
            
        if (messageObject.getLogType() == "Info") and self.infoBox.isOn():
            self.messageEdit.append(messageObject.getLogMessage())
            self.messageEdit.append("\n")
            return
            
###############################################################################

    def newMessage(self, messageObject):
        self.logObjectList.append(messageObject)
        if len(self.logObjectList) > 100:
                del self.logObjectList[0]
                
        if not (self.parent.orientation() == Qt.DockMinimized):
                self.appendMessage(messageObject)
                
###############################################################################

    def clearLogger(self):
        self.logObjectList = []
        self.messageEdit.clear()
        
###############################################################################

    def saveSettings(self):
        configParser = ConfigParser()
            
        try:
            configParser.readfp(open(self.configFile, 'r'))
        except Exception, errorData:
            tmpString = "Could not read logger settings file. Reason:\n"
            tmpString += str(errorData)
            environment.logMessage(LogObject("Debug", tmpString))
            
        if not configParser.has_section("Logger"):
            configParser.add_section("Logger")
            
        configParser.set("Logger", "Show_Error", str(self.errorBox.isOn()))
        configParser.set("Logger", "Show_Debug", str(self.debugBox.isOn()))
        configParser.set("Logger", "Show_Info", str(self.infoBox.isOn()))
        
        try:
            configParser.write(open(self.configFile, 'w'))
        except Exception, errorData:
            tmpString = "Could not save logger settings file. Reason:\n"
            tmpString += str(errorData)
            environment.logMessage(LogObject("Error", tmpString))
            
###############################################################################

    def readSettings(self):
        configParser = ConfigParser()
            
        try:
            configParser.readfp(open(self.configFile, 'r'))
        except Exception, errorData:
            tmpString = "Could not read logger settings file. Reason:\n"
            tmpString += str(errorData)
            print tmpString
            #environment.logMessage(LogObject("Debug", tmpString))
            
        if not configParser.has_section("Logger"):
            return
         
        if configParser.has_option("Logger", "Show_Error"):
            tmpBool = configParser.getboolean("Logger", "Show_Error")
            self.errorBox.setChecked(tmpBool)
            
        if configParser.has_option("Logger", "Show_Debug"):
            tmpBool = configParser.getboolean("Logger", "Show_Debug")
            self.debugBox.setChecked(tmpBool)
            
        if configParser.has_option("Logger", "Show_Info"):
            tmpBool = configParser.getboolean("Logger", "Show_Info")
            self.infoBox.setChecked(tmpBool)
            
            
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.