Re: libglademm example



Em Qui, 2005-05-19 às 08:29 +0200, Johan Kohler escreveu:
> Hi,
> Apologies if this is considered off-topic.  I'm looking for
> the libglademm example mentioned in the online docs (Ch
> 19):
> 
> "The basic example in the libglademm package shows how to
> load a Glade file at runtime and access the widgets with
> libglademm."
> 
> Can anyone give me a url or email one example to me please?
> 
> --Johan
> _____________________________________________________________________
> For super low premiums, click here http://www.dialdirect.co.za/quote
Here is a little programm i'm writting... 
The glade part runs... ;) 
forget the thread parts, don't have nothing with gtk "per se"
Any problem, send me a note
#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H

#include "message_handler.H"

#include <gtkmm.h>
#include <libglademm.h>

#include <queue>

extern message_handler* msg_handler;

class main_window : public Gtk::Window {
private:
	
	/* glade xml description */
	Glib::RefPtr<Gnome::Glade::Xml> gladeXml;
	
	/* widgets */
	Gtk::Button* send_button;
	Gtk::TextView* txt_messages;
	Gtk::TextView* txt_textpad;

	void on_send_button_click();

public:
	main_window();
	virtual ~main_window(){};

	void append_message(Glib::ustring& host, Glib::ustring& message);
};

#endif
#include "message_handler.H"
#include "main_window.H"

#include <glibmm.h>

#include <iostream>

message_handler* msg_handler = 0;
main_window* window = 0;
char* remote_host = 0;

int main(int argc, char** argv)
{
	
	/* checking parameters */
	if (argc > 1)
		remote_host = argv[1];

	/* initializing thread subsystem */
	Glib::thread_init();
	
	/* creating message handlers */
	msg_handler = new message_handler();

	Glib::Thread::
		create(sigc::
					 mem_fun(msg_handler,&message_handler::incomming_handler),false);

	Glib::Thread::
		create(sigc::
					 mem_fun(msg_handler,&message_handler::outgoing_handler),false);

	Glib::Thread::
		create(sigc::mem_fun(msg_handler,&message_handler::listener),false);

	/* initializing GTK */
	Gtk::Main kit(argc,argv);
	window = new main_window();
	kit.run((*window));
	kit.quit();
	return 0;
}
/*
 * Main class for f2rComm.
 * TODO:
 * Better error handling (return errors)
 */

#include "main_window.H"

#include <iostream>

main_window::main_window()
{
	/* loading glade file */
	gladeXml = Gnome::Glade::Xml::create("../glade/f2rcommcpp.glade","mainVBox");

	/* setting main window parameters */
	set_title("f2rComm");
	resize(320,240);
	
	Gtk::VBox* mainVBox = dynamic_cast<Gtk::VBox*>(gladeXml->get_widget("mainVBox"));
	add((*mainVBox));

	/* retrieving widget pointers */
	txt_messages = dynamic_cast<Gtk::TextView*>(gladeXml->get_widget("txtMessages"));
	if (txt_messages == 0){
		std::cerr << "Failure casting Gtk::Widget* to Gtk::TextView* in main" << std::endl;
	}

	txt_textpad = dynamic_cast<Gtk::TextView*>(gladeXml->get_widget("txtTextPad"));
	if (txt_textpad == 0){
		std::cerr << "Failure casting Gtk::Widget* to Gtk::TextView* in main" << std::endl;
	}

	send_button = dynamic_cast<Gtk::Button*>(gladeXml->get_widget("btnSend"));
	if (send_button == 0){
		std::cerr << "Failure casting Gtk::Widget* to Gtk::Button* in main" << std::endl;
	}

	/* messages window is readonly */
	txt_messages->set_editable(false);

	/* connecting callbacks */
	send_button->signal_clicked().connect(sigc::mem_fun((*this),&main_window::on_send_button_click));
	
	/* setting focus on textpad */
	txt_textpad->grab_focus();

}

void main_window::on_send_button_click()
{
	Glib::ustring message = txt_textpad->get_buffer()->get_text();

	/* cleaning textpad */
	txt_textpad->set_buffer(Gtk::TextBuffer::create());
	
	msg_handler->send(message);

	/* appendig to messages window */
	Glib::ustring host = Glib::ustring("local");
	this->append_message(host,message);
}

void main_window::append_message(Glib::ustring& host, Glib::ustring& message)
{
	Glib::ustring msg_buffer = host + ": " + message;
	txt_messages->get_buffer()->
		insert(txt_messages->get_buffer()->end(),msg_buffer + '\n');
}

Attachment: signature.asc
Description: This is a digitally signed message part



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