Changeset 1300

Show
Ignore:
Timestamp:
09/11/05 19:32:36 (3 years ago)
Author:
paul
Message:

Refactored lots of the hook methods for events out of dGrid and
made lots of new dEvents, both for the header as well as for the
grid region. For example:

dEvents.GridHeaderMouseRightClick?
dEvents.GridMouseRightClick?

#1 will happen when the user right-clicks in the header, and
#2 will happen when the user right-clicks anywhere in the grid
region.

Reorganized the code so that it isn't quite so spread around.

The datanav grid was relying on one of the hook methods, so I
had to make an explicit binding instead since autoBindEvents
isn't enabled yet.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/dEvents.py

    r1246 r1300  
    373373    pass 
    374374 
     375class GridContextMenu(GridEvent, MenuEvent): 
     376    """Occurs when the context menu is requested in the grid region.""" 
     377    pass 
     378 
     379class GridHeaderContextMenu(GridEvent, MenuEvent): 
     380    """Occurs when the context menu is requested in the grid header region.""" 
     381    pass 
     382 
     383class GridHeaderMouseLeftClick(GridEvent, MouseEvent): 
     384    """Occurs when the left mouse button is clicked in the header region.""" 
     385    pass 
     386 
     387class GridHeaderMouseLeftDoubleClick(GridEvent, MouseEvent): 
     388    """Occurs when the left mouse button is double-clicked in the header region.""" 
     389    pass 
     390 
     391class GridHeaderMouseLeftDown(GridEvent, MouseEvent): 
     392    """Occurs when the left mouse button goes down in the header region.""" 
     393    pass 
     394 
     395class GridHeaderMouseLeftUp(GridEvent, MouseEvent): 
     396    """Occurs when the left mouse button goes up in the header region.""" 
     397    pass 
     398 
     399class GridHeaderMouseRightDown(GridEvent, MouseEvent): 
     400    """Occurs when the left mouse button goes down in the header region.""" 
     401    pass 
     402 
     403class GridHeaderMouseRightUp(GridEvent, MouseEvent): 
     404    """Occurs when the left mouse button goes up in the header region.""" 
     405    pass 
     406 
     407class GridHeaderMouseMove(GridEvent, MouseEvent): 
     408    """Occurs when the mouse moves in the grid header region.""" 
     409    pass 
     410 
     411class GridHeaderPaint(GridEvent): 
     412    """Occurs when it's time to paint the grid header.""" 
     413    pass 
     414 
     415class GridMouseLeftClick(GridEvent, MouseEvent): 
     416    """Occurs when the left mouse button is clicked in the grid region.""" 
     417    pass 
     418 
     419class GridMouseLeftDoubleClick(GridEvent, MouseEvent): 
     420    """Occurs when the left mouse button is double-clicked in the grid region.""" 
     421    pass 
     422 
     423class GridMouseLeftDown(GridEvent, MouseEvent): 
     424    """Occurs when the left mouse button goes down in the grid region.""" 
     425    pass 
     426 
     427class GridMouseLeftUp(GridEvent, MouseEvent): 
     428    """Occurs when the left mouse button goes up in the grid region.""" 
     429    pass 
     430 
     431class GridMouseRightClick(GridEvent, MouseEvent): 
     432    """Occurs when the right mouse button is clicked in the header region.""" 
     433    pass 
     434 
     435class GridMouseRightDown(GridEvent, MouseEvent): 
     436    """Occurs when the right mouse button goes down in the grid region.""" 
     437    pass 
     438 
     439class GridMouseRightUp(GridEvent, MouseEvent): 
     440    """Occurs when the right mouse button goes up in the grid region.""" 
     441    pass 
     442 
     443class GridMouseMove(GridEvent, MouseEvent): 
     444    """Occurs when the mouse moves in the grid region (not the headers).""" 
     445    pass 
     446 
    375447class GridRowSize(GridEvent): 
    376448    """Occurs when the grid's rows are resized.""" 
  • trunk/dabo/lib/datanav/Grid.py

    r1211 r1300  
    1111dabo.ui.loadUI("wx") 
    1212from dabo.dLocalize import _, n_ 
    13  
     13import dabo.dEvents as dEvents 
    1414 
    1515class Grid(dabo.ui.dGrid): 
     16    def _initProperties(self): 
     17        super(Grid, self)._initProperties() 
     18        self.bindEvent(dEvents.GridMouseLeftDoubleClick, self.onGridLeftDClick) 
     19 
    1620    def _afterInit(self): 
    1721        super(Grid, self)._afterInit() 
  • trunk/dabo/ui/uiwx/dGrid.py

    r1298 r1300  
    7575 
    7676        # I have no idea what the kind arg is for. It is sent by wxGrid to this 
    77         # function, it always seems to be either 0 or 4 (4 when the , and it isn't documented in the  
     77        # function, it always seems to be either 0 or 4, and it isn't documented in the  
    7878        # wxWidgets docs (but it does appear in the wxPython method signature  
    7979        # but still isn't documented there.) 
     
    921921        self.sortArrowColor = "Silver" 
    922922 
    923         self.headerDragging = False    # flag used by mouse motion event handler 
    924         self.headerDragFrom = 0 
    925         self.headerDragTo = 0 
    926         self.headerSizing = False 
     923        self._headerDragging = False    # flag used by mouse motion event handler 
     924        self._headerDragFrom = 0 
     925        self._headerDragTo = 0 
     926        self._headerSizing = False 
    927927        #Call the default behavior 
    928928        super(dGrid, self)._afterInit() 
     
    938938        self.Bind(wx.grid.EVT_GRID_ROW_SIZE, self.__onWxGridRowSize) 
    939939        self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.__onWxGridSelectCell) 
    940         self.Bind(wx.grid.EVT_GRID_COL_SIZE, self.__onWxColSize) 
    941         self.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.__onWxRightClick) 
    942         self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.__onWxCellChange) 
    943  
    944         self.bindEvent(dEvents.KeyDown, self.onKeyDown) 
    945         self.bindEvent(dEvents.MouseLeftDoubleClick, self._onLeftDClick) 
     940        self.Bind(wx.grid.EVT_GRID_COL_SIZE, self.__onWxGridColSize) 
     941        self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.__onWxMouseLeftClick) 
     942        self.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.__onWxMouseRightClick) 
     943        self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.__onWxGridCellChange) 
     944 
     945        gridWindow = self.GetGridWindow() 
     946 
     947        gridWindow.Bind(wx.EVT_MOTION, self.__onWxMouseMotion) 
     948        gridWindow.Bind(wx.EVT_LEFT_DCLICK, self.__onWxMouseLeftDoubleClick) 
     949        gridWindow.Bind(wx.EVT_LEFT_DOWN, self.__onWxMouseLeftDown) 
     950        gridWindow.Bind(wx.EVT_LEFT_UP, self.__onWxMouseLeftUp) 
     951        gridWindow.Bind(wx.EVT_RIGHT_DOWN, self.__onWxMouseRightDown) 
     952        gridWindow.Bind(wx.EVT_RIGHT_UP, self.__onWxMouseRightUp) 
     953        gridWindow.Bind(wx.EVT_CONTEXT_MENU, self.__onWxContextMenu) 
     954 
     955        self.bindEvent(dEvents.KeyDown, self._onKeyDown) 
    946956        self.bindEvent(dEvents.GridRowSize, self._onGridRowSize) 
    947957        self.bindEvent(dEvents.GridSelectCell, self._onGridSelectCell) 
    948958        self.bindEvent(dEvents.GridColSize, self._onGridColSize) 
    949         self.bindEvent(dEvents.GridRightClick, self.onGridRightClick) 
    950959        self.bindEvent(dEvents.GridCellEdited, self._onGridCellEdited) 
     960 
     961        ## wx.EVT_CONTEXT_MENU doesn't appear to be working for dGrid yet: 
     962#       self.bindEvent(dEvents.GridContextMenu, self._onContextMenu) 
     963        self.bindEvent(dEvents.GridMouseRightDown, self._onContextMenu) 
    951964 
    952965 
     
    956969        self.defaultHdrCursor = header.GetCursor() 
    957970 
    958         header.Bind(wx.EVT_LEFT_DCLICK, self.__onWxMouseLeftDoubleClick) 
    959         header.Bind(wx.EVT_LEFT_DOWN, self.__onWxMouseLeftDown) 
    960         header.Bind(wx.EVT_LEFT_UP, self.__onWxMouseLeftUp) 
    961         header.Bind(wx.EVT_RIGHT_UP, self.__onWxMouseRightUp) 
    962         header.Bind(wx.EVT_MOTION, self.__onWxMouseMotion) 
     971        header.Bind(wx.EVT_LEFT_DCLICK, self.__onWxHeaderMouseLeftDoubleClick) 
     972        header.Bind(wx.EVT_LEFT_DOWN, self.__onWxHeaderMouseLeftDown) 
     973        header.Bind(wx.EVT_LEFT_UP, self.__onWxHeaderMouseLeftUp) 
     974        header.Bind(wx.EVT_RIGHT_DOWN, self.__onWxHeaderMouseRightDown) 
     975        header.Bind(wx.EVT_RIGHT_UP, self.__onWxHeaderMouseRightUp) 
     976        header.Bind(wx.EVT_MOTION, self.__onWxHeaderMouseMotion) 
    963977        header.Bind(wx.EVT_PAINT, self.__onWxHeaderPaint) 
    964  
    965         self.bindEvent(dEvents.MouseLeftDown, self.onMouseLeftDown) 
    966         self.bindEvent(dEvents.MouseLeftUp, self.onMouseLeftUp
    967         self.bindEvent(dEvents.MouseRightUp, self.onMouseRightUp
    968         self.bindEvent(dEvents.MouseMove, self.onMouseMove) 
    969         self.bindEvent(dEvents.Paint, self.onHeaderPaint
    970  
     978        header.Bind(wx.EVT_CONTEXT_MENU, self.__onWxHeaderContextMenu) 
     979 
     980        self.bindEvent(dEvents.GridHeaderMouseLeftDown, self._onGridHeaderMouseLeftDown
     981        self.bindEvent(dEvents.GridHeaderPaint, self._onHeaderPaint
     982        self.bindEvent(dEvents.GridHeaderMouseMove, self._onGridHeaderMouseMove) 
     983        self.bindEvent(dEvents.GridHeaderMouseLeftUp, self._onGridHeaderMouseLeftUp
     984        self.bindEvent(dEvents.GridHeaderMouseRightUp, self._onGridHeaderMouseRightUp) 
    971985 
    972986    def GetCellValue(self, row, col): 
     
    12071221         
    12081222 
    1209     def _onGridCellEdited(self, evt): 
    1210         row, col = evt.EventData["row"], evt.EventData["col"] 
    1211         rowData = self.getDataSet()[row] 
    1212         fld = self.Columns[col].Field 
    1213         newVal = self.GetCellValue(row, col) 
    1214         oldVal = rowData[fld] 
    1215         if newVal != oldVal: 
    1216             # Update the local copy of the data 
    1217             rowData[fld] = self.GetCellValue(row, col) 
    1218             # Call the hook 
    1219             self.onGridCellEdited(row, col, newVal) 
    1220  
    1221     def onGridCellEdited(self, row, col, newVal):  
    1222         """Called when the user has edited a cell 
    1223         and changed the value. Changes to the cell 
    1224         can be written back to the data source if  
    1225         desired. 
    1226         """ 
    1227         pass 
    1228  
    1229  
    1230     def _onGridColSize(self, evt): 
    1231         "Occurs when the user resizes the width of the column." 
    1232         colNum = evt.EventData["rowOrCol"] 
    1233         col = self.Columns[colNum] 
    1234         colName = "Column_%s" % col.Field 
    1235  
    1236         # Sync our column object up with what the grid is reporting, and because 
    1237         # the user made this change, save to the userSettings: 
    1238         width = col.Width = self.GetColSize(colNum) 
    1239         app = self.Application 
    1240         if app is not None: 
    1241             app.setUserSetting("%s.%s.%s.%s" % (self.Form.Name,  
    1242                                               self.Name, colName,  
    1243                                               "Width"), width) 
    1244         self.onGridColSize(evt) 
    1245  
    1246      
    1247     def onGridColSize(self, evt): pass 
    1248  
    1249  
    1250     def _onGridSelectCell(self, evt): 
    1251         """ Occurs when the grid's cell focus has changed.""" 
    1252         oldRow = self.CurrentRow 
    1253         newRow = evt.EventData["row"] 
    1254          
    1255         if oldRow != newRow: 
    1256             if self.bizobj: 
    1257                 self.bizobj.RowNumber = newRow 
    1258         self.Form.refreshControls() 
    1259         self.onGridSelectCell(evt) 
    1260  
    1261     def onGridSelectCell(self, evt): pass 
    1262  
    1263  
    12641223    def onColumnChange(self, col, chgType): 
    12651224        """Called by the grid columns whenever any of their properties 
     
    12751234         
    12761235 
    1277     def __onWxHeaderPaint(self, evt): 
    1278         self.raiseEvent(dEvents.Paint, evt) 
    1279     def onHeaderPaint(self, evt): 
    1280         """ Occurs when it is time to paint the grid column headers.""" 
    1281         dabo.ui.callAfter(self.hdrPaint) 
    1282      
    1283     def hdrPaint(self): 
     1236    def _paintHeader(self): 
    12841237        w = self.Header 
    12851238        dc = wx.ClientDC(w) 
     
    13651318            self.incSearchTimer.stop() 
    13661319 
    1367  
    1368     def __onWxMouseMotion(self, evt): 
    1369         self.raiseEvent(dEvents.MouseMove, evt) 
    1370     def onMouseMove(self, evt): 
    1371         ## pkm: commented out the evt.Continue=False because it doesn't appear 
    1372         ##      to be needed, and it prevents the native UI from responding. 
    1373         #evt.Continue = False 
    1374         if evt.EventData.has_key("row"): 
    1375             self.onGridMouseMove(evt) 
    1376         else: 
    1377             self.onHeaderMouseMove(evt) 
    1378     def onGridMouseMove(self, evt): 
    1379         """ Occurs when the left mouse button moves over the grid.""" 
    1380         pass 
    1381     def onHeaderMouseMove(self, evt): 
    1382         """ Occurs when the mouse moves in the grid header.""" 
    1383         headerIsDragging = self.headerDragging 
    1384         headerIsSizing = self.headerSizing 
    1385         dragging = evt.EventData["mouseDown"] 
    1386         header = self.Header 
    1387  
    1388         if dragging: 
    1389             x,y = evt.EventData["mousePosition"] 
    1390  
    1391             if not headerIsSizing and ( 
    1392                 self.getColByX(x) == self.getColByX(x-2) == self.getColByX(x+2)): 
    1393                 if not headerIsDragging: 
    1394                     # A header reposition is beginning 
    1395                     self.headerDragging = True 
    1396                     self.headerDragFrom = (x,y) 
    1397  
    1398                 else: 
    1399                     # already dragging. 
    1400                     begCol = self.getColByX(self.headerDragFrom[0]) 
    1401                     curCol = self.getColByX(x) 
    1402  
    1403                     # The visual indicators (changing the mouse cursor) isn't currently 
    1404                     # working. It would work without the evt.Skip() below, but that is  
    1405                     # needed for when the column is resized. 
    1406                     uic = dUICursors 
    1407                     if begCol == curCol: 
    1408                         # Give visual indication that a move is initiated 
    1409                         header.SetCursor(uic.getStockCursor(uic.Cursor_Size_WE)) 
    1410                     else: 
    1411                         # Give visual indication that this is an acceptable drop target 
    1412                         header.SetCursor(uic.getStockCursor(uic.Cursor_Bullseye)) 
    1413             else: 
    1414                 # A size action is happening 
    1415                 self.headerSizing = True 
    1416  
    1417  
    1418     def __onWxMouseLeftUp(self, evt): 
    1419         self.raiseEvent(dEvents.MouseLeftUp, evt) 
    1420     def onMouseLeftUp(self, evt): 
    1421         ## pkm: commented out the evt.Continue=False because it doesn't appear 
    1422         ##      to be needed, and it prevents the native UI from responding. 
    1423         #evt.Continue = False 
    1424         if evt.EventData.has_key("row"): 
    1425             self.onGridLeftUp(evt) 
    1426         else: 
    1427             self.onHeaderLeftUp(evt) 
    1428     def onGridLeftUp(self, evt): 
    1429         """ Occurs when the left mouse button is released in the grid.""" 
    1430         pass 
    1431     def onHeaderLeftUp(self, evt): 
    1432         """ Occurs when the left mouse button is released in the grid header. 
    1433  
    1434         Basically, this comes down to two possibilities: the end of a drag 
    1435         operation, or a single-click operation. If we were dragging, then 
    1436         it is possible a column needs to change position. If we were clicking, 
    1437         then it is a sort operation. 
    1438         """ 
    1439         x,y = evt.EventData["mousePosition"] 
    1440         if self.headerDragging: 
    1441             # A drag action is ending 
    1442             self.headerDragTo = (x,y) 
    1443  
    1444             begCol = self.getColByX(self.headerDragFrom[0]) 
    1445             curCol = self.getColByX(x) 
    1446  
    1447             if begCol != curCol: 
    1448                 if curCol > begCol: 
    1449                     curCol += 1 
    1450                 self.MoveColumn(begCol, curCol) 
    1451             self.Header.SetCursor(self.defaultHdrCursor) 
    1452         elif self.headerSizing: 
    1453             pass 
    1454         else: 
    1455             # we weren't dragging, and the mouse was just released. 
    1456             # Find out the column we are in based on the x-coord, and 
    1457             # do a processSort() on that column. 
    1458             col = self.getColByX(x) 
    1459             self.processSort(col) 
    1460         self.headerDragging = False 
    1461         self.headerSizing = False 
    1462         ## pkm: commented out the evt.Continue=False because it doesn't appear 
    1463         ##      to be needed, and it prevents the native UI from responding. 
    1464         #evt.Continue = False 
    1465  
    1466  
    1467     def __onWxMouseLeftDown(self, evt): 
    1468         self.raiseEvent(dEvents.MouseLeftDown, evt) 
    1469     def onMouseLeftDown(self, evt): 
    1470         evt.Continue = False 
    1471         if evt.EventData.has_key("row"): 
    1472             self.onGridLeftDown(evt) 
    1473         else: 
    1474             self.onHeaderLeftDown(evt) 
    1475     def onGridLeftDown(self, evt): 
    1476         """ Occurs when the left mouse button is pressed in the grid.""" 
    1477         pass 
    1478     def onHeaderLeftDown(self, evt): 
    1479         """ Occurs when the left mouse button is pressed in the grid header.""" 
    1480         evt.Continue = False 
    1481  
    1482  
    1483     def onHeaderLeftDClick(self, evt): 
    1484         """ Occurs when the left mouse button is double-clicked in the grid header.""" 
    1485         pass 
    1486  
    1487  
    1488     def __onWxMouseRightUp(self, evt): 
    1489         self.raiseEvent(dEvents.MouseRightUp, evt) 
    1490     def onMouseRightUp(self, evt): 
    1491         evt.Continue = False 
    1492         if evt.EventData.has_key("row"): 
    1493             self.onGridRightUp(evt) 
    1494         else: 
    1495             self.onHeaderRightUp(evt) 
    1496     def onGridRightUp(self, evt): 
    1497         """ Occurs when the right mouse button goes up in the grid.""" 
    1498         pass 
    1499     def onHeaderRightUp(self, evt): 
    1500         """ Occurs when the right mouse button goes up in the grid header.""" 
    1501         pass 
    1502         self.autoSizeCol( self.getColByX(evt.GetX())) 
    1503  
    1504      
    1505     def _onLeftDClick(self, evt):  
    1506         """Occurs when the user double-clicks anywhere in the grid.""" 
    1507         if evt.EventData.has_key("row"): 
    1508             # User double-clicked on a cell 
    1509             self.onGridLeftDClick(evt) 
    1510         else: 
    1511             # On the header 
    1512             self.onHeaderLeftDClick(evt) 
    1513  
    1514  
    1515     def onGridLeftDClick(self, evt): 
    1516         """The user double-clicked on a cell in the grid.""" 
    1517         pass 
    1518  
    1519  
    1520     def onGridRightClick(self, evt): 
    1521         """ Occurs when the user right-clicks a cell in the grid.  
    1522         By default, this is interpreted as a request to display the popup  
    1523         menu, as defined in self.popupMenu(). 
    1524         NOTE: evt is a wxPython event, not a Dabo event. 
    1525         """ 
    1526         # Select the cell that was right-clicked upon 
    1527         self.CurrentRow = evt.GetRow() 
    1528         self.CurrentColumn = evt.GetCol() 
    1529  
    1530         # Make the popup menu appear in the location that was clicked 
    1531         self.mousePosition = evt.GetPosition() 
    1532  
    1533         # Display the popup menu, if any 
    1534         self.popupMenu() 
    1535  
    1536  
    1537     def OnGridLabelLeftClick(self, evt): 
    1538         """ Occurs when the user left-clicks a grid column label.  
    1539         By default, this is interpreted as a request to sort the column. 
    1540         NOTE: evt is a wxPython event, not a Dabo event. 
    1541         """ 
    1542         self.processSort(evt.GetCol()) 
    1543      
    1544      
     1320     
     1321    ##----------------------------------------------------------## 
     1322    ##               begin: user hook methods                   ## 
     1323    ##----------------------------------------------------------## 
    15451324    def onEnterKeyAction(self): 
    15461325        "Customize in subclasses" 
     
    15651344        return False 
    15661345         
    1567  
    1568     def onKeyDown(self, evt):  
    1569         """ Occurs when the user presses a key inside the grid.  
    1570         Default actions depend on the key being pressed: 
    1571                     Enter:  edit the record 
    1572                         Del:  delete the record 
    1573                         F2:  sort the current column 
    1574                 AlphaNumeric:  incremental search 
    1575         """ 
    1576         if self.Editable and self.Columns[self.CurrentColumn].Editable: 
    1577             # Can't search and edit at the same time 
    1578             return 
    1579  
    1580         keyCode = evt.EventData["keyCode"] 
    1581         try: 
    1582             char = chr(keyCode) 
    1583         except ValueError:       # keycode not in ascii range 
    1584             char = None 
    1585  
    1586         if keyCode == dKeys.keyStrings["enter"]:           # Enter 
    1587             self.onEnterKeyAction() 
    1588             evt.stop() 
    1589         else: 
    1590             if keyCode == dKeys.keyStrings["delete"]:      # Del 
    1591                 self.onDeleteKeyAction() 
    1592                 evt.stop() 
    1593             elif keyCode == dKeys.keyStrings["escape"]: 
    1594                 self.onEscapeAction() 
    1595                 evt.stop() 
    1596             elif char and (self.Searchable and self.Columns[self.CurrentColumn].Searchable) and (char.isalnum() or char.isspace()) and not evt.HasModifiers(): 
    1597                 self.addToSearchStr(char) 
    1598                 # For some reason, without this the key happens twice 
    1599                 evt.stop() 
    1600             else: 
    1601                 if self.processKeyPress(keyCode): 
    1602                     # Key was handled 
    1603                     evt.stop() 
    1604                  
     1346    ##----------------------------------------------------------## 
     1347    ##                end: user hook methods                    ## 
     1348    ##----------------------------------------------------------## 
    16051349 
    16061350 
     
    18331577 
    18341578 
    1835     def _onGridRowSize(self, evt): 
    1836         """ Occurs when the user sizes the height of the row. If the 
    1837         property 'SameSizeRows' is True, Dabo overrides the wxPython  
    1838         default and applies that size change to all rows, not just the row  
    1839         the user sized. 
    1840         """ 
    1841         row = evt.GetRowOrCol() 
    1842         size = self.GetRowSize(row) 
    1843  
    1844         # Persist the new size 
    1845         app = self.Application 
    1846         if app is not None: 
    1847             app.setUserSetting("%s.%s.%s" % ( 
    1848                                self.Form.Name, self.Name, "RowSize"), size) 
    1849          
    1850         if self.SameSizeRows: 
    1851             self.SetDefaultRowSize(size, True) 
    1852             self.ForceRefresh() 
    1853         # Call the user hook 
    1854         self.onGridRowSize(evt) 
    1855          
    1856     def onGridRowSize(self, evt): pass 
    1857  
    1858      
    18591579    def getColByX(self, x): 
    18601580        """ Given the x-coordinate, return the column number. 
     
    18641584            col = -1 
    18651585        return col 
    1866  
    1867  
    1868     def __onWxGridRowSize(self, evt): 
    1869         self.raiseEvent(dEvents.GridRowSize, evt) 
    1870         evt.Skip() 
    1871  
    1872     def __onWxColSize(self, evt): 
    1873         self.raiseEvent(dEvents.GridColSize, evt) 
    1874         evt.Skip() 
    1875          
    1876     def __onWxGridSelectCell(self, evt): 
    1877         self.raiseEvent(dEvents.GridSelectCell, evt) 
    1878         evt.Skip() 
    1879  
    1880     def __onWxRightClick(self, evt): 
    1881         self.raiseEvent(dEvents.GridRightClick, evt) 
    1882         evt.Skip() 
    1883  
    1884     def __onWxMouseLeftDoubleClick(self, evt): 
    1885         self.raiseEvent(dEvents.MouseLeftDoubleClick, evt) 
    1886         evt.Skip() 
    1887  
    1888     def __onWxCellChange(self, evt): 
    1889         self.raiseEvent(dEvents.GridCellEdited, evt) 
    1890         evt.Skip() 
    18911586 
    18921587 
     
    19401635 
    19411636     
    1942          
    19431637    def cell(self, row, col): 
    19441638        class GridCell(object): 
     
    19561650         
    19571651 
     1652    ##----------------------------------------------------------## 
     1653    ##        begin: dEvent callbacks for internal use          ## 
     1654    ##----------------------------------------------------------## 
     1655    def _onGridCellEdited(self, evt): 
     1656        row, col = evt.EventData["row"], evt.EventData["col"] 
     1657        rowData = self.getDataSet()[row] 
     1658        fld = self.Columns[col].Field 
     1659        newVal = self.GetCellValue(row, col) 
     1660        oldVal = rowData[fld] 
     1661        if newVal != oldVal: 
     1662            # Update the local copy of the data 
     1663            rowData[fld] = self.GetCellValue(row, col) 
     1664 
     1665 
     1666    def _onGridColSize(self, evt): 
     1667        "Occurs when the user resizes the width of the column." 
     1668        colNum = evt.EventData["rowOrCol"] 
     1669        col = self.Columns[colNum] 
     1670        colName = "Column_%s" % col.Field 
     1671 
     1672        # Sync our column object up with what the grid is reporting, and because 
     1673        # the user made this change, save to the userSettings: 
     1674        width = col.Width = self.GetColSize(colNum) 
     1675        app = self.Application 
     1676        if app is not None: 
     1677            app.setUserSetting("%s.%s.%s.%s" % (self.Form.Name,  
     1678                                              self.Name, colName,  
     1679                                              "Width"), width) 
     1680     
     1681 
     1682    def _onGridSelectCell(self, evt): 
     1683        """ Occurs when the grid's cell focus has changed.""" 
     1684        oldRow = self.CurrentRow 
     1685        newRow = evt.EventData["row"] 
     1686         
     1687        if oldRow != newRow: 
     1688            if self.bizobj: 
     1689                self.bizobj.RowNumber = newRow 
     1690        self.Form.refreshControls() 
     1691 
     1692 
     1693    def _onGridHeaderMouseMove(self, evt): 
     1694        headerIsDragging = self._headerDragging 
     1695        headerIsSizing = self._headerSizing 
     1696        dragging = evt.EventData["mouseDown"] 
     1697        header = self.Header 
     1698 
     1699        if dragging: 
     1700            x,y = evt.EventData["mousePosition"] 
     1701 
     1702            if not headerIsSizing and ( 
     1703                self.getColByX(x) == self.getColByX(x-2) == self.getColByX(x+2)): 
     1704                if not headerIsDragging: 
     1705                    # A header reposition is beginning 
     1706                    self._headerDragging = True 
     1707                    self._headerDragFrom = (x,y) 
     1708 
     1709                else: 
     1710                    # already dragging. 
     1711                    begCol = self.getColByX(self._headerDragFrom[0]) 
     1712                    curCol = self.getColByX(x) 
     1713 
     1714                    # The visual indicators (changing the mouse cursor) isn't currently 
     1715                    # working. It would work without the evt.Skip() below, but that is  
     1716                    # needed for when the column is resized. 
     1717                    uic = dUICursors 
     1718                    if begCol == curCol: 
     1719                        # Give visual indication that a move is initiated 
     1720                        header.SetCursor(uic.getStockCursor(uic.Cursor_Size_WE)) 
     1721                    else: 
     1722                        # Give visual indication that this is an acceptable drop target 
     1723                        header.SetCursor(uic.getStockCursor(uic.Cursor_Bullseye)) 
     1724            else: 
     1725                # A size action is happening 
     1726                self._headerSizing = True 
     1727 
     1728 
     1729    def _onGridHeaderMouseLeftUp(self, evt): 
     1730        """ Occurs when the left mouse button is released in the grid header. 
     1731 
     1732        Basically, this comes down to two possibilities: the end of a drag 
     1733        operation, or a single-click operation. If we were dragging, then 
     1734        it is possible a column needs to change position. If we were clicking, 
     1735        then it is a sort operation. 
     1736        """ 
     1737        x,y = evt.EventData["mousePosition"] 
     1738        if self._headerDragging: 
     1739            # A drag action is ending 
     1740            self._headerDragTo = (x,y) 
     1741 
     1742            begCol = self.getColByX(self._headerDragFrom[0]) 
     1743            curCol = self.getColByX(x) 
     1744 
     1745            if begCol != curCol: 
     1746                if curCol > begCol: 
     1747                    curCol += 1 
     1748                self.MoveColumn(begCol, curCol) 
     1749            self.Header.SetCursor(self.defaultHdrCursor) 
     1750        elif self._headerSizing: 
     1751            pass 
     1752        else: 
     1753            # we weren't dragging, and the mouse was just released. 
     1754            # Find out the column we are in based on the x-coord, and 
     1755            # do a processSort() on that column. 
     1756            col = self.getColByX(x) 
     1757            self.processSort(col) 
     1758        self._headerDragging = False 
     1759        self._headerSizing = False 
     1760        ## pkm: commented out the evt.Continue=False because it doesn't appear 
     1761        ##      to be needed, and it prevents the native UI from responding. 
     1762        #evt.Continue = False 
     1763 
     1764 
     1765    def _onGridHeaderMouseRightUp(self, evt): 
     1766        """ Occurs when the right mouse button goes up in the grid header.""" 
     1767        self.autoSizeCol( self.getColByX(evt.GetX())) 
     1768 
     1769     
     1770    def _onContextMenu(self, evt): 
     1771        # Make the popup menu appear in the location that was clicked 
     1772        self.mousePosition = evt.GetPosition() 
     1773 
     1774        # Display the popup menu, if any 
     1775        self.popupMenu() 
     1776 
     1777    def _onGridHeaderMouseLeftDown(self, evt): 
     1778        evt.Continue = False 
     1779 
     1780    def _onGridRowSize(self, evt): 
     1781        """ Occurs when the user sizes the height of the row. If the 
     1782        property 'SameSizeRows' is True, Dabo overrides the wxPython  
     1783        default and applies that size change to all rows, not just the row  
     1784        the user sized. 
     1785        """ 
     1786        row = evt.GetRowOrCol() 
     1787        size = self.GetRowSize(row) 
     1788 
     1789        # Persist the new size 
     1790        app = self.Application 
     1791        if app is not None: 
     1792            app.setUserSetting("%s.%s.%s" % ( 
     1793                               self.Form.Name, self.Name, "RowSize"), size) 
     1794         
     1795        if self.SameSizeRows: 
     1796            self.SetDefaultRowSize(size, True) 
     1797            self.ForceRefresh() 
     1798 
     1799     
     1800    def _onKeyDown(self, evt):  
     1801        """ Occurs when the user presses a key inside the grid.  
     1802        Default actions depend on the key being pressed: 
     1803                    Enter:  edit the record 
     1804                        Del:  delete the record 
     1805                        F2:  sort the current column 
     1806                AlphaNumeric:  incremental search 
     1807        """ 
     1808        if self.Editable and self.Columns[self.CurrentColumn].Editable: 
     1809            # Can't search and edit at the same time 
     1810            return 
     1811 
     1812        keyCode = evt.EventData["keyCode"] 
     1813        try: 
     1814            char = chr(keyCode) 
     1815        except ValueError:       # keycode not in ascii range 
     1816            char = None 
     1817 
     1818        if keyCode == dKeys.keyStrings["enter"]:           # Enter 
     1819            self.onEnterKeyAction() 
     1820            evt.stop() 
     1821        else: 
     1822            if keyCode == dKeys.keyStrings["delete"]:      # Del 
     1823                self.onDeleteKeyAction() 
     1824                evt.stop() 
     1825            elif keyCode == dKeys.keyStrings["escape"]: 
     1826                self.onEscapeAction() 
     1827                evt.stop() 
     1828            elif char and (self.Searchable and self.Columns[self.CurrentColumn].Searchable) \ 
     1829                and (char.isalnum() or char.isspace()) and not evt.HasModifiers(): 
     1830                self.addToSearchStr(char) 
     1831                # For some reason, without this the key happens twice 
     1832                evt.stop() 
     1833            else: 
     1834                if self.processKeyPress(keyCode): 
     1835                    # Key was handled 
     1836                    evt.stop() 
     1837 
     1838 
     1839    def _onHeaderPaint(self, evt): 
     1840        dabo.ui.callAfter(self._paintHeader) 
     1841     
     1842    ##----------------------------------------------------------## 
     1843    ##        end: dEvent callbacks for internal use            ## 
     1844    ##----------------------------------------------------------## 
     1845 
     1846 
     1847    ##----------------------------------------------------------## 
     1848    ##      begin: wx callbacks to re-route to dEvents          ## 
     1849    ##----------------------------------------------------------## 
     1850     
     1851    ## dGrid has to reimplement all of this to augment what dPemMixin does, 
     1852    ## to offer separate events in the grid versus the header region. 
     1853    def __onWxContextMenu(self, evt): 
     1854        self.raiseEvent(dEvents.GridContextMenu, evt) 
     1855        evt.Skip() 
     1856 
     1857    def __onWxGridColSize(self, evt): 
     1858        self.raiseEvent(dEvents.GridColSize, evt) 
     1859        evt.Skip() 
     1860         
     1861    def __onWxGridCellChange(self, evt): 
     1862        self.raiseEvent(dEvents.GridCellEdited, evt) 
     1863        evt.Skip() 
     1864 
     1865    def __onWxGridRowSize(self, evt): 
     1866        self.raiseEvent(dEvents.GridRowSize, evt) 
     1867        evt.Skip() 
     1868 
     1869    def __onWxGridSelectCell(self, evt): 
     1870        self.raiseEvent(dEvents.GridSelectCell, evt) 
     1871        evt.Skip() 
     1872 
     1873    def __onWxHeaderContextMenu(self, evt): 
     1874        self.raiseEvent(dEvents.GridHeaderContextMenu, evt) 
     1875        evt.Skip() 
     1876 
     1877    def __onWxHeaderMouseLeftDoubleClick(self, evt): 
     1878        self.raiseEvent(dEvents.GridHeaderMouseLeftDoubleClick, evt) 
     1879        evt.Skip() 
     1880 
     1881    def __onWxHeaderMouseLeftDown(self, evt): 
     1882        self.raiseEvent(dEvents.GridHeaderMouseLeftDown, evt) 
     1883        #evt.Skip() #- don't skip or all the rows will be selected. 
     1884 
     1885    def __onWxHeaderMouseLeftUp(self, evt): 
     1886        self.raiseEvent(dEvents.GridHeaderMouseLeftUp, evt) 
     1887        evt.Skip() 
     1888 
     1889    def __onWxHeaderMouseMotion(self, evt): 
     1890        self.raiseEvent(dEvents.GridHeaderMouseMove, evt) 
     1891        evt.Skip() 
     1892 
     1893    def __onWxHeaderMouseRightDown(self, evt): 
     1894        self.raiseEvent(dEvents.GridHeaderMouseRightDown, evt) 
     1895        evt.Skip() 
     1896 
     1897    def __onWxHeaderMouseRightUp(self, evt): 
     1898        self.raiseEvent(dEvents.GridHeaderMouseRightUp, evt) 
     1899        evt.Skip() 
     1900 
     1901    def __onWxHeaderPaint(self, evt): 
     1902        self.raiseEvent(dEvents.GridHeaderPaint, evt) 
     1903 
     1904    def __onWxMouseLeftDoubleClick(self, evt): 
     1905        self.raiseEvent(dEvents.GridMouseLeftDoubleClick, evt) 
     1906        evt.Skip() 
     1907 
     1908    def __onWxMouseLeftClick(self, evt): 
     1909        self.raiseEvent(dEvents.GridMouseLeftClick, evt) 
     1910        evt.Skip() 
     1911 
     1912    def __onWxMouseLeftDown(self, evt): 
     1913        self.raiseEvent(dEvents.GridMouseLeftDown, evt) 
     1914        evt.Skip() 
     1915 
     1916    def __onWxMouseLeftUp(self, evt): 
     1917        self.raiseEvent(dEvents.GridMouseLeftUp, evt) 
     1918        evt.Skip() 
     1919 
     1920    def __onWxMouseMotion(self, evt): 
     1921        self.raiseEvent(dEvents.GridMouseMove, evt) 
     1922        evt.Skip() 
     1923 
     1924    def __onWxMouseRightClick(self, evt): 
     1925        self.raiseEvent(dEvents.GridRightClick, evt) 
     1926        evt.Skip() 
     1927 
     1928    def __onWxMouseRightDown(self, evt): 
     1929        self.raiseEvent(dEvents.GridMouseRightDown, evt) 
     1930        evt.Skip() 
     1931 
     1932    def __onWxMouseRightUp(self, evt): 
     1933        self.raiseEvent(dEvents.GridMouseRightUp, evt) 
     1934        evt.Skip() 
     1935 
     1936    ##----------------------------------------------------------## 
     1937    ##       end: wx callbacks to re-route to dEvents           ## 
     1938    ##----------------------------------------------------------## 
     1939 
     1940 
    19581941    def _getDefaultGridColAttr(self): 
    19591942        """ Return the GridCellAttr that will be used for all columns by default.""" 
     
    19641947     
    19651948 
     1949 
     1950    ##----------------------------------------------------------## 
     1951    ##              begin: property definitions                 ## 
     1952    ##----------------------------------------------------------## 
    19661953    def _getColumns(self): 
    19671954        try: 
     
    22732260            _("Reference to the internal table class  (dGridDataTable)") ) 
    22742261 
     2262    ##----------------------------------------------------------## 
     2263    ##               end: property definitions                  ## 
     2264    ##----------------------------------------------------------## 
     2265 
    22752266 
    22762267class _dGrid_test(dGrid):