def InsertRows(self,pos,numRows=1): onDlg = wx.TextEntryDialog(None,'Enter obstacle name','New Obstacle','',style=wx.OK|wx.CANCEL) if (onDlg.ShowModal() == wx.ID_OK): obsName = onDlg.GetValue() if (obsName != ''): if (pos == -1): pos = 0 newPos = pos + 1 try: self.om.add(newPos,obsName) except ARM.ARMException,errorText: dlg = wx.MessageDialog(self.GetView(),str(errorText),'Add Obstacle',wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return self.addToView(newPos) grid = self.GetView() grid.SetCellEditor(newPos,NAME_POS,wx.grid.GridCellAutoWrapStringEditor()) grid.SetCellRenderer(newPos,NAME_POS,wx.grid.GridCellAutoWrapStringRenderer()) grid.SetCellEditor(newPos,DEFINITION_POS,wx.grid.GridCellAutoWrapStringEditor()) grid.SetCellRenderer(newPos,DEFINITION_POS,wx.grid.GridCellAutoWrapStringRenderer()) grid.SetCellEditor(newPos,CATEGORY_POS,wx.grid.GridCellChoiceEditor(catChoices)) grid.SetCellEditor(newPos,ORIGINATOR_POS,wx.grid.GridCellAutoWrapStringEditor()) grid.SetCellRenderer(newPos,ORIGINATOR_POS,wx.grid.GridCellAutoWrapStringRenderer())
def _updateColAttrs(self, grid): """ wx.grid.Grid -> update the column attributes to add the appropriate renderer given the column name. Otherwise default to the default renderer. """ for row in range(self.GetNumberRows()): row_highlights = self.Highlights.get(row, {}) for col in range(self.GetNumberCols()): editor = None renderer = None colname = self.GetColLabelValue(col, False) if col != 0: grid.SetReadOnly(row, col, False) if colname == "Name": editor = wx.grid.GridCellTextEditor() renderer = wx.grid.GridCellStringRenderer() elif colname == "Initial Value": editor = wx.grid.GridCellTextEditor() renderer = wx.grid.GridCellStringRenderer() elif colname == "Type": editor = wx.grid.GridCellTextEditor() else: grid.SetReadOnly(row, col, True) grid.SetCellEditor(row, col, editor) grid.SetCellRenderer(row, col, renderer) highlight_colours = row_highlights.get( colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] grid.SetCellBackgroundColour(row, col, highlight_colours[0]) grid.SetCellTextColour(row, col, highlight_colours[1]) self.ResizeRow(grid, row)
def _updateColAttrs(self, grid): """ wxGrid -> update the column attributes to add the appropriate renderer given the column name. Otherwise default to the default renderer. """ for row in range(self.GetNumberRows()): for col in range(self.GetNumberCols()): editor = None renderer = None colname = self.GetColLabelValue(col, False) if colname in [ "Name", "Initial", "Description", "OnChange", "Options" ]: editor = wx.grid.GridCellTextEditor() elif colname == "Class": editor = wx.grid.GridCellChoiceEditor() editor.SetParameters("input,memory,output") elif colname == "Type": pass else: grid.SetReadOnly(row, col, True) grid.SetCellEditor(row, col, editor) grid.SetCellRenderer(row, col, renderer) grid.SetCellBackgroundColour(row, col, wx.WHITE) self.ResizeRow(grid, row)
def _updateColAttrs(self, grid, row=None): """ wxGrid -> update the column attributes to add the appropriate renderer given the column name. Otherwise default to the default renderer. """ for row in range(self.GetNumberRows()): row_highlights = self.Highlights.get(row, {}) for col in range(self.GetNumberCols()): editor = None renderer = None colname = self.GetColLabelValue(col, False) editortype = self.columnTypes.get(colname, None) if editortype is not None: editor = editortype(self, row, col) grid.SetCellEditor(row, col, editor) grid.SetCellRenderer(row, col, renderer) highlight_colours = row_highlights.get( colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] grid.SetCellBackgroundColour(row, col, highlight_colours[0]) grid.SetCellTextColour(row, col, highlight_colours[1]) self.ResizeRow(grid, row)
def _updateColAttrs(self, grid): """ wx.grid.Grid -> update the column attributes to add the appropriate renderer given the column name. Otherwise default to the default renderer. """ for col in range(self.GetNumberCols()): attr = wx.grid.GridCellAttr() attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) grid.SetColAttr(col, attr) grid.SetColSize(col, self.ColSizes[col]) for row in range(self.GetNumberRows()): row_highlights = self.Highlights.get(row, {}) for col in range(self.GetNumberCols()): editor = None renderer = None colname = self.GetColLabelValue(col, False) grid.SetReadOnly(row, col, False) if colname == "Name": editor = wx.grid.GridCellTextEditor() renderer = wx.grid.GridCellStringRenderer() elif colname == "Interval": editor = DurationCellEditor(self) renderer = wx.grid.GridCellStringRenderer() if self.GetValueByName(row, "Triggering") != "Cyclic": grid.SetReadOnly(row, col, True) elif colname == "Single": editor = wx.grid.GridCellChoiceEditor() editor.SetParameters(self.Parent.VariableList) if self.GetValueByName(row, "Triggering") != "Interrupt": grid.SetReadOnly(row, col, True) elif colname == "Triggering": editor = wx.grid.GridCellChoiceEditor() editor.SetParameters( ",".join([""] + map(_, GetTaskTriggeringOptions()))) elif colname == "Type": editor = wx.grid.GridCellChoiceEditor() editor.SetParameters(self.Parent.TypeList) elif colname == "Priority": editor = wx.grid.GridCellNumberEditor() editor.SetParameters("0,65535") elif colname == "Task": editor = wx.grid.GridCellChoiceEditor() editor.SetParameters(self.Parent.TaskList) grid.SetCellEditor(row, col, editor) grid.SetCellRenderer(row, col, renderer) highlight_colours = row_highlights.get( colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] grid.SetCellBackgroundColour(row, col, highlight_colours[0]) grid.SetCellTextColour(row, col, highlight_colours[1]) self.ResizeRow(grid, row)
class StepTable(wx.grid.PyGridTableBase): def __init__(self, s=None): wx.grid.PyGridTableBase.__init__(self) self.colLabels = ['Step'] if (s != None): self.steps = s else: self.steps = Steps() def GetNumberRows(self): return (self.steps).size() def GetNumberCols(self): return 1 def GetColLabelValue(self, col): return 'Step' def IsEmptyCell(self, row, col): return False def GetValue(self, row, col): return (self.steps[row]).text() def SetValue(self, row, col, value): self.steps[row].setText(value) def AppendRows(self, numRows=1): pos = self.steps.size() - 1 self.InsertRows(pos, numRows) def InsertRows(self, pos, numRows=1): if (pos == -1): pos = 0 newPos = pos + 1 if (self.steps.size() == 0): lastLabel = 0 else: lastLabel = pos newLabel = lastLabel + 1 try: self.steps.append(Step()) except ARMException, errorText: dlg = wx.MessageDialog(self.GetView(), str(errorText), 'Add Step', wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return self.addToView(newLabel) grid = self.GetView() grid.SetCellEditor(newPos, 0, wx.grid.GridCellAutoWrapStringEditor()) grid.SetCellRenderer(newPos, 0, wx.grid.GridCellAutoWrapStringRenderer()) return True
def _updateColAttrs(self, grid, row=None): """ wx.Grid -> update the column attributes to add the appropriate renderer given the column name. Otherwise default to the default renderer. """ for row in range(self.GetNumberRows()): for col in range(self.GetNumberCols()): editor = None renderer = None readonly = False colname = self.GetColLabelValue(col, False) if colname == "Qualifier": editor = wx.grid.GridCellChoiceEditor( self.Parent.QualifierList.split(',')) editor.SetParameters(self.Parent.QualifierList) if colname == "Duration": editor = wx.grid.GridCellTextEditor() renderer = wx.grid.GridCellStringRenderer() readonly = not self.Parent.DurationList[ self.data[row].qualifier] elif colname == "Type": editor = wx.grid.GridCellChoiceEditor(GetTypeList()) editor.SetParameters(self.Parent.TypeList) elif colname == "Value": value_type = self.data[row].type if value_type == "Action": editor = wx.grid.GridCellChoiceEditor( self.Parent.ActionList.split(',')) editor.SetParameters(self.Parent.ActionList) elif value_type == "Variable": editor = wx.grid.GridCellChoiceEditor( self.Parent.VariableList.split('1')) editor.SetParameters(self.Parent.VariableList) elif value_type == "Inline": editor = wx.grid.GridCellTextEditor() renderer = wx.grid.GridCellStringRenderer() elif colname == "Indicator": editor = wx.grid.GridCellChoiceEditor( self.Parent.VariableList.split(',')) editor.SetParameters(self.Parent.VariableList) grid.SetCellEditor(row, col, editor) grid.SetCellRenderer(row, col, renderer) grid.SetReadOnly(row, col, readonly) grid.SetCellBackgroundColour(row, col, wx.WHITE) self.ResizeRow(grid, row)
def InsertChildRows(self, pos): newPos = pos + 1 lastLabel = self.om.reqs[pos].label() newLabel = lastLabel + '.1' # guess the parent - can get req based on current pos and use this I guess parentReq = self.om.reqs[pos] self.om.addChild(childLabel=newLabel, childIdx=newPos, parent=parentReq) self.om.sort() self.addToView(newPos) grid = self.GetView() grid.SetCellEditor(newPos, NAME_POS, wx.grid.GridCellAutoWrapStringEditor()) grid.SetCellRenderer(newPos, NAME_POS, wx.grid.GridCellAutoWrapStringRenderer()) grid.SetCellEditor(newPos, DESCRIPTION_POS, wx.grid.GridCellAutoWrapStringEditor()) grid.SetCellRenderer(newPos, DESCRIPTION_POS, wx.grid.GridCellAutoWrapStringRenderer()) grid.SetCellEditor(newPos, PRIORITY_POS, wx.grid.GridCellChoiceEditor(priorityChoices)) grid.SetCellEditor(newPos, RATIONALE_POS, wx.grid.GridCellAutoWrapStringEditor()) grid.SetCellRenderer(newPos, RATIONALE_POS, wx.grid.GridCellAutoWrapStringRenderer()) grid.SetCellEditor(newPos, FITCRITERION_POS, wx.grid.GridCellAutoWrapStringEditor()) grid.SetCellRenderer(newPos, FITCRITERION_POS, wx.grid.GridCellAutoWrapStringRenderer()) grid.SetCellEditor(newPos, ORIGINATOR_POS, wx.grid.GridCellAutoWrapStringEditor()) grid.SetCellRenderer(newPos, ORIGINATOR_POS, wx.grid.GridCellAutoWrapStringRenderer()) grid.SetCellEditor(newPos, TYPE_POS, wx.grid.GridCellChoiceEditor(typeChoices))
def _updateColAttrs(self, grid): """ wxGrid -> update the column attributes to add the appropriate renderer given the column name. Otherwise default to the default renderer. """ for row in range(self.GetNumberRows()): for col in range(self.GetNumberCols()): editor = None renderer = None colname = self.GetColLabelValue(col, False) editortype = self.columnTypes.get(colname, None) if editortype is not None: editor = editortype(self, row, col) grid.SetCellEditor(row, col, editor) grid.SetCellRenderer(row, col, renderer) grid.SetCellBackgroundColour(row, col, wx.WHITE) self.ResizeRow(grid, row)
def _updateColAttrs(self, grid): """ wx.grid.Grid -> update the column attributes to add the appropriate renderer given the column name. Otherwise default to the default renderer. """ for col in range(self.GetNumberCols()): attr = wx.grid.GridCellAttr() attr.SetAlignment(ColAlignements[col], wx.ALIGN_CENTRE) grid.SetColAttr(col, attr) grid.SetColMinimalWidth(col, ColSizes[col]) grid.AutoSizeColumn(col, False) typelist = None maplist = None for row in range(self.GetNumberRows()): editors = self.editors[row] if wx.Platform == '__WXMSW__': grid.SetRowMinimalHeight(row, 20) else: grid.SetRowMinimalHeight(row, 28) grid.AutoSizeRow(row, False) for col in range(self.GetNumberCols()): editor = None renderer = None colname = self.GetColLabelValue(col, False) editortype = editors[colname] if editortype == "dcf": editor = wx.grid.GridCellTextEditor() renderer = wx.grid.GridCellStringRenderer() elif editortype and self.Editable: grid.SetReadOnly(row, col, False) if editortype == "string": editor = wx.grid.GridCellTextEditor() renderer = wx.grid.GridCellStringRenderer() if colname == "value" and "length" in editors: editor.SetParameters(editors["length"]) elif editortype == "number": editor = wx.grid.GridCellNumberEditor() renderer = wx.grid.GridCellNumberRenderer() if colname == "value" and "min" in editors and "max" in editors: editor.SetParameters("%s,%s"%(editors["min"],editors["max"])) elif editortype == "float": editor = wx.grid.GridCellTextEditor() renderer = wx.grid.GridCellStringRenderer() elif editortype == "bool": editor = wx.grid.GridCellBoolEditor() # editor.SetParameters(BoolList) elif editortype == "access": editor = wx.grid.GridCellChoiceEditor(AccessList, False) # editor.SetParameters(AccessList) elif editortype == "raccess": editor = wx.grid.GridCellChoiceEditor(RAccessList, False) # editor.SetParameters(RAccessList) elif editortype == "option": editor = wx.grid.GridCellChoiceEditor(OptionList, False) # editor.SetParameters(OptionList) elif editortype == "type": if typelist == None: typelist = self.Parent.Manager.GetCurrentTypeList() editor = wx.grid.GridCellChoiceEditor(typelist.split(",")) # editor.SetParameters(typelist) elif editortype == "map": if maplist == None: maplist = self.Parent.Manager.GetCurrentMapList() editor = wx.grid.GridCellChoiceEditor(maplist.split(",")) # editor.SetParameters(maplist) elif editortype == "time": editor = wx.grid.GridCellTextEditor() renderer = wx.grid.GridCellStringRenderer() elif editortype == "domain": editor = wx.grid.GridCellTextEditor() renderer = wx.grid.GridCellStringRenderer() else: grid.SetReadOnly(row, col, True) grid.SetCellEditor(row, col, editor) grid.SetCellRenderer(row, col, renderer) grid.SetCellBackgroundColour(row, col, wx.WHITE)
def _updateColAttrs(self, grid): """ wx.grid.Grid -> update the column attributes to add the appropriate renderer given the column name. Otherwise default to the default renderer. """ for row in range(self.GetNumberRows()): var_class = self.GetValueByName(row, "Class") var_type = self.GetValueByName(row, "Type") row_highlights = self.Highlights.get(row, {}) for col in range(self.GetNumberCols()): editor = None renderer = None colname = self.GetColLabelValue(col, False) if self.Parent.Debug: grid.SetReadOnly(row, col, True) else: if colname == "Option": options = GetOptions( constant=var_class in ["Local", "External", "Global"], retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"], non_retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"]) if len(options) > 1: editor = wx.grid.GridCellChoiceEditor() editor.SetParameters(",".join(map(_, options))) else: grid.SetReadOnly(row, col, True) elif col != 0 and self.GetValueByName(row, "Edit"): grid.SetReadOnly(row, col, False) if colname == "Name": editor = wx.grid.GridCellTextEditor() renderer = wx.grid.GridCellStringRenderer() elif colname == "Initial Value": if var_class not in ["External", "InOut"]: if self.Parent.Controler.IsEnumeratedType( var_type): editor = wx.grid.GridCellChoiceEditor() editor.SetParameters(",".join( self.Parent.Controler. GetEnumeratedDataValues(var_type))) else: editor = wx.grid.GridCellTextEditor() renderer = wx.grid.GridCellStringRenderer() else: grid.SetReadOnly(row, col, True) elif colname == "Location": if var_class in [ "Local", "Global" ] and self.Parent.Controler.IsLocatableType( var_type): editor = LocationCellEditor( self, self.Parent.Controler) renderer = wx.grid.GridCellStringRenderer() else: grid.SetReadOnly(row, col, True) elif colname == "Class": if len(self.Parent.ClassList) == 1: grid.SetReadOnly(row, col, True) else: editor = wx.grid.GridCellChoiceEditor() excluded = [] if self.Parent.IsFunctionBlockType(var_type): excluded.extend(["Local", "Temp"]) editor.SetParameters(",".join([ _(choice) for choice in self.Parent.ClassList if choice not in excluded ])) elif colname != "Documentation": grid.SetReadOnly(row, col, True) grid.SetCellEditor(row, col, editor) grid.SetCellRenderer(row, col, renderer) if colname == "Location" and LOCATION_MODEL.match( self.GetValueByName(row, colname)) is None: highlight_colours = ERROR_HIGHLIGHT else: highlight_colours = row_highlights.get( colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] grid.SetCellBackgroundColour(row, col, highlight_colours[0]) grid.SetCellTextColour(row, col, highlight_colours[1]) self.ResizeRow(grid, row)
class RequirementsTable(wx.grid.PyGridTableBase): def __init__(self, modCombo, envCombo): wx.grid.PyGridTableBase.__init__(self) self.dimension = 'requirement' self.colLabels = [ 'Name', 'Description', 'Priority', 'Rationale', 'Fit Criterion', 'Originator', 'Type' ] if (modCombo.GetValue() != ''): self.om = RequirementManager(modCombo) else: self.om = RequirementManager(envCombo, False) def GetNumberRows(self): return self.om.size() def GetNumberCols(self): return len(self.colLabels) def GetColLabelValue(self, col): return self.colLabels[col] def GetRowLabelValue(self, row): return self.om.reqs[row].label() def IsEmptyCell(self, row, col): return False def GetValue(self, row, col): if (col == NAME_POS): return self.om.reqs[row].name() elif (col == DESCRIPTION_POS): return self.om.reqs[row].description() elif (col == PRIORITY_POS): return self.om.reqs[row].priority() elif (col == RATIONALE_POS): return self.om.reqs[row].rationale() elif (col == FITCRITERION_POS): return self.om.reqs[row].fitCriterion() elif (col == ORIGINATOR_POS): return self.om.reqs[row].originator() elif (col == TYPE_POS): return self.om.reqs[row].type() def SetValue(self, row, col, value): label = self.GetRowLabelValue(row) if (col == NAME_POS): self.om.update(label, 'name', value) elif (col == DESCRIPTION_POS): self.om.update(label, 'description', value) elif (col == PRIORITY_POS): self.om.update(label, 'priority', value) elif (col == RATIONALE_POS): self.om.update(label, 'rationale', value) elif (col == FITCRITERION_POS): self.om.update(label, 'fitCriterion', value) elif (col == ORIGINATOR_POS): self.om.update(label, 'originator', value) elif (col == TYPE_POS): self.om.update(label, 'type', value) def AppendRows(self, numRows=1): pos = self.om.size() - 1 self.InsertRows(pos, numRows) def InsertRows(self, pos, numRows=1): try: if (pos == -1): pos = 0 newPos = pos + 1 if (self.om.size() == 0): lastLabel = 0 else: lastGridLabel = self.om.reqs[pos].label() if (len(str(lastGridLabel).split('-')) > 1): raise ARMException( 'Asset or Environment must be specified') lastLabel = int(lastGridLabel) newLabel = lastLabel + 1 self.om.add(newLabel, newPos) except ARMException, errorText: dlg = wx.MessageDialog(self.GetView(), str(errorText), 'Add Requirement', wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return newReqPos, newReq = self.om.requirementByLabel(newLabel) self.addToView(newReqPos) grid = self.GetView() grid.SetCellEditor(newPos, NAME_POS, wx.grid.GridCellAutoWrapStringEditor()) grid.SetCellRenderer(newPos, NAME_POS, wx.grid.GridCellAutoWrapStringRenderer()) grid.SetCellEditor(newPos, DESCRIPTION_POS, wx.grid.GridCellAutoWrapStringEditor()) grid.SetCellRenderer(newPos, DESCRIPTION_POS, wx.grid.GridCellAutoWrapStringRenderer()) grid.SetCellEditor(newPos, PRIORITY_POS, wx.grid.GridCellChoiceEditor(priorityChoices)) grid.SetCellEditor(newPos, RATIONALE_POS, wx.grid.GridCellAutoWrapStringEditor()) grid.SetCellRenderer(newPos, RATIONALE_POS, wx.grid.GridCellAutoWrapStringRenderer()) grid.SetCellEditor(newPos, FITCRITERION_POS, wx.grid.GridCellAutoWrapStringEditor()) grid.SetCellRenderer(newPos, FITCRITERION_POS, wx.grid.GridCellAutoWrapStringRenderer()) grid.SetCellEditor(newPos, ORIGINATOR_POS, wx.grid.GridCellAutoWrapStringEditor()) grid.SetCellRenderer(newPos, ORIGINATOR_POS, wx.grid.GridCellAutoWrapStringRenderer()) grid.SetCellEditor(newPos, TYPE_POS, wx.grid.GridCellChoiceEditor(typeChoices)) return True
def _updateColAttrs(self, grid, row=None): """ wx.grid.Grid -> update the column attributes to add the appropriate renderer given the column name. Otherwise default to the default renderer. """ for col in range(self.GetNumberCols()): attr = wx.grid.GridCellAttr() attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) grid.SetColAttr(col, attr) grid.SetColSize(col, self.ColSizes[col]) for row in range(self.GetNumberRows()): row_highlights = self.Highlights.get(row, {}) for col in range(self.GetNumberCols()): editor = None renderer = None error = False colname = self.GetColLabelValue(col, False) grid.SetReadOnly(row, col, False) if colname == "Name": editor = wx.grid.GridCellTextEditor() renderer = wx.grid.GridCellStringRenderer() elif colname == "Interval": editor = DurationCellEditor(self, colname) renderer = wx.grid.GridCellStringRenderer() if self.GetValueByName(row, "Triggering") != "Cyclic": grid.SetReadOnly(row, col, True) interval = self.GetValueByName(row, colname) if interval != "" and IEC_TIME_MODEL.match( interval.upper()) is None: error = True elif colname == "Single": editor = SingleCellEditor(self, colname) editor.SetParameters(self.Parent.VariableList) if self.GetValueByName(row, "Triggering") != "Interrupt": grid.SetReadOnly(row, col, True) single = self.GetValueByName(row, colname) if single != "" and not CheckSingle( single, self.Parent.VariableList): error = True elif colname == "Triggering": editor = wx.grid.GridCellChoiceEditor( GetTaskTriggeringOptions()) editor.SetParameters(",".join( map(_, GetTaskTriggeringOptions()))) elif colname == "Type": editor = wx.grid.GridCellChoiceEditor( self.Parent.TypeList.split(',')) # editor.SetParameters(self.Parent.TypeList) elif colname == "Priority": editor = wx.grid.GridCellNumberEditor() editor.SetParameters("0,65535") elif colname == "Task": editor = wx.grid.GridCellChoiceEditor( self.Parent.TaskList.split(',')) # editor.SetParameters(self.Parent.TaskList) if editor: editor.IncRef() grid.SetCellEditor(row, col, editor) grid.SetCellRenderer(row, col, renderer) if error: highlight_colours = ERROR_HIGHLIGHT else: highlight_colours = row_highlights.get( colname.lower(), [(wx.WHITE, wx.BLACK)])[-1] grid.SetCellBackgroundColour(row, col, highlight_colours[0]) grid.SetCellTextColour(row, col, highlight_colours[1]) self.ResizeRow(grid, row)
import wx