예제 #1
0
 def updateView(self):
   grid = self.GetView()
   if grid:
     grid.BeginBatch()
     msg = wx.grid.GridTableMessage(self,wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
     grid.ProcessTableMessage(msg)
     grid.EndBatch() 
예제 #2
0
    def ResetView(self):
        """Trim/extend the control's rows and update all values"""
        grid=self.getGrid()
        grid.BeginBatch()
        for current, new, delmsg, addmsg in [
             (self.currentRows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED),
             (self.currentCols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED),
              ]:
              if new < current:
                  msg = wx.grid.GridTableMessage(self, delmsg, new, current-new)
                  #for i in range(current-new): 
                  grid.ProcessTableMessage(msg)
                  self.currentRows=new
              elif new > current:
                  msg = wx.grid.GridTableMessage(self, addmsg,  new-current)
                  grid.ProcessTableMessage(msg)
                  self.currentRows=new
        self.UpdateValues()
        if len(self._obj)==0: 
            ml=8
        else:
            ml=max([len(x[0]) for x in self._obj])
            grid.SetRowLabelSize(ml*10) #10 is an ad-hoc number
        grid.EndBatch()

       # print 'current row', self.currentRows
  
        # The scroll bars aren't resized (at least on windows)
        # Jiggling the size of the window rescales the scrollbars
        w, h = grid.GetSize()       
        grid.SetSize((w+1, h))
        grid.SetSize((w, h))

        grid.ForceRefresh()
    def ResetGrid(self, oldNumRows):
        """
        Call this to update the grid if rows and columns have been added or 
        deleted.
        """
        grid = self.grid
        grid.BeginBatch()
        
        new = self.GetNumberRows()
        delmsg = wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED
        addmsg = wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED

        if new < oldNumRows:
            msg = wx.grid.GridTableMessage(self, delmsg, new, oldNumRows - new)
            grid.ProcessTableMessage(msg)
        elif new > oldNumRows:
            msg = wx.grid.GridTableMessage(self, addmsg, new - oldNumRows)
            grid.ProcessTableMessage(msg)
            msg = wx.grid.GridTableMessage(self,
                                      wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
            grid.ProcessTableMessage(msg)

        grid.EndBatch()

        grid.AdjustScrollbars()
        grid.ForceRefresh()
예제 #4
0
    def ResetView(self, grid):
        """
        (wx.grid.Grid) -> Reset the grid view.   Call this to
        update the grid if rows and columns have been added or deleted
        """
        grid.BeginBatch()
        for current, new, delmsg, addmsg in [
            (self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED),
            (self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED),
        ]:
            if new < current:
                msg = wx.grid.GridTableMessage(self,delmsg,new,current-new)
                grid.ProcessTableMessage(msg)
            elif new > current:
                msg = wx.grid.GridTableMessage(self,addmsg,new-current)
                grid.ProcessTableMessage(msg)
                self.UpdateValues(grid)
        grid.EndBatch()

        self._rows = self.GetNumberRows()
        self._cols = self.GetNumberCols()
        # update the column rendering scheme
        self._updateColAttrs(grid)

        # update the scrollbars and the displayed part of the grid
        grid.AdjustScrollbars()
        grid.ForceRefresh()
예제 #5
0
    def OnColMove(self, evt):
        frm = evt.GetMoveColumn()  # Column being moved
        to = evt.GetBeforeColumn()  # Before which column to insert

        print 'frm', frm
        print 'to', to
        grid = self.GetView()

        if grid:
            # Move the rowLabels and data rows
            oldLabel = self.rowLabels[frm]
            oldData = self.data[frm]
            del self.rowLabels[frm]
            del self.data[frm]

            if to > frm:
                self.rowLabels.insert(to - 1, oldLabel)
                self.data.insert(to - 1, oldData)
            else:
                self.rowLabels.insert(to, oldLabel)
                self.data.insert(to, oldData)

            # Notify the grid
            grid.BeginBatch()

            msg = gridlib.GridTableMessage(
                self, gridlib.GRIDTABLE_NOTIFY_ROWS_DELETED, frm, 1)

            grid.ProcessTableMessage(msg)

            msg = gridlib.GridTableMessage(
                self, gridlib.GRIDTABLE_NOTIFY_ROWS_INSERTED, to, 1)

            grid.ProcessTableMessage(msg)
            grid.EndBatch()
예제 #6
0
    def MoveRow(self, frm, to):
        grid = self.grid

        if grid:
            # Move the rowLabels and data rows
            oldLabel = self.grid.rowLabels[frm]
            oldData = self.grid.data[frm]
            del self.grid.rowLabels[frm]
            del self.grid.data[frm]

            if to > frm:
                self.grid.rowLabels.insert(to - 1, oldLabel)
                self.grid.data.insert(to - 1, oldData)
            else:
                self.grid.rowLabels.insert(to, oldLabel)
                self.grid.data.insert(to, oldData)

            # Notify the grid
            grid.BeginBatch()

            msg = wx.grid.GridTableMessage(
                self.grid, wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, frm, 1)

            grid.ProcessTableMessage(msg)

            msg = wx.grid.GridTableMessage(
                self.grid, wx.grid.GRIDTABLE_NOTIFY_ROWS_INSERTED, to, 1)

            grid.ProcessTableMessage(msg)
            grid.EndBatch()
예제 #7
0
 def addToView(self,pos):
   grid = self.GetView()
   if grid:
     grid.BeginBatch()
     msg = wx.grid.GridTableMessage(self,wx.grid.GRIDTABLE_NOTIFY_ROWS_INSERTED,pos,1)
     grid.ProcessTableMessage(msg)
     grid.EndBatch() 
예제 #8
0
    def resetRows(self, grid, before):
        """
        (Grid) -> Reset the grid view.   Call this to
        update the grid if rows and columns have been added or deleted
        """
        grid.BeginBatch()

        current = self.GetNumberRows()

        if current < before:
            msg = wx.grid.GridTableMessage(
                self, wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, current,
                before - current)
            grid.ProcessTableMessage(msg)
        elif current > before:
            msg = wx.grid.GridTableMessage(
                self, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED, current - before)
            grid.ProcessTableMessage(msg)
            self.updateValues(grid)

        grid.EndBatch()

        # update the column rendering plugins
        #self._updateColAttrs(grid)

        # update the scrollbars and the displayed part of the grid
        grid.AdjustScrollbars()
        grid.ForceRefresh()
예제 #9
0
 def deleteFromView(self,pos,noOfRows=1):
   grid = self.GetView()
   if grid:
     grid.EnableCellEditControl(False)
     grid.BeginBatch()
     msg = wx.grid.GridTableMessage(self,wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED,pos,noOfRows)
     grid.ProcessTableMessage(msg)
     grid.EndBatch() 
예제 #10
0
 def DeleteRows(self,pos,numRows = 1):
   del self.data[(pos,0)]
   del self.data[(pos,1)]
   grid = self.GetView()
   if grid:
     grid.BeginBatch()
     msg = wx.grid.GridTableMessage(self,wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED,pos,numRows)
     grid.ProcessTableMessage(msg)
     grid.EndBatch()
예제 #11
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
예제 #12
0
 def load(self,threats):
   idx = 0
   grid = self.GetView()
   if grid:
     for idx, threat in enumerate(threats):
       self.data[(idx,0)] = threat[0]
       self.data[(idx,1)] = threat[1]
       grid.BeginBatch()
       msg = wx.grid.GridTableMessage(self,wx.grid.GRIDTABLE_NOTIFY_ROWS_INSERTED,idx,1)
       grid.ProcessTableMessage(msg)
       grid.EndBatch()
예제 #13
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()
예제 #14
0
 def MoveRow(self,frm,to):
   grid = self.GetView()
   if grid:
     oldObs = self.om.obstacles[frm]
     del self.om.obstacles[frm]
     if (to > frm):
       self.om.obstacles.insert(to-1,oldObs)
     else:
       self.om.obstacles.insert(to,oldGoal)
     self.om.commitChanges()
     grid.BeginBatch()
     msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_NOTIFY_ROWS_INSERTED,to,1)
     grid.ProcessTableMessage(msg)
     msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED,frm,1)
     grid.ProcessTableMessage(msg)
     grid.EndBatch()
