File: pickers.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 (71 lines) | stat: -rw-r--r-- 1,800 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Copyright (c) 2015-2016 Ruby-GNOME2 Project Team
# This program is licenced under the same licence as Ruby-GNOME2.
#
=begin
= Pickers

These widgets are mainly intended for use in preference dialogs.
They allow to select colors, fonts, files, directories and applications.
=end
class PickersDemo
  def initialize(main_window)
    @window = Gtk::Window.new(:toplevel)
    @window.screen = main_window.screen
    @window.title = "Pickers"
    @window.border_width = 10

    initialize_grid

    label = generate_label("Color:")
    picker = Gtk::ColorButton.new
    @table.attach(label, 0, 0, 1, 1)
    @table.attach(picker, 1, 0, 1, 1)

    label = generate_label("Font:")
    picker = Gtk::FontButton.new
    @table.attach(label, 0, 1, 1, 1)
    @table.attach(picker, 1, 1, 1, 1)

    label = generate_label("File:")
    picker = Gtk::FileChooserButton.new("Pick a file", :open)
    @table.attach(label, 0, 2, 1, 1)
    @table.attach(picker, 1, 2, 1, 1)

    label = generate_label("Folder:")
    picker = Gtk::FileChooserButton.new("Pick a folder", :select_folder)
    @table.attach(label, 0, 3, 1, 1)
    @table.attach(picker, 1, 3, 1, 1)

    label = generate_label("Mail:")
    picker = Gtk::AppChooserButton.new("x-scheme-handler/mailto")
    picker.set_show_dialog_item(true)
    @table.attach(label, 0, 4, 1, 1)
    @table.attach(picker, 1, 4, 1, 1)
  end

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

  private

  def initialize_grid
    @table = Gtk::Grid.new
    @table.row_spacing = 3
    @table.column_spacing = 10
    @window.add(@table)
  end

  def generate_label(label)
    label = Gtk::Label.new(label)
    label.set_halign(:start)
    label.set_valign(:center)
    label.set_hexpand(true)
    label
  end
end