flatnotebook on mac, wxPython 2.8.6.1

Hi all.

I recently updated my dev box to wx 2.8.6.1, and flatnotebook is still broken on the mac, although it appears to not be as severe. In 2.8.6.0, it threw the error and the notebook failed to render or display; now it’s rendering, it’s just still erroring out. That’s better at least :slight_smile:

The output is:

Mon Nov 19 21:18:20 Nicholas.local Python[5476] : CGBitmapContextCreate: invalid data bytes/row: should be at least 4 for 8 integer bits/component, 3 components, kCGImageAlphaNoneSkipFirst.

Mon Nov 19 21:18:20 Nicholas.local Python[5476] : CGContextTranslateCTM: invalid context

Mon Nov 19 21:18:20 Nicholas.local Python[5476] : CGContextScaleCTM: invalid context

Mon Nov 19 21:18:20 Nicholas.local Python[5476] : CGBitmapContextCreate: invalid data bytes/row: should be at least 4 for 8 integer bits/component, 3 components, kCGImageAlphaPremultipliedFirst.

Mon Nov 19 21:18:20 Nicholas.local Python[5476] : CGContextTranslateCTM: invalid context

Mon Nov 19 21:18:20 Nicholas.local Python[5476] : CGContextScaleCTM: invalid context

Traceback (most recent call last):

File “/Library/Python/2.5/site-packages/wx-2.8-mac-unicode/wx/lib/flatnotebook.py”, line 3885, in OnPaint

renderer.DrawTabs(self, dc)

File “/Library/Python/2.5/site-packages/wx-
2.8-mac-unicode/wx/lib/flatnotebook.py”, line 1776, in DrawTabs

mem_dc.Blit(0, 0, rect.width, rect.height, dc, rect.x, rect.y)

File “/Library/Python/2.5/site-packages/wx-2.8-mac-unicode
/wx/_gdi.py”, line 3381, in Blit

return gdi.DC_Blit(*args, **kwargs)

wx._core.PyAssertionError: C++ assertion “wxAssertFailure” failed at /BUILD/wxPython-src-2.8.6.1/src/common/dcgraph.cpp(821) in DoBlit(): Cannot Blit. Unable to get contents of DC as bitmap.

I dug around in DrawTabs some more, but couldn’t at all figure out what is wrong-- drawing is not my thing :slight_smile: Any ideas, or suggestions on where I can look? This is on leopard w/ Python 2.5, but the same behavior was previously seen on Tiger w/ Python 2.4.

–Stephen

Scratch that, the behavior is exactly the same and the tabs fail to load.

···

On Nov 19, 2007 9:23 PM, Stephen Hansen apt.shansen@gmail.com wrote:

Hi all.

I recently updated my dev box to wx 2.8.6.1, and flatnotebook is still broken on the mac, although it appears to not be as severe. In 2.8.6.0, it threw the error and the notebook failed to render or display; now it’s rendering, it’s just still erroring out. That’s better at least :slight_smile:

Hi Stephen,

>
> I didn't even know that FlatNotebook doesn't work on Mac (!). The
> traceback doesn't turn on any light to me, but this ia always the case
> with Mac. Unfortunately, I can't test it (I don't have a Mac) and I
> can't provide any useful suggestions without actually play with the
> code on the platform which gives problems. Anyway, if it works on
> Windows and Linux, I would say this is just another incompatibility of
> wxWidgets on Mac with respect to the other 2 platforms. The code that
> throws the error is:
>

The original thread I started when I noticed this problem was in
ActiveState Community - Boosting coder and team productivity with ready-to-use open source languages and tools. , and
one user reported they could get around it by adding a page in the init of
the notebook-- which doesn't work for me as the pages are dynamic and I
can't load them that early.