예제 #15
0
파일: StepGrid.py 프로젝트: notabyte/cairis
 def MoveRow(self, frm, to):
     grid = self.GetView()
     if grid:
         oldLabel = frm
         oldStep = self.steps[frm]
         self.steps.remove(frm)
         if (to > frm):
             self.steps.insert(to - 1, oldStep)
         else:
             self.steps.insert(to, oldStep)
         grid.BeginBatch()
         msg = wx.grid.GridTableMessage(
             self, wx.grid.GRIDTABLE_NOTIFY_ROWS_INSERTED, to, 1)
         grid.ProcessTableMessage(msg)
         msg = wx.grid.GridTableMessage(
             self, wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, frm, 1)
         grid.ProcessTableMessage(msg)
         grid.EndBatch()
예제 #16
0
 def MoveRow(self, frm, to):
     grid = self.GetView()
     if grid:
         oldLabel = self.om.reqs[frm].label()
         oldReq = self.om.reqs[frm]
         del self.om.reqs[frm]
         if (to > frm):
             self.om.reqs.insert(to - 1, oldReq)
         else:
             self.om.reqs.insert(to, oldReq)
         self.om.relabel()
         self.om.commitChanges()
         grid.BeginBatch()
         msg = wx.grid.GridTableMessage(
             self, wx.grid.GRIDTABLE_NOTIFY_ROWS_INSERTED, to, 1)
         grid.ProcessTableMessage(msg)
         msg = wx.grid.GridTableMessage(
             self, wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, frm, 1)
         grid.ProcessTableMessage(msg)
         grid.EndBatch()
