#include <gtkmm.h>
#include <iostream>

#include "config.h"

#ifdef ENABLE_NLS
#  include <libintl.h>
#endif

Gtk::Window* main_win = 0;

/* For testing propose use the local (not installed) ui file */
/* #define UI_FILE PACKAGE_DATA_DIR"/gtk_test_1/ui/gtk_test_1.ui" */
#define UI_FILE "src/gtk_test_1.ui"

Glib::RefPtr<Gtk::Builder> builder;

Glib::ustring id;
Glib::ustring pass;

Gtk::Entry* idbox = 0;
Gtk::Entry* passbox = 0;

void destroy()
{
exit(0);
}

void debug_on_console()
{
printf("successed debug\n") ;
}

void test()
{
if(idbox)
{
id = idbox->get_text();
}
if(passbox)
{
pass = passbox->get_text();
}
if(id == "1234" && pass == "1234")
{
Gtk::MessageDialog dialog(*main_win,"로그인 성공!",false);
dialog.run();
}
else
{
}
}

int
main (int argc, char *argv[])
{
//pair < int , int > ttwa ;
Gtk::Main kit(argc, argv);

//Load the Glade file and instiate its widgets:
try
{
builder = Gtk::Builder::create_from_file(UI_FILE);
}
catch (const Glib::FileError & ex)
{
std::cerr << ex.what() << std::endl;
return 1;
}
builder->get_widget("main_window", main_win);
builder->get_widget("pwbox", passbox);
builder->get_widget("idbox", idbox);
if (main_win)
{
Gtk::Button* btnexit = 0;
Gtk::Button* btnok = 0;
Gtk::Button* btnclose = 0;
builder->get_widget("btnexit", btnexit);
if(btnexit)
{
btnexit->signal_clicked ().connect(sigc::ptr_fun (&destroy));
}
builder->get_widget("btnlogin", btnok);
if(btnok)
{
btnok->signal_clicked ().connect (sigc::ptr_fun(&test));
}
kit.run(*main_win);
}
return 0;
}

void testing()
{
printf("TEST");
}

Glade의 도움을 받아 UI를 작성하고 코드에서 불러오는 형태이다.

위에 나온거처럼 signal_type().connect(sigc::ptr_fun(&함수이름)); 의 형식으로 시그널과 함수를 이어주는 역활을 한다. 근데 이상하게 인자값이 존재하는 함수를 해봤을땐 에러가 나서 어떻게 값을 주고받지...하고 고민하다가 결국 Gtk::Entry와 Glib::ustring(Entry에서 텍스트를 뽑아오는 함수 get_text()의 리턴값이 Glib::ustring 이다)을 전역변수로 사용하는 길을 택했다.

기능은 login버튼을 눌렀을때 맨위 상자에 1234, 두번째 상자에도 1234라는 값이 있으면 다이얼로그를 띄우는 형식이다.

'프로그래밍 > Gtk+/binding gtk' 카테고리의 다른 글

본격 Gtk에서 Cairo 사용하기  (0) 2011.11.15
gtkmm! Anjuta!  (0) 2011.11.02
gtkbuilder의 사용  (0) 2011.06.09

설정

트랙백

댓글