From: <sir...@us...> - 2003-02-28 21:32:27
|
Update of /cvsroot/btplusplus/BT++/src/TabTrans In directory sc8-pr-cvs1:/tmp/cvs-serv28244/src/TabTrans Modified Files: Renderer.py GridTable.py Grid.py Log Message: The grid has been replaced by a class derived fro wxScrolledWindow, implementing everything by hand in Python and using double buffering. Not everything is working yet(but most of it) and the buffering is not yet working correctly. But flickering is already reduced and since I now paint the whole thing myself I can make(have made) it look better than the standard wxWindows grid. Index: Renderer.py =================================================================== RCS file: /cvsroot/btplusplus/BT++/src/TabTrans/Renderer.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Renderer.py 22 Feb 2003 21:12:30 -0000 1.3 --- Renderer.py 28 Feb 2003 21:31:51 -0000 1.4 *************** *** 5,12 **** ########################################################################################################### ! class Default(wxPyGridCellRenderer): def __init__(self): - wxPyGridCellRenderer.__init__(self) # Init some variables ( Change colors HERE ) --- 5,11 ---- ########################################################################################################### ! class Default: def __init__(self): # Init some variables ( Change colors HERE ) *************** *** 24,31 **** wxFONTENCODING_SYSTEM ) ! def Clone(self): ! return Default() ! ! def Update( self, grid, attr, dc, rect, row, col, isSelected): self.Grid = grid --- 23,27 ---- wxFONTENCODING_SYSTEM ) ! def Update(self, grid, attr, dc, rect, row, col, isSelected): self.Grid = grid *************** *** 47,52 **** self.Update(grid, attr, dc, rect, row, col, isSelected) - dc.BeginDrawing() - # Draw the background self.DrawBackground() --- 43,46 ---- *************** *** 55,60 **** self.DrawForeground() - dc.EndDrawing() - def DrawBackground(self): pass --- 49,52 ---- *************** *** 62,70 **** def DrawForeground(self): try: ! rect = wxRect( self.Rect.x, ! self.Rect.y, ! self.Rect.width - 6, ! self.Rect.height ) ! self.Clip( self.DC, rect ) self.DC.SetTextForeground( self.FgColor ) --- 54,59 ---- def DrawForeground(self): try: ! self.Rect.width = self.Rect.width - 8 ! self.Clip() self.DC.SetTextForeground( self.FgColor ) *************** *** 72,87 **** self.DC.DrawText( self.ValueStr, self.Rect.x + 6, self.Rect.y + 4 ) finally: ! self.DC.SetPen( wxNullPen ) ! self.DC.SetBrush( wxNullBrush ) ! self.Unclip(self.DC) ########################################################################################################### ########################################################################################################### ! def Clip( self, dc, rect ): ! dc.SetClippingRegion( rect.x, rect.y, rect.width, rect.height ) ! def Unclip( self, dc ): ! dc.DestroyClippingRegion() ########################################################################################################### --- 61,74 ---- self.DC.DrawText( self.ValueStr, self.Rect.x + 6, self.Rect.y + 4 ) finally: ! self.Unclip() ########################################################################################################### ########################################################################################################### ! def Clip( self ): ! self.DC.SetClippingRegion( self.Rect.x, self.Rect.y, self.Rect.width, self.Rect.height ) ! def Unclip( self ): ! self.DC.DestroyClippingRegion() ########################################################################################################### *************** *** 98,104 **** self.BarLoadDone = wxColour(0,244,0) self.BarLoadRemain = wxColour(224,0,0) ! ! def Clone(self): ! return ProcessBar() def DrawForeground(self): --- 85,90 ---- self.BarLoadDone = wxColour(0,244,0) self.BarLoadRemain = wxColour(224,0,0) ! ! ########################################################################################################### def DrawForeground(self): *************** *** 109,153 **** remain = 1 - done ! done_end = self.Rect.x + (self.Rect.width * done) ! remain_start = done_end + 1 ! self.Clip( self.DC, self.Rect ) ! ! try: ! if done != -1.0: ! status = self.Grid.GetCellValue( self.Row, 5 ) ! ! if status == 'Hashing' or status == 'Allocating': ! color_done = self.BarHashDone ! color_remain = self.BarHashRemain ! else: ! color_done = self.BarLoadDone ! color_remain = self.BarLoadRemain ! self.DrawBCBGradient( wxRect(self.Rect.x, ! self.Rect.y + 3, ! done_end, ! self.Rect.height - 6), ! color_remain, ! 7 ) ! ! self.DrawBCBGradient( wxRect(remain_start, ! self.Rect.y + 3, ! self.Rect.width - done_end, ! self.Rect.height - 6), ! color_done, ! 7 ) else: ! self.DrawBCBGradient( wxRect(self.Rect.x, ! self.Rect.y + 3, ! self.Rect.width, ! self.Rect.height - 6), ! wxColour(0,210,255), ! 7 ) ! finally: ! self.DC.SetPen( wxNullPen ) ! self.DC.SetBrush( wxNullBrush ) ! self.Unclip(self.DC) def DrawBCBGradient(self, rect, color, gradheight): --- 95,134 ---- remain = 1 - done ! done_width = self.Rect.width * done ! remain_start = self.Rect.x + done_width ! remain_width = self.Rect.width - done_width ! if done != -1.0: ! status = self.Grid.GetCellValue( self.Row, 5 ) ! if status == 'Hashing' or status == 'Allocating': ! color_done = self.BarHashDone ! color_remain = self.BarHashRemain else: ! color_done = self.BarLoadDone ! color_remain = self.BarLoadRemain ! self.DrawBCBGradient( wxRect(remain_start, ! self.Rect.y + 3, ! remain_width, ! self.Rect.height - 6), ! color_remain, ! 7 ) ! ! self.DrawBCBGradient( wxRect(self.Rect.x, ! self.Rect.y + 3, ! done_width, ! self.Rect.height - 6), ! color_done, ! 7 ) ! else: ! self.DrawBCBGradient( wxRect(self.Rect.x, ! self.Rect.y + 3, ! self.Rect.width, ! self.Rect.height - 6), ! wxColour(0,210,255), ! 7 ) ! ! ########################################################################################################### def DrawBCBGradient(self, rect, color, gradheight): *************** *** 172,176 **** color, wxColour(0,0,0) ) ! def DrawGradient(self, rect, color_start, color_end): steps = rect.height --- 153,159 ---- color, wxColour(0,0,0) ) ! ! ########################################################################################################### ! def DrawGradient(self, rect, color_start, color_end): steps = rect.height *************** *** 180,183 **** --- 163,168 ---- b_dif = color_end.Blue() - color_start.Blue() + length = rect.x + rect.width + for y in range(steps): mod = float(y) / float(steps - 1) *************** *** 186,190 **** color_start.Blue() + (mod * b_dif) ) ! self.DC.SetPen( wxTRANSPARENT_PEN ) ! self.DC.SetBrush( wxBrush( color, wxSOLID) ) ! self.DC.DrawRectangle( rect.x, rect.y + y, rect.width, 1 ) --- 171,174 ---- color_start.Blue() + (mod * b_dif) ) ! self.DC.SetPen( wxPen(color) ) ! self.DC.DrawLine( rect.x, rect.y + y, length, rect.y + y) Index: GridTable.py =================================================================== RCS file: /cvsroot/btplusplus/BT++/src/TabTrans/GridTable.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GridTable.py 22 Feb 2003 15:53:28 -0000 1.3 --- GridTable.py 28 Feb 2003 21:31:52 -0000 1.4 *************** *** 5,12 **** --- 5,32 ---- from TabLog.LogWindow import Log + import Renderer + class GridTable(wxPyGridTableBase): currentRows = 0 currentCols = 7 + Sizes = { + 'ColLabel': 18, + 'RowLabel': 25, + + 'RowsDef': 22, + 'ColsDef': 50, + + 'Rows': {}, + 'Cols': {} + } + + Renderers = { + 'Default': Renderer.Default(), + + 'Rows': {}, + 'Cols': {4: Renderer.ProgressBar()} + } + def __init__(self, grid): wxPyGridTableBase.__init__(self) *************** *** 17,22 **** def Update(self): self.Manager.Update() - self.ResetView() - self.AdjustScrollbars() ########################################################################################################### --- 37,40 ---- *************** *** 28,32 **** --- 46,82 ---- def GetNumberCols(self): return 7 + + ########################################################################################################### + ########################################################################################################### + + def GetColLabelSize(self): + return self.Sizes['ColLabel'] + + ########################################################################################################### + + def GetRowLabelSize(self): + return self.Sizes['RowLabel'] + + ########################################################################################################### + def GetColSize(self, col): + if self.Sizes['Cols'].has_key(col): + return self.Sizes['Cols'][col] + else: + return self.Sizes['ColsDef'] + + def SetColSize(self, col, size): + self.Sizes['Cols'][col] = size + + ########################################################################################################### + + def GetRowSize(self, row): + if self.Sizes['Rows'].has_key(row): + return self.Sizes['Rows'][row] + else: + return self.Sizes['RowsDef'] + + ########################################################################################################### + def IsEmptyCell(self, row, col): if col > 6: *************** *** 46,54 **** if col == 6: return 'Remaining' ! def GetTypeName(self, row, col): ! if col == 4: ! return 'ProgressBar' else: ! return 'Default' ########################################################################################################### --- 96,106 ---- if col == 6: return 'Remaining' ! def GetCellRenderer(self, row, col): ! if self.Renderers['Cols'].has_key(col): ! return self.Renderers['Cols'][col] ! elif self.Renderers['Rows'].has_key(row): ! return self.Renderers['Rowss'][row] else: ! return self.Renderers['Default'] ########################################################################################################### *************** *** 92,128 **** ########################################################################################################### ########################################################################################################### - - def ResetView(self): - grid = self.GetView() - if not grid: - return - - grid.BeginBatch() - - for current, new, delmsg, addmsg in [ (self.currentRows, self.GetNumberRows(), wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_NOTIFY_ROWS_APPENDED), - (self.currentCols, self.GetNumberCols(), wxGRIDTABLE_NOTIFY_COLS_DELETED, wxGRIDTABLE_NOTIFY_COLS_APPENDED) ]: - if new < current: - msg = wxGridTableMessage( self, delmsg, new, current-new ) - grid.ProcessTableMessage(msg) - elif new > current: - msg = wxGridTableMessage( self, addmsg, new-current ) - grid.ProcessTableMessage(msg) - - self.currentRows = self.GetNumberRows() - self.currentCols = self.GetNumberCols() - - self.UpdateValues() - grid.EndBatch() - - def UpdateValues(self): - grid = self.GetView() - if not grid: - return - - msg = wxGridTableMessage(self, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES) - grid.ProcessTableMessage(msg) - - ########################################################################################################### - ########################################################################################################### def Destroy(self, evt = wxCloseEvent()): --- 144,147 ---- *************** *** 137,144 **** def AdjustScrollbars(self): self.Grid.AdjustScrollbars() - - def GetView(self): - return self.Grid - - ########################################################################################################### - ########################################################################################################### --- 156,157 ---- Index: Grid.py =================================================================== RCS file: /cvsroot/btplusplus/BT++/src/TabTrans/Grid.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Grid.py 24 Feb 2003 14:35:46 -0000 1.7 --- Grid.py 28 Feb 2003 21:31:52 -0000 1.8 *************** *** 1,7 **** ! from wxPython.wx import * ! from wxPython.grid import * ! from wxPython.lib.gridmovers import wxGridRowMover, EVT_GRID_ROW_MOVE ! ! from os import unlink, path from ConfigFile import Config --- 1,4 ---- ! from wxPython.wx import * ! from os import unlink, path from ConfigFile import Config *************** *** 12,59 **** import Renderer ! class Grid(wxGrid): ! currentSelection = [] ! def __init__(self, parent): ! wxGrid.__init__(self, parent, -1, wxPoint(0,0), wxSize(786,335), style = wxSIMPLE_BORDER) ! ! self.RegisterDataType( 'ProgressBar', Renderer.ProgressBar(), None ) ! self.RegisterDataType( 'Default', Renderer.Default(), None ) ! self.Table = GridTable(self) - self.SetTable(self.Table) - - # Me wants no cell highlight ;-) - self.SetCellHighlightPenWidth( 0 ) - - self.AutoSizeColumns(false) - self.SetRowLabelAlignment(wxALIGN_CENTER, wxALIGN_CENTRE) ! self.SetColLabelSize(18) ! self.SetRowLabelSize(25) ! self.SetDefaultRowSize(22, false) ! self.SetColSize(0, 230) ! self.SetColSize(1, 80) ! self.SetColSize(2, 80) ! self.SetColSize(3, 70) ! self.SetColSize(4, 120) ! self.SetColSize(5, 70) ! self.SetColSize(6, 90) ! self.SetLabelFont( wxFont(8, wxDEFAULT, wxNORMAL, wxNORMAL) ) ! self.SetGridLineColour( wxSystemSettings_GetColour(wxSYS_COLOUR_3DFACE) ) ! self.SetSelectionBackground( wxSystemSettings_GetColour(wxSYS_COLOUR_HIGHLIGHT) ) ! self.SetSelectionForeground( wxColour(255,255,255) ) ! self.EnableGridLines(false) ! self.EnableEditing(false) ! self.EnableDragRowSize(false) - self.SetSelectionMode( wxGrid.wxGridSelectRows ) - self.Updater = TimedUpdate( 10.0, self.Update ) self.Updater.Start() self.Menu = wxMenu( '' ) self.Menu.Sel = -1 --- 9,43 ---- import Renderer ! class Grid(wxScrolledWindow): ! Selection = { ! 'Set': [], ! 'Add': false ! } ! def __init__(self, parent): ! wxScrolledWindow.__init__(self, parent, -1, wxPoint(0,0), wxSize(786,335), style = wxSIMPLE_BORDER | wxCLIP_CHILDREN | wxNO_FULL_REPAINT_ON_RESIZE) ! self.Table = GridTable(self) ! self.SetBackgroundColour(wxColour(255,255,255)) ! #self.SetColLabelSize(18) ! #self.SetRowLabelSize(25) ! #self.SetDefaultRowSize(22, false) ! self.Table.SetColSize(0, 230) ! self.Table.SetColSize(1, 80) ! self.Table.SetColSize(2, 80) ! self.Table.SetColSize(3, 70) ! self.Table.SetColSize(4, 120) ! self.Table.SetColSize(5, 70) ! self.Table.SetColSize(6, 90) ! self.SetScrollRate( 5, 5 ) self.Updater = TimedUpdate( 10.0, self.Update ) self.Updater.Start() + # Menu creation self.Menu = wxMenu( '' ) self.Menu.Sel = -1 *************** *** 72,83 **** self.Menu.AppendItem( self.itemDown ) - wxGridRowMover(self) - EVT_GRID_ROW_MOVE(self, self.GetId(), self.MoveRow) - EVT_GRID_COL_SIZE(self, self.OnColSize ) - - EVT_GRID_RANGE_SELECT( self, self.OnSelectedRange ) - EVT_GRID_SELECT_CELL( self, self.OnSelectedCell ) - - EVT_GRID_CELL_RIGHT_CLICK( self, self.ShowMenu ) EVT_MENU( self, self.itemCancel.GetId(), self.Menu_Cancel ) EVT_MENU( self, self.itemResume.GetId(), self.Menu_Resume ) --- 56,59 ---- *************** *** 86,89 **** --- 62,71 ---- EVT_MENU( self, self.itemDown.GetId(), self.Menu_Down ) + EVT_KEY_DOWN( self, self.OnKeyDown ) + EVT_KEY_UP( self, self.OnKeyUp ) + + EVT_LEFT_DOWN( self, self.OnMouseLeftDown ) + EVT_RIGHT_DOWN( self, self.OnMouseRightDown ) + self.DrawTools = { 'HighlightOutline': wxPen( wxColour( 10, 36,106) ), *************** *** 92,96 **** 'EmptyBackground': wxBrush( wxColour(255,255,255), wxSOLID), - #'LabelBackColor': 'LabelFontColor': wxColour(0, 0, 0), 'LabelFont': wxFont( 8, --- 74,77 ---- *************** *** 102,188 **** wxFONTENCODING_SYSTEM ), 'ArrowBitmap': GetBitmap('Grid_Arrow') } - EVT_ERASE_BACKGROUND( self, self.OnEraseBg ) EVT_PAINT( self, self.OnPaint ) EVT_SIZE( self, self.OnSize ) def Update(self): self.Table.Update() - wxGrid.Update(self) ! def GetDownloader(self): ! return self.Table.Manager.GetDownloader(self.GetGridCursorRow()) ! def MoveRow(self, evt): ! self.Table.Move(evt.GetMoveRow(), evt.GetBeforeRow()) ########################################################################################################### - ########################################################################################################### ! def ShowMenu(self, evt): ! self.SelectRow( evt.GetRow() ) ! self.SetGridCursor( evt.GetRow(), 0 ) ! ! self.itemCancel.Enable(true) ! ! file = self.GetDownloader() ! if file == None: ! return ! if file.IsRunning(): ! self.itemPause.Enable(true) ! self.itemResume.Enable(false) ! else: ! self.itemPause.Enable(false) ! self.itemResume.Enable(true) ! ! if evt.GetRow() == 0: ! self.itemUp.Enable(false) ! self.itemDown.Enable(true) ! elif evt.GetRow() == self.GetNumberRows()-1: ! self.itemUp.Enable(true) ! self.itemDown.Enable(false) ! else: ! self.itemUp.Enable(true) ! self.itemDown.Enable(true) ! ! self.PopupMenu( self.Menu, evt.GetPosition() ) def Menu_Cancel(self, evt): ! file = self.GetDownloader() ! if file != None: ! file.PauseDownload() ! dlg = wxMessageDialog( self, ! "Do you really want to cancel the download of '" + file.Config['File'] + "'?\nThis will result in the torrent being deleted.", ! "Cancel?", ! wxYES_NO | wxICON_QUESTION | wxSTAY_ON_TOP ) ! if dlg.ShowModal() == wxID_NO: ! return ! ! try: ! file.PauseDownload() ! unlink( file.Config['TorFull'] ) ! except: ! wxMessageBox("Couldn't delete torrent file.") self.Table.Update() def Menu_Pause(self, evt): ! file = self.GetDownloader() ! if file != None: ! file.PauseDownload() def Menu_Resume(self, evt): ! file = self.GetDownloader() ! if file != None: file.StartDownload() def Menu_Up(self, evt): sel = self.GetGridCursorRow() self.Table.Manager.Move( sel, sel - 1) ! def Menu_Down(self, evt): sel = self.GetGridCursorRow() --- 83,160 ---- wxFONTENCODING_SYSTEM ), + 'LabelOutlineC1': wxPen( wxColor(255,255,255) ), + 'LabelOutlineC2': wxPen( wxColor(128,128,128) ), + 'LabelOutlineC3': wxPen( wxColor( 64, 64, 64) ), + 'LabelFill': wxBrush( wxColor(212,208,200), wxSOLID ), + 'ArrowBitmap': GetBitmap('Grid_Arrow') } EVT_PAINT( self, self.OnPaint ) EVT_SIZE( self, self.OnSize ) + ########################################################################################################### + def Update(self): self.Table.Update() ! ########################################################################################################### ! def GetLoaders(self, sel): ! loaders = [] ! for i in sel: ! loaders.append( self.Table.Manager.Loaders[i] ) ! ! return loaders ########################################################################################################### ! #def MoveRow(self, evt): ! #self.Table.Move(evt.GetMoveRow(), evt.GetBeforeRow()) ! ########################################################################################################### ! ########################################################################################################### def Menu_Cancel(self, evt): ! loaders = self.GetLoaders(self.Selection['Set']) ! for l in loaders: ! dlg = wxMessageDialog( self, ! "Do you really want to cancel the download of '" + l.Config['File'] + "'?\nThis will result in the torrent being deleted.", ! "Cancel?", ! wxYES_NO | wxICON_QUESTION | wxSTAY_ON_TOP ) ! if dlg.ShowModal() == wxID_NO: ! return + try: + l.PauseDownload() + unlink( l.Config['TorFull'] ) + except: + wxMessageBox("Couldn't delete torrent file.") + self.Table.Update() + ########################################################################################################### + def Menu_Pause(self, evt): ! loaders = self.GetLoaders(self.Selection['Set']) ! for l in loaders: ! l.PauseDownload() ! ! ########################################################################################################### def Menu_Resume(self, evt): ! loaders = self.GetLoaders(self.Selection['Set']) ! for l in loaders: file.StartDownload() + ########################################################################################################### + def Menu_Up(self, evt): sel = self.GetGridCursorRow() self.Table.Manager.Move( sel, sel - 1) ! ! ########################################################################################################### ! def Menu_Down(self, evt): sel = self.GetGridCursorRow() *************** *** 190,230 **** ########################################################################################################### ########################################################################################################### ! def OnSelectedRange(self, evt): ! if evt.Selecting(): # adding to the list... ! for index in range( evt.GetTopRow(), evt.GetBottomRow()+1): ! if index not in self.currentSelection: ! self.currentSelection.append( index ) ! else: # removal from list ! for index in range( evt.GetTopRow(), evt.GetBottomRow()+1): ! while index in self.currentSelection: ! self.currentSelection.remove( index ) ! evt.Skip() ! def OnSelectedCell(self, evt): ! self.currentSelection = [ evt.GetRow() ] ! evt.Skip() ########################################################################################################### ########################################################################################################### ! def OnEraseBg(self, evt): ! pass ! ! def OnPaint(self, evt = None): if self.IsShown() == false: return try: - scx, scy = self.GetViewStart() - unx, uny = self.GetScrollPixelsPerUnit() - - scx = -scx * unx - scy = -scy * uny - dc = self.BufferDC dc.BeginDrawing() --- 162,301 ---- ########################################################################################################### + + def OnMouseRightDown(self, evt): + row = self.GetCursorRow(evt.GetY()) + + if row == -1: + return + + if not row in self.Selection['Set']: + self.Selection['Set'] = [row] + self.Refresh() + + sel = self.Selection['Set'] + if sel == []: + return + + loaders = self.GetLoaders(sel) + + pause = false + resume = false + mup = true + mdown = true + + if 0 in sel: + mup = false + + if (self.Table.GetNumberRows() - 1) in sel: + mdown = false + + if len(sel) > 1: + pause = true + resume = true + else: + if loaders[0].IsRunning(): + pause = true + else: + resume = true + + self.itemCancel .Enable( true ) + self.itemPause .Enable( pause ) + self.itemResume .Enable( resume ) + self.itemUp .Enable( false ) + self.itemDown .Enable( false ) + + self.PopupMenu( self.Menu, evt.GetPosition() ) + + ########################################################################################################### ########################################################################################################### ! def OnMouseLeftDown(self, evt): ! x = evt.GetX() ! y = evt.GetY() ! ! row = self.GetCursorRow(y) ! ! if row == -1: ! self.Selection['Set'] = [] ! ! if self.Selection['Add'] == false: ! self.Selection['Set'] = [] ! ! self.Selection['Set'].append( row ) ! ! ########################################################################################################### ! ! def OnKeyDown(self, evt): ! code = evt.GetKeyCode() ! ! if code == WXK_CONTROL: ! self.Selection['Add'] = true ! ! ########################################################################################################### ! ! def OnKeyUp(self, evt): ! code = evt.GetKeyCode() ! ! if code == WXK_CONTROL: ! self.Selection['Add'] = false ! ! ########################################################################################################### ! ! def GetCursorRow(self, y): ! ! if y < self.Table.GetColLabelSize(): ! return -1 ! ! InRow = -1 ! ! y = y - self.Table.GetColLabelSize() ! for row in range(self.Table.GetNumberRows()): ! y = y - self.Table.GetRowSize(row) ! InRow = InRow + 1 ! ! if y <= 0: ! break ! ! if y > 0: ! return -1 ! ! ! return InRow ! ! ########################################################################################################### ! ########################################################################################################### ! ! #def OnSelectedRange(self, evt): ! #if evt.Selecting(): # adding to the list... ! #for index in range( evt.GetTopRow(), evt.GetBottomRow()+1): ! #if index not in self.currentSelection: ! #self.currentSelection.append( index ) ! #else: # removal from list ! #for index in range( evt.GetTopRow(), evt.GetBottomRow()+1): ! #while index in self.currentSelection: ! #self.currentSelection.remove( index ) ! #evt.Skip() ! #def OnSelectedCell(self, evt): ! #self.currentSelection = [ evt.GetRow() ] ! #evt.Skip() ! ! ########################################################################################################### ! ########################################################################################################### ! ! #def SetFullSize(self): ! ########################################################################################################### ########################################################################################################### ! def OnPaint(self, evt): if self.IsShown() == false: return try: dc = self.BufferDC dc.BeginDrawing() *************** *** 234,321 **** dc.Clear() ! # Draw the selections ! dc.SetPen( self.DrawTools['HighlightOutline'] ) ! dc.SetBrush( self.DrawTools['HighlightColor'] ) ! if self.currentSelection != []: ! sel = self.currentSelection ! rect = self.BlockToDeviceRect( wxGridCellCoords(sel[0], 0), ! wxGridCellCoords(sel[len(sel)-1], 6) ) ! ! dc.DrawRectangle( scx + rect.x + 2, ! scy + rect.y + 20, ! rect.width + 21, ! rect.height - 5 ) - numcols = range(self.Table.GetNumberCols()) - numrows = range(self.Table.GetNumberRows()) - - x = 0 - y = 0 - # Draw the col labels ! dc.SetPen( self.DrawTools['HighlightOutline'] ) ! dc.SetBrush( self.DrawTools['HighlightColor'] ) ! dc.SetTextForeground( self.DrawTools['LabelFontColor'] ) ! dc.SetFont( self.DrawTools['LabelFont'] ) ! for col in numcols: ! rect = wxRect( x, 0, self.GetColSize(col), 18 ) ! x = x + self.GetColSize(col) ! dc.DrawRectangle( scx + rect.x + 25, ! scy + rect.y, ! rect.width, ! rect.height ) ! dc.DrawText( self.Table.GetColLabelValue(col), ! scx + rect.x + 29, ! scy + rect.y + 2 ) ! # Draw the row 'labels' ! for row in numrows: ! dc.DrawBitmap( self.DrawTools['ArrowBitmap'], scx, scy + y + 20, true ) ! y = y + self.GetRowSize(row) ! for col in numcols: ! for row in numrows: ! ! rect = self.CellToRect(row, col) ! rend = self.GetCellRenderer(row, col) ! rend.Draw( self, ! None, ! dc, ! wxRect( scx + rect.x + 25, ! scy + rect.y + 18, ! rect.width, ! rect.height ), ! row, ! col, ! true ) ! ! dc.EndDrawing() ! w, h = dc.GetSizeTuple() ! ondc = wxClientDC(self) ! ondc.BeginDrawing() ! ondc.Blit(0, 0, w, h, dc, 0, 0 ) ! ondc.EndDrawing() ! except: ! pass def OnSize(self, evt): ! size = self.GetClientSizeTuple() ! self.BufferImg = wxEmptyBitmap(size[0], size[1]) self.BufferDC = wxMemoryDC() self.BufferDC.SelectObject( self.BufferImg ) ! ! self.Table.ResetView() ! self.AdjustScrollbars() ########################################################################################################### --- 305,509 ---- dc.Clear() ! # Draw the selection ! self.DrawSelection(dc) ! # Draw space where col + row labels cross ! self.DrawColRowCross(dc) # Draw the col labels ! self.DrawColLabels(dc) ! # Draw the row labels ! self.DrawRowLabels(dc) ! ! # Draw grid ! self.DrawGrid(dc) ! ! dc.EndDrawing() ! w, h = dc.GetSizeTuple() ! ondc = wxPaintDC(self) ! self.PrepareDC(ondc) ! ondc.BeginDrawing() ! ondc.Blit(0, 0, w, h, dc, 0, 0 ) ! ondc.EndDrawing() ! except: ! pass ! ! ########################################################################################################### ! ! def DrawSelection(self, dc): ! dc.SetPen( self.DrawTools['HighlightOutline'] ) ! dc.SetBrush( self.DrawTools['HighlightColor'] ) ! ! if self.Selection['Set'] != []: ! sel = self.Selection['Set'] ! width = self.Table.GetRowLabelSize() ! for col in range(self.Table.GetNumberCols()): ! width = width + self.Table.GetColSize(col) ! ! y = self.Table.GetColLabelSize() ! for row in range(self.Table.GetNumberRows()): ! if row in sel: ! dc.DrawRectangle( 2, ! y + 2, ! width - 4, ! self.Table.GetRowSize(row) - 4) ! ! y = y + self.Table.GetRowSize(row) ! ########################################################################################################### ! ! def DrawColRowCross(self, dc): ! rect = wxRect( 0, ! 0, ! self.Table.GetRowLabelSize(), ! self.Table.GetColLabelSize() ) ! ! self.Draw3DLabel(dc, rect) ! ! ########################################################################################################### ! ! def DrawColLabels(self, dc): ! cols = range(self.Table.GetNumberCols()) ! ! dc.SetTextForeground( self.DrawTools['LabelFontColor'] ) ! dc.SetFont( self.DrawTools['LabelFont'] ) ! x = self.Table.GetRowLabelSize() ! y = self.Table.GetColLabelSize() ! ! for col in cols: ! ! rect = wxRect( x, ! 0, ! self.Table.GetColSize(col), ! y ) ! ! x = x + rect.width ! ! self.Draw3DLabel(dc, rect) ! ! dc.DrawText( self.Table.GetColLabelValue(col), ! rect.x + 4, ! rect.y + 2 ) ! ! ########################################################################################################### ! def DrawRowLabels(self, dc): ! rows = range(self.Table.GetNumberRows()) ! y = self.Table.GetColLabelSize() ! ! for row in rows: ! dc.DrawBitmap( self.DrawTools['ArrowBitmap'], 0, y, true ) ! y = y + self.Table.GetRowSize(row) ! ! ########################################################################################################### ! def DrawGrid(self, dc): ! rows = range(self.Table.GetNumberRows()) ! cols = range(self.Table.GetNumberCols()) ! ! x = self.Table.GetRowLabelSize() ! y = self.Table.GetColLabelSize() ! ! for row in rows: ! for col in cols: ! rect = wxRect( x, ! y, ! self.Table.GetColSize(col), ! self.Table.GetRowSize(row) ) ! x = x + rect.width ! ! rend = self.Table.GetCellRenderer(row, col) ! rend.Draw( self, ! None, ! dc, ! rect, ! row, ! col, ! true ) ! ! x = self.Table.GetRowLabelSize() ! y = y + rect.height ! ! ########################################################################################################### ! ! def Draw3DLabel(self, dc, rect): ! # White lines ! dc.SetPen( self.DrawTools['LabelOutlineC1'] ) ! dc.DrawLine( rect.x, ! rect.y, ! rect.x, ! rect.y + rect.height - 1 ) ! ! dc.DrawLine( rect.x, ! rect.y, ! rect.x + rect.width - 1, ! rect.y ) ! ! # Grey lines ! dc.SetPen( self.DrawTools['LabelOutlineC2'] ) ! dc.DrawLine( rect.x + 1, ! rect.y + rect.height - 2, ! rect.x + rect.width, ! rect.y + rect.height - 2 ) ! ! dc.DrawLine( rect.x + rect.width - 2, ! rect.y + 1, ! rect.x + rect.width - 2, ! rect.y + rect.height - 1 ) ! ! # Black lines ! dc.SetPen( self.DrawTools['LabelOutlineC3'] ) ! dc.DrawLine( rect.x + rect.width - 1, ! rect.y, ! rect.x + rect.width - 1, ! rect.y + rect.height ) ! ! dc.DrawLine( rect.x, ! rect.y + rect.height - 1, ! rect.x + rect.width, ! rect.y + rect.height - 1 ) ! ! # Fill ! dc.SetPen( wxTRANSPARENT_PEN ) ! dc.SetBrush( self.DrawTools['LabelFill'] ) ! dc.DrawRectangle( rect.x + 1, ! rect.y + 1, ! rect.width - 3, ! rect.height - 3 ) + ########################################################################################################### + + def GetCellValue(self, row, col): + return self.Table.GetValue(row, col) + + ########################################################################################################### def OnSize(self, evt): ! cols = range(self.Table.GetNumberCols()) ! rows = range(self.Table.GetNumberCols()) ! ! width = self.Table.GetRowLabelSize() ! height = self.Table.GetColLabelSize() ! ! for col in cols: ! width = width + self.Table.GetColSize(col) ! ! for row in rows: ! height = height + self.Table.GetRowSize(row) ! ! self.SetVirtualSize( wxSize(width + 8, height) ) ! ! self.BufferImg = wxEmptyBitmap(width, height) self.BufferDC = wxMemoryDC() self.BufferDC.SelectObject( self.BufferImg ) ! ########################################################################################################### *************** *** 323,331 **** def OnColSize(self, evt): ! self.Table.ResetView() ! self.AdjustScrollbars() def Destroy(self, evt = wxCloseEvent()): self.Table.Destroy() self.Updater.Shutdown() ! wxGrid.Destroy(self) --- 511,520 ---- def OnColSize(self, evt): ! pass ! #self.Table.ResetView() ! #self.AdjustScrollbars() def Destroy(self, evt = wxCloseEvent()): self.Table.Destroy() self.Updater.Shutdown() ! wxScrolledWindow.Destroy(self) |