C:/mesDocs/QT_confDbVis_canvas/LogWindow.py

Go to the documentation of this file.
00001 import string
00002 
00003 from wxPython.wx import *
00004 from wxPython.grid import *
00005 
00006 from cdbVisCore import *
00007 
00008 ##################################################
00009 # ErrorMessageGrid Class                        ##
00010 ##################################################
00011 
00012 ##
00013 #  A custom data grid class inherited from wxGrid to show 
00014 #       all information and error messages throughout the current session.
00015 #       
00016 class ErrorMessageGrid(wxGrid):
00017         
00018         ##
00019         #  Constructor.
00020         # 
00021         #                   Parameters;
00022         #                   @parent - the parent of this class (usually LogWindow)
00023         #               
00024         def __init__(self,parent):
00025                 
00026                 wxGrid.__init__(self,parent,-1,size=wxSize(540,200))
00027                 
00028                 self.CreateGrid(0,2)
00029                 self.SetColLabelSize(20)
00030                 self.SetRowLabelSize(0)
00031                 self.SetColLabelValue(0,"Message Type")
00032                 self.SetColLabelValue(1,"Message")
00033                 self.EnableEditing(False) #Sets the whole data grid to read only
00034 
00035 
00036 ##################################################
00037 # LogWindow Class                               ##
00038 ##################################################
00039 
00040 # GUI CONSTANTS
00041 MESSAGE_ID = 123
00042 ERRORTYPES_ID = 124
00043 
00044 ##
00045 #  The whole window displaying the error message data grid and a possibillity
00046 #       to double-click on the items in this grid to view the whole message in a text
00047 #       box control.
00048 # 
00049 #       The error and information messages are loaded in from the log file of the current session.
00050 #       
00051 class LogWindow(wxDialog):
00052         ##
00053         #  Constructor.
00054         # 
00055         #                   Parameters:
00056         #                   @parent - the parent of this window (usually MainWindow)
00057         #                   @id     - the id of this window (set by its parent)
00058         #                   @file   - the log session file for the current session (string)
00059         #               
00060         def __init__(self,parent,id,file):
00061                 
00062                 wxDialog.__init__(self,parent,id,"CdbVis Session log",wxDefaultPosition,wxSize(560,460))
00063 
00064                 self.main = parent
00065                 self.file = file
00066 
00067                 # Panel
00068                 self.__panel = wxPanel(self,-1,wxDLG_PNT(self,wxPoint(5,5)))
00069 
00070                 # Message text box
00071                 self.__messagecaption = wxStaticText(self.__panel,-1,"Message:")
00072                 self.__messagetxtbox = wxTextCtrl(self.__panel,MESSAGE_ID,"",wxPoint(-1,-1),size=wxSize(400,100),style=wxTE_READONLY | wxTE_MULTILINE)
00073 
00074                 # Choose which messages to show (filter out)
00075                 radiochoices = ["All","Info","Error","Critical"]
00076                 self.__errortypes = wxRadioBox(self.__panel,ERRORTYPES_ID,"View errors of type:",wxDefaultPosition,wxDefaultSize,radiochoices,1,wxRA_SPECIFY_ROWS)
00077                 EVT_RADIOBOX(self.__panel,ERRORTYPES_ID,self.OnErrorTypeChoice)
00078 
00079                 # The error message grid
00080                 self.__datagrid = ErrorMessageGrid(self.__panel)
00081                 self.__infocaption = wxStaticText(self.__panel,-1,"Double-click on a message row to display the message in the text control above.")
00082 
00083                 self.__okbutton = wxButton(self.__panel,wxID_OK,"&Ok")
00084 
00085                 # Load the messages from the log file at startup of this window
00086                 self.LoadLogFileData(self.__errortypes.GetSelection())
00087                 
00088                 # can double click on items in the error message grid
00089                 EVT_GRID_CELL_LEFT_DCLICK(self.__datagrid,self.OnRowChoice)
00090 
00091 
00092                 #Layout
00093                 self.__mylayout = wxBoxSizer(wxVERTICAL)
00094                 self.__mylayout.Add(self.__messagecaption)
00095                 self.__mylayout.Add(self.__messagetxtbox)
00096                 self.__mylayout.AddSpacer((-1,10))
00097                 self.__mylayout.Add(self.__errortypes)
00098                 self.__mylayout.AddSpacer((-1,10))
00099                 self.__mylayout.Add(self.__datagrid)
00100                 self.__mylayout.AddSpacer((-1,5))
00101                 self.__mylayout.Add(self.__infocaption)
00102 
00103                 buttonlayout = wxBoxSizer(wxHORIZONTAL)
00104                 buttonlayout.AddSpacer((400,-1))
00105                 buttonlayout.Add(self.__okbutton)
00106                 
00107                 self.__mylayout.AddSpacer((-1,5))
00108                 self.__mylayout.Add(buttonlayout)
00109 
00110                 self.SetSizer(self.__mylayout)
00111                 self.SetAutoLayout(1)
00112                 self.__mylayout.Fit(self.__panel)
00113 
00114 
00115         ##
00116         #  Load the messages from the log session file
00117         #               and display them in the error message grid.
00118         # 
00119         #               Parameters:
00120         #               @choice - Which of the radioboxes that are checked ( what type(s) of messages to show)
00121         #               
00122         def LoadLogFileData(self,choice):
00123                 
00124                 # Reset the message data grid
00125                 nrofrows = self.__datagrid.GetNumberRows()
00126                 while nrofrows > 0:
00127                         self.__datagrid.DeleteRows(0,1)
00128                         nrofrows -= 1
00129                 
00130                 # Open log session file
00131                 try:
00132                         file = open(self.file,"r")
00133                 except IOError,err:
00134                         self.main.ShowError("Log file not found!",ERR_ERROR,True)
00135                         return False
00136 
00137                 # Read from the log session file, but it is empty
00138                 if file.read(1) == "":
00139                         self.main.ShowError("Log file was empty!",ERR_ERROR,True)
00140                         file.close()
00141                         # self.LoadLogFileData(self.__errortypes.GetSelection()) #since we added a error message, show it :)
00142                         # Can lead to neverending loop...therefore skipped
00143                         return False
00144                 file.close()
00145 
00146                 # Read from the log session file, and it is not empty
00147                 file = open(self.file,"r")
00148                 for line in file:
00149                         message_line = line.split("|") #split into 4 array indexes: index 1 contains now the errortype, index 3 the message
00150                 
00151                         msgtype = message_line[1].strip()
00152 
00153                         # Add the messages to the message grid
00154                         if (choice == 0) or (choice == 1 and msgtype == "Information") or (choice == 2 and msgtype == "Error") or (choice == 3 and msgtype == "Critical"):
00155                                 self.__datagrid.InsertRows(0,1) # 1 row at position 0
00156                                 self.__datagrid.SetCellValue(0,0,str(message_line[1]))
00157                                 self.__datagrid.SetCellValue(0,1,str(message_line[3]))
00158 
00159                 file.close()
00160                 self.__datagrid.AutoSizeColumns()
00161         
00162         
00163         ##
00164         #  If one clicks on a message row, we will display the message
00165         #               row that was click in the text box..so that the user can read the
00166         #               whole message.
00167         #               
00168         def OnRowChoice(self,event):
00169                 
00170                 row = event.GetRow()
00171                 self.__messagetxtbox.SetValue(self.__datagrid.GetCellValue(row,1))
00172 
00173         ##
00174         #  If we change the selection of what kinds of error types to
00175         #               view and filter out; reload all data.
00176         #               
00177         def OnErrorTypeChoice(self,event):
00178                 
00179                 errortype = self.__errortypes.GetSelection()
00180                 self.LoadLogFileData(errortype)
00181 
00182 

Generated on Fri Aug 31 11:11:14 2007 for CDBVis by  doxygen 1.5.3