예제 #17
0
    def ResetView(self):
        """
        (Grid) -> Reset the grid view.   Call this to
        update the grid if rows and columns have been added or deleted

        """

        grid = self.grid

        current_rows = self.grid.GetNumberRows()
        current_cols = self.grid.GetNumberCols()

        grid.BeginBatch()

        for current, new, delmsg, addmsg in [
            (current_rows, self.GetNumberRows(),
             wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED,
             wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED),
            (current_cols, self.GetNumberCols(),
             wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED,
             wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED)
        ]:

            if new < current:
                msg = wx.grid.GridTableMessage(self, delmsg, new,
                                               current - new)
                grid.ProcessTableMessage(msg)
            elif new > current:
                msg = wx.grid.GridTableMessage(self, addmsg, new - current)
                grid.ProcessTableMessage(msg)
                self.UpdateValues()

        grid.EndBatch()

        # Reset cell sizes to standard cell size

        grid.SetDefaultRowSize(grid.GetDefaultRowSize(),
                               resizeExistingRows=True)
        grid.SetDefaultColSize(grid.GetDefaultColSize(),
                               resizeExistingCols=True)

        # Adjust rows
        row_heights = grid.code_array.row_heights
        for key in row_heights:
            if key[1] == grid.current_table and \
               key[0] < self.code_array.shape[0]:
                row = key[0]
                if row_heights[key] is None:
                    # Default row size
                    grid.SetRowSize(row, grid.GetDefaultRowSize())
                else:
                    grid.SetRowSize(row, row_heights[key])

        # Adjust columns
        col_widths = grid.code_array.col_widths
        for key in col_widths:
            if key[1] == grid.current_table and \
               key[0] < self.code_array.shape[1]:
                col = key[0]
                if col_widths[key] is None:
                    # Default row size
                    grid.SetColSize(col, grid.GetDefaultColSize())
                else:
                    grid.SetColSize(col, col_widths[key])

        # update the scrollbars and the displayed part
        # of the grid

        grid.Freeze()
        grid.AdjustScrollbars()
        grid.Refresh()
        grid.Thaw()
예제 #18
0
    def updateData(self, data, grid):
        # Old number of rows
        start = len(self.data)

        # New number of rows
        end = len(data)

        # Names we actually hit this time -- used to delete old references later
        updatedNames = []

        # Currently selected tasks in the table
        selectedNames = []
        for row in grid.GetSelectedRows():
            selectedNames.append(self.data[row][0])

        data = self.sortData(data)

        # Batch mode ensures all updates happen at once
        grid.BeginBatch()

        # Map each row from the new data object onto the current data object
        # and set the corresponding values on the wx.Grid
        for row, info in enumerate(data):
            updatedNames.append(info[0])
            if row < len(self.data):
                # Nothing has changed, don't waste cycles remapping the same data
                if data[row] == self.data[row]:
                    continue
            self.rowMapping[info[0]] = row
            # We're short some rows, append the data instead of mapping
            if row >= len(self.data):
                self.data.append(info)
            else:
                self.data[row] = info
            # Map this row onto the grid
            for i in xrange(0, 6):
                self.SetValue(row, i, info[i])
        # Grid updates done, end the batch
        grid.EndBatch()

        # Delete unused references in the rowMapping dictionary
        for name in self.rowMapping.keys():
            if name not in updatedNames:
                del self.rowMapping[name]

        # Clear selection and reselect any previously selected
        # tasks which still exist somewhere in the grid
        grid.ClearSelection()
        for name in selectedNames:
            if name in self.rowMapping:
                grid.SelectRow(self.rowMapping[name], True)

        # We've got too many rows, inform the grid that it needs to delete some
        if end < start:
            for row in xrange(end, start):
                del self.data[row]
            msg = wx.grid.GridTableMessage(
                self, wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, end, start - end)
            grid.ProcessTableMessage(msg)

        # We're short one or more rows, inform the grid it needs to add some
        elif end > start:
            msg = wx.grid.GridTableMessage(
                self, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED, end - start)
            grid.ProcessTableMessage(msg)