Exploring zetcode wxwidget tutorial on Menus and Toolbars:A Simple Toolbar/

The rain in Spain falls mainly on the plain… By Jove he’s got it… My progress in the zetcode tutorial seems to have taken an uptick…. Let see if continues with my exploration of toolbars.
Short answer… No….
Up to now, every piece of tutorial code that I have tried as worked perfectly as described up to now.
In this particular instance, I’m suppose to be getting an image that’s supposed to look like this.

What I’m getting is a frame without the toolbar and some error message that appears in the terminal session:
Unfortunately, for some reason I can’t copy the text, I have to copy the image. Here it is:

So the error message is:
gdk_drawable_get_depth: assertion GDK_IS_DRAWABLE (drawable) failed
From a quick google search, apparently this happens quite often.  I think I Jinxed myself….. So much for the forward progress.

Ok then…. where to go….  Is the issue with Wxwidgets or GDK????.  Just a thought here… The tutorial mentioned that there was a different way to create a toolbar… If the problem, continues, than we’re going to have to come to a halt to figure out what’s going on.  So lets see if we try the next sample.
Just loading up the next sample and running I get this error:

11:41:52 AM: Can’t load image from file ‘exit.png’: file does not exist.
11:41:52 AM: Can’t load image from file ‘new.png’: file does not exist.
11:41:52 AM: Can’t load image from file ‘open.png’: file does not exist.
11:41:52 AM: Can’t load image from file ‘save.png’: file does not exist.

Ok… We’ll lets see what we have on my computer:

jonas@Ubuntu4://$ locate /exit.png
/usr/lib/qt4/demos/undo/icons/exit.png
/usr/lib/qt4/examples/network/torrent/icons/exit.png
/usr/share/childsplay/lib/PackidData/exit.png
/usr/share/codeblocks/images/16×16/exit.png
/usr/share/doc/qt4-doc/demos/undo/icons/exit.png
/usr/share/doc/qt4-doc/examples/network/torrent/icons/exit.png
/usr/share/doc/wx2.8-examples/examples/wxPython/bmp_source/exit.png
/usr/share/games/madbomber/images/title/exit.png
/usr/share/icons/Human/16×16/actions/exit.png
/usr/share/icons/Human/24×24/actions/exit.png
/usr/share/icons/gnome/16×16/actions/exit.png
/usr/share/icons/gnome/22×22/actions/exit.png
/usr/share/icons/gnome/24×24/actions/exit.png
/usr/share/icons/gnome/32×32/actions/exit.png
jonas@Ubuntu4://$ locate /new.png
/usr/lib/qt4/examples/mainwindows/application/images/new.png
/usr/lib/qt4/examples/mainwindows/dockwidgets/images/new.png
/usr/lib/qt4/examples/mainwindows/mdi/images/new.png
/usr/lib/qt4/examples/mainwindows/sdi/images/new.png
/usr/share/doc/qt4-doc/examples/mainwindows/application/images/new.png
/usr/share/doc/qt4-doc/examples/mainwindows/dockwidgets/images/new.png
/usr/share/doc/qt4-doc/examples/mainwindows/mdi/images/new.png
/usr/share/doc/qt4-doc/examples/mainwindows/sdi/images/new.png
/usr/share/wxformbuilder/resources/icons/new.png
jonas@Ubuntu4://$ locate /open.png
/usr/lib/qt4/examples/assistant/simpletextviewer/documentation/images/open.png
/usr/lib/qt4/examples/help/simpletextviewer/documentation/images/open.png
/usr/lib/qt4/examples/mainwindows/application/images/open.png
/usr/lib/qt4/examples/mainwindows/mdi/images/open.png
/usr/lib/qt4/examples/mainwindows/sdi/images/open.png
/usr/lib/qt4/examples/widgets/movie/images/open.png
/usr/share/doc/qt4-doc/examples/assistant/simpletextviewer/documentation/images/open.png
/usr/share/doc/qt4-doc/examples/mainwindows/application/images/open.png
/usr/share/doc/qt4-doc/examples/mainwindows/mdi/images/open.png
/usr/share/doc/qt4-doc/examples/mainwindows/sdi/images/open.png
/usr/share/doc/qt4-doc/examples/widgets/movie/images/open.png
/usr/share/emacs/22.1/etc/tree-widget/default/open.png
/usr/share/emacs/22.1/etc/tree-widget/folder/open.png
/usr/share/wxformbuilder/resources/icons/open.png
jonas@Ubuntu4://$ locate /save.png
/usr/lib/qt4/examples/mainwindows/application/images/save.png
/usr/lib/qt4/examples/mainwindows/dockwidgets/images/save.png
/usr/lib/qt4/examples/mainwindows/mdi/images/save.png
/usr/lib/qt4/examples/mainwindows/sdi/images/save.png
/usr/share/doc/qt4-doc/examples/mainwindows/application/images/save.png
/usr/share/doc/qt4-doc/examples/mainwindows/dockwidgets/images/save.png
/usr/share/doc/qt4-doc/examples/mainwindows/mdi/images/save.png
/usr/share/doc/qt4-doc/examples/mainwindows/sdi/images/save.png
/usr/share/wxformbuilder/resources/icons/save.png
jonas@Ubuntu4://$

