Hi, I have a question how to use wxBitmap.
I was trying to create a tool bar with a gif image. There is a tool bar
example in wxPython distribution, but it does not use the external image
file for a tool bar icon. I thought I could use the external gif image with
wxBitmap() object and tried the following.
I put "positive.gif" and the python script code in the same directory. But
it didn't work. I got "No ImageHandler for type 13 is defined" error message
with the above code. I guess, I need to something to use gif file.
After reading wxWindow online document, I came to know the image handler for
BMP is installed by default so I tried to use BMP instead of GIF as follows:
toolBar.AddSimpleTool( 10, wxBitmap( "positive.bmp", wxBITMAP_TYPE_BMP ), \
"Positive", "Assign Positive Relation" )
With this code, I don't have any error message, but I don't have tool bar
icon, either.
Finally, I tried to use wxBITMAP macro because wxWindow online document said
wxBITMAP should be used in every case, but it didn't work either. I got
"NameError: global name 'wxBITMAP' is not defined" error message. It seems
that wxBITMAP macro is not implemented in wxPython, yet.
Is there any one who can help me with the above problems?
You need to call wxInitAllImageHandlers() prior to loading any images from
file.
···
On Wednesday 14 November 2001 08:03, Young-Jin Lee wrote:
Finally, I tried to use wxBITMAP macro because wxWindow online document
said wxBITMAP should be used in every case, but it didn't work either. I
got "NameError: global name 'wxBITMAP' is not defined" error message. It
seems that wxBITMAP macro is not implemented in wxPython, yet.
"Positive", "Assign Positive Relation" )
With this code, I don't have any error message, but I don't have tool bar
icon, either.
Is your image 16x15 pixels? If not did you call SetToolBitmapSize? Are you
sure that the current working directory of your program is still the
directory where the image file is located? (If you are running the hybrid
version on Windows then you will get a warning message about being unable to
find the file.) If not then specify a full path to the file.
···
--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters? http://wxPython.org Relax with wxPython!
I tried to use BMP instead of GIF as follows:
toolBar.AddSimpleTool( 10, wxBitmap( "positive.bmp", wxBITMAP_TYPE_BMP ), \
"Positive", "Assign Positive Relation" )
With this code, I don't have any error message, but I don't have tool bar
icon, either.
I'm not sure what's wrong with that code, but I can tell you that this
works for me:
What is AddSimpleTool() ? I havn't been able to find it in the docs.
%addmethods {
// wrap ClientData in a class that knows about PyObjects
wxToolBarToolBase *AddTool(int id,
const wxBitmap& bitmap,
const wxBitmap& pushedBitmap = wxNullBitmap,
int isToggle = FALSE,
PyObject *clientData = NULL,
const wxString& shortHelpString = wxPyEmptyStr,
const wxString& longHelpString = wxPyEmptyStr) {
wxPyUserData* udata = NULL;
if (clientData)
udata = new wxPyUserData(clientData);
return self->AddTool(id, bitmap, pushedBitmap, (bool)isToggle,
udata, shortHelpString, longHelpString);
}
// This one is easier to use...
wxToolBarToolBase *AddSimpleTool(int id,
const wxBitmap& bitmap,
const wxString& shortHelpString = wxPyEmptyStr,
const wxString& longHelpString = wxPyEmptyStr,
int isToggle = FALSE) {
return self->AddTool(id, bitmap, wxNullBitmap, isToggle, NULL,
shortHelpString, longHelpString);
}
}
It just leaves out the less commonly used parameters (the 2nd bitmap and the
client data.) It was put there before SWIG allowed for keyword parameters
and so to use AddTool and the help strings or the toggle flag you had to
pass wxNullBitmap and None everytime.
···
--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters? http://wxPython.org Relax with wxPython!
It just leaves out the less commonly used parameters (the 2nd bitmap and the
client data.) It was put there before SWIG allowed for keyword parameters
and so to use AddTool and the help strings or the toggle flag you had to
pass wxNullBitmap and None everytime.
Thanks Robin. Now that SWIG does allow keyword arguments, are you going
to keep this around?