Re: Gtk::Assistant and Glade
- From: Josh Sinykin <jsinykin gmail com>
- To: Murray Cumming <murrayc murrayc com>
- Cc: "gtkmm-list gnome org" <gtkmm-list gnome org>
- Subject: Re: Gtk::Assistant and Glade
- Date: Fri, 11 Mar 2011 08:32:59 -0500
Main.cpp
=========
#include <iostream>
#include "ExampleAssistant.h"
int main(int argc, char* argv[])
{
Gtk::Main kit(argc, argv);
if(!Glib::thread_supported()) Glib::thread_init();
//Load the Glade file and instiate its widgets:
Glib::RefPtr<Gtk::Builder> refBuilder = Gtk::Builder::create();
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
refBuilder->add_from_file("assistant.glade");
}
catch(const Glib::FileError& ex)
{
std::cerr << "FileError: " << ex.what() << std::endl;
return 1;
}
catch(const Gtk::BuilderError& ex)
{
std::cerr << "BuilderError: " << ex.what() << std::endl;
return 1;
}
#else
std::auto_ptr<Glib::Error> error;
if (!refBuilder->add_from_file("assistant.glade", error))
{
std::cerr << error->what() << std::endl;
return 1;
}
#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
//Get the GtkBuilder-instantiated dialog::
ExampleAssistant * pAssistant = 0;
refBuilder->get_widget_derived("assistant1", pAssistant);
// start the event loop
Gtk::Main::run( *pAssistant );
delete pAssistant;
return 0;
}
====
Assistant class
#include <iostream>
#include "ExampleAssistant.h"
ExampleAssistant::ExampleAssistant( BaseObjectType* base_object, const Glib::RefPtr<Gtk::Builder>& builder) :
m_box(false, 12),
m_label1("Type text to allow the assistant to continue:"),
m_label2("Confirmation page"),
m_check("Optional extra information")
{
signal_apply().connect(sigc::mem_fun(*this,
&ExampleAssistant::on_assistant_apply));
signal_cancel().connect(sigc::mem_fun(*this,
&ExampleAssistant::on_assistant_cancel));
signal_close().connect(sigc::mem_fun(*this,
&ExampleAssistant::on_assistant_close));
signal_prepare().connect(sigc::mem_fun(*this,
&ExampleAssistant::on_assistant_prepare));
show_all_children();
}
ExampleAssistant::~ExampleAssistant()
{
}
void ExampleAssistant::get_result(bool& check_state, Glib::ustring& entry_text)
{
check_state = m_check.get_active();
entry_text = m_entry.get_text();
}
void ExampleAssistant::on_assistant_apply()
{
std::cout << "Apply was clicked";
print_status();
}
void ExampleAssistant::on_assistant_cancel()
{
std::cout << "Cancel was clicked";
print_status();
hide();
}
void ExampleAssistant::on_assistant_close()
{
std::cout << "Assistant was closed";
print_status();
hide();
}
void ExampleAssistant::on_assistant_prepare(Gtk::Widget* /* widget */)
{
set_title(Glib::ustring::compose("Gtk::Assistant example (Page %1 of %2)",
get_current_page() + 1, get_n_pages()));
}
void ExampleAssistant::on_entry_changed()
{
// The page is only complete if the entry contains text.
if(m_entry.get_text_length())
set_page_complete(m_box, true);
else
set_page_complete(m_box, false);
}
void ExampleAssistant::print_status()
{
std::cout << ", entry contents: \"" << m_entry.get_text()
<< "\", checkbutton status: " << m_check.get_active() << std::endl;
}
=====
Assistant header
===
#include <gtkmm.h>
class ExampleAssistant : public Gtk::Assistant
{
public:
//ExampleAssistant();
ExampleAssistant( BaseObjectType* base_object, const Glib::RefPtr<Gtk::Builder>& builder);
virtual ~ExampleAssistant();
void get_result(bool& check_state, Glib::ustring& entry_text);
private:
// Signal handlers:
void on_assistant_apply();
void on_assistant_cancel();
void on_assistant_close();
void on_assistant_prepare(Gtk::Widget* widget);
void on_entry_changed();
// Member functions:
void print_status();
// Child widgets:
Gtk::HBox m_box;
Gtk::Label m_label1, m_label2;
Gtk::CheckButton m_check;
Gtk::Entry m_entry;
Gtk::VBox *PtrPage1Vbox;
};
===
sample glade file
===
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkAssistant" id="assistant1">
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label" translatable="yes">Introduction page</property>
</object>
<packing>
<property name="page_type">intro</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="label" translatable="yes">Content page</property>
</object>
</child>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="label" translatable="yes">Confirmation page</property>
</object>
<packing>
<property name="page_type">confirm</property>
</packing>
</child>
</object>
</interface>
=====
On Wed, Mar 9, 2011 at 6:36 AM, Murray Cumming
<murrayc murrayc com> wrote:
On Wed, 2011-03-09 at 06:11 -0500, Josh Sinykin wrote:
> The assistant will not draw the containers defined the original way I had intended. Ie. Make the glade. The. Load it. And tell it to show.
>
> Even if you open glade and drop an assistant it fills in some sample labels onto pages. If you take this glade file and load it with the builder example pointed to this file the assistant will not draw the pages.
Sorry. I can't understand that clearly. Maybe you could make a small
complete test case. It might be a GtkBuilder problem rather than a
Gtk::Builder problem, but a test case would help us to figure that out.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]