Accessing Gtk::ComboBox's popup window

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

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

HTH,
Mathieu

|Gdk.pointer_grab(window, owner_events, event_mask, confine_to, cursor,
time)| 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 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

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

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.

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.