File: style_property.rb

package info (click to toggle)
ruby-gnome2 0.12.0-2sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,820 kB
  • ctags: 7,421
  • sloc: ansic: 61,387; ruby: 17,307; makefile: 85; xml: 35; sql: 13
file content (67 lines) | stat: -rwxr-xr-x 1,574 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
#!/usr/local/bin/ruby
=begin
  style_property.rb - Ruby/GTK sample script.

  Copyright (c) 2004 Ruby-GNOME2 Project Team
  This program is licenced under the same licence as Ruby-GNOME2.

  $Id: style_property.rb,v 1.1 2004/01/25 15:52:38 mutoh Exp $
=end

require 'gtk2'

class MyButton < Gtk::Button
  type_register

  def initialize(label = nil)
    # When type_register() is used.
    # super is equivalent to GLib::Object#initialize.
    super("label" => label)
  end

  install_style_property(GLib::Param::Int.new("foo", # name
					      "Foo", # nick
					      "FOO", # blurb
					      0,     #min 
					      100,   #max
					      5,     #default
					      GLib::Param::READABLE |
					      GLib::Param::WRITABLE)) do |pspec, str|
    p pspec, str
    str.to_i + 10  #return the converted value.
  end

  install_style_property(GLib::Param::Enum.new("bar", # name
					       "Bar", # nick
					       "BAR", # blurb
					       GLib::Type["GdkCursorType"], #Enum type
					       Gdk::Cursor::ARROW, #default
					       GLib::Param::READABLE |
					       GLib::Param::WRITABLE)) do |pspec, str|
    p pspec, str
    if str.strip! == "boat"
      Gdk::Cursor::BOAT
    else
      pspec.default
    end
  end
end

Gtk.init

Gtk::RC.parse("./style_property.rc")

win = Gtk::Window.new
b = MyButton.new("Hello")
b.signal_connect("clicked"){ Gtk.main_quit }

p MyButton.style_properties

win.add(b).show_all

# You need to call them after "Gtk::Widget#show"
# (Or in expose event).
p b.style_get_property("foo")
p cursor = b.style_get_property("bar")

Gtk.main