|
From: Kevin A. <ka...@us...> - 2006-07-28 21:25:58
|
Update of /cvsroot/pythoncard/PythonCard/samples/iacGrid In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11706 Modified Files: iacGrid.py iacGrid.rsrc.py Log Message: added getSelectedCells method and factored out display update code to updateDisplay method so both rangeSelect and selectCell could call it Index: iacGrid.rsrc.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/iacGrid/iacGrid.rsrc.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** iacGrid.rsrc.py 28 Jul 2006 15:37:29 -0000 1.2 --- iacGrid.rsrc.py 28 Jul 2006 21:23:40 -0000 1.3 *************** *** 1,5 **** { 'application':{ 'type':'Application', ! 'name':'SimpleGrid', 'backgrounds': --- 1,5 ---- { 'application':{ 'type':'Application', ! 'name':'IACGrid', 'backgrounds': *************** *** 7,11 **** { 'type':'Background', 'name':'bgMin', ! 'title':'Simple Grid PythonCard Application', 'size':( 600, 400 ), 'style':['resizeable'], --- 7,11 ---- { 'type':'Background', 'name':'bgMin', ! 'title':'IAC Grid', 'size':( 600, 400 ), 'style':['resizeable'], Index: iacGrid.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/iacGrid/iacGrid.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** iacGrid.py 28 Jul 2006 16:22:30 -0000 1.4 --- iacGrid.py 28 Jul 2006 21:23:40 -0000 1.5 *************** *** 87,108 **** """ ! def on_mygrid_rangeSelect(self, event): ! if event.Selecting(): ! self.log.write("rangeSelect: top-left %s, bottom-right %s\n" % ! (event.GetTopLeftCoords(), event.GetBottomRightCoords())) ! tl = r1, c1 = event.GetTopLeftCoords() ! br = r2, c2 = event.GetBottomRightCoords() result = [] ! if r1 == r2: ! for col in range(c1, c2+1): ! result.append(self.mygrid.GetCellValue(r1, col)) ! elif c1 == c2: ! for row in range(r1, r2+1): ! result.append(self.mygrid.GetCellValue(row, c1)) ! else: ! for row in range(r1, r2+1): ! for col in range(c1, c2+1): ! result.append(self.mygrid.GetCellValue(row, col)) iac.reset() print 'Touching', ' '.join(result) --- 87,129 ---- """ ! def getSelectedCells(self): ! if self.mygrid.IsSelection(): ! mygrid = self.mygrid ! sel = [] ! ! """ ! # KEA 2006-07-28 ! # probably a much more efficient way of building ! # this list so that we only return a list of ! # unique cells in the selection ! for c in mygrid.GetSelectedCols(): ! for r in range(mygrid.GetNumberRows()): ! if (r, c) not in sel: ! sel.append((r, c)) ! for r in mygrid.GetSelectedRows(): ! for c in range(mygrid.GetNumberCols()): ! if (r, c) not in sel: ! sel.append((r, c)) ! for rc in mygrid.GetSelectedCells(): ! if rc not in sel: ! sel.append(rc) ! # deal with GetSelectionBlockTopLeft, GetSelectionBlockBottomRight here ! """ ! ! # brute force solution ! # possibly even easier to reduce to a single statement ! for row in xrange(mygrid.GetNumberRows()): ! for col in xrange(mygrid.GetNumberCols()): ! if mygrid.IsInSelection(row, col): ! sel.append((row, col)) ! return sel ! else: ! return [] ! def updateDisplay(self): result = [] ! for row, col in self.getSelectedCells(): ! result.append(self.mygrid.GetCellValue(row, col)) ! iac.reset() print 'Touching', ' '.join(result) *************** *** 118,125 **** mygrid.SetCellBackgroundColour(r, c, color) ! # force refresh mygrid.Refresh() mygrid.Update() event.skip() --- 139,152 ---- mygrid.SetCellBackgroundColour(r, c, color) ! # force refresh, may not be necessary depending on platform mygrid.Refresh() mygrid.Update() + def on_mygrid_rangeSelect(self, event): + if event.Selecting(): + self.log.write("rangeSelect: top-left %s, bottom-right %s\n" % + (event.GetTopLeftCoords(), event.GetBottomRightCoords())) + + self.updateDisplay() event.skip() *************** *** 129,142 **** (event.row, event.column, event.position)) ! # Another way to stay in a cell that has a bad value... ! mygrid = self.components.mygrid ! row = mygrid.GetGridCursorRow() ! col = mygrid.GetGridCursorCol() ! if mygrid.IsCellEditControlEnabled(): ! mygrid.HideCellEditControl() ! mygrid.DisableCellEditControl() ! value = mygrid.GetCellValue(row, col) ! if value == 'no good 2': ! return # cancels the cell selection event.skip() --- 156,160 ---- (event.row, event.column, event.position)) ! self.updateDisplay() event.skip() |