File: entry_completion.rb

package info (click to toggle)
ruby-gnome2 3.1.0-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 16,072 kB
  • ctags: 17,433
  • sloc: ansic: 93,621; ruby: 62,273; xml: 335; sh: 246; makefile: 25
file content (56 lines) | stat: -rw-r--r-- 1,334 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Copyright (c) 2015-2016 Ruby-GNOME2 Project Team
# This program is licenced under the same licence as Ruby-GNOME2.
#
=begin
= Entry/Entry Completion

GtkEntryCompletion provides a mechanism for adding support for
completion in GtkEntry.
=end
class EntryCompletionDemo
  def initialize(main_window)
    @window = Gtk::Window.new(:toplevel)
    @window.screen = main_window.screen
    @window.title = "Entry Completion"
    @window.resizable = true

    vbox = Gtk::Box.new(:vertical, 5)
    @window.add(vbox)
    vbox.border_width = 5

    label = Gtk::Label.new
    markup = "Completion demo, try writing <b>total</b> or <b>gnome</b> for example."
    label.markup = markup
    vbox.pack_start(label, :expand => false, :fill => false, :padding => 0)

    entry = Gtk::Entry.new
    vbox.pack_start(entry, :expand => false, :fill => false, :padding => 0)

    completion = Gtk::EntryCompletion.new
    entry.completion = completion

    completion.model = create_completion_model
    completion.text_column = 0
  end

  def run
    if !@window.visible?
      @window.show_all
    else
      @window.destroy
    end
    @window
  end

  private

  def create_completion_model
    store = Gtk::ListStore.new(String)
    %w(GNOME total totally).each do |word|
      iter = store.append
      iter[0] = word
    end

    store
  end
end