Ok…. I pasted in the path and it seemed to work…. Ok… I wonder if I past a valid path in “A Simple Toobar” to see if it goes away also….. and the answer is yepp…. That was easy….

‘Ok… I guess I’ll paste “/usr/share/icons/Human/16×16/actions/exit.png” to see what happens..
Hmmm… Seem to work on one. I guess I’ll paste the rest to see what happens. Ok… That worked…

I suppose that begs the question, if I was making a cross-platform application for distribution, how the heck would I program this?? That is a todo for another day, when I’m in that situation.

Ok…. So back to a Simple Toolbar….
With my little adjustment here’s the code with references to things I never seen before.

#include “toolbar.h”

Toolbar::Toolbar(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(280, 180))
{
//  wxBitmap exit(wxT(“exit.png”));
wxBitmap exit(wxT(“/usr/share/icons/gnome/32×32/actions/exit.png”));// this is what I added

wxToolBar *toolbar = CreateToolBar();
toolbar->AddTool(wxID_EXIT, exit, wxT(“Exit application”));
toolbar->Realize();

Connect(wxID_EXIT, wxEVT_COMMAND_TOOL_CLICKED,
wxCommandEventHandler(Toolbar::OnQuit));

Centre();

}

void Toolbar::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(true);
}

Ok.. I’m getting the rhythm of this….On to the tutorial “toolbars”…

Same deal, I made a couple of modifications and I hyperlinked what was unfamiliar to me.

#include “toolbars.h”

Toolbar::Toolbar(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(280, 180))
{

wxImage::AddHandler( new wxPNGHandler );

wxBitmap exit(wxT(“/usr/share/icons/Human/16×16/actions/exit.png”), wxBITMAP_TYPE_PNG);
wxBitmap newb(wxT(“/usr/share/wxformbuilder/resources/icons/new.png”), wxBITMAP_TYPE_PNG);
wxBitmap open(wxT(“/usr/share/wxformbuilder/resources/icons/open.png”), wxBITMAP_TYPE_PNG);
wxBitmap save(wxT(“/usr/share/wxformbuilder/resources/icons/save.png”), wxBITMAP_TYPE_PNG);

wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);

toolbar1 = new wxToolBar(this, wxID_ANY);
toolbar1->AddTool(wxID_ANY, newb, wxT(“”));
toolbar1->AddTool(wxID_ANY, open, wxT(“”));
toolbar1->AddTool(wxID_ANY, save, wxT(“”));
toolbar1->Realize();

toolbar2 = new wxToolBar(this, wxID_ANY);
toolbar2->AddTool(wxID_EXIT, exit, wxT(“Exit application”));
toolbar2->Realize();

vbox->Add(toolbar1, 0, wxEXPAND);
vbox->Add(toolbar2, 0, wxEXPAND);

SetSizer(vbox);

Connect(wxID_EXIT, wxEVT_COMMAND_TOOL_CLICKED,
wxCommandEventHandler(Toolbar::OnQuit));

Centre();
}

void Toolbar::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(true);
}

Ok… Enough on that one… Hot darn through another chapter. . On to layout management

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *