wx.GCDC not working on Windows?

On Windows XP I do not the alpha blended in cursor_bitmap.
On Mac OS X and Linux this same code works problem free.

Why dosen't it work on Windows?

Barry

    def OnPaint( self, event ):
        self._debugSpeed( 'OnPaint() begin' )

        self.SetFocusIgnoringChildren()

        if self.first_paint:
            self._debugPanel( 'EmacsPanel.OnPaint() first paint' )
            self.first_paint = False

            dc = wx.PaintDC( self )

            dc.SetBackgroundMode( wx.SOLID )
            dc.SetBackground( wx.Brush( bg_colours[ SYNTAX_DULL ] ) )
            dc.Clear()

            self.__initFont( dc )

            dc = None

            self.__calculateWindowSize()

            # queue up this action until after the rest of GUI init has happend
            self.app.onGuiThread( self.app.onEmacsPanelReady, () )

        elif self.editor_bitmap is not None:
            self._debugPanel( 'EmacsPanel.OnPaint() editor_bitmap' )

            pdc = wx.PaintDC( self )

            pdc.SetBackgroundMode( wx.SOLID )

            self._debugSpeed( 'DrawBitmap() start' )
            pdc.DrawBitmap( self.editor_bitmap, 0, 0, False )
            self._debugSpeed( 'DrawBitmap() end %d x %d' % (self.pixel_width, self.pixel_length) )

            c_x, c_y = self.__pixelPoint( self.cursor_x, self.cursor_y )

            # Create a dc to alpha blend just the cursor as wx.GCDC is very slow on large bitmaps
            cursor_bitmap = self.editor_bitmap.GetSubBitmap( (c_x, c_y, self.char_width, self.char_length) )
            cur_dc_mem = wx.MemoryDC()
            cur_dc_mem.SelectObject( cursor_bitmap )
            cur_dc = wx.GCDC( cur_dc_mem )

            # alpha blend the cursor
            cur_dc.SetBackgroundMode( wx.TRANSPARENT )
            cursor_colour = wx.Colour( 255, 0, 0, 64 )
            cur_dc.SetPen( wx.Pen( cursor_colour ) )
            cur_dc.SetBrush( wx.Brush( cursor_colour ) )
            cur_dc.DrawRectangle( 0, 0, self.char_width, self.char_length )

            pdc.DrawBitmap( cursor_bitmap, c_x, c_y, False )

            pdc = None

            self._debugSpeed( 'at end' )
        else:
            self._debugPanel( 'EmacsPanel.OnPaint() Nothing to do' )
            event.Skip()

        self._debugSpeed( 'OnPaint() end' )

···

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Hi,

On Windows XP I do not the alpha blended in cursor_bitmap.
On Mac OS X and Linux this same code works problem free.

Why dosen't it work on Windows?

On Windows, you *must* create a wx.PaintDC regardless of your IFs
conditions, always without exception. I have no idea if this will
solve your problem, but this is something to keep in mind as in your
"else" clause you don't have any wx.PaintDC.

···

On 25 April 2010 15:05, Barry Scott wrote:

Barry

def OnPaint( self, event ):
self._debugSpeed( 'OnPaint() begin' )

   self\.SetFocusIgnoringChildren\(\)

   if self\.first\_paint:
       self\.\_debugPanel\( 'EmacsPanel\.OnPaint\(\) first paint' \)
       self\.first\_paint = False

       dc = wx\.PaintDC\( self \)

       dc\.SetBackgroundMode\( wx\.SOLID \)
       dc\.SetBackground\( wx\.Brush\( bg\_colours\[ SYNTAX\_DULL \] \) \)
       dc\.Clear\(\)

       self\.\_\_initFont\( dc \)

       dc = None

       self\.\_\_calculateWindowSize\(\)

       \# queue up this action until after the rest of GUI init has happend
       self\.app\.onGuiThread\( self\.app\.onEmacsPanelReady, \(\) \)

   elif self\.editor\_bitmap is not None:
       self\.\_debugPanel\( 'EmacsPanel\.OnPaint\(\) editor\_bitmap' \)

       pdc = wx\.PaintDC\( self \)

       pdc\.SetBackgroundMode\( wx\.SOLID \)

       self\.\_debugSpeed\( 'DrawBitmap\(\) start' \)
       pdc\.DrawBitmap\( self\.editor\_bitmap, 0, 0, False \)
       self\.\_debugSpeed\( 'DrawBitmap\(\) end %d x %d' % \(self\.pixel\_width, self\.pixel\_length\) \)

       c\_x, c\_y = self\.\_\_pixelPoint\( self\.cursor\_x, self\.cursor\_y \)

       \# Create a dc to alpha blend just the cursor as wx\.GCDC is very slow on large bitmaps
       cursor\_bitmap = self\.editor\_bitmap\.GetSubBitmap\( \(c\_x, c\_y, self\.char\_width, self\.char\_length\) \)
       cur\_dc\_mem = wx\.MemoryDC\(\)
       cur\_dc\_mem\.SelectObject\( cursor\_bitmap \)
       cur\_dc = wx\.GCDC\( cur\_dc\_mem \)

       \# alpha blend the cursor
       cur\_dc\.SetBackgroundMode\( wx\.TRANSPARENT \)
       cursor\_colour = wx\.Colour\( 255, 0, 0, 64 \)
       cur\_dc\.SetPen\( wx\.Pen\( cursor\_colour \) \)
       cur\_dc\.SetBrush\( wx\.Brush\( cursor\_colour \) \)
       cur\_dc\.DrawRectangle\( 0, 0, self\.char\_width, self\.char\_length \)

       pdc\.DrawBitmap\( cursor\_bitmap, c\_x, c\_y, False \)

       pdc = None

       self\.\_debugSpeed\( 'at end' \)
   else:
       self\.\_debugPanel\( 'EmacsPanel\.OnPaint\(\) Nothing to do' \)
       event\.Skip\(\)

   self\.\_debugSpeed\( 'OnPaint\(\) end' \)

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