Unfortunately, my knowledge of drawing and the like is such that I can't
even begin to debug the error; I just don't understand the lower level
graphics things enough to see why a Blit may or may not work. The odd thing
is that before 2.8.4.2(be that 2.4.8.1 or 2.4.8.0 I don't know), it worked
fine-- and there's no obvious changes that I can find that may lead to the
incompatibility.

Uhm, yes, I remember now that thread... there is one thing we can try:
inside the DrawTabs method, let's say at line 1775 of flatnotebook.py,
could you please put these 2 statements:

# After rect = wx.Rect(self.GetXPos(pc), 6, 16, 14)

print rect
print len(pc._pagesInfoVec)

And report back the result of the print? It might be that with no
pages, wx.Rect assumes some strange value for which Mac bombs out, or
having zero pages creates problems on Mac. In this case, I believe we
can find an easy solution.

Thank you.

Andrea.

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

···

On Nov 20, 2007 10:01 AM, Stephen Hansen wrote:

Hello,

I didn’t even know that FlatNotebook doesn’t work on Mac (!). The

traceback doesn’t turn on any light to me, but this ia always the case
with Mac. Unfortunately, I can’t test it (I don’t have a Mac) and I
can’t provide any useful suggestions without actually play with the
code on the platform which gives problems. Anyway, if it works on
Windows and Linux, I would say this is just another incompatibility of
wxWidgets on Mac with respect to the other 2 platforms. The code that
throws the error is:

The original thread I started when I noticed this problem was in http://aspn.activestate.com/ASPN/Mail/Message/wxpython-users/3550174 , and one user reported they could get around it by adding a page in the init of the notebook-- which doesn’t work for me as the pages are dynamic and I can’t load them that early.

Ahh, I thought this sounded familiar, that was me, I did some checking with the script I was having trouble with and cannot reproduce this problem anymore with the latest 2.8.7 pre-release build (on OSX 10.4, python 2.5). You may want to trying to run your code against that and see if it is ok. If not feel free to post a small runnable sample that reproduces the problem and I will be more than happy to spend some time on debugging.

Unfortunately, my knowledge of drawing and the like is such that I can’t even begin to debug the error; I just don’t understand the lower level graphics things enough to see why a Blit may or may not work. The odd thing is that before 2.8.4.2(be that 2.4.8.1 or 2.4.8.0 I don’t know), it worked fine-- and there’s no obvious changes that I can find that may lead to the incompatibility.

–Stephen

Regards,

Cody Precord

···

On Nov 20, 2007, at 4:01 AM, Stephen Hansen wrote:

Stephen Hansen wrote:

Traceback (most recent call last):
  File "/Library/Python/2.5/site-packages/wx-2.8-mac-unicode/wx/lib/flatnotebook.py", line 3885, in OnPaint
    renderer.DrawTabs(self, dc)
  File "/Library/Python/2.5/site-packages/wx- 2.8-mac-unicode/wx/lib/flatnotebook.py", line 1776, in DrawTabs
    mem_dc.Blit(0, 0, rect.width, rect.height, dc, rect.x, rect.y)
  File "/Library/Python/2.5/site-packages/wx-2.8-mac-unicode /wx/_gdi.py", line 3381, in Blit
    return _gdi_.DC_Blit(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed at /BUILD/wxPython-src-2.8.6.1/src/common/dcgraph.cpp(821) in DoBlit(): Cannot Blit. Unable to get contents of DC as bitmap.

Andrea Gavana wrote:

The code that
throws the error is:

        mem_dc = wx.MemoryDC()

        #---------------------------------------
        # X button
        #---------------------------------------
        rect = wx.Rect(self.GetXPos(pc), 6, 16, 14)
        mem_dc.SelectObject(self._xBgBmp)
        mem_dc.Blit(0, 0, rect.width, rect.height, dc, rect.x, rect.y)
        mem_dc.SelectObject(wx.NullBitmap)

What kind of wx.DC is dc? This bug is probably related to the fact that Mac doesn't allow read access to the graphics buffer. It's essentially write-only, so things that require read access can't be supported. (Like GetPixel, logical function blends, blitting from screen DCs, etc.) Basically it's a matter of the wx.DC model not fitting very well with the CoreGraphics model: square peg, round hole.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi Stephen,

Now, here's my observation: I commented out the blit's entirely in that
section (all 3 of them), and it appears to work fine. It even still draws
the left and right buttons.

Looking at that code with my VERY limited knowledge of drawing, what I
*think* you're doing is copying what is currently in the area of the control
into the control-- in effect you're making it 'transparent' so whatever is
behind it, you're drawing onto your background so it doesn't get overwritten
unless necessary.

My question is, why is that necessary? Would not painting over the full
background of the control with a transparent brush and pen accomplish the
same end? (... and then not require Blit'n the screen which mac's hate?)

Ok, I will try to play a bit to avoid wx.MemoryDC/blitting altogether
and I will commit the new changes to SVN once it's ready. I will
probably post a revised version of FlatNotebook on the wxPython list
*before* committing to SVN to be sure not to include stupid mistakes
in my code. I will be more than happy to have someone testing
FlatNotebook on Linux and Mac :smiley:

Thank you for the report!

Andrea.

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

···

On Nov 20, 2007 10:13 PM, Stephen Hansen wrote:

--
Andrea.

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

mem_dc = wx.MemoryDC()
#---------------------------------------

X button

#---------------------------------------
rect = wx.Rect(self.GetXPos(pc), 6, 16, 14)
mem_dc.SelectObject(self._xBgBmp)
mem_dc.Blit(0, 0, rect.width, rect.height, dc, rect.x, rect.y)
mem_dc.SelectObject(wx.NullBitmap
)

So, I can’t really understand what is going on. Am I reading data from
the dc? It doesn’t look like, but I may be wrong. Not having a way to
test my modifications does not help either.

Looking at: http://wxpython.org/docs/api/wx.DC-class.html#Blit

It looks like the fifth object is “dc” – the source. So it looks like it’s copying -from- dc -to- mem_dc. And you can’t read from dc-- which is the screen. Or am I reading this wrong?

–Stephen

Hi Stephen & All,

>
> mem_dc = wx.MemoryDC()
> #---------------------------------------
> # X button
> #---------------------------------------
> rect = wx.Rect(self.GetXPos(pc), 6, 16, 14)
> mem_dc.SelectObject(self._xBgBmp)
> mem_dc.Blit(0, 0, rect.width, rect.height, dc, rect.x, rect.y)
> mem_dc.SelectObject(wx.NullBitmap )
>
> So, I can't really understand what is going on. Am I reading data from
> the dc? It doesn't look like, but I may be wrong. Not having a way to
> test my modifications does not help either.

Looking at: wxPython API Documentation — wxPython Phoenix 4.2.2 documentation

It looks like the fifth object is "dc" -- the source. So it looks like it's
copying -from- dc -to- mem_dc. And you can't read from dc-- which is the
screen. Or am I reading this wrong?

Could you (or someone else with a Mac readily available) please try
the attached version of FlatNotebook and let me know if it works on
Mac?

Thank you.

Andrea.

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

flatnotebook.py (157 KB)

···

On Nov 22, 2007 9:08 AM, Stephen Hansen wrote:

Could you (or someone else with a Mac readily available) please try

the attached version of FlatNotebook and let me know if it works on
Mac?

It appears to work fine :slight_smile:

Yay!

–Stephen

Hi Stephen,

>
>
> Could you (or someone else with a Mac readily available) please try
> the attached version of FlatNotebook and let me know if it works on
> Mac?

It appears to work fine :slight_smile:

Yay!

Very well, at least it didn't take 1000 iterations between me (without
Mac) and you as a "beta tester" of my sometimes stupid code :smiley: . I
have committed the changes to SVN, so it should work from next
wxPython version on. Thank you for the bug report and for the help in
testing the modifications on Mac.

Andrea.

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

···

On Nov 22, 2007 8:27 PM, Stephen Hansen wrote: