From f7cfc39c07d0cf872559f9716643491b8d79de75 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Mon, 25 May 2009 18:12:41 +0200 Subject: Incorporate grapher widget in real application * grapher/grapher.cxx (GrapherWindow): New class. (main): Instantiate GrapherWindow. --- grapher/grapher.cxx | 89 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 11 deletions(-) (limited to 'grapher/grapher.cxx') diff --git a/grapher/grapher.cxx b/grapher/grapher.cxx index 4f9ccae8..b7292cfd 100644 --- a/grapher/grapher.cxx +++ b/grapher/grapher.cxx @@ -1,40 +1,107 @@ #include "GraphWidget.hxx" #include "StapParser.hxx" +#include #include +#include +#include #include #include #include +#include +#include #include #include #include #include +#include +#include +#include using namespace systemtap; +class GrapherWindow : public Gtk::Window +{ +public: + GrapherWindow(); + virtual ~GrapherWindow() {} + Gtk::VBox m_Box; + GraphWidget w; +protected: + virtual void on_menu_file_quit(); + // menu support + Glib::RefPtr m_refUIManager; + Glib::RefPtr m_refActionGroup; + +}; + +GrapherWindow::GrapherWindow() +{ + set_title("systemtap grapher"); + add(m_Box); + w.setExtents(0.0, 1.0, 5.0, 0.0); + w.setLineWidth(2); + + + + //Create actions for menus and toolbars: + m_refActionGroup = Gtk::ActionGroup::create(); + //File menu: + m_refActionGroup->add(Gtk::Action::create("FileMenu", "File")); + m_refActionGroup->add(Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), + sigc::mem_fun(*this, &GrapherWindow::on_menu_file_quit)); + m_refUIManager = Gtk::UIManager::create(); + m_refUIManager->insert_action_group(m_refActionGroup); + + add_accel_group(m_refUIManager->get_accel_group()); + //Layout the actions in a menubar and toolbar: + Glib::ustring ui_info = + "" + " " + " " + " " + " " + " " + ""; + try + { + m_refUIManager->add_ui_from_string(ui_info); + } + catch(const Glib::Error& ex) + { + std::cerr << "building menus failed: " << ex.what(); + } + Gtk::Widget* pMenubar = m_refUIManager->get_widget("/MenuBar"); + if(pMenubar) + m_Box.pack_start(*pMenubar, Gtk::PACK_SHRINK); + m_Box.pack_start(w, Gtk::PACK_EXPAND_WIDGET); + w.show(); + + show_all_children(); + +} +void GrapherWindow::on_menu_file_quit() +{ + hide(); +} + int main(int argc, char** argv) { - Gtk::Main app(argc, argv); + Gtk::Main app(argc, argv); - Gtk::Window win; + GrapherWindow win; - win.set_title("Grapher"); - win.set_default_size(600, 200); + win.set_title("Grapher"); + win.set_default_size(600, 200); - GraphWidget w; - - w.setExtents(0.0, 1.0, 5.0, 0.0); - w.setLineWidth(2); + StapParser stapParser(win, win.w); StapParser stapParser(win, w); Glib::signal_io().connect(sigc::mem_fun(stapParser, &StapParser::ioCallback), 0, Glib::IO_IN); - win.add(w); - w.show(); - Gtk::Main::run(win); return 0; -- cgit