00001 import string
00002
00003 from wxPython.wx import *
00004 from wxPython.grid import *
00005
00006 from cdbVisCore import *
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 class ErrorMessageGrid(wxGrid):
00017
00018
00019
00020
00021
00022
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)
00034
00035
00036
00037
00038
00039
00040
00041 MESSAGE_ID = 123
00042 ERRORTYPES_ID = 124
00043
00044
00045
00046
00047
00048
00049
00050
00051 class LogWindow(wxDialog):
00052
00053
00054
00055
00056
00057
00058
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
00068 self.__panel = wxPanel(self,-1,wxDLG_PNT(self,wxPoint(5,5)))
00069
00070
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
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
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
00086 self.LoadLogFileData(self.__errortypes.GetSelection())
00087
00088
00089 EVT_GRID_CELL_LEFT_DCLICK(self.__datagrid,self.OnRowChoice)
00090
00091
00092
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
00117
00118
00119
00120
00121
00122 def LoadLogFileData(self,choice):
00123
00124
00125 nrofrows = self.__datagrid.GetNumberRows()
00126 while nrofrows > 0:
00127 self.__datagrid.DeleteRows(0,1)
00128 nrofrows -= 1
00129
00130
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
00138 if file.read(1) == "":
00139 self.main.ShowError("Log file was empty!",ERR_ERROR,True)
00140 file.close()
00141
00142
00143 return False
00144 file.close()
00145
00146
00147 file = open(self.file,"r")
00148 for line in file:
00149 message_line = line.split("|")
00150
00151 msgtype = message_line[1].strip()
00152
00153
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)
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
00165
00166
00167
00168 def OnRowChoice(self,event):
00169
00170 row = event.GetRow()
00171 self.__messagetxtbox.SetValue(self.__datagrid.GetCellValue(row,1))
00172
00173
00174
00175
00176
00177 def OnErrorTypeChoice(self,event):
00178
00179 errortype = self.__errortypes.GetSelection()
00180 self.LoadLogFileData(errortype)
00181
00182