ExampleWindow::ExampleWindow(regex_key_value ®x) : m_Box(Gtk::ORIENTATION_VERTICAL),m_VBox(Gtk::ORIENTATION_VERTICAL),m_HBox(Gtk::ORIENTATION_VERTICAL), m_frame("Data from file :"),o_frame("Output from file :"),m_Alignment(Gtk::ALIGN_END, Gtk::ALIGN_CENTER, 1.0, 0.0) { set_title("Key Value Extraction"); set_default_size(800, 600); set_position(Gtk::WIN_POS_CENTER); add(m_Box); // put a MenuBar at the top of the box and other stuff below it. //Create actions for menus and toolbars: m_refActionGroup = Gtk::ActionGroup::create(); //File|New sub menu: // m_refActionGroup->add(Gtk::Action::create("FileNewStandard", // Gtk::Stock::NEW, "_New", "Create a new file"), // sigc::mem_fun(*this, &ExampleWindow::on_menu_file_new_generic)); m_refActionGroup->add(Gtk::Action::create("FileNewStandard", Gtk::Stock::EXECUTE, "_New", "Output"), sigc::mem_fun(*this, &ExampleWindow::on_button_output_click)); //file menu subgroups // m_refActionGroup->add(Gtk::Action::create("FileNewFoo", // Gtk::Stock::NEW, "New Foo", "Create a new foo"), // sigc::mem_fun(*this, &ExampleWindow::on_menu_file_new_generic)); // m_refActionGroup->add(Gtk::Action::create("FileNewGoo", // Gtk::Stock::NEW, "_New Goo", "Create a new goo"), // sigc::mem_fun(*this, &ExampleWindow::on_menu_file_new_generic)); //File menu: m_refActionGroup->add(Gtk::Action::create("FileMenu", "File")); //Sub-menu. //m_refActionGroup->add(Gtk::Action::create("FileNew", Gtk::Stock::NEW)); m_refActionGroup->add(Gtk::Action::create("FileOpen", Gtk::Stock::OPEN, "_Open", "Open File"), sigc::mem_fun(*this, &ExampleWindow::on_menu_folder_open)); m_refActionGroup->add(Gtk::Action::create("FileSave", Gtk::Stock::SAVE, "_Save", "Save File"), sigc::mem_fun(*this, &ExampleWindow::on_menu_others)); // m_refActionGroup->add(Gtk::Action::create("FilePageSetup", Gtk::Stock::PRINT,"Page Setup"), // sigc::mem_fun(*this, &ExampleWindow::on_menu_file_quit)); // m_refActionGroup->add(Gtk::Action::create("FilePrintPreview", Gtk::Stock::PRINT, "Print Preview"), // sigc::mem_fun(*this, &ExampleWindow::on_menu_file_quit)); // m_refActionGroup->add(Gtk::Action::create("FilePrint", // Gtk::Stock::PRINT,"_Print","Print"), // sigc::mem_fun(*this, &ExampleWindow::on_menu_others)); m_refActionGroup->add(Gtk::Action::create("FileQuit", Gtk::Stock::QUIT, "_Quit","Quit"), sigc::mem_fun(*this, &ExampleWindow::on_menu_file_quit)); //m_refActionGroup->add(Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), //sigc::mem_fun(*this, &ExampleWindow::on_menu_file_quit)); //Edit menu: // m_refActionGroup->add(Gtk::Action::create("EditMenu", "Edit")); // m_refActionGroup->add(Gtk::Action::create("EditCut", Gtk::Stock::CUT), // sigc::mem_fun(*this, &ExampleWindow::on_menu_others)); // m_refActionGroup->add(Gtk::Action::create("EditCopy", Gtk::Stock::COPY), // sigc::mem_fun(*this, &ExampleWindow::on_menu_others)); // m_refActionGroup->add(Gtk::Action::create("EditPaste", Gtk::Stock::PASTE), // sigc::mem_fun(*this, &ExampleWindow::on_menu_others)); // m_refActionGroup->add(Gtk::Action::create("EditUndo", Gtk::Stock::UNDO), // sigc::mem_fun(*this, &ExampleWindow::on_menu_others)); // m_refActionGroup->add(Gtk::Action::create("EditRedo", Gtk::Stock::REDO), // sigc::mem_fun(*this, &ExampleWindow::on_menu_others)); // m_refActionGroup->add( Gtk::Action::create("HelpMenu", "More") ); m_refActionGroup->add( Gtk::Action::create("About", Gtk::Stock::ABOUT), sigc::mem_fun(*this, &ExampleWindow::on_menu_about) ); m_refActionGroup->add( Gtk::Action::create("Help", Gtk::Stock::ABOUT,"_Help","Help"), sigc::mem_fun(*this, &ExampleWindow::on_menu_help) ); 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 = "<ui>" " <menubar name='MenuBar'>" " <menu action='FileMenu'>" //" <menu action='FileNew'>" //" <menuitem action='FileNewStandard'/>" //" <menuitem action='FileNewFoo'/>" //" <menuitem action='FileNewGoo'/>" //" </menu>" " <menuitem action='FileOpen'/>" " <menuitem action='FileSave'/>" //" <menuitem action='FilePageSetup'/>" //" <menuitem action='FilePrintPreview'/>" //" <menuitem action='FilePrint'/>" " <menuitem action='FileQuit'/>" " </menu>" //" <menu action='EditMenu'>" //" <menuitem action='EditCut'/>" //" <menuitem action='EditCopy'/>" //" <menuitem action='EditPaste'/>" //" <menuitem action='EditUndo'/>" //" <menuitem action='EditRedo'/>" //" </menu>" " <menu action='HelpMenu'>" " <menuitem action='About'/>" " <menuitem action='Help'/>" " </menu>" " </menubar>" " <toolbar name='ToolBar'>" " <toolitem action='FileNewStandard'/>" " <separator/>" " <toolitem action='FileOpen'/>" " <separator/>" " <toolitem action='FileSave'/>" " <separator/>" // " <toolitem action='FilePrint'/>" " <separator/>" " <toolitem action='FileQuit'/>" " </toolbar>" "</ui>"; try { m_refUIManager->add_ui_from_string(ui_info); } catch(const Glib::Error& ex) { std::cerr << "building menus failed: " << ex.what(); } //Get the menubar and toolbar widgets, and add them to a container widget: Gtk::Widget* pMenubar = m_refUIManager->get_widget("/MenuBar"); if(pMenubar) m_Box.pack_start(*pMenubar, Gtk::PACK_SHRINK); Gtk::Widget* pToolbar = m_refUIManager->get_widget("/ToolBar") ; if(pToolbar) m_Box.pack_start(*pToolbar, Gtk::PACK_SHRINK); show_all_children(); //add the grid for the treeview and button //Add the Notebook, with the button underneath: m_Notebook.set_border_width(10); m_Box.pack_start(m_Notebook); m_Box.pack_start(m_ButtonBox, Gtk::PACK_SHRINK); //m_ButtonBox.pack_start(m_Button_Quit, Gtk::PACK_SHRINK); //m_Button_Quit.signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_quit_click) ); //Add the Notebook pages: m_Notebook.append_page(m_grid, "Regex"); m_Notebook.append_page(m_grid2, "Log File"); m_Notebook.append_page(m_grid3, "Output"); m_Notebook.signal_switch_page().connect(sigc::mem_fun(*this, &ExampleWindow::on_notebook_switch_page) ); add(m_grid); m_grid.set_border_width(20); m_grid.set_row_spacing(5); m_Box.add(m_grid); Gtk::TreeView *treeview = Gtk::manage(new Gtk::TreeView); treeview->set_hexpand(true); treeview->set_vexpand(true); //treeview->get_selection()->set_mode(Gtk::SELECTION_MULTIPLE) ; treeview->set_search_column(columns.col_cnt) ; treeview_ScrolledWindow.add(*treeview) ; //Only show the scrollbars when they are necessary: treeview_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); m_grid.attach(treeview_ScrolledWindow, 0, 0, 3, 1); refTreeModel = Gtk::ListStore::create(columns); treeview->set_model(refTreeModel); treeview->append_column("S.N", columns.col_cnt); treeview->append_column("Datatype", columns.col_text); treeview->append_column("Regex Data", columns.col_text2); label = Gtk::manage(new Gtk::Label); label2 = Gtk::manage(new Gtk::Label); label->set_markup("<b><span color='black'>Enter Datatype: </span></b>"); label2->set_markup("<b><span color='black'>Enter Regex Data: </span></b>"); m_grid.attach(*label, 0, 1, 1, 1); m_grid.attach(*label2, 0, 2, 1, 1); text = Gtk::manage(new Gtk::Entry); m_grid.attach(*text, 1, 1, 2, 1); text2 = Gtk::manage(new Gtk::Entry); m_grid.attach(*text2, 1, 2, 2, 3); Gtk::Button *b_add = Gtk::manage(new Gtk::Button("Click to add")); b_add->signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_add_data_click)); m_grid.attach(*b_add, 2, 8, 1, 1); Gtk::Button *b_remove = Gtk::manage(new Gtk::Button("Click to remove")); b_remove->signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_delete_data_click)); //m_grid.attach(*b_remove, 2, 10, 1, 1); // Gtk::Button *b_output = Gtk::manage(new Gtk::Button("Press here for output")); // b_output->signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_output_click)); // m_grid.attach(*b_output, 2, 10, 1, 1); m_grid.show_all(); add(m_grid2); m_grid2.set_border_width(20); m_grid2.set_row_spacing(5); m_Box.add(m_grid2); label3 = Gtk::manage(new Gtk::Label); label3->set_markup("<b><span color='black'>Open a text file: </span></b>"); m_grid2.attach(*label3, 0, 1, 1, 1); text3 = Gtk::manage(new Gtk::Entry); m_grid2.attach(*text3, 10, 1, 1, 1); Gtk::Button *b_addfile = Gtk::manage(new Gtk::Button("Browse")); b_addfile->signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_menu_folder_open)); m_grid2.attach(*b_addfile, 15, 1, 1, 1); //m_Entry.set_max_length(50); //label2->set_markup("<b><span color='black'>Text file data: </span></b>"); //m_grid2.attach(*label4, 1, 2, 1, 1); add(m_HBox); add(m_Alignment); m_HBox.pack_start(m_VBox); //m_frame.add(m_Label_Normal); m_grid2.attach(m_frame, 0,5,200,100); //label4 = Gtk::manage(new Gtk::Label); //label4->set_markup("<b><span color='black'>The data from text file will appear here. </span></b>"); //m_Entry.set_text("The data from text file"); //m_Entry.set_text(m_Entry.get_text() + " will appear here."); //m_Entry.select_region(0, m_Entry.get_text_length()); //m_grid2.attach(m_Entry, 10, 10, 100, 10); //m_frame.add(*label4); editor = Gtk::manage(new Gtk::TextView) ; editor_buffer = Gtk::TextBuffer::create() ; editor->set_buffer(editor_buffer) ; editor->set_cursor_visible(true) ; editor_ScrolledWindow.add(*editor) ; //Only show the scrollbars when they are necessary: editor_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); m_frame.add(editor_ScrolledWindow) ; m_frame.set_hexpand(true); m_frame.set_vexpand(true); // Gtk::Button *m_Button = Gtk::manage(new Gtk::Button("Output")); // m_Button->signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_output_click)); //m_frame.set_label_align(Gtk::ALIGN_END, Gtk::ALIGN_START); //m_grid2.attach(*m_Button,40,1,20,1); //m_Alignment.add(*m_Button); m_frame.add(m_Alignment); m_frame.set_shadow_type(Gtk::SHADOW_ETCHED_OUT); m_Alignment.show_all(); m_HBox.show_all(); m_grid2.show_all(); //----------------------------------------------------------------------------------- add(m_grid3); m_grid3.set_border_width(20); m_grid3.set_row_spacing(5); m_Box.add(m_grid3); add(m_HBox); add(o_Alignment); m_HBox.pack_start(m_VBox); m_grid3.attach(o_frame, 0,5,200,100); _output = Gtk::manage(new Gtk::TextView) ; _output_buffer = Gtk::TextBuffer::create() ; _output->set_buffer(_output_buffer) ; _output->set_cursor_visible(true) ; _output_ScrolledWindow.add(*_output) ; //Only show the scrollbars when they are necessary: _output_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); o_frame.add(_output_ScrolledWindow) ; o_frame.set_hexpand(true); o_frame.set_vexpand(true); Gtk::Button *analyse_Button = Gtk::manage(new Gtk::Button("Analyse")); analyse_Button->signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_analyse_click)); //o_frame.set_label_align(Gtk::ALIGN_START,Gtk::ALIGN_END); //attach (Widget& child, int left, int top, int width, int height) m_grid3.attach(*analyse_Button,100,110,100,1); o_Alignment.add(*analyse_Button); o_frame.add(o_Alignment); o_frame.set_shadow_type(Gtk::SHADOW_ETCHED_OUT); o_Alignment.show_all(); m_HBox.show_all(); m_grid3.show_all(); //--------------------------------------------------------------------------------------------- reg = ®x ; //reg->readFromFile("regex.tl") ; show_all_children(); rowcount = 0 ; for(; rowcount < reg->get_regex_count();rowcount++){ Gtk::TreeModel::Row row = *(refTreeModel->append()); row[columns.col_cnt] = rowcount; row[columns.col_text] = reg->gettype(rowcount); row[columns.col_text2] = reg->getRegex(rowcount); } }
void on_button_clicked(Gtk::TreeModel::Path path, Gtk::TreeViewColumn* column, Glib::RefPtr<Gtk::TreeModel> model) { Gtk::TreeModel::iterator iter = model->get_iter(path); Gtk::TreeModel::Row row = *iter; string shortname = row[m_columns.name]; string longname = row[m_columns.longname]; BOARD = shortname; LONGBOARD = longname; boardView(); Gtk::TreeView *threadlist = 0; builder->get_widget("treeview2", threadlist); pWebKitView = WEBKIT_WEB_VIEW (webkit_web_view_new ()); Gtk::ScrolledWindow *imgview = 0; builder->get_widget("scrolledwindow3", imgview); imgview->set_visible(true); imgview->show(); gtk_container_add (GTK_CONTAINER (imgview->gobj()), GTK_WIDGET (pWebKitView)); webkit_web_view_load_uri(pWebKitView, "about:blank"); webkit_web_view_set_zoom_level(pWebKitView, true); gtk_widget_set_can_focus(GTK_WIDGET(pWebKitView), true); gtk_widget_show(GTK_WIDGET(pWebKitView)); Glib::RefPtr<Gtk::ListStore> m_threads_tree_model; m_threads_tree_model = Gtk::ListStore::create(m_thread_list); m_threads_tree_model->clear(); threadlist->set_model(m_threads_tree_model); threadlist->set_search_column(1); threadlist->get_column(1)->set_visible(false); threadlist->get_column(2)->set_visible(false); threadlist->get_column(3)->set_visible(false); threadlist->get_column(4)->set_visible(false); threadlist->signal_key_press_event().connect(sigc::bind<Glib::RefPtr<Gtk::ListStore> >(sigc::ptr_fun(&on_key_press_or_release_event), m_threads_tree_model)); threadlist->signal_key_release_event().connect(sigc::bind<Glib::RefPtr<Gtk::ListStore> >(sigc::ptr_fun(&on_key_press_or_release_event), m_threads_tree_model)); threadlist->add_events(Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK); Gtk::CellRendererText* cellRender = dynamic_cast<Gtk::CellRendererText*>(threadlist->get_column_cell_renderer(0)); cellRender->property_wrap_mode() = Pango::WRAP_WORD; cellRender->property_wrap_width() = 400; cellRender->set_alignment(0, 0); Glib::RefPtr<Gtk::TreeSelection> thread_selection = threadlist->get_selection(); thread_selection->signal_changed().connect(sigc::bind<Glib::RefPtr<Gtk::TreeSelection>, WebKitWebView*>(sigc::ptr_fun(&on_selection_changed), thread_selection, pWebKitView)); getThreadData(m_threads_tree_model); threadlist->grab_focus(); Gtk::ToolButton* refresh; builder->get_widget("toolbutton5", refresh); refresh->set_visible(true); refresh->show(); if(!THREAD_REFRESH_CONNECTED) { THREAD_REFRESH_CONNECT = refresh->signal_clicked().connect(sigc::bind<Glib::RefPtr<Gtk::ListStore> >(sigc::ptr_fun(&on_refresh_threads_clicked), m_threads_tree_model)); } THREAD_CLICK_CONNECT = threadlist->signal_row_activated().connect(sigc::bind<Glib::RefPtr<Gtk::TreeModel>, Glib::RefPtr<Gtk::ListStore> >(sigc::ptr_fun(&on_thread_activated), threadlist->get_model(), m_threads_tree_model)); }
void startup(Glib::RefPtr<Gtk::Application> app) { ///To be run at startup GtkSettings *settings; settings = gtk_settings_get_default(); g_object_set (G_OBJECT (settings), "gtk-application-prefer-dark-theme", FALSE, NULL); Gtk::Main kit; builder = Gtk::Builder::create_from_file(DATADIR "/main.glade"); Gtk::Window *window = 0; builder->get_widget("window1", window); window->set_wmclass("org.gtkmm.examples.application", name); window->maximize(); Gtk::TreeView *listview = 0; builder->get_widget("treeview1", listview); Glib::RefPtr<Gtk::ListStore> m_refTreeModel; m_refTreeModel = Gtk::ListStore::create(m_columns); listview->set_model(m_refTreeModel); listview->set_search_column(1); Glib::RefPtr<Gtk::TreeSelection> list_selection = listview->get_selection(); listview->signal_row_activated().connect(sigc::bind<Glib::RefPtr<Gtk::TreeModel> >(sigc::ptr_fun(&on_button_clicked), listview->get_model())); Json::Value json = readFile(getRemoteFile("https://api.4chan.org/boards.json")); Json::Value boards = json["boards"]; for(int i=0;i<boards.size();++i) { Gtk::TreeModel::Row row = *(m_refTreeModel->append()); row[m_columns.name] = "/"+boards[i]["board"].asString()+"/"; row[m_columns.longname] = boards[i]["title"].asString(); } listview->set_rules_hint(true); Gtk::Menu *mainmenu = 0; builder->get_widget("menu1", mainmenu); Gtk::MenuToolButton *toolbut = 0; builder->get_widget("toolbutton2", toolbut); toolbut->set_menu(*mainmenu); Gtk::MenuItem *item1 = 0; builder->get_widget("menuitem1", item1); item1->signal_activate().connect(sigc::ptr_fun(&nameSettingsDialog)); Gtk::CheckMenuItem *hideimages = 0; builder->get_widget("menuitem2", hideimages); hideimages->signal_toggled().connect(sigc::ptr_fun(&on_hide_toggled)); Gtk::MenuItem *item3 = 0; builder->get_widget("menuitem3", item3); item3->signal_activate().connect(sigc::ptr_fun(&open_thread_in_browser)); Gtk::MenuItem *d_image = 0; builder->get_widget("menuitem5", d_image); d_image->signal_activate().connect(sigc::ptr_fun(&saveImageAs)); Gtk::ToolButton *post_but; builder->get_widget("toolbutton8", post_but); post_but->signal_clicked().connect(sigc::ptr_fun(&on_post_button_toggled)); Gtk::Button *post_but2 = 0; builder->get_widget("button4", post_but2); post_but2->signal_clicked().connect(sigc::ptr_fun(&on_post_clicked)); kit.run(*window); }
void on_thread_activated(Gtk::TreeModel::Path path, Gtk::TreeViewColumn* column, Glib::RefPtr<Gtk::TreeModel> model, Glib::RefPtr<Gtk::ListStore> store) { ///To be run when a thread is double clicked Gtk::TreeModel::iterator iter = model->get_iter(path); Gtk::TreeModel::Row row = *iter; string no = row[m_thread_list.no]; THREAD = no; cout << THREAD << endl; cout << BOARD << endl; threadView(); Gtk::TreeView *postlist = 0; builder->get_widget("treeview4", postlist); postlist->set_visible(true); postlist->show(); Gtk::ScrolledWindow *imgview = 0; builder->get_widget("scrolledwindow3", imgview); gtk_container_add (GTK_CONTAINER (imgview->gobj()), GTK_WIDGET (pWebKitView)); webkit_web_view_load_uri(pWebKitView, "about:blank"); webkit_web_view_set_zoom_level(pWebKitView, true); gtk_widget_set_can_focus(GTK_WIDGET(pWebKitView), true); gtk_widget_show(GTK_WIDGET(pWebKitView)); Glib::RefPtr<Gtk::ListStore> m_posts_tree_model; m_posts_tree_model = Gtk::ListStore::create(m_post_list); m_posts_tree_model->clear(); postlist->set_model(m_posts_tree_model); postlist->set_search_column(1); postlist->get_column(1)->set_visible(false); postlist->get_column(2)->set_visible(false); postlist->get_column(3)->set_visible(false); postlist->get_column(4)->set_visible(false); postlist->get_column(5)->set_visible(false); postlist->signal_key_press_event().connect(sigc::bind<Glib::RefPtr<Gtk::ListStore> >(sigc::ptr_fun(&on_key_press_thread), m_posts_tree_model)); postlist->signal_key_release_event().connect(sigc::bind<Glib::RefPtr<Gtk::ListStore> >(sigc::ptr_fun(&on_key_press_thread), m_posts_tree_model)); postlist->add_events(Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK); Gtk::CellRendererText* cellRender = dynamic_cast<Gtk::CellRendererText*>(postlist->get_column_cell_renderer(0)); cellRender->property_wrap_mode() = Pango::WRAP_WORD; cellRender->property_wrap_width() = 400; cellRender->set_alignment(0, 0); Glib::RefPtr<Gtk::TreeSelection> thread_selection = postlist->get_selection(); thread_selection->signal_changed().connect(sigc::bind<Glib::RefPtr<Gtk::TreeSelection>, WebKitWebView*>(sigc::ptr_fun(&on_selection_changed_post), thread_selection, pWebKitView)); getPostData(m_posts_tree_model); postlist->grab_focus(); Gtk::ToolButton* refresh; builder->get_widget("toolbutton6", refresh); refresh->set_visible(true); refresh->show(); POST_REFRESH_CONNECT = refresh->signal_clicked().connect(sigc::bind<Glib::RefPtr<Gtk::ListStore> >(sigc::ptr_fun(&on_refresh_posts_clicked), m_posts_tree_model)); Gtk::ScrolledWindow *postwin = 0; builder->get_widget("scrolledwindow4", postwin); postwin->set_visible(true); postwin->show(); POST_CLICK_CONNECT = postlist->signal_row_activated().connect(sigc::bind<Glib::RefPtr<Gtk::TreeModel>, Glib::RefPtr<Gtk::ListStore> >(sigc::ptr_fun(&on_post_activated1), postlist->get_model(), m_posts_tree_model)); }