示例#1
0
void MainWindow::run(Glib::RefPtr<Gtk::Application> app)
{   
    Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create();

	try{
 	   builder->add_from_resource("/nethogs_gui/window.glade");
	}
	catch(Gtk::BuilderError const& e){
		std::cout << e.what() << std::endl;
		return;
	}
	try{
		builder->add_from_resource("/nethogs_gui/headerbar.ui");
	}
	catch(Gtk::BuilderError const& e){
		std::cout << e.what() << std::endl;
		return;
	}
	
	//get widgets
	m_window = loadWiget<Gtk::ApplicationWindow>(builder, "main_window");
	m_p_status_label_1 = loadWiget<Gtk::Label>(builder, "status_label_1");
	m_p_status_label_2 = loadWiget<Gtk::Label>(builder, "status_label_2");
	m_p_status_label_3 = loadWiget<Gtk::Label>(builder, "status_label_3");
	m_p_status_label_4 = loadWiget<Gtk::Label>(builder, "status_label_4");
	
	std::shared_ptr<Gtk::TreeView>  tree_view = loadWiget<Gtk::TreeView>(builder, "treeview");
	std::shared_ptr<Gtk::HeaderBar> pheaderbar = loadWiget<Gtk::HeaderBar>(builder, "headerbar");
		
	//set title bar
	m_window->set_titlebar(*pheaderbar);
		
	//Create the Tree model
	 m_list_store = m_tree_data.createListStore(); 
	 assert(m_list_store);
	tree_view->set_model(m_list_store);
	m_tree_data.setTreeColumns(tree_view.get());
	
	//Connect signals
	m_window->signal_realize().connect(std::bind(&MainWindow::onLoaded, this));
	m_window->signal_delete_event().connect(sigc::mem_fun(this,&MainWindow::onClosed));
	m_window->signal_show().connect(sigc::mem_fun(this,&MainWindow::onShow));
	
	//add actions
	app->add_action("about", sigc::mem_fun(this,&MainWindow::onAction_About));
	app->add_action("quit",  sigc::mem_fun(this,&MainWindow::onAction_Quit));
		
	app->run(*m_window);
}
示例#2
0
Tab_OpenFile::Tab_OpenFile(BaseObjectType *obj,
	const Glib::RefPtr<Gtk::Builder>& refBuilder)
	:	Gtk::Box(obj),
		refBuilder(refBuilder)
{
	Glib::RefPtr<Gio::SimpleActionGroup> refActionGroup =
		Gio::SimpleActionGroup::create();
	refActionGroup->add_action("open", sigc::mem_fun(this, &Tab_OpenFile::on_open));
	this->insert_action_group("tab_openfile", refActionGroup);
}
示例#3
0
Gtk::MenuBar* MainWindow::createMenu()
{
    Glib::RefPtr<Gio::SimpleActionGroup> actionGroup;
    actionGroup = Gio::SimpleActionGroup::create();

    actionGroup->add_action(
        "about",
        sigc::mem_fun(m_about, &About::open));

    actionGroup->add_action(
        "sources",
        sigc::mem_fun(m_library, &Library::openSourcesDialog));

/*
    actionGroup->add_action(
        "selectAll",
        sigc::mem_fun(m_photoView, &PhotoView::selectAll));
*/

    insert_action_group("fotofing", actionGroup);

    m_refBuilder = Gtk::Builder::create();

    Glib::ustring ui_info =
        "<interface>"
        "  <menu id='main-menu'>"
        "    <submenu>"
        "      <attribute name='label' translatable='yes'>_File</attribute>"
        "        <section>"
        "          <item>"
        "            <attribute name='label' translatable='yes'>_Import Index</attribute>"
        "            <attribute name='action' translatable='yes'>fotofing.importindex</attribute>"
        "          </item>"
        "        </section>"
        "        <section>"
        "          <item>"
        "            <attribute name='label' translatable='yes'>_Sources...</attribute>"
        "            <attribute name='action' translatable='yes'>fotofing.sources</attribute>"
        "          </item>"
        "        </section>"
        "    </submenu>"
        "    <submenu>"
        "      <attribute name='label' translatable='yes'>_Edit</attribute>"
        "        <section>"
        "          <item>"
        "            <attribute name='label' translatable='yes'>Select _All</attribute>"
        "            <attribute name='action' translatable='yes'>fotofing.selectAll</attribute>"
        "            <attribute name='accel'>&lt;Primary&gt;a</attribute>"
        "          </item>"
        "        </section>"
        "        <section>"
        "          <item>"
        "            <attribute name='label' translatable='yes'>Preferences</attribute>"
        "            <attribute name='action' translatable='yes'>fotofing.preferences</attribute>"
        "          </item>"
        "        </section>"
        "    </submenu>"
        "    <submenu>"
        "      <attribute name='label' translatable='yes'>_Help</attribute>"
        "        <section>"
        "          <item>"
        "            <attribute name='label' translatable='yes'>About</attribute>"
        "            <attribute name='action' translatable='yes'>fotofing.about</attribute>"
        "          </item>"
        "        </section>"
        "    </submenu>"
        "  </menu>"
        "</interface>";

    m_refBuilder->add_from_string(ui_info);

    Glib::RefPtr<Glib::Object> object = m_refBuilder->get_object("main-menu");
    Glib::RefPtr<Gio::Menu> gmenu = Glib::RefPtr<Gio::Menu>::cast_dynamic(object);

    return Gtk::manage(new Gtk::MenuBar(gmenu));
}