GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Apr 21, 2014 2:20 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Problems with Gtk::Window::activate_default() on gtkmm
PostPosted: Sun Aug 12, 2012 7:27 pm 
Offline
Familiar Face

Joined: Sun Aug 12, 2012 7:11 pm
Posts: 5
Hello.

I'm writing a program on Ubuntu using gtkmm-3.0 and am having a problem with the method activate_default()

There is a window with an Gtk::Entry with set_activates_default(1) called, but even if I press Enter with the focus on this entry, the function activate_default() I wrote isn't called.

I don't understand why it isn't working. I already used it on 4 diferent windows I programmed, and it works fine on them.

I'm calling set_activates_default(1) on line 51 of "PackageManager.cpp".

Thanks a lot for the help.

PackageManager.hpp
Code:
#ifndef PackageManager_HPP
#define PackageManager_HPP

class PackageManager;

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

#include "ThumbnailWidget.hpp"
#include "TreeView_Tag_Package_Manager.hpp"
#include "TagListOnPackage.hpp"
#include "ExampleWindow.hpp"

using namespace std;

class PackageManager : public Gtk::Window
{
   public:
      ExampleWindow* window;
   
   private:
      Gtk::HBox main_hbox;
      Gtk::HBox name_hbox;
      Gtk::HBox files_hbox;
      
      Gtk::VBox name_files_vbox;
      Gtk::VBox outside_files_vbox;
      Gtk::VBox inside_files_vbox;
      Gtk::VBox file_buttons_vbox;
      Gtk::VBox file_buttons_shrink_vbox;
      Gtk::VBox tags_buttons_vbox;
      
      Gtk::ScrolledWindow all_tags_scroll;
      ThumbnailWidget* outside_files_scroll;
      ThumbnailWidget* inside_files_scroll;
      Gtk::ScrolledWindow package_tags_scroll;
      
      Gtk::Button enter_package_button;
      Gtk::Button leave_package_button;
      Gtk::Button track_new_file_button;
      Gtk::Button done_button;
      Gtk::Button cancel_button;
      
      Gtk::Entry name_entry;
      Gtk::Entry search_entry;
      
      Gtk::Label name_label;
      
      TreeView_Tag_Package_Manager* all_tags_treeview;
      TagListOnPackage* tags_treeview;
   
   public:
      PackageManager(ExampleWindow* new_win);
   
   private:
      void activate_default();
};

#endif


PackageManager.cpp
Code:
#include "PackageManager.hpp"

PackageManager::PackageManager(ExampleWindow* new_win)
{
   set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
   set_title("Package manager");
   set_size_request(900,400);
   set_resizable(0);
   
   window = new_win;
   
   add(main_hbox);
   {
      main_hbox.set_margin_top(10);
      main_hbox.set_margin_left(10);
      main_hbox.set_margin_right(10);
      main_hbox.set_margin_bottom(10);
      
      main_hbox.pack_start(all_tags_scroll,Gtk::PACK_EXPAND_WIDGET);
      {
         all_tags_scroll.set_size_request(150,-1);
         
         all_tags_treeview = new TreeView_Tag_Package_Manager();
         all_tags_scroll.add(*all_tags_treeview);
         {
            all_tags_treeview->window = window;
            all_tags_treeview->fill();
         }
      }
      
      main_hbox.pack_start(name_files_vbox,Gtk::PACK_EXPAND_WIDGET,20);
      {
         name_files_vbox.pack_start(name_hbox,Gtk::PACK_SHRINK,20);
         {
            name_hbox.pack_start(name_label,Gtk::PACK_SHRINK,20);
            {
               name_label.set_text("Package name:");
            }
            
            name_hbox.pack_start(name_entry);
         }
         
         name_files_vbox.pack_start(files_hbox,Gtk::PACK_EXPAND_WIDGET);
         {
            files_hbox.pack_start(outside_files_vbox,Gtk::PACK_EXPAND_WIDGET);
            {
               outside_files_vbox.set_size_request(150,-1);
               
               outside_files_vbox.pack_start(search_entry,Gtk::PACK_SHRINK);
               {
                  search_entry.set_max_length(100);
                  search_entry.set_activates_default(1);
               }
               
               outside_files_scroll = new ThumbnailWidget();
               outside_files_vbox.pack_start(*outside_files_scroll);
               {
                  outside_files_scroll->size_limit = 100;
                  outside_files_scroll->label_width_limit = 20;
               }
            }
            
            files_hbox.pack_start(file_buttons_vbox,Gtk::PACK_SHRINK,10);
            {
               file_buttons_vbox.pack_start(file_buttons_shrink_vbox,Gtk::PACK_EXPAND_PADDING);
               {
                  file_buttons_shrink_vbox.pack_start(enter_package_button,Gtk::PACK_SHRINK,10);
                  {
                     enter_package_button.set_label(">");
                     enter_package_button.set_size_request(50,50);
                  }
                  
                  file_buttons_shrink_vbox.pack_start(leave_package_button,Gtk::PACK_SHRINK,10);
                  {
                     leave_package_button.set_label("<");
                     leave_package_button.set_size_request(50,50);
                  }
               }
            }
            
            files_hbox.pack_start(inside_files_vbox,Gtk::PACK_EXPAND_WIDGET);
            {
               inside_files_vbox.set_size_request(150,-1);
               
               inside_files_vbox.pack_start(track_new_file_button,Gtk::PACK_SHRINK);
               {
                  track_new_file_button.set_label("Track new file");
               }
               
               inside_files_scroll = new ThumbnailWidget();
               inside_files_vbox.pack_start(*inside_files_scroll);
            }
         }
      }
      
      main_hbox.pack_start(tags_buttons_vbox);
      {
         tags_buttons_vbox.pack_start(package_tags_scroll);
         {
            tags_treeview = new TagListOnPackage();
            package_tags_scroll.add(*tags_treeview);
         }
         
         tags_buttons_vbox.pack_start(done_button,Gtk::PACK_SHRINK,10);
         {
            done_button.set_label("Done");
         }
         
         tags_buttons_vbox.pack_start(cancel_button,Gtk::PACK_SHRINK);
         {
            cancel_button.set_label("Cancel");
         }
      }
   }
   
   show_all_children();
}

void PackageManager::activate_default()
{
   cout << search_entry.get_text() << '\n';
}


Top
 Profile  
 
 Post subject: Re: Problems with Gtk::Window::activate_default() on gtkmm
PostPosted: Sun Aug 12, 2012 10:53 pm 
Offline
Familiar Face

Joined: Sun Aug 12, 2012 7:11 pm
Posts: 5
I managed to solve the problem by connecting the signal manualy, by adding the following line:

Code:
search_entry.signal_activate().connect(sigc::mem_fun(*this,&PackageManager::activate_default));


But I still don't understand why it wasn't working before. If anybody knows the reason, please tell me.

Thanks.


Top
 Profile  
 
 Post subject: Re: Problems with Gtk::Window::activate_default() on gtkmm
PostPosted: Mon Aug 13, 2012 5:57 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 709
Location: UK
Hi

I think your original problem was that you did not declare your call back as a virtual method. Therefore only the top level class had access to it and none of the lower level classes could see it to call it as a call-back.

As as a note since you are using gtkmm v3. Avoid using Gtk::HBox and Gtk::VBox as these are now deprecated and also do not use Gtk::Box as this will also soon be deprecated. Use Gtk::Grid instead.

_________________
E.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group