MemoryDC, GetFullTextExtent and Darwin

Hi Folks

I'm trying to port a working GUI to Darwin

Python 2.4.3 (#1, Apr 7 2006, 10:54:33)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on
darwin
Type "help", "copyright", "credits" or "license" for
more information.

import wx
wx.GetOsDescription()

u'MacOS (Darwin 8.6.1 i386)'

wx.VERSION_STRING

'2.6.3.3'

but this code

  def ConstructBMP(self):
    memory = wxMemoryDC()
    border = 10
    width, height, d, e =
memory.GetFullTextExtent(self.text)

gives this error

    width, height, d, e =
memory.GetFullTextExtent(self.text)
  File
"//Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/wx-2.6-mac-unicode/wx/_gdi.py",
line 3445, in GetFullTextExtent
    return _gdi_.DC_GetFullTextExtent(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion
"wxAssertFailure" failed in
/BUILD/wxPython-src-2.6.3.3/src/mac/carbon/dc.cpp(1482):
Invalid DC

Any ideas

Nigel

···

---
Nigel W. Moriarty

__________________________________________________________________________________________
Check out the New Yahoo! Mail - Fire up a more powerful email and get things done faster.
(http://advision.webevents.yahoo.com/mailbeta)

Nigel W. Moriarty wrote:

I'm trying to port a working GUI to Darwin
  def ConstructBMP(self):
    memory = wxMemoryDC()
    border = 10
    width, height, d, e =
memory.GetFullTextExtent(self.text)

Invalid DC

I haven't tested it, but a wxMemoryDC may be invalid if it hasn't had a bitmap selected into it yet. Try:

def ConstructBMP(self):
      memory = wx.MemoryDC()
      memory.SelectObject(wx.EmptyBitmap(32, 32))
      border = 10
      width, height, d, e = memory.GetFullTextExtent(self.text)

Of course you may be trying to find out how big the text is to that you know how big to make the Bitmap. In that case, you can either make a new on after getting the size, of maybe use a wx.ScreenDC or other DC to do your text measurement, then create the wx.MemoryDC

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Hello NG,

Of course you may be trying to find out how big the text is to that you
know how big to make the Bitmap. In that case, you can either make a new
on after getting the size, of maybe use a wx.ScreenDC or other DC to do
your text measurement, then create the wx.MemoryDC

Uhm, I don't think the size of the bitmap matters... but maybe on
Darwin is different than on Windows:

import wx
import random

def ConstructBMP(bmpSize, text):

    memory = wx.MemoryDC()
    memory.SelectObject(wx.EmptyBitmap(bmpSize, bmpSize))
    return memory.GetFullTextExtent(text)

app = wx.PySimpleApp()
text = ""
for i in xrange(100):
    text += chr(random.randint(0, 255))

print ConstructBMP(1, text)
print ConstructBMP(15, text)
print ConstructBMP(220, text)

(670, 16, 3, 0)

Andrea.

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

Andrea Gavana wrote:

Of course you may be trying to find out how big the text is to that you
know how big to make the Bitmap. In that case, you can either make a new
on after getting the size, of maybe use a wx.ScreenDC or other DC to do
your text measurement, then create the wx.MemoryDC

Uhm, I don't think the size of the bitmap matters... but maybe on
Darwin is different than on Windows:

you're right -- but that's not what I meant. What I was imagining was that the OP was trying to make a bitmap large enough to to hold a given text string -- to do that, you'd need to know how large it was before you could make the bitmap.

-CHB

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Hi Chris,

you're right -- but that's not what I meant. What I was imagining was
that the OP was trying to make a bitmap large enough to to hold a given
text string -- to do that, you'd need to know how large it was before
you could make the bitmap.

Sorry, I did not understand correctly what you meant. Yes, if this is
the final target of the code, you have to know if advance how large is
the text indeed. Sorry for my somewhat approximative mastering of the
english language :wink:

···

--
Andrea.

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

Christopher Barker wrote:

Nigel W. Moriarty wrote:

I'm trying to port a working GUI to Darwin
  def ConstructBMP(self):
    memory = wxMemoryDC()
    border = 10
    width, height, d, e =
memory.GetFullTextExtent(self.text)

Invalid DC

I haven't tested it, but a wxMemoryDC may be invalid if it hasn't had a bitmap selected into it yet.

That is correct.

···

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