From: Kevin A. <ka...@us...> - 2006-07-28 22:05:46
|
Update of /cvsroot/pythoncard/PythonCard/samples/iacGrid In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27476 Modified Files: iacGrid.py Log Message: added selectCell and hopefully fixed both events to handle all cases Index: iacGrid.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/iacGrid/iacGrid.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** iacGrid.py 28 Jul 2006 21:23:40 -0000 1.5 --- iacGrid.py 28 Jul 2006 22:05:38 -0000 1.6 *************** *** 7,12 **** import sys ! import wx ! from wx import grid from PythonCard import dialog, model --- 7,11 ---- import sys ! import wx # used for sizer constants from PythonCard import dialog, model *************** *** 25,29 **** def on_initialize(self, event): self.log = sys.stdout - self.moveTo = None self.mygrid = mygrid = self.components.mygrid --- 24,27 ---- *************** *** 77,90 **** - """ - KEA 2006-07-28 - in order to support discontinuous selections it appears - we need to check the grid for which cells are actually - selected on selectCell and rangeSelect and/or keep - an updated dictionary of cells after each selection is - made. GetSelectedCells() appears to only return an empty - list, which is probably another bug - """ - def getSelectedCells(self): if self.mygrid.IsSelection(): --- 75,78 ---- *************** *** 92,114 **** 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 --- 80,83 ---- *************** *** 117,129 **** 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) --- 86,95 ---- if mygrid.IsInSelection(row, col): sel.append((row, col)) + print "Current Selection:", sel return sel else: return [] ! def updateDisplay(self, result): iac.reset() print 'Touching', ' '.join(result) *************** *** 148,153 **** (event.GetTopLeftCoords(), event.GetBottomRightCoords())) ! self.updateDisplay() ! event.skip() --- 114,126 ---- (event.GetTopLeftCoords(), event.GetBottomRightCoords())) ! result = [] ! for row, col in self.getSelectedCells(): ! result.append(self.mygrid.GetCellValue(row, col)) ! print "rangeSelect result:", result ! self.updateDisplay(result) ! else: ! # just for debugging, else clause can go away later ! print "NOT SELECTING in rangeSelect", event.GetTopLeftCoords(), event.GetBottomRightCoords() ! #event.skip() *************** *** 155,161 **** self.log.write("selectCell: (%d,%d) %s\n" % (event.row, event.column, event.position)) ! ! self.updateDisplay() ! event.skip() --- 128,139 ---- self.log.write("selectCell: (%d,%d) %s\n" % (event.row, event.column, event.position)) ! if event.Selecting(): ! result = [self.mygrid.GetCellValue(event.row, event.column)] ! print "selectCell result:", result ! self.updateDisplay(result) ! else: ! # just for debugging, else clause can go away later ! print "NOT SELECTING in selectCell", event.row, event.column, event.position ! #event.skip() |