(my first post, I hope I'm doing it right) I have two questions about wxImage.
Using the statement:
self._img = wx.Image(self.fname, wx.BITMAP_TYPE_ANY)
with self.fname not pointing to a valid file, gives me an invalid image (no surprise there). The console shows a message from wxWidgets:
04:35:19: Error: Can't load image from file 'DB_72928.jpg': file does not exist.
My main question is how to properly detect this. The constructor does not throw an exception, and may or may not return None. However when methods are called on this wx.Image object, we get exceptions then. For example, the statement
xyzzy = self._img.GetHeight()
I tried a workaround of simply making such a call immediately after creating the object, but that brings up my second question. For the statement:
self._img = wx.Image.Create(oldImage, 42, 42, True) #create a plain black image, 42 x 42 pixels
TypeError: unbound method Create() must be called with Image instance as first argument (got NoneType instance instead)
How are you supposed to create an empty (black) image if you don't already have an oldImage? I would have expected the Create() method to be a class method, but it's apparently an instance method.
with self.fname not pointing to a valid file, gives me an invalid image (no surprise there). The console shows a message from wxWidgets:
04:35:19: Error: Can’t load image from file ‘DB_72928.jpg’: file does not exist.
My main question is how to properly detect this. The constructor does not throw an exception, and may or may not return None. However when methods are called on this wx.Image object, we get exceptions then. For example, the statement
xyzzy = self._img.GetHeight()
see: self._img.IsOk()
I tried a workaround of simply making such a call immediately after creating the object, but that brings up my second question. For the statement:
self._img = wx.Image.Create(oldImage, 42, 42, True) #create a plain black image, 42 x 42 pixels
TypeError: unbound method Create() must be called with Image instance as first argument (got NoneType instance instead)
wx.Image.Create is not a static method so it needs an instance of wxImage to be called.
How are you supposed to create an empty (black) image if you don’t already have an oldImage? I would have expected the Create() method to be a class method, but it’s apparently an instance method.
see: wx.EmptyImage
Cody
···
On Tue, Mar 10, 2009 at 9:51 AM, Dave Angel davea@ieee.org wrote:
Problem 2 is simpler: use wx.EmptyImage(width, height)
For the first problem I’ll simply use os.path.exists(filename) and either throw an exception or recover using some other way appropriate for your application (the empty image)
Peter
···
On Tue, Mar 10, 2009 at 4:51 PM, Dave Angel davea@ieee.org wrote:
(my first post, I hope I’m doing it right) I have two questions about wxImage.
with self.fname not pointing to a valid file, gives me an invalid image (no surprise there). The console shows a message from wxWidgets:
04:35:19: Error: Can't load image from file 'DB_72928.jpg': file does not exist.
My main question is how to properly detect this. The constructor does not throw an exception, and may or may not return None. However when methods are called on this wx.Image object, we get exceptions then. For example, the statement
xyzzy = self._img.GetHeight()
I tried a workaround of simply making such a call immediately after creating the object, but that brings up my second question. For the statement:
self._img = wx.Image.Create(oldImage, 42, 42, True) #create a plain black image, 42 x 42 pixels
TypeError: unbound method Create() must be called with Image instance as first argument (got NoneType instance instead)
How are you supposed to create an empty (black) image if you don’t already have an oldImage? I would have expected the Create() method to be a class method, but it’s apparently an instance method.