--
Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

==> Never *EVER* use RemovalGroup for your house removal. You'll
regret it forever.
The Doomed City: Removal Group: the nightmare <==

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Try doing either a "del cur_dc" or "cur_dc.SelectObject(wx.NullBitmap)" before drawing the cursor_bitmap. You can't select the same bitmap in more than one DC at the same time, and in some cases DrawBitmap is implemented by selecting it into a temporary DC and then blitting it to the target DC.

···

On 4/25/10 7:05 AM, Barry Scott wrote:

On Windows XP I do not the alpha blended in cursor_bitmap.
On Mac OS X and Linux this same code works problem free.

Why dosen't it work on Windows?

             pdc = wx.PaintDC( self )

             pdc.SetBackgroundMode( wx.SOLID )

             self._debugSpeed( 'DrawBitmap() start' )
             pdc.DrawBitmap( self.editor_bitmap, 0, 0, False )
             self._debugSpeed( 'DrawBitmap() end %d x %d' % (self.pixel_width, self.pixel_length) )

             c_x, c_y = self.__pixelPoint( self.cursor_x, self.cursor_y )

             # Create a dc to alpha blend just the cursor as wx.GCDC is very slow on large bitmaps
             cursor_bitmap = self.editor_bitmap.GetSubBitmap( (c_x, c_y, self.char_width, self.char_length) )
             cur_dc_mem = wx.MemoryDC()
             cur_dc_mem.SelectObject( cursor_bitmap )
             cur_dc = wx.GCDC( cur_dc_mem )

             # alpha blend the cursor
             cur_dc.SetBackgroundMode( wx.TRANSPARENT )
             cursor_colour = wx.Colour( 255, 0, 0, 64 )
             cur_dc.SetPen( wx.Pen( cursor_colour ) )
             cur_dc.SetBrush( wx.Brush( cursor_colour ) )
             cur_dc.DrawRectangle( 0, 0, self.char_width, self.char_length )

             pdc.DrawBitmap( cursor_bitmap, c_x, c_y, False )

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

The event.Skip() should remove the need to create the wx.PaintDC for the else clause, since it will cause the system to treat the event as unhandled.

···

On 4/25/10 9:02 AM, Andrea Gavana wrote:

Hi,

On 25 April 2010 15:05, Barry Scott wrote:

On Windows XP I do not the alpha blended in cursor_bitmap.
On Mac OS X and Linux this same code works problem free.

Why dosen't it work on Windows?

On Windows, you *must* create a wx.PaintDC regardless of your IFs
conditions, always without exception. I have no idea if this will
solve your problem, but this is something to keep in mind as in your
"else" clause you don't have any wx.PaintDC.

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Thank you Robin for straightening my wrong assumption on that. I seem
to have taken too much to the letter Vadim's comment here:

http://old.nabble.com/CPU-hungry-EVT_PAINT-on-Windows-td8107716.html

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

==> Never *EVER* use RemovalGroup for your house removal. You'll
regret it forever.
The Doomed City: Removal Group: the nightmare <==

···

On 26 April 2010 18:29, Robin Dunn wrote:

On 4/25/10 9:02 AM, Andrea Gavana wrote:

Hi,

On 25 April 2010 15:05, Barry Scott wrote:

On Windows XP I do not the alpha blended in cursor_bitmap.
On Mac OS X and Linux this same code works problem free.

Why dosen't it work on Windows?

On Windows, you *must* create a wx.PaintDC regardless of your IFs
conditions, always without exception. I have no idea if this will
solve your problem, but this is something to keep in mind as in your
"else" clause you don't have any wx.PaintDC.

The event.Skip() should remove the need to create the wx.PaintDC for the
else clause, since it will cause the system to treat the event as unhandled.

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Yep, it's an easy assumption to make, especially given how drastic of an effect that it causes if you have an EVT_PAINT handler that doesn't create a wx.PaintDC. 100% CPU consumption vs. dropping down to a more reasonable level simply by adding a wx.PaintDC. But since using event.Skip is essentially telling the system to pretend that there wasn't a matching event handler then, assuming there isn't another matching binding, the system will take care of painting the window in whatever is the default manner for the window type.

···

On 4/26/10 1:10 PM, Andrea Gavana wrote:

On 26 April 2010 18:29, Robin Dunn wrote:

On 4/25/10 9:02 AM, Andrea Gavana wrote:

Hi,

On 25 April 2010 15:05, Barry Scott wrote:

On Windows XP I do not the alpha blended in cursor_bitmap.
On Mac OS X and Linux this same code works problem free.

Why dosen't it work on Windows?

On Windows, you *must* create a wx.PaintDC regardless of your IFs
conditions, always without exception. I have no idea if this will
solve your problem, but this is something to keep in mind as in your
"else" clause you don't have any wx.PaintDC.

The event.Skip() should remove the need to create the wx.PaintDC for the
else clause, since it will cause the system to treat the event as unhandled.

Thank you Robin for straightening my wrong assumption on that. I seem
to have taken too much to the letter Vadim's comment here:

http://old.nabble.com/CPU-hungry-EVT_PAINT-on-Windows-td8107716.html

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en