Re: A signal for Gtk::MessageDialog



Thanks again Chris,
I did some more research, but I cannot see how that Gtk::Dialog::signal_response() can help me, if what I want to do is to destroy the dialog box after the user presses the 'Exit' button.
Can you please regroup and see if you can give me a hand.

Thanks Chris

--------------
namespace jme{
class GtkmmException : public virtual Gtk::MessageDialog{
private:
   jme::Exception* ex;

protected:
public:
   GtkmmException(Glib::ustring&,   //! file name used as icon
                  jme::Exception&); //! Exception class

   ~GtkmmException();
private:

   //Signal handlers:
   virtual void on_button_clicked();
}; // class
}  // namespace


jme::GtkmmException::GtkmmException( Glib::ustring& str, jme::Exception& e)
: Gtk::MessageDialog("",false,Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, false){
try{ex = new jme::Exception();}
catch(std::bad_alloc& x){ std::cout << x.what() <<
                          "\n press any key to continue";
                          std::cin.get();
                          exit(-1);
                         }
ex->copy(e);



Gtk::MessageDialog::set_message(ex->where(), false);
Gtk::MessageDialog::set_secondary_text("secondary text", false);
Gtk::MessageDialog::set_title(ex->getTitle());
Gtk::MessageDialog::set_modal(false);
UnknownButtonVariableName.connect( sigc::mem_fun(*this, &GtkmmException::on_button_clicked) );
}
void jme::GtkmmException::on_button_clicked(){ destroy_(); /*??*/}

jme::GtkmmException::~GtkmmException(){ delete ex;}

On 12/28/06, Chris Vine <chris cvine freeserve co uk > wrote:
On Thursday 28 December 2006 03:03, Jamiil Abduqadir wrote:
> Hello,
> I am writing a class that derives from 'Gtk::MessageDialog'. What does the
> class do? you got it, it displays a dialog box with some information on it.
> Now, to the problem. Just like any 'Gtk::MessageDialog' it has a button in
> there that I need to connect to a signal, but since I don't know the name
> of the button, I cannot write something like
>
> Mybutton.signal_clicked().connect(sigc::ptr_fun(&on_button_clicked));

Gtk::MessageDialog derives from Gtk::Dialog which has a
Gtk::Dialog::get_action_area() method returning a pointer to its
Gtk::HButtonBox member.  Gtk::HButtonBox derives from Gtk::Box and you can
obtain its childer (the buttons) with Gtk::Box::children().

However you should rarely need to do that.  You can just connect to
Gtk::Dialog::signal_response signal.  The response_id parameter will indicate
which button was pressed (if the dialog has more than one button).

Chris




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