Esempio n. 1
0
  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())
Esempio n. 2
0
    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)
Esempio n. 3
0
    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)
Esempio n. 4
0
    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):
        """
        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)
Esempio n. 6
0
 def InsertRows(self,pos,numRows = 1):
   newPos = pos + 1
   grid = self.GetView()
   if grid:
     grid.BeginBatch()
     msg = wx.grid.GridTableMessage(self,wx.grid.GRIDTABLE_NOTIFY_ROWS_INSERTED,newPos,numRows)
     grid.ProcessTableMessage(msg)
     grid.EndBatch()
     grid.SetCellEditor(pos,1,wx.grid.GridCellChoiceEditor(self.likelihoodChoices))
   return newPos
Esempio n. 7
0
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
Esempio n. 8
0
 def addThreat(self,threatName):
   pos = (len(self.data) / 2)
   self.data[(pos,0)] = threatName
   self.data[(pos,1)] = ''
   grid = self.GetView()
   if grid:
     grid.BeginBatch()
     msg = wx.grid.GridTableMessage(self,wx.grid.GRIDTABLE_NOTIFY_ROWS_INSERTED,pos,1)
     grid.ProcessTableMessage(msg)
     grid.SetReadOnly(pos,0)
     grid.SetCellEditor(pos,1,wx.grid.GridCellChoiceEditor(self.likelihoodChoices))
     grid.EndBatch()
Esempio n. 9
0
    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 update_grid(self, *args):
        """Fill the grid rows with data, and set the right editors."""
        # @type grid wx.grid.Grid
        grid = self.panel.gridExp

        #Adjust number of rows
        num_rows = len(model.instrument.inst.positions)
        if grid.GetNumberRows() > num_rows:
            grid.DeleteRows(0, grid.GetNumberRows() - num_rows)
        else:
            old_num_rows = grid.GetNumberRows()
            grid.AppendRows(num_rows - grid.GetNumberRows())
            #Set the editors for the new rows
            choices = model.experiment.get_stopping_criteria_names()
            for row in xrange(old_num_rows, num_rows):
                grid.SetCellEditor(row, self.criterion_col,
                                   wx.grid.GridCellChoiceEditor(choices))

        #Font for angles
        angle_font = wx.Font(10, 76, wx.NORMAL, wx.NORMAL, False, u'Monospace')
        for (i, poscov) in enumerate(model.instrument.inst.positions):
            row = i
            #The checkbox
            grid.SetCellAlignment(row, 0, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
            grid.SetReadOnly(row, 0, True)  #Do set it read-only
            #The angles
            for (j, angleinfo) in enumerate(model.instrument.inst.angles):
                x = poscov.angles[j]
                col = j + 1
                grid.SetCellValue(row, col,
                                  u"%8.2f" % angleinfo.internal_to_friendly(x))
                grid.SetReadOnly(row, col, True)  #Do set it read-only
                grid.SetCellAlignment(row, col, wx.ALIGN_CENTRE,
                                      wx.ALIGN_CENTRE)
                grid.SetCellFont(row, col, angle_font)
            #The criterion
            grid.SetCellValue(
                row, self.criterion_col,
                model.experiment.get_stopping_criterion_friendly_name(
                    poscov.criterion))
            grid.SetCellValue(row, self.criterion_col + 1,
                              str(poscov.criterion_value))
            #Comment string
            grid.SetCellValue(row, self.criterion_col + 2, str(poscov.comment))

        self.update_selection()
Esempio n. 11
0
def test(par=0):
    """
    Тестируем класс icGrid
    """
    from ic.components import ictestapp
    import ic.components.icGridCellEditors as icEdt

    app = ictestapp.TestApp(par)
    frame = wx.Frame(None, -1, 'icGrid Test')
    win = wx.Panel(frame, -1)

    grid = icGrid(win, -1, {
        'size': (400, 300),
        'keyDown': 'print(\'keyDown in Grid\')'
    })
    grid.CreateGrid(30, 7)
    grid.SetCellEditor(0, 0, icEdt.icGridCellDateEditor())
    grid.SetMargins(2, 2)
    grid.SetColLabelRenderer(0, MyColLabelRenderer('#e0ffe0'))

    frame.Show(True)
    app.MainLoop()
    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)
Esempio n. 13
0
    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))
Esempio n. 14
0
    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)
Esempio n. 15
0
    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)
Esempio n. 16
0
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
Esempio n. 17
0
    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)
Esempio n. 18
0
 def InitUI(self): 
     vbox = wx.BoxSizer(wx.VERTICAL)
     (server, group, item) = self.rulePath
     labelText = u"地址:{}.{}.{}".format(server, group, item)
     addressLabel = wx.StaticText(self, -1, label=labelText)
     font = wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
     addressLabel.SetFont(font)
     vbox.Add(addressLabel, flag=(wx.ALL | wx.ALIGN_CENTER | wx.BOTTOM), border=5) 
     
     grid = wx.grid.Grid(self)
     grid.CreateGrid(6, 2)
     grid.SetDefaultRowSize(25)
     grid.SetColLabelValue(0, u"值")
     grid.SetColLabelValue(1, u"报警信息")
     
     grid.SetRowLabelValue(0, u'低低')
     grid.SetRowLabelValue(1, u'低')
     grid.SetRowLabelValue(2, u'高')
     grid.SetRowLabelValue(3, u'高高')
     grid.SetRowLabelValue(4, u'当')
     grid.SetRowLabelValue(5, u'间隔时间(分)')
     grid.SetRowLabelSize(70)
     
     # attr = wx.grid.GridCellAttr()
     # attr.SetEditor(wx.grid.GridCellChoiceEditor())
     # attr.SetRenderer(wx.grid.GridCellChoiceEditor(['5', '15', '30', '60'], True))
     grid.SetCellEditor(4, 0, wx.grid.GridCellChoiceEditor([u'真', u'假'], True))
     grid.SetCellValue(4, 0, u'假')
     
     grid.SetCellEditor(5, 0, wx.grid.GridCellChoiceEditor(['5', '15', '30', '60'], True))
     grid.SetCellValue(5, 0, '5')
     
     grid.SetColSize(0, 50)
     grid.SetColSize(1, 300)
     
     grid.SetDefaultCellAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
     grid.SetCellValue(5, 1, u"当前温度:{}".format(self.itemValue[0]))
     grid.SetReadOnly(5, 1, True)
     
     vbox.Add(grid, proportion=1, flag=(wx.ALL | wx.ALIGN_CENTER))
     
     btn = wx.Button(self, -1, label=u"确定")
     btn.Bind(wx.EVT_BUTTON, lambda event, grid=grid: self.btnClick(event, grid))
     vbox.Add(btn, proportion=1, flag=(wx.TOP | wx.CENTRE), border=5)
     self.SetSizer(vbox)  
 
     if self.rule.isBool:
         (dang1, dang2) = self.rule.dang
         interal = self.rule.interal
         grid.SetCellValue(4, 0, u'真' if dang1 else u'假')
         grid.SetCellValue(4, 1, dang2)
         grid.SetCellValue(5, 0, interal)
     else:
         (lower1, lower2) = self.rule.lower
         (low1, low2) = self.rule.low
         (high1, high2) = self.rule.high
         (higher1, higher2) = self.rule.higher
         interal = self.rule.interal
             
         grid.SetCellValue(0, 0, lower1)
         grid.SetCellValue(0, 1, lower2)
         grid.SetCellValue(1, 0, low1)
         grid.SetCellValue(1, 1, low2)
         grid.SetCellValue(2, 0, high1)
         grid.SetCellValue(2, 1, high2)
         grid.SetCellValue(3, 0, higher1)
         grid.SetCellValue(3, 1, higher2)
             
         grid.SetCellValue(5, 0, interal)