RessourceEditor.py
changeset 564 5024d42e1050
parent 560 3757f0de0d07
child 566 6014ef82a98a
equal deleted inserted replaced
563:3f92a5e18804 564:5024d42e1050
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24 
    24 
    25 import wx
    25 import wx
    26 import wx.grid
    26 import wx.grid
    27 
    27 
       
    28 from dialogs import DurationEditorDialog
    28 
    29 
    29 #-------------------------------------------------------------------------------
    30 #-------------------------------------------------------------------------------
    30 #                          Configuration Editor class
    31 #                          Configuration Editor class
    31 #-------------------------------------------------------------------------------
    32 #-------------------------------------------------------------------------------
    32 
    33 
   212             for col in range(self.GetNumberCols()):
   213             for col in range(self.GetNumberCols()):
   213                 editor = None
   214                 editor = None
   214                 renderer = None
   215                 renderer = None
   215                 colname = self.GetColLabelValue(col, False)
   216                 colname = self.GetColLabelValue(col, False)
   216                 grid.SetReadOnly(row, col, False)
   217                 grid.SetReadOnly(row, col, False)
   217                 if colname in ["Name", "Interval"]:
   218                 if colname == "Name":
   218                     editor = wx.grid.GridCellTextEditor()
   219                     editor = wx.grid.GridCellTextEditor()
   219                     renderer = wx.grid.GridCellStringRenderer()
   220                     renderer = wx.grid.GridCellStringRenderer()
   220                     if colname == "Interval" and self.GetValueByName(row, "Triggering") != "Cyclic":
   221                 elif colname == "Interval":
       
   222                     editor = DurationCellEditor(self)
       
   223                     renderer = wx.grid.GridCellStringRenderer()
       
   224                     if self.GetValueByName(row, "Triggering") != "Cyclic":
   221                         grid.SetReadOnly(row, col, True)
   225                         grid.SetReadOnly(row, col, True)
   222                 elif colname == "Single":
   226                 elif colname == "Single":
   223                     editor = wx.grid.GridCellChoiceEditor()
   227                     editor = wx.grid.GridCellChoiceEditor()
   224                     editor.SetParameters(self.Parent.VariableList)
   228                     editor.SetParameters(self.Parent.VariableList)
   225                     if self.GetValueByName(row, "Triggering") != "Interrupt":
   229                     if self.GetValueByName(row, "Triggering") != "Interrupt":
   462         self.TagName = tagname
   466         self.TagName = tagname
   463         
   467         
   464         self.TasksDefaultValue = {"Name" : "", "Triggering" : "", "Single" : "", "Interval" : "", "Priority" : 0}
   468         self.TasksDefaultValue = {"Name" : "", "Triggering" : "", "Single" : "", "Interval" : "", "Priority" : 0}
   465         self.TasksTable = ResourceTable(self, [], GetTasksTableColnames())
   469         self.TasksTable = ResourceTable(self, [], GetTasksTableColnames())
   466         self.TasksTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT])
   470         self.TasksTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT])
   467         self.TasksTable.SetColSizes([200, 100, 100, 100, 100])
   471         self.TasksTable.SetColSizes([200, 100, 100, 150, 100])
   468         self.TasksGrid.SetTable(self.TasksTable)
   472         self.TasksGrid.SetTable(self.TasksTable)
   469         self.TasksGrid.SetRowLabelSize(0)
   473         self.TasksGrid.SetRowLabelSize(0)
   470         self.TasksTable.ResetView(self.TasksGrid)
   474         self.TasksTable.ResetView(self.TasksGrid)
   471 
   475 
   472         self.InstancesDefaultValue = {"Name" : "", "Type" : "", "Task" : ""}
   476         self.InstancesDefaultValue = {"Name" : "", "Type" : "", "Task" : ""}
   536                 task_select = len(tasks) - 1
   540                 task_select = len(tasks) - 1
   537             else:
   541             else:
   538                 task_select = min(task_select, len(tasks) - 1)
   542                 task_select = min(task_select, len(tasks) - 1)
   539             col = self.TasksGrid.GetGridCursorCol()
   543             col = self.TasksGrid.GetGridCursorCol()
   540             self.TasksGrid.SetGridCursor(task_select, col)
   544             self.TasksGrid.SetGridCursor(task_select, col)
   541             self.TasksGrid.MakeCellVisible(instance_select, col)
   545             self.TasksGrid.MakeCellVisible(task_select, col)
   542             self.TasksGrid.SetFocus()
   546             self.TasksGrid.SetFocus()
   543         if instance_select is not None and len(instances) > 0:
   547         if instance_select is not None and len(instances) > 0:
   544             if instance_select == -1:
   548             if instance_select == -1:
   545                 instance_select = len(instances) - 1
   549                 instance_select = len(instances) - 1
   546             else:
   550             else:
   547                 task_select = min(task_select, len(instances) - 1)
   551                 instance_select = min(instance_select, len(instances) - 1)
   548             col = self.InstancesGrid.GetGridCursorCol()
   552             col = self.InstancesGrid.GetGridCursorCol()
   549             self.InstancesGrid.SetGridCursor(instance_select, col)
   553             self.InstancesGrid.SetGridCursor(instance_select, col)
   550             self.InstancesGrid.MakeCellVisible(instance_select, col)
   554             self.InstancesGrid.MakeCellVisible(instance_select, col)
   551             self.InstancesGrid.SetFocus()
   555             self.InstancesGrid.SetFocus()
   552         
   556         
   676     def AddShownError(self, infos, start, end):
   680     def AddShownError(self, infos, start, end):
   677         if infos[0] == "task":
   681         if infos[0] == "task":
   678             self.TasksTable.AddError(infos[1:])
   682             self.TasksTable.AddError(infos[1:])
   679         elif infos[0] == "instance":
   683         elif infos[0] == "instance":
   680             self.InstancesTable.AddError(infos[1:])
   684             self.InstancesTable.AddError(infos[1:])
   681         
   685 
       
   686 
       
   687 class DurationCellControl(wx.PyControl):
       
   688     
       
   689     def _init_coll_MainSizer_Items(self, parent):
       
   690         parent.AddWindow(self.Duration, 0, border=0, flag=wx.GROW)
       
   691         parent.AddWindow(self.EditButton, 0, border=0, flag=wx.GROW)
       
   692         
       
   693     def _init_coll_MainSizer_Growables(self, parent):
       
   694         parent.AddGrowableCol(0)
       
   695         parent.AddGrowableRow(0)
       
   696     
       
   697     def _init_sizers(self):
       
   698         self.MainSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0)
       
   699         
       
   700         self._init_coll_MainSizer_Items(self.MainSizer)
       
   701         self._init_coll_MainSizer_Growables(self.MainSizer)
       
   702         
       
   703         self.SetSizer(self.MainSizer)
       
   704     
       
   705     def _init_ctrls(self, prnt):
       
   706         wx.Control.__init__(self, id=-1, 
       
   707               name='DurationCellControl', parent=prnt,  
       
   708               size=wx.DefaultSize, style=0)
       
   709         
       
   710         # create location text control
       
   711         self.Duration = wx.TextCtrl(id=-1, name='Duration', parent=self,
       
   712               pos=wx.Point(0, 0), size=wx.Size(0, 0), style=wx.TE_PROCESS_ENTER)
       
   713         self.Duration.Bind(wx.EVT_KEY_DOWN, self.OnDurationChar)
       
   714         
       
   715         # create browse button
       
   716         self.EditButton = wx.Button(id=-1, label='...', 
       
   717               name='EditButton', parent=self, pos=wx.Point(0, 0), 
       
   718               size=wx.Size(30, 0), style=0)
       
   719         self.EditButton.Bind(wx.EVT_BUTTON, self.OnEditButtonClick)
       
   720 
       
   721         self.Bind(wx.EVT_SIZE, self.OnSize)
       
   722         
       
   723         self._init_sizers()
       
   724 
       
   725     '''
       
   726     Custom cell editor control with a text box and a button that launches
       
   727     the DurationEditorDialog.
       
   728     '''
       
   729     def __init__(self, parent):
       
   730         self._init_ctrls(parent)
       
   731         
       
   732     def SetValue(self, value):
       
   733         self.Duration.SetValue(value)
       
   734     
       
   735     def GetValue(self):
       
   736         return self.Duration.GetValue()
       
   737 
       
   738     def OnSize(self, event):
       
   739         self.Layout()
       
   740 
       
   741     def OnEditButtonClick(self, event):
       
   742         # pop up the Duration Editor dialog
       
   743         dialog = DurationEditorDialog(self)
       
   744         dialog.SetDuration(self.Duration.GetValue())
       
   745         if dialog.ShowModal() == wx.ID_OK:
       
   746             # set the duration
       
   747             self.Duration.SetValue(dialog.GetDuration())
       
   748 
       
   749         dialog.Destroy()
       
   750 
       
   751         self.Duration.SetFocus()
       
   752 
       
   753     def OnDurationChar(self, event):
       
   754         keycode = event.GetKeyCode()
       
   755         if keycode == wx.WXK_RETURN or keycode == wx.WXK_TAB:
       
   756             self.Parent.Parent.ProcessEvent(event)
       
   757             self.Parent.Parent.SetFocus()
       
   758         else:
       
   759             event.Skip()
       
   760 
       
   761     def SetInsertionPoint(self, i):
       
   762         self.Duration.SetInsertionPoint(i)
       
   763     
       
   764     def SetFocus(self):
       
   765         self.Duration.SetFocus()
       
   766 
       
   767 class DurationCellEditor(wx.grid.PyGridCellEditor):
       
   768     '''
       
   769     Grid cell editor that uses DurationCellControl to display an edit button.
       
   770     '''
       
   771     def __init__(self, table):
       
   772         wx.grid.PyGridCellEditor.__init__(self)
       
   773         self.Table = table
       
   774     
       
   775     def __del__(self):
       
   776         self.CellControl = None
       
   777     
       
   778     def Create(self, parent, id, evt_handler):
       
   779         self.CellControl = DurationCellControl(parent)
       
   780         self.SetControl(self.CellControl)
       
   781         if evt_handler:
       
   782             self.CellControl.PushEventHandler(evt_handler)
       
   783 
       
   784     def BeginEdit(self, row, col, grid):
       
   785         self.CellControl.SetValue(self.Table.GetValueByName(row, 'Interval'))
       
   786         self.CellControl.SetFocus()
       
   787 
       
   788     def EndEdit(self, row, col, grid):
       
   789         duration = self.CellControl.GetValue()
       
   790         old_duration = self.Table.GetValueByName(row, 'Interval')
       
   791         if duration != old_duration:
       
   792             self.Table.SetValueByName(row, 'Interval', duration)
       
   793             return True
       
   794         return False
       
   795 
       
   796     def SetSize(self, rect):
       
   797         self.CellControl.SetDimensions(rect.x + 1, rect.y,
       
   798                                         rect.width, rect.height,
       
   799                                         wx.SIZE_ALLOW_MINUS_ONE)
       
   800 
       
   801     def Clone(self):
       
   802         return DurationCellEditor(self.Table)
       
   803