Re: [gtkmm] Converting from GTK+ to Gtkmm



Murray Cumming Comneon com writes:

> 1. With libglademm, you need to manually connect your signals after getting
> the widgets from the Gnome::Glade::Xml. There is no autoconnect yet.

OK.  Is this planned for the future?

On a sort-of-related note, will the Glade VariablesMap support a wider
range of widgets in the future, like SpinButtons etc.?

> 2. I don't think you need to get the Gnome::Glade::Xml from the widget. You
> should probably just remember the Gnome::Glade::Xml that you used, as a
> member variable. But I was not even aware of this function so you might want
> to patch libglademm to support it.

You are right--I don't need it.  Being used to C GTK+, I was initially
quite confused about how to get a widget in a signal handler.  Then,
it hit me: the signal handler is a member function, so it already
knows which widget it is!  Nice!

I now have a small program converted to Gtkmm/Glademm; I think I've
got the hang of it.  My only remaining problem is connecting one
signal handler:

This is my class (which I think is the correct way to do things in
Gtkmm):

class ogcalc : public Gtk::Window
{
public:
  ogcalc();
  virtual ~ogcalc();

protected:
  // Signal handlers
  virtual void calculate(); // Calculation callback
  virtual void reset();     // Reset callback

  // The widgets that are manipulted.
  Gtk::SpinButton* pg_entry;
  Gtk::SpinButton* ri_entry;
  Gtk::SpinButton* cf_entry;
  Gtk::Label* og_result;
  Gtk::Label* abv_result;
  Gtk::Button* quit_button;
  Gtk::Button* reset_button;
  Gtk::Button* calculate_button;

  Glib::RefPtr<Gnome::Glade::Xml> xml_interface; // Glade interface description
};


In my constructor, I load the Glade interface, pull out my widgets and
then set up the signal handlers:

ogcalc::ogcalc()
{
  // Get the Glade user interface and add it to this window.
  xml_interface = Gnome::Glade::Xml::create("ogcalc-gl.glade");
  xml_interface->reparent_widget("vbox1", *this);

  // Pull all of the widgets out of the Glade interface.
  xml_interface->get_widget("pg_entry", pg_entry);
[...]
  xml_interface->get_widget("calculate_button", calculate_button);

  // Set up signal handers for buttons.
[...]
  if (calculate_button && reset_button)
    {
      calculate_button->signal_clicked().connect( SigC::slot(*this,
                                                             &ogcalc::calculate) );
      calculate_button->signal_clicked().connect( SigC::slot(*reset_button,
                                                             &Gtk::Widget::grab_focus) );
    }

  // Set up signal handlers for numeric entries.
[...]
  if (cf_entry)
    cf_entry->signal_activate().connect( SigC::hide_return( SigC::slot(*this,
    &Gtk::Window::activate_default) ) );
}


This all works, but with one exception.  The last signal hander
(Gtk::Window::activate_default()) returns a bool, so I can't connect
it with SigC::slot.  The sigc++ documentation says to use
SigC::hide_return, but using the above call results in a segfault when
it is triggered (gdb shows it use up all the stack as it recurses
forever).

What is the correct method to connect to this handler?

SigC::hide_return isn't included by default, using <gtkmm.h>, I had to
include <sigc++/retype_return.h> myself--a bug in the sigc++ headers?


(I'm using libsigc++ 1.2.5 and libgtkmm 2.2.3, BTW.)


Thanks,
Roger


-- 
Roger Leigh

                Printing on GNU/Linux?  http://gimp-print.sourceforge.net/
                GPG Public Key: 0x25BFB848 available on public keyservers



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]