2003-11-12 16:34:20 -05:00
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
# Name: GridColMover.py
|
|
|
|
# Purpose: Grid Column Mover Extension
|
|
|
|
#
|
|
|
|
# Author: Gerrit van Dyk (email: gerritvd@decillion.net)
|
|
|
|
#
|
|
|
|
# Version 0.1
|
|
|
|
# Date: Nov 19, 2002
|
|
|
|
# RCS-ID: $Id$
|
|
|
|
# Licence: wxWindows license
|
|
|
|
#----------------------------------------------------------------------------
|
2003-12-16 19:34:40 -05:00
|
|
|
# 12/07/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o 2.5 Compatability changes
|
|
|
|
#
|
2003-12-20 14:36:30 -05:00
|
|
|
# 12/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o wxGridColMoveEvent -> GridColMoveEvent
|
|
|
|
# o wxGridRowMoveEvent -> GridRowMoveEvent
|
|
|
|
# o wxGridColMover -> GridColMover
|
|
|
|
# o wxGridRowMover -> GridRowMover
|
|
|
|
#
|
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
import wx
|
|
|
|
import wx.grid
|
2003-07-02 19:13:10 -04:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
#----------------------------------------------------------------------------
|
2003-12-16 19:34:40 -05:00
|
|
|
# event class and macros
|
|
|
|
#
|
|
|
|
# New style 12/7/03
|
|
|
|
#
|
2003-11-12 16:34:20 -05:00
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
wxEVT_COMMAND_GRID_COL_MOVE = wx.NewEventType()
|
|
|
|
wxEVT_COMMAND_GRID_ROW_MOVE = wx.NewEventType()
|
2003-11-12 16:34:20 -05:00
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
EVT_GRID_COL_MOVE = wx.PyEventBinder(wxEVT_COMMAND_GRID_COL_MOVE, 1)
|
|
|
|
EVT_GRID_ROW_MOVE = wx.PyEventBinder(wxEVT_COMMAND_GRID_ROW_MOVE, 1)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
#----------------------------------------------------------------------------
|
2003-11-12 16:34:20 -05:00
|
|
|
|
2003-12-20 14:36:30 -05:00
|
|
|
class GridColMoveEvent(wx.PyCommandEvent):
|
2003-11-12 16:34:20 -05:00
|
|
|
def __init__(self, id, dCol, bCol):
|
2003-12-16 19:34:40 -05:00
|
|
|
wx.PyCommandEvent.__init__(self, id = id)
|
2003-11-12 16:34:20 -05:00
|
|
|
self.SetEventType(wxEVT_COMMAND_GRID_COL_MOVE)
|
|
|
|
self.moveColumn = dCol
|
|
|
|
self.beforeColumn = bCol
|
|
|
|
|
|
|
|
def GetMoveColumn(self):
|
|
|
|
return self.moveColumn
|
|
|
|
|
|
|
|
def GetBeforeColumn(self):
|
|
|
|
return self.beforeColumn
|
|
|
|
|
|
|
|
|
2003-12-20 14:36:30 -05:00
|
|
|
class GridRowMoveEvent(wx.PyCommandEvent):
|
2003-11-12 16:34:20 -05:00
|
|
|
def __init__(self, id, dRow, bRow):
|
2003-12-16 19:34:40 -05:00
|
|
|
wx.PyCommandEvent.__init__(self,id = id)
|
2003-11-12 16:34:20 -05:00
|
|
|
self.SetEventType(wxEVT_COMMAND_GRID_ROW_MOVE)
|
|
|
|
self.moveRow = dRow
|
|
|
|
self.beforeRow = bRow
|
|
|
|
|
|
|
|
def GetMoveRow(self):
|
|
|
|
return self.moveRow
|
|
|
|
|
|
|
|
def GetBeforeRow(self):
|
|
|
|
return self.beforeRow
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
# graft new methods into the wxGrid class
|
|
|
|
|
|
|
|
def _ColToRect(self,col):
|
|
|
|
if self.GetNumberRows() > 0:
|
|
|
|
rect = self.CellToRect(0,col)
|
|
|
|
else:
|
2004-10-14 20:51:57 -04:00
|
|
|
rect = wx.Rect()
|
2003-11-12 16:34:20 -05:00
|
|
|
rect.height = self.GetColLabelSize()
|
|
|
|
rect.width = self.GetColSize(col)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
for cCol in range(0,col):
|
|
|
|
rect.x += self.GetColSize(cCol)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
rect.y = self.GetGridColLabelWindow().GetPosition()[1]
|
|
|
|
return rect
|
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
wx.grid.Grid.ColToRect = _ColToRect
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
|
|
|
|
def _RowToRect(self,row):
|
|
|
|
if self.GetNumberCols() > 0:
|
|
|
|
rect = self.CellToRect(row,0)
|
|
|
|
else:
|
2004-10-14 20:51:57 -04:00
|
|
|
rect = wx.Rect()
|
2003-11-12 16:34:20 -05:00
|
|
|
rect.width = self.GetRowLabelSize()
|
|
|
|
rect.height = self.GetRowSize(row)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
for cRow in range(0,row):
|
|
|
|
rect.y += self.GetRowSize(cRow)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
rect.x = self.GetGridRowLabelWindow().GetPosition()[0]
|
|
|
|
return rect
|
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
wx.grid.Grid.RowToRect = _RowToRect
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
class ColDragWindow(wx.Window):
|
2003-11-12 16:34:20 -05:00
|
|
|
def __init__(self,parent,image,dragCol):
|
2003-12-16 19:34:40 -05:00
|
|
|
wx.Window.__init__(self,parent,-1, style=wx.SIMPLE_BORDER)
|
2003-11-12 16:34:20 -05:00
|
|
|
self.image = image
|
|
|
|
self.SetSize((self.image.GetWidth(),self.image.GetHeight()))
|
|
|
|
self.ux = parent.GetScrollPixelsPerUnit()[0]
|
|
|
|
self.moveColumn = dragCol
|
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
def DisplayAt(self,pos,y):
|
|
|
|
x = self.GetPositionTuple()[0]
|
|
|
|
if x == pos:
|
|
|
|
self.Refresh() # Need to display insertion point
|
|
|
|
else:
|
|
|
|
self.MoveXY(pos,y)
|
|
|
|
|
|
|
|
def GetMoveColumn(self):
|
|
|
|
return self.moveColumn
|
|
|
|
|
|
|
|
def _GetInsertionInfo(self):
|
|
|
|
parent = self.GetParent()
|
|
|
|
sx = parent.GetViewStart()[0] * self.ux
|
|
|
|
sx -= parent._rlSize
|
2003-12-16 19:34:40 -05:00
|
|
|
x = self.GetPosition()[0]
|
|
|
|
w = self.GetSize()[0]
|
2003-11-12 16:34:20 -05:00
|
|
|
sCol = parent.XToCol(x + sx)
|
|
|
|
eCol = parent.XToCol(x + w + sx)
|
|
|
|
iPos = xPos = xCol = 99999
|
|
|
|
centerPos = x + sx + (w / 2)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
for col in range(sCol,eCol + 1):
|
|
|
|
cx = parent.ColToRect(col)[0]
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
if abs(cx - centerPos) < iPos:
|
|
|
|
iPos = abs(cx - centerPos)
|
|
|
|
xCol = col
|
|
|
|
xPos = cx
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
if xCol < 0 or xCol > parent.GetNumberCols():
|
|
|
|
xCol = parent.GetNumberCols()
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
return (xPos - sx - x,xCol)
|
|
|
|
|
|
|
|
def GetInsertionColumn(self):
|
|
|
|
return self._GetInsertionInfo()[1]
|
|
|
|
|
|
|
|
def GetInsertionPos(self):
|
|
|
|
return self._GetInsertionInfo()[0]
|
|
|
|
|
|
|
|
def OnPaint(self,evt):
|
2003-12-16 19:34:40 -05:00
|
|
|
dc = wx.PaintDC(self)
|
2003-11-12 16:34:20 -05:00
|
|
|
w,h = self.GetSize()
|
2004-05-01 22:41:33 -04:00
|
|
|
dc.DrawBitmap(self.image, 0,0)
|
2003-12-16 19:34:40 -05:00
|
|
|
dc.SetPen(wx.Pen(wx.BLACK,1,wx.SOLID))
|
|
|
|
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
2004-05-01 22:41:33 -04:00
|
|
|
dc.DrawRectangle(0,0, w,h)
|
2003-11-12 16:34:20 -05:00
|
|
|
iPos = self.GetInsertionPos()
|
2004-05-01 22:41:33 -04:00
|
|
|
dc.DrawLine(iPos,h - 10, iPos,h)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
class RowDragWindow(wx.Window):
|
2003-11-12 16:34:20 -05:00
|
|
|
def __init__(self,parent,image,dragRow):
|
2003-12-16 19:34:40 -05:00
|
|
|
wx.Window.__init__(self,parent,-1, style=wx.SIMPLE_BORDER)
|
2003-11-12 16:34:20 -05:00
|
|
|
self.image = image
|
|
|
|
self.SetSize((self.image.GetWidth(),self.image.GetHeight()))
|
|
|
|
self.uy = parent.GetScrollPixelsPerUnit()[1]
|
|
|
|
self.moveRow = dragRow
|
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
def DisplayAt(self,x,pos):
|
2003-12-16 19:34:40 -05:00
|
|
|
y = self.GetPosition()[1]
|
2003-11-12 16:34:20 -05:00
|
|
|
if y == pos:
|
|
|
|
self.Refresh() # Need to display insertion point
|
|
|
|
else:
|
|
|
|
self.MoveXY(x,pos)
|
|
|
|
|
|
|
|
def GetMoveRow(self):
|
|
|
|
return self.moveRow
|
|
|
|
|
|
|
|
def _GetInsertionInfo(self):
|
|
|
|
parent = self.GetParent()
|
|
|
|
sy = parent.GetViewStart()[1] * self.uy
|
|
|
|
sy -= parent._clSize
|
2003-12-16 19:34:40 -05:00
|
|
|
y = self.GetPosition()[1]
|
|
|
|
h = self.GetSize()[1]
|
2003-11-12 16:34:20 -05:00
|
|
|
sRow = parent.YToRow(y + sy)
|
|
|
|
eRow = parent.YToRow(y + h + sy)
|
|
|
|
iPos = yPos = yRow = 99999
|
|
|
|
centerPos = y + sy + (h / 2)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
for row in range(sRow,eRow + 1):
|
|
|
|
cy = parent.RowToRect(row)[1]
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
if abs(cy - centerPos) < iPos:
|
|
|
|
iPos = abs(cy - centerPos)
|
|
|
|
yRow = row
|
|
|
|
yPos = cy
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
if yRow < 0 or yRow > parent.GetNumberRows():
|
|
|
|
yRow = parent.GetNumberRows()
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
return (yPos - sy - y,yRow)
|
|
|
|
|
|
|
|
def GetInsertionRow(self):
|
|
|
|
return self._GetInsertionInfo()[1]
|
|
|
|
|
|
|
|
def GetInsertionPos(self):
|
|
|
|
return self._GetInsertionInfo()[0]
|
|
|
|
|
|
|
|
def OnPaint(self,evt):
|
2003-12-16 19:34:40 -05:00
|
|
|
dc = wx.PaintDC(self)
|
2003-11-12 16:34:20 -05:00
|
|
|
w,h = self.GetSize()
|
2004-05-01 22:41:33 -04:00
|
|
|
dc.DrawBitmap(self.image, 0,0)
|
2003-12-16 19:34:40 -05:00
|
|
|
dc.SetPen(wx.Pen(wx.BLACK,1,wx.SOLID))
|
|
|
|
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
2004-05-01 22:41:33 -04:00
|
|
|
dc.DrawRectangle(0,0, w,h)
|
2003-11-12 16:34:20 -05:00
|
|
|
iPos = self.GetInsertionPos()
|
2004-05-01 22:41:33 -04:00
|
|
|
dc.DrawLine(w - 10,iPos, w,iPos)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
2003-12-20 14:36:30 -05:00
|
|
|
class GridColMover(wx.EvtHandler):
|
2003-11-12 16:34:20 -05:00
|
|
|
def __init__(self,grid):
|
2003-12-16 19:34:40 -05:00
|
|
|
wx.EvtHandler.__init__(self)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
self.grid = grid
|
|
|
|
self.grid._rlSize = self.grid.GetRowLabelSize()
|
|
|
|
self.lwin = grid.GetGridColLabelWindow()
|
|
|
|
self.lwin.PushEventHandler(self)
|
|
|
|
self.colWin = None
|
|
|
|
self.ux = self.grid.GetScrollPixelsPerUnit()[0]
|
|
|
|
self.startX = -10
|
|
|
|
self.cellX = 0
|
|
|
|
self.didMove = False
|
|
|
|
self.isDragging = False
|
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
self.Bind(wx.EVT_MOTION, self.OnMouseMove)
|
|
|
|
self.Bind(wx.EVT_LEFT_DOWN, self.OnPress)
|
|
|
|
self.Bind(wx.EVT_LEFT_UP, self.OnRelease)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
def OnMouseMove(self,evt):
|
|
|
|
if self.isDragging:
|
|
|
|
if abs(self.startX - evt.m_x) >= 3:
|
|
|
|
self.didMove = True
|
|
|
|
sx,y = self.grid.GetViewStart()
|
2003-12-16 19:34:40 -05:00
|
|
|
w,h = self.lwin.GetClientSize()
|
2003-11-12 16:34:20 -05:00
|
|
|
x = sx * self.ux
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
if (evt.m_x + x) < x:
|
|
|
|
x = evt.m_x + x
|
|
|
|
elif evt.m_x > w:
|
|
|
|
x += evt.m_x - w
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
if x < 1: x = 0
|
|
|
|
else: x /= self.ux
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
if x != sx:
|
2003-12-16 19:34:40 -05:00
|
|
|
if wx.Platform == '__WXMSW__':
|
2003-11-12 16:34:20 -05:00
|
|
|
self.colWin.Show(False)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
self.grid.Scroll(x,y)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
x,y = self.lwin.ClientToScreenXY(evt.m_x,0)
|
|
|
|
x,y = self.grid.ScreenToClientXY(x,y)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
if not self.colWin.IsShown():
|
|
|
|
self.colWin.Show(True)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
px = x - self.cellX
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
if px < 0 + self.grid._rlSize: px = 0 + self.grid._rlSize
|
2003-12-16 19:34:40 -05:00
|
|
|
|
|
|
|
if px > w - self.colWin.GetSize()[0] + self.grid._rlSize:
|
|
|
|
px = w - self.colWin.GetSize()[0] + self.grid._rlSize
|
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
self.colWin.DisplayAt(px,y)
|
|
|
|
return
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
evt.Skip()
|
|
|
|
|
|
|
|
def OnPress(self,evt):
|
|
|
|
self.startX = evt.m_x
|
|
|
|
sx = self.grid.GetViewStart()[0] * self.ux
|
|
|
|
sx -= self.grid._rlSize
|
|
|
|
px,py = self.lwin.ClientToScreenXY(evt.m_x,evt.m_y)
|
|
|
|
px,py = self.grid.ScreenToClientXY(px,py)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
|
|
|
if self.grid.XToEdgeOfCol(px + sx) != wx.NOT_FOUND:
|
2003-11-12 16:34:20 -05:00
|
|
|
evt.Skip()
|
|
|
|
return
|
|
|
|
|
|
|
|
self.isDragging = True
|
|
|
|
self.didMove = False
|
|
|
|
col = self.grid.XToCol(px + sx)
|
|
|
|
rect = self.grid.ColToRect(col)
|
|
|
|
self.cellX = px + sx - rect.x
|
2003-12-16 19:34:40 -05:00
|
|
|
size = self.lwin.GetSize()
|
2003-11-12 16:34:20 -05:00
|
|
|
rect.y = 0
|
|
|
|
rect.x -= sx + self.grid._rlSize
|
|
|
|
rect.height = size[1]
|
|
|
|
colImg = self._CaptureImage(rect)
|
|
|
|
self.colWin = ColDragWindow(self.grid,colImg,col)
|
|
|
|
self.colWin.Show(False)
|
|
|
|
self.lwin.CaptureMouse()
|
2004-07-15 20:12:48 -04:00
|
|
|
evt.Skip()
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
def OnRelease(self,evt):
|
|
|
|
if self.isDragging:
|
|
|
|
self.lwin.ReleaseMouse()
|
|
|
|
self.colWin.Show(False)
|
|
|
|
self.isDragging = False
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
if not self.didMove:
|
|
|
|
px = self.lwin.ClientToScreenXY(self.startX,0)[0]
|
|
|
|
px = self.grid.ScreenToClientXY(px,0)[0]
|
|
|
|
sx = self.grid.GetViewStart()[0] * self.ux
|
|
|
|
sx -= self.grid._rlSize
|
|
|
|
col = self.grid.XToCol(px+sx)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
|
|
|
if col != wx.NOT_FOUND:
|
2003-11-12 16:34:20 -05:00
|
|
|
self.grid.SelectCol(col,evt.m_controlDown)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
return
|
|
|
|
else:
|
|
|
|
bCol = self.colWin.GetInsertionColumn()
|
|
|
|
dCol = self.colWin.GetMoveColumn()
|
2003-12-16 19:34:40 -05:00
|
|
|
wx.PostEvent(self,
|
2003-12-20 14:36:30 -05:00
|
|
|
GridColMoveEvent(self.grid.GetId(), dCol, bCol))
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
self.colWin.Destroy()
|
|
|
|
evt.Skip()
|
|
|
|
|
|
|
|
def _CaptureImage(self,rect):
|
2003-12-16 19:34:40 -05:00
|
|
|
bmp = wx.EmptyBitmap(rect.width,rect.height)
|
|
|
|
memdc = wx.MemoryDC()
|
2003-11-12 16:34:20 -05:00
|
|
|
memdc.SelectObject(bmp)
|
2003-12-16 19:34:40 -05:00
|
|
|
dc = wx.WindowDC(self.lwin)
|
2004-05-01 22:41:33 -04:00
|
|
|
memdc.Blit(0,0, rect.width, rect.height, dc, rect.x, rect.y)
|
2003-12-16 19:34:40 -05:00
|
|
|
memdc.SelectObject(wx.NullBitmap)
|
2003-11-12 16:34:20 -05:00
|
|
|
return bmp
|
|
|
|
|
|
|
|
|
2003-12-20 14:36:30 -05:00
|
|
|
class GridRowMover(wx.EvtHandler):
|
2003-11-12 16:34:20 -05:00
|
|
|
def __init__(self,grid):
|
2003-12-16 19:34:40 -05:00
|
|
|
wx.EvtHandler.__init__(self)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
self.grid = grid
|
|
|
|
self.grid._clSize = self.grid.GetColLabelSize()
|
|
|
|
self.lwin = grid.GetGridRowLabelWindow()
|
|
|
|
self.lwin.PushEventHandler(self)
|
|
|
|
self.rowWin = None
|
|
|
|
self.uy = self.grid.GetScrollPixelsPerUnit()[1]
|
|
|
|
self.startY = -10
|
|
|
|
self.cellY = 0
|
|
|
|
self.didMove = False
|
|
|
|
self.isDragging = False
|
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
self.Bind(wx.EVT_MOTION, self.OnMouseMove)
|
|
|
|
self.Bind(wx.EVT_LEFT_DOWN, self.OnPress)
|
|
|
|
self.Bind(wx.EVT_LEFT_UP, self.OnRelease)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
def OnMouseMove(self,evt):
|
|
|
|
if self.isDragging:
|
|
|
|
if abs(self.startY - evt.m_y) >= 3:
|
|
|
|
self.didMove = True
|
|
|
|
x,sy = self.grid.GetViewStart()
|
|
|
|
w,h = self.lwin.GetClientSizeTuple()
|
|
|
|
y = sy * self.uy
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
if (evt.m_y + y) < y:
|
|
|
|
y = evt.m_y + y
|
|
|
|
elif evt.m_y > h:
|
|
|
|
y += evt.m_y - h
|
2003-12-16 19:34:40 -05:00
|
|
|
|
|
|
|
if y < 1:
|
|
|
|
y = 0
|
|
|
|
else:
|
|
|
|
y /= self.uy
|
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
if y != sy:
|
2003-12-16 19:34:40 -05:00
|
|
|
if wx.Platform == '__WXMSW__':
|
2003-11-12 16:34:20 -05:00
|
|
|
self.rowWin.Show(False)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
self.grid.Scroll(x,y)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
x,y = self.lwin.ClientToScreenXY(0,evt.m_y)
|
|
|
|
x,y = self.grid.ScreenToClientXY(x,y)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
if not self.rowWin.IsShown():
|
|
|
|
self.rowWin.Show(True)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
py = y - self.cellY
|
2003-12-16 19:34:40 -05:00
|
|
|
|
|
|
|
if py < 0 + self.grid._clSize:
|
|
|
|
py = 0 + self.grid._clSize
|
|
|
|
|
|
|
|
if py > h - self.rowWin.GetSize()[1] + self.grid._clSize:
|
|
|
|
py = h - self.rowWin.GetSize()[1] + self.grid._clSize
|
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
self.rowWin.DisplayAt(x,py)
|
|
|
|
return
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
evt.Skip()
|
|
|
|
|
|
|
|
def OnPress(self,evt):
|
|
|
|
self.startY = evt.m_y
|
|
|
|
sy = self.grid.GetViewStart()[1] * self.uy
|
|
|
|
sy -= self.grid._clSize
|
|
|
|
px,py = self.lwin.ClientToScreenXY(evt.m_x,evt.m_y)
|
|
|
|
px,py = self.grid.ScreenToClientXY(px,py)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
|
|
|
if self.grid.YToEdgeOfRow(py + sy) != wx.NOT_FOUND:
|
2003-11-12 16:34:20 -05:00
|
|
|
evt.Skip()
|
|
|
|
return
|
|
|
|
|
|
|
|
self.isDragging = True
|
|
|
|
self.didMove = False
|
|
|
|
row = self.grid.YToRow(py + sy)
|
|
|
|
rect = self.grid.RowToRect(row)
|
|
|
|
self.cellY = py + sy - rect.y
|
2003-12-16 19:34:40 -05:00
|
|
|
size = self.lwin.GetSize()
|
2003-11-12 16:34:20 -05:00
|
|
|
rect.x = 0
|
|
|
|
rect.y -= sy + self.grid._clSize
|
|
|
|
rect.width = size[0]
|
|
|
|
rowImg = self._CaptureImage(rect)
|
|
|
|
self.rowWin = RowDragWindow(self.grid,rowImg,row)
|
|
|
|
self.rowWin.Show(False)
|
|
|
|
self.lwin.CaptureMouse()
|
2004-07-15 20:12:48 -04:00
|
|
|
evt.Skip()
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
def OnRelease(self,evt):
|
|
|
|
if self.isDragging:
|
|
|
|
self.lwin.ReleaseMouse()
|
|
|
|
self.rowWin.Show(False)
|
|
|
|
self.isDragging = False
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
if not self.didMove:
|
|
|
|
py = self.lwin.ClientToScreenXY(0,self.startY)[1]
|
|
|
|
py = self.grid.ScreenToClientXY(0,py)[1]
|
|
|
|
sy = self.grid.GetViewStart()[1] * self.uy
|
|
|
|
sy -= self.grid._clSize
|
|
|
|
row = self.grid.YToRow(py + sy)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
|
|
|
if row != wx.NOT_FOUND:
|
2003-11-12 16:34:20 -05:00
|
|
|
self.grid.SelectRow(row,evt.m_controlDown)
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
bRow = self.rowWin.GetInsertionRow()
|
|
|
|
dRow = self.rowWin.GetMoveRow()
|
2003-12-16 19:34:40 -05:00
|
|
|
|
|
|
|
wx.PostEvent(self,
|
2003-12-20 14:36:30 -05:00
|
|
|
GridRowMoveEvent(self.grid.GetId(), dRow, bRow))
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
self.rowWin.Destroy()
|
|
|
|
evt.Skip()
|
|
|
|
|
|
|
|
def _CaptureImage(self,rect):
|
2003-12-16 19:34:40 -05:00
|
|
|
bmp = wx.EmptyBitmap(rect.width,rect.height)
|
|
|
|
memdc = wx.MemoryDC()
|
2003-11-12 16:34:20 -05:00
|
|
|
memdc.SelectObject(bmp)
|
2003-12-16 19:34:40 -05:00
|
|
|
dc = wx.WindowDC(self.lwin)
|
2004-05-01 22:41:33 -04:00
|
|
|
memdc.Blit(0,0, rect.width, rect.height, dc, rect.x, rect.y)
|
2003-12-16 19:34:40 -05:00
|
|
|
memdc.SelectObject(wx.NullBitmap)
|
2003-11-12 16:34:20 -05:00
|
|
|
return bmp
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|