RessourceEditor.py
changeset 566 6014ef82a98a
parent 564 5024d42e1050
child 573 0a6b2e1f8ce3
equal deleted inserted replaced
565:94c11207aa6f 566:6014ef82a98a
    99     def __init__(self, parent, data, colnames):
    99     def __init__(self, parent, data, colnames):
   100         # The base class must be initialized *first*
   100         # The base class must be initialized *first*
   101         wx.grid.PyGridTableBase.__init__(self)
   101         wx.grid.PyGridTableBase.__init__(self)
   102         self.data = data
   102         self.data = data
   103         self.colnames = colnames
   103         self.colnames = colnames
   104         self.Errors = {}
   104         self.Highlights = {}
   105         self.Parent = parent
   105         self.Parent = parent
   106         
   106         
   107         self.ColAlignements = []
   107         self.ColAlignements = []
   108         self.ColSizes = []
   108         self.ColSizes = []
   109         # XXX
   109         # XXX
   208             attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
   208             attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
   209             grid.SetColAttr(col, attr)
   209             grid.SetColAttr(col, attr)
   210             grid.SetColSize(col, self.ColSizes[col])
   210             grid.SetColSize(col, self.ColSizes[col])
   211         
   211         
   212         for row in range(self.GetNumberRows()):
   212         for row in range(self.GetNumberRows()):
       
   213             row_highlights = self.Highlights.get(row, {})
   213             for col in range(self.GetNumberCols()):
   214             for col in range(self.GetNumberCols()):
   214                 editor = None
   215                 editor = None
   215                 renderer = None
   216                 renderer = None
   216                 colname = self.GetColLabelValue(col, False)
   217                 colname = self.GetColLabelValue(col, False)
   217                 grid.SetReadOnly(row, col, False)
   218                 grid.SetReadOnly(row, col, False)
   242                     editor.SetParameters(self.Parent.TaskList)
   243                     editor.SetParameters(self.Parent.TaskList)
   243                     
   244                     
   244                 grid.SetCellEditor(row, col, editor)
   245                 grid.SetCellEditor(row, col, editor)
   245                 grid.SetCellRenderer(row, col, renderer)
   246                 grid.SetCellRenderer(row, col, renderer)
   246                 
   247                 
   247                 if row in self.Errors and self.Errors[row][0] == colname.lower():
   248                 highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
   248                     grid.SetCellBackgroundColour(row, col, wx.Colour(255, 255, 0))
   249                 grid.SetCellBackgroundColour(row, col, highlight_colours[0])
   249                     grid.SetCellTextColour(row, col, wx.RED)
   250                 grid.SetCellTextColour(row, col, highlight_colours[1])
   250                     grid.MakeCellVisible(row, col)
       
   251                 else:
       
   252                     grid.SetCellTextColour(row, col, wx.BLACK)
       
   253                     grid.SetCellBackgroundColour(row, col, wx.WHITE)
       
   254             if wx.Platform == '__WXMSW__':
   251             if wx.Platform == '__WXMSW__':
   255                 grid.SetRowMinimalHeight(row, 20)
   252                 grid.SetRowMinimalHeight(row, 20)
   256             else:
   253             else:
   257                 grid.SetRowMinimalHeight(row, 28)
   254                 grid.SetRowMinimalHeight(row, 28)
   258             grid.AutoSizeRow(row, False)
   255             grid.AutoSizeRow(row, False)
   287 
   284 
   288     def Empty(self):
   285     def Empty(self):
   289         self.data = []
   286         self.data = []
   290         self.editors = []
   287         self.editors = []
   291 
   288 
   292     def AddError(self, infos):
   289 #-------------------------------------------------------------------------------
   293         self.Errors[infos[0]] = infos[1:]
   290 #                        Highlights showing functions
   294 
   291 #-------------------------------------------------------------------------------
   295     def ClearErrors(self):
   292 
   296         self.Errors = {}
   293     def OnRefreshHighlightsTimer(self, event):
       
   294         self.Table.ResetView(self.VariablesGrid)
       
   295         event.Skip()
       
   296 
       
   297     def AddHighlight(self, infos, highlight_type):
       
   298         row_highlights = self.Highlights.setdefault(infos[0], {})
       
   299         col_highlights = row_highlights.setdefault(infos[1], [])
       
   300         col_highlights.append(highlight_type)
       
   301         self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
       
   302 
       
   303     def ClearHighlights(self, highlight_type=None):
       
   304         if highlight_type is None:
       
   305             self.Highlights = {}
       
   306         else:
       
   307             for row, row_highlights in self.Highlights.iteritems():
       
   308                 row_items = row_highlights.items()
       
   309                 for col, col_highlights in row_items:
       
   310                     if highlight_type in col_highlights:
       
   311                         col_highlights.remove(highlight_type)
       
   312                     if len(col_highlights) == 0:
       
   313                         row_highlights.pop(col)
   297 
   314 
   298 [ID_RESOURCEEDITOR, ID_RESOURCEEDITORSTATICTEXT1,
   315 [ID_RESOURCEEDITOR, ID_RESOURCEEDITORSTATICTEXT1,
   299  ID_RESOURCEEDITORSTATICTEXT2, ID_RESOURCEEDITORINSTANCESGRID,
   316  ID_RESOURCEEDITORSTATICTEXT2, ID_RESOURCEEDITORINSTANCESGRID,
   300  ID_RESOURCEEDITORTASKSGRID, ID_RESOURCEEDITORADDINSTANCEBUTTON,
   317  ID_RESOURCEEDITORTASKSGRID, ID_RESOURCEEDITORADDINSTANCEBUTTON,
   301  ID_RESOURCEEDITORDELETEINSTANCEBUTTON, ID_RESOURCEEDITORUPINSTANCEBUTTON,
   318  ID_RESOURCEEDITORDELETEINSTANCEBUTTON, ID_RESOURCEEDITORUPINSTANCEBUTTON,
   463         
   480         
   464         self.ParentWindow = window
   481         self.ParentWindow = window
   465         self.Controler = controler
   482         self.Controler = controler
   466         self.TagName = tagname
   483         self.TagName = tagname
   467         
   484         
       
   485         self.RefreshHighlightsTimer = wx.Timer(self, -1)
       
   486         self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
       
   487         
   468         self.TasksDefaultValue = {"Name" : "", "Triggering" : "", "Single" : "", "Interval" : "", "Priority" : 0}
   488         self.TasksDefaultValue = {"Name" : "", "Triggering" : "", "Single" : "", "Interval" : "", "Priority" : 0}
   469         self.TasksTable = ResourceTable(self, [], GetTasksTableColnames())
   489         self.TasksTable = ResourceTable(self, [], GetTasksTableColnames())
   470         self.TasksTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT])
   490         self.TasksTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT])
   471         self.TasksTable.SetColSizes([200, 100, 100, 150, 100])
   491         self.TasksTable.SetColSizes([200, 100, 100, 150, 100])
   472         self.TasksGrid.SetTable(self.TasksTable)
   492         self.TasksGrid.SetTable(self.TasksTable)
   478         self.InstancesTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT])
   498         self.InstancesTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT])
   479         self.InstancesTable.SetColSizes([200, 150, 150])
   499         self.InstancesTable.SetColSizes([200, 150, 150])
   480         self.InstancesGrid.SetTable(self.InstancesTable)
   500         self.InstancesGrid.SetTable(self.InstancesTable)
   481         self.InstancesGrid.SetRowLabelSize(0)
   501         self.InstancesGrid.SetRowLabelSize(0)
   482         self.InstancesTable.ResetView(self.InstancesGrid)
   502         self.InstancesTable.ResetView(self.InstancesGrid)
       
   503 
       
   504     def __del__(self):
       
   505         self.RefreshHighlightsTimer.Stop()
   483 
   506 
   484     def SetTagName(self, tagname):
   507     def SetTagName(self, tagname):
   485         self.TagName = tagname
   508         self.TagName = tagname
   486         
   509         
   487     def GetTagName(self):
   510     def GetTagName(self):
   666         self.RefreshModel()
   689         self.RefreshModel()
   667         self.ParentWindow.RefreshInstancesTree()
   690         self.ParentWindow.RefreshInstancesTree()
   668         event.Skip()
   691         event.Skip()
   669 
   692 
   670 #-------------------------------------------------------------------------------
   693 #-------------------------------------------------------------------------------
   671 #                        Errors showing functions
   694 #                      Search result showing functions
   672 #-------------------------------------------------------------------------------
   695 #-------------------------------------------------------------------------------
   673 
   696 
   674     def ClearErrors(self):
   697     def AddShownSearchResult(self, infos, start, end):
   675         self.TasksTable.ClearErrors()
   698         if infos[0] == "task":
   676         self.InstancesTable.ClearErrors()
   699             self.TasksTable.AddSearchResult(infos[1:])
       
   700         elif infos[0] == "instance":
       
   701             self.InstancesTable.AddSearchResult(infos[1:])
       
   702 
       
   703     def ClearSearchResults(self):
       
   704         self.TasksTable.ClearSearchResults()
       
   705         self.InstancesTable.ClearSearchResults()
   677         self.TasksTable.ResetView(self.TasksGrid)
   706         self.TasksTable.ResetView(self.TasksGrid)
   678         self.InstancesTable.ResetView(self.InstancesGrid)
   707         self.InstancesTable.ResetView(self.InstancesGrid)
   679 
   708 
   680     def AddShownError(self, infos, start, end):
   709 
       
   710 #-------------------------------------------------------------------------------
       
   711 #                        Highlights showing functions
       
   712 #-------------------------------------------------------------------------------
       
   713 
       
   714     def AddHighlight(self, infos, start, end, highlight_type):
   681         if infos[0] == "task":
   715         if infos[0] == "task":
   682             self.TasksTable.AddError(infos[1:])
   716             self.TasksTable.AddHighlight(infos[1:], highlight_type)
   683         elif infos[0] == "instance":
   717         elif infos[0] == "instance":
   684             self.InstancesTable.AddError(infos[1:])
   718             self.InstancesTable.AddHighlight(infos[1:], highlight_type)
   685 
   719 
       
   720     def ClearHighlights(self, highlight_type=None):
       
   721         self.TasksTable.ClearHighlights(highlight_type)
       
   722         self.InstancesTable.ClearHighlights(highlight_type)
       
   723         self.TasksTable.ResetView(self.TasksGrid)
       
   724         self.InstancesTable.ResetView(self.InstancesGrid)
   686 
   725 
   687 class DurationCellControl(wx.PyControl):
   726 class DurationCellControl(wx.PyControl):
   688     
   727     
   689     def _init_coll_MainSizer_Items(self, parent):
   728     def _init_coll_MainSizer_Items(self, parent):
   690         parent.AddWindow(self.Duration, 0, border=0, flag=wx.GROW)
   729         parent.AddWindow(self.Duration, 0, border=0, flag=wx.GROW)