Re: Gtk::Builder: autoconnecting signal handlers



Hi.

Great, thanks for taking a look! :)

20.07.2009 15:20, Murray Cumming wrote:
*** Do we want this?
I'll copy/paste here my thoughts about it
that I already expressed on the bugzilla entry:
---
> And I unfortunately still don't find this much nicer than
> connecting manually.
> It only saves me from having to remember the names of the
> signals that I am
> connecting to, though
You first need to remember all the widgets you
need to connect. Recall their names. Their type.
Get those widgets by names. Recall their respective
handlers. Then connect.
You write the wrapper by doing so. Wrapper needs
to be recompiled when the form changes. You change
the widget name in the GUI builder - adjust the
wrapper + recompile. You add another button that
can use the already existing handler - you nevertheless
adjust the wrapper + recompile.
I agree to recompile when I change or add the
handler itself - this is unavoidable and obviously
justified. But I don't want to have the wrapper,
neither do I want to write it, nor to recompile
every time I am changing the form.
I want only a single call that loads the GUI from
XML and makes it alive. A single call, not more. :)
QT uses wrappers too, but at least, they are
generated there. Here, the wrappers are hand-written.
---

Also, I'd like to show people the usage example
of this, it is clearly demonstrated by the
patch below. All it does is to add the inheritance
from Glib::SlotsContainer and a trivial definition
for the handler, and then the wrapper is gone.

---
Index: examples/book/builder/derived/deriveddialog.cc
===================================================================
--- examples/book/builder/derived/deriveddialog.cc	(revision 85)
+++ examples/book/builder/derived/deriveddialog.cc	(working copy)
@@ -23,12 +23,7 @@
   m_refGlade(refGlade),
   m_pButton(0)
 {
-  //Get the Glade-instantiated Button, and connect a signal handler:
-  m_refGlade->get_widget("quit_button", m_pButton);
-  if(m_pButton)
-  {
- m_pButton->signal_clicked().connect( sigc::mem_fun(*this, &DerivedDialog::on_button_quit) );
-  }
+  m_refGlade->connect_signals(*this);
 }

 DerivedDialog::~DerivedDialog()
Index: examples/book/builder/derived/deriveddialog.h
===================================================================
--- examples/book/builder/derived/deriveddialog.h	(revision 85)
+++ examples/book/builder/derived/deriveddialog.h	(working copy)
@@ -22,7 +22,7 @@
 #include <gtkmm.h>


-class DerivedDialog : public Gtk::Dialog
+class DerivedDialog : public Gtk::Dialog, public Glib::SlotsContainer
 {
 public:
DerivedDialog(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade);
@@ -34,6 +34,11 @@

   Glib::RefPtr<Gtk::Builder> m_refGlade;
   Gtk::Button* m_pButton;
+
+private:
+GLIBMM_DECLARE_SLOTS(
+  GLIBMM_SLOT(DerivedDialog::on_button_quit)
+);
 };

 #endif //GTKMM_EXAMPLE_DERIVED_WINDOW_H

Index: examples/book/builder/derived/basic.ui
===================================================================
--- examples/book/builder/derived/basic.ui	(revision 85)
+++ examples/book/builder/derived/basic.ui	(working copy)
@@ -34,7 +34,7 @@
 	      <property name="label">gtk-quit</property>
 	      <property name="use_stock">True</property>
 	      <property name="relief">GTK_RELIEF_NORMAL</property>
-	
+	      <signal name="clicked" handler="DerivedDialog::on_button_quit"/>
 	    </object>
 	  </child>
 	</object>
---


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