hi to all…
problem:
I’m having one grid control and need to paint over that…
when a button is clicked, current cell must be crossed by a line… It’s my application requirement…
by the way… I tried pygridcellrenderer class (draw method)… managed to get a cross line…
but when my application started particular cell is not crossed…
only it is crossed when that cell has received focus by mouse or keyboard…
and that cross line disappeared when i moved the grid cursor beyond some distance…
I need that painted cross line must be retained..
anyone knows how to fix this problem give me right direction —>
I’ve attached the code… and run the code staright…
Hi,
Your problem is that you forgot to set the pen before drawing the line. So, it’s set to wx.TRANSPARENT when the cell isn’t selected and wx.BLACK_PEN when it is (or something like that). You just need to add dc.Pen = wx.BLACK_PEN before calling dc.DrawLine, like this:
def Draw(self, grid, attr, dc, rect, row, col, isSelected):
text = grid.GetCellValue(row, col)
hAlign, vAlign = attr.GetAlignment()
dc.SetFont( attr.GetFont())
x1 , y1 = rect.GetBottomLeft()
x2 , y2 = rect.GetTopRight()
dc.SetTextBackground(wx.WHITE)
dc.SetTextForeground(wx.RED)
dc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID))
#dc.SetPen(wx.TRANSPARENT_PEN) # if enabled not working
dc.DrawRectangleRect(rect)
grid.DrawTextRectangle(dc, text, rect, hAlign, vAlign)
dc.Pen = wx.BLACK_PEN ##ADD THIS LINE
dc.DrawLine(x1+2,y1-2,x2-2,y2+2)
I do read the docs and wxpython in action…
but nowhere i get this hint…
can u tell me how u got these hint… I think u r well experienced…
by the way… some things remains…
After moving the cursor focus of particular cell, the rectangle border remains…
only when it disappears, when i moved the cursor beyond some distance…
particularly move upward or downward the cursor in D column… watch rendered cell…
there is some border appears…
That crossed line in rendered cell, is remains fine when the cursor within D column…
when the cursor moves D or beyond that columns, for every move that crossed line/cell is repainted…
plz tell me how to fix these problems… becoz, finer control is required for my application…
Hi,
Your problem is that you forgot to set the pen before drawing the line. So, it’s set to wx.TRANSPARENT when the cell isn’t selected and wx.BLACK_PEN when it is (or something like that). You just need to add dc.Pen = wx.BLACK_PEN before calling dc.DrawLine, like this:
def Draw(self, grid, attr, dc, rect, row, col, isSelected):
text = grid.GetCellValue(row, col)
hAlign, vAlign = attr.GetAlignment()
dc.SetFont( attr.GetFont())
x1 , y1 = rect.GetBottomLeft()
x2 , y2 = rect.GetTopRight()
dc.SetTextBackground(wx.WHITE)
dc.SetTextForeground(wx.RED)
dc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID))
#dc.SetPen(wx.TRANSPARENT_PEN) # if enabled not working
dc.DrawRectangleRect(rect)
grid.DrawTextRectangle(dc, text, rect, hAlign, vAlign)
dc.Pen = wx.BLACK_PEN ##ADD THIS LINE
dc.DrawLine(x1+2,y1-2,x2-2,y2+2)
I do read the docs and wxpython in action…
but nowhere i get this hint…
can u tell me how u got these hint… I think u r well experienced…
Well experienced? Not really: I use trial and error and try to glean useful information from the wiki, the (C++ and Python) docs and the demo. I don’t know where there’s a good and comprehensive explanation of device contexts or of wxGrids though the wxGrid manual on the wiki is a nice start for the latter.
by the way… some things remains…
After moving the cursor focus of particular cell, the rectangle border remains…
only when it disappears, when i moved the cursor beyond some distance…
particularly move upward or downward the cursor in D column… watch rendered cell…
there is some border appears…
That crossed line in rendered cell, is remains fine when the cursor within D column…
when the cursor moves D or beyond that columns, for every move that crossed line/cell is repainted…
plz tell me how to fix these problems… becoz, finer control is required for my application…
Uncommenting the line #dc.SetPen(wx.TRANSPARENT_PEN)
seems to fix all your problems, for reasons similar as in my first answer.
can u tell me how u got these hint… I think u r well experienced…
Well experienced? Not really: I use trial and error and try to glean useful information from the wiki, the (C++ and Python) docs and the demo. I don’t know where there’s a good and comprehensive explanation of device contexts or of wxGrids though the wxGrid manual on the wiki is a nice start for the latter.
by the way… some things remains…
After moving the cursor focus of particular cell, the rectangle border remains…
only when it disappears, when i moved the cursor beyond some distance…
particularly move upward or downward the cursor in D column… watch rendered cell…
there is some border appears…
That crossed line in rendered cell, is remains fine when the cursor within D column…
when the cursor moves D or beyond that columns, for every move that crossed line/cell is repainted…
plz tell me how to fix these problems… becoz, finer control is required for my application…
Uncommenting the line #dc.SetPen(wx.TRANSPARENT_PEN)
seems to fix all your problems, for reasons similar as in my first answer.
can u tell me how u got these hint… I think u r well experienced…
Well experienced? Not really: I use trial and error and try to glean useful information from the wiki, the (C++ and Python) docs and the demo. I don’t know where there’s a good and comprehensive explanation of device contexts or of wxGrids though the wxGrid manual on the wiki is a nice start for the latter.
by the way… some things remains…
After moving the cursor focus of particular cell, the rectangle border remains…
only when it disappears, when i moved the cursor beyond some distance…
particularly move upward or downward the cursor in D column… watch rendered cell…
there is some border appears…
That crossed line in rendered cell, is remains fine when the cursor within D column…
when the cursor moves D or beyond that columns, for every move that crossed line/cell is repainted…
plz tell me how to fix these problems… becoz, finer control is required for my application…
Uncommenting the line #dc.SetPen(wx.TRANSPARENT_PEN)
seems to fix all your problems, for reasons similar as in my first answer.
When running my attached code, that crossed line in rendered cell, is remains fine when the cursor within A-C column.. when the cursor moves D or beyond that columns, for every move that crossed line/cell is repainted..
When running my attached code, that crossed line in rendered cell, is remains fine when the cursor within A-C column.. when the cursor moves D or beyond that columns, for every move that crossed line/cell is repainted.. (watch my print statement 'cross' in console o/p..)
When running my attached code, that crossed line in rendered cell, is remains fine when the cursor within A-C column… when the cursor moves D or beyond that columns, for every move that crossed line/cell is repainted… (watch my print statement ‘cross’ in console o/p…)
grid.SetDefaultCellAlignment(wx.CENTRE,wx.CENTRE)
when i add this line in test frame class, this doesn’t (centre alignment) seem to be working…
* When running my attached code, that crossed line in rendered cell, is remains fine when the cursor within A-C column.. when the cursor moves D or beyond that columns, for every move that crossed line/cell is repainted.. (watch my print statement 'cross' in console o/p..)
The renderer's Draw method is called whenever there is a paint event in which the update region intersects with the cell. This happens when another window obscures part of the grid, the grid is scrolled, when the borders need to be redrawn as the cell highlight moves to a new cell, and whenever else that the grid calls RefreshRect on itself. In other words, it is happening for a reason and so you just need to be prepared for it to be called often.
* grid.SetDefaultCellAlignment(wx.CENTRE,wx.CENTRE)
when i add this line in test frame class, this doesn't (centre alignment) seem to be working...
Because the alignment constant you want to use is wx.ALIGN_CENTER.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
In previous mail i’ve attached a simple code with one renderer…
In my application,
I’m using many custom renderer’s simultaneously…(ex: cross the cell with a line…)
one paint event called by a timer function in particular time interval… (ex: 1 or 2 secs)
For this scenario, when i run, my application is hangs sometimes… (paint event not performed…grid refresh not performed…) I think this is caused by custom renderer’s…
so, please give me right direction to the way go…
also give me some performance advice for the last mail…
When running my attached code, that crossed line in rendered cell, is remains fine when the cursor within A-C column… when the cursor moves D or beyond that columns, for every move that crossed line/cell is repainted… (watch my print statement ‘cross’ in console o/p…)
The renderer’s Draw method is called whenever there is a paint event in which the update region intersects with the cell. This happens when another window obscures part of the grid, the grid is scrolled, when the borders need to be redrawn as the cell highlight moves to a new cell, and whenever else that the grid calls RefreshRect on itself. In other words, it is happening for a reason and so you just need to be prepared for it to be called often.
grid.SetDefaultCellAlignment(wx.CENTRE,wx.CENTRE)
when i add this line in test frame class, this doesn’t (centre alignment) seem to be working…
Because the alignment constant you want to use is wx.ALIGN_CENTER.
In previous mail i've attached a simple code with one renderer..
In my application,
* I'm using many custom renderer's simultaneously...(ex: cross the cell with a line..)
* one paint event called by a timer function in particular time interval.. (ex: 1 or 2 secs)
Do you actually send a paint event or just call one of the Refresh methods?
For this scenario, when i run, my application is hangs sometimes.. (paint event not performed..grid refresh not performed..) I think this is caused by custom renderer's..
What makes you think that?
so, please give me right direction to the way go..
also give me some performance advice for the last mail..
It's not that hard. Like I said before, just be prepared to have the Draw method be called very many times. So anything that it does that could take some non-trivial time should be optimized (like cache some calculated values, etc.) and don't do anything that could take a long time (access a database) if you don't need to do it.
I have a very complex renderer that I am working on right now for the day-job and I've been very pleased with the performance. All I did was some common sense optimizations like you would/should do for any python code that could be executed many times.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
In previous mail i’ve attached a simple code with one renderer…
In my application,
I’m using many custom renderer’s simultaneously…(ex: cross the cell with a line…)
one paint event called by a timer function in particular time interval… (ex: 1 or 2 secs)
Do you actually send a paint event or just call one of the Refresh methods?
calling Refresh in my timer handler …
For this scenario, when i run, my application is hangs sometimes… (paint event not performed…grid refresh not performed…) I think this is caused by custom renderer’s…
What makes you think that?
U R CORRECT… actually i’m removed all print statement’s and did some tweaks… now it seems to be performing…
so, please give me right direction to the way go…
also give me some performance advice for the last mail…
It’s not that hard. Like I said before, just be prepared to have the Draw method be called very many times. So anything that it does that could take some non-trivial time should be optimized (like cache some calculated values, etc.) and don’t do anything that could take a long time (access a database) if you don’t need to do it.
I have a very complex renderer that I am working on right now for the day-job and I’ve been very pleased with the performance. All I did was some common sense optimizations like you would/should do for any python code that could be executed many times.
Thanks for ur reply…
and what to do clear all my custom renderer’s at once…?
clear grid only clears cell values… (now i did setting default renderer’s for all cells)
and what to do clear all my custom renderer's at once..?
clear grid only clears cell values.. (now i did setting default renderer's for all cells)
I guess it depends on what you mean by "clear my custom renderers". Most likely you want to add code to the renderer's Draw method that draws the cell in a "cleared" state when there is no data in the table for that cell.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!