# Accessing Gtk::ComboBox's popup window

**URL:** <https://www.ruby-forum.com/t/accessing-gtk-comboboxs-popup-window/172504>\
**Category:** Ruby-Gnome 2\
**Created:** [July 22, 2009, 2:28pm UTC](https://www.ruby-forum.com/t/accessing-gtk-comboboxs-popup-window/172504 "2009-07-22T14:28:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@Dobai-Pataky\_B](https://www.ruby-forum.com/u/Dobai-Pataky_B)\
**Post date:** [July 22, 2009, 2:28pm UTC](https://www.ruby-forum.com/t/accessing-gtk-comboboxs-popup-window/172504/1 "2009-07-22T14:28:27Z")

</div>

hi,

is there a way to access a ComboBox’s popup window?

i have an Gtk::AccelGroup.connect on the Window holding the ComboBox,  
and i can handle the following situation:  
user presses control-f  
i show a modal window with an entry  
user types text, presses enter  
i refilter the combo using the entry’s text

there are more comboes, user has to focus the combo first, then press  
control-f  
to focus the combo user clicks the combo - that drops down, then user  
clicks the combo for the second time, so the combo hides it’s dropdown,  
but remains focused - then user can press control-f and get the filter  
window for the specific combobox

Target combobox focused:

the filter window active for the Target combobox

and my question is: how can i connect my AccelGroup to the ComboBox’s  
popup window, so user can see click the combobox, press control-f, type  
in the filter, watch the combobox filter it’s rows, press enter to hide  
the filter window, select one row from the popup?

thanks in advice  
balint

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@Dobai-Pataky\_B](https://www.ruby-forum.com/u/Dobai-Pataky_B)\
**Post date:** [July 23, 2009, 3:40am UTC](https://www.ruby-forum.com/t/accessing-gtk-comboboxs-popup-window/172504/2 "2009-07-23T03:40:51Z")

</div>

Hi,

I’m not sure to understand what you’re trying to do but maybe you  
should have a look at Gdk.pointer\_grab and Gdk.keyboard\_grab. Those  
will allow your popup window to receive the events instead of your  
main window. sample/misc/ has an example and you can probably find  
some more using Google code search.

[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gdk](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gdk)

HTH,  
Mathieu

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@Dobai-Pataky\_B](https://www.ruby-forum.com/u/Dobai-Pataky_B)\
**Post date:** [July 23, 2009, 9:56am UTC](https://www.ruby-forum.com/t/accessing-gtk-comboboxs-popup-window/172504/3 "2009-07-23T09:56:00Z")

</div>

|Gdk.pointer\_grab(window, owner\_events, event\_mask, confine\_to, cursor,  
time)| [http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gdk#Gdk.pointer\_grab](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gdk#Gdk.pointer_grab)  
window: the Gdk::Window  
[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gdk%3A%3AWindow](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gdk%3A%3AWindow) which will  
own the grab (the grab window).  
this is my problem, i don’t know how to find the popup window object

i’d need somethinke like: Gtk::ComboBox.popup\_window to be of class  
Gtk::Window

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@Dobai-Pataky\_B](https://www.ruby-forum.com/u/Dobai-Pataky_B)\
**Post date:** [July 23, 2009, 2:22pm UTC](https://www.ruby-forum.com/t/accessing-gtk-comboboxs-popup-window/172504/4 "2009-07-23T14:22:52Z")

</div>

Dobai-Pataky B. wrote:

> hi,
> 
> is there a way to access a ComboBox’s popup window?
> 
> …
> 
> and my question is: how can i connect my AccelGroup to the ComboBox’s  
> popup window, so user can see click the combobox, press control-f, type  
> in the filter, watch the combobox filter it’s rows, press enter to hide  
> the filter window, select one row from the popup?
> 
> thanks in advice  
> balint

I don’t have the answer to your question, but it really seems you do not  
need a combobox.

For a problem similar to yours, I just use a Gtk::Entry and a  
Gtk::EntryCompletion. I think that’s what you are looking for.

Let me know if you want to look at some code.

Simon

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@Dobai-Pataky\_B](https://www.ruby-forum.com/u/Dobai-Pataky_B)\
**Post date:** [July 23, 2009, 2:42pm UTC](https://www.ruby-forum.com/t/accessing-gtk-comboboxs-popup-window/172504/5 "2009-07-23T14:42:28Z")

</div>

i’m using trees and icons on those comboes, i also use them modelled, so  
the value they return is an id which must exist in the databse behind  
it. can Entry do that?  
the missing features of the filtering are not as important as the rest  
of the functionality.

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@Dobai-Pataky\_B](https://www.ruby-forum.com/u/Dobai-Pataky_B)\
**Post date:** [July 24, 2009, 12:07pm UTC](https://www.ruby-forum.com/t/accessing-gtk-comboboxs-popup-window/172504/6 "2009-07-24T12:07:19Z")

</div>

Dobai-Pataky BÃ¡lint wrote:

> i’m using trees and icons on those comboes, i also use them modelled, so  
> the value they return is an id which must exist in the databse behind  
> it. can Entry do that?

I think the EntryCompletion supports tree, not sure about icons.

However, it does not support ids, unfortunately. I read on a Gtk mailing  
list it was a missing widget, Entry with id. But I still managed to curb  
entries to do it. It’s not very clean, but it works.

It looks like that :

class EnumEntry \< SyncedEntry  
attr\_accessor :selected\_id  
def initialize(_args)  
super  
 @selected\_id = nil  
 @changed\_handler = signal\_connect(‘changed’) do |me|  
if me.text =~ /^(\d+) (._)$/ then  
me.selected\_id = $1.to\_i  
me.text = $2  
elsif me.text.strip.empty?  
me.selected\_id = nil  
end  
end  
end  
def update\_id\_and\_text(id, text)  
@selected\_id = id  
update\_text(text)  
end  
def has\_id?  
true  
end  
def update(sample)  
self.update\_id\_and\_text(sample.send((@attribute.to\_s +  
“\_id”).to\_sym), (r = sample.send(@attribute)) == nil ? “” : r.text)  
end  
end

The SyncedEntry is a subclass of Gtk::Entry which provides a few methods  
that I need, nothing related to the problem.  
The update method is because I reuse a lot the entry.

While the entry completion has a special ‘match-selected’ signal.  
class TestCompletion \< Gtk::EntryCompletion  
def initialize(\*args)  
super(\*args)  
self.popup\_set\_width = false  
self.minimum\_key\_length = 3  
self.text\_column = 1  
self.model = Gtk::ListStore.new(Integer, String)  
my\_items.each do |t| # replace my\_items with your data  
row = self.model.append  
row[0] = t[:id]  
row[1] = t[:text]  
end  
signal\_connect(“match-selected”) do |me, model, iter|  
id = model.get\_value(iter, 0).to\_i  
text = model.get\_value(iter, 1)  
me.entry.text = id.to\_s + " " + text  
true  
end  
end  
end

So, when a match is selected, it returns, for example “394 foo”, which  
changes the entry. The entry proceeds to parse and get the id, and leave  
only the text in the entry.
