Module: Gtk2AppLib::Widgets

Includes:
Missing
Included in:
Menu
Defined in:
lib/gtk2applib/widgets/core.rb,
lib/gtk2applib.rb,
lib/gtk2applib/widgets/menu.rb,
lib/gtk2applib/widgets/fixed.rb,
lib/gtk2applib/widgets/label.rb,
lib/gtk2applib/widgets/button.rb,
lib/gtk2applib/widgets/evented.rb,
lib/gtk2applib/widgets/text_view.rb,
lib/gtk2applib/widgets/composite.rb,
lib/gtk2applib/widgets/combo_box.rb,
lib/gtk2applib/widgets/cached_image.rb,
lib/gtk2applib/widgets/check_button.rb,
lib/gtk2applib/widgets/toggle_button.rb,
lib/gtk2applib/widgets/on_off_button.rb,
lib/gtk2applib/widgets/combo_box_entry.rb,
lib/gtk2applib/widgets/standard_widgets.rb,
lib/gtk2applib/widgets/fixed_interpreter.rb

Overview

TODO

Defined Under Namespace

Classes: Button, CachedImage, CheckButton, ComboBox, ComboBoxEntry, Fixed, FixedInterpreter, Label, Menu, OnOffButton, TextView, ToggleButton

Constant Summary

Constant Summary

Constants included from Missing

Missing::REQUIRES

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Missing

missing

Instance Attribute Details

- (Object) hold

Returns the value of attribute hold



148
149
150
# File 'lib/gtk2applib/widgets/core.rb', line 148

def hold
  @hold
end

- (Object) is

Returns the value of attribute is



148
149
150
# File 'lib/gtk2applib/widgets/core.rb', line 148

def is
  @is
end

- (Object) options

Returns the value of attribute options



148
149
150
# File 'lib/gtk2applib/widgets/core.rb', line 148

def options
  @options
end

Class Method Details

+ (Object) _each(parameters, method)



121
122
123
# File 'lib/gtk2applib/widgets/core.rb', line 121

def self._each(parameters, method)
  parameters.each { |state, color| method.call(state, color) }
end

+ (Object) autoloads



108
109
110
111
112
# File 'lib/gtk2applib.rb', line 108

def self.autoloads
  Widgets.autoloads_buttons
  Widgets.autoloads_texts
  Widgets.autoloads_others
end

+ (Object) autoloads_buttons



87
88
89
90
91
92
# File 'lib/gtk2applib.rb', line 87

def self.autoloads_buttons
  autoload :Button, 'gtk2applib/widgets/button'
  autoload :CheckButton, 'gtk2applib/widgets/check_button'
  autoload :ToggleButton, 'gtk2applib/widgets/toggle_button'
  autoload :OnOffButton, 'gtk2applib/widgets/on_off_button'
end

+ (Object) autoloads_others



101
102
103
104
105
# File 'lib/gtk2applib.rb', line 101

def self.autoloads_others
  autoload :CachedImage, 'gtk2applib/widgets/cached_image'
  autoload :Fixed, 'gtk2applib/widgets/fixed'
  autoload :FixedInterpreter, 'gtk2applib/widgets/fixed_interpreter'
end

+ (Object) autoloads_texts



94
95
96
97
98
99
# File 'lib/gtk2applib.rb', line 94

def self.autoloads_texts
  autoload :ComboBox, 'gtk2applib/widgets/combo_box'
  autoload :ComboBoxEntry, 'gtk2applib/widgets/combo_box_entry'
  autoload :Label, 'gtk2applib/widgets/label'
  autoload :TextView, 'gtk2applib/widgets/text_view'
end

+ (Strng) define(clss, sprclss = clss)

Generates code for the constructor of a Gtk2AppLib::Widget widget.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gtk2applib/widgets/standard_widgets.rb', line 12

def self.define(clss, sprclss=clss)
  Widgets.symbol_check(clss, sprclss)
  # This enforces the expected api
  code = <<-EOT
  # TODO
  class #{clss} < Gtk::#{sprclss}
    include Widgets
  end
  EOT
  eval(code)
end

+ (String) define_composite(clss, sprclss, hbox = :HBox)

Generates the code of a Composite class



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gtk2applib/widgets/composite.rb', line 11

def self.define_composite(clss, sprclss, hbox=:HBox)
  Widgets.symbol_check(clss, sprclss, hbox)
  clss_to_s_downcase = clss.to_s.downcase
  code = <<-EOT
  # TODO
  class #{clss}#{sprclss} < #{sprclss}
    include Widgets
    attr_reader :#{clss_to_s_downcase}, :#{hbox.to_s.downcase}
    def initialize(*parameters2,&block)
      parameters1 = (parameters2.first.class == Array)?
        parameters2.shift: []
      container, parameters2, signals = Widgets.get_options(parameters2)
      widgets_container = #{hbox}.new(container)
      parameters1.push(widgets_container)
      @#{clss_to_s_downcase} = #{clss}.new(*parameters1,&block)
      parameters2.push(widgets_container)
      super(*(parameters2+signals),&block)
    end
  end
  EOT
  eval(code)
end

+ (String) define_evented(clss)

Generates to code for an Evented class



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
# File 'lib/gtk2applib/widgets/evented.rb', line 9

def self.define_evented(clss)
  Widgets.symbol_check(clss)
  # The first parameter is significant to the super class unless it's a
  # container.  Here only the first container is valid for event box and
  # any others are discarded.  Other than first parameter, Strings are
  # assumed to be signals.
  code = <<-EOT
  # TODO
  class Evented#{clss} < #{clss}
    def initialize(*parameters,&block)
      container, options, signals = Widgets.get_options(parameters)
      @container = EventBox.new(container,*signals,&block)
      parameters.push(@container)
      super(*options)
    end

    def is
      @container.is
    end
    def is=(value)
      @container.is=value
    end
  end
  EOT
  eval(code)
end

+ (Object) execute(method, parameters)



125
126
127
128
129
130
131
132
133
134
# File 'lib/gtk2applib/widgets/core.rb', line 125

def self.execute(method, parameters)
  clss = parameters.class
  if clss == Array then
    method.call(*parameters)
  elsif clss == Hash then
    Widgets._each(parameters, method)
  else
    method.call(parameters)
  end
end

+ (Object) get_options(parameters, *options)



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/gtk2applib/widgets/core.rb', line 58

def self.get_options(parameters, *options)
  container, signals = nil, []
  parameters.each do |parameter|
    if parameter.kind_of?(Hash)
      options.push(parameter)
    elsif container.nil? && parameter.kind_of?(Gtk::Container)
      container = parameter
    else
      # but might be something else
      signals.push(parameter) unless signals.include?(parameter)
    end
  end
  return container, options, signals
end

+ (Object) method_missing(missing, *arguments, &block)



123
124
125
# File 'lib/gtk2applib.rb', line 123

def self.method_missing(missing, *arguments, &block)
  Missing.missing(missing, self, arguments, block) { super }
end

+ (Object) pack(container, widget)

Creates a high level abstraction for packs so that the implementation can always call widget.into(container) and have the correct pack method called... :pack, :pack_start, :pack_end



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/gtk2applib/widgets/core.rb', line 108

def self.pack(container, widget)
  options=widget.options
  if container.respond_to?(:pack_start) then # it also responds to pack_end
    if pack_end = options[:pack_end] then
      container.pack_end(widget, *pack_end)
    else # pack_start parameters must be there
      container.pack_start(widget, *options[:pack_start])
    end
  else # container must define a pack
    container.pack(widget, *options[:pack])
  end
end

+ (Object) symbol_check(*symbols)



3
4
5
# File 'lib/gtk2applib/widgets/standard_widgets.rb', line 3

def self.symbol_check(*symbols)
  symbols.each { |symbol| raise ':P' unless symbol.class == Symbol }
end

+ (Object) widgets



114
115
116
117
118
119
120
121
# File 'lib/gtk2applib.rb', line 114

def self.widgets
  require 'gtk2applib/widgets/core'
  require 'gtk2applib/widgets/standard_widgets'
  # These have to be called after core b/c
  # their parent class is created there
  require 'gtk2applib/widgets/menu'
  Widgets.autoloads
end

Instance Method Details

- (Object) class_symbol



17
18
19
# File 'lib/gtk2applib/widgets/core.rb', line 17

def class_symbol
  self.class.to_s.split(/\W+/).last.to_sym
end

- (Object) common(parameters, block = nil, &blck)

Interpreter of the constructor parameters, Determines the container, signals, and options. Connects to signals. Invokes methods listed in options. Packs self into container.



176
177
178
179
180
181
# File 'lib/gtk2applib/widgets/core.rb', line 176

def common(parameters, block=nil, &blck)
  container, options, signals = Widgets.get_options(parameters)
  set_signals(signals, block, &blck) if block || blck
  set_options(options)
  Widgets.pack(container, self) if container
end

- (Object) connect(signal, block)

Connects the widget to a signal



96
97
98
99
100
101
# File 'lib/gtk2applib/widgets/core.rb', line 96

def connect(signal, block)
  is = nil
  self.signal_connect(signal) { |*emits|
    block.call(is, signal, *emits) if is = self.is
  }
end

- (Object) execute(options = self.options)

Iterates through the options calling on each method keyed for



139
140
141
142
143
144
145
146
# File 'lib/gtk2applib/widgets/core.rb', line 139

def execute(options=self.options)
  options.each do |method, parameters|
    next if [:pack, :pack_start, :pack_end].include?(method)
    if self.respond_to?(method) then
      Widgets.execute(self.method(method), parameters)
    end
  end
end

- (Widgets) initialize(*parameters, &block)



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
# File 'lib/gtk2applib/widgets/core.rb', line 21

def initialize(*parameters, &block)
  parameters = Parameters.map(
    parameters+[self.class_symbol, :Widgets])
  first = parameters.shift
  begin
    case first
    when Array then super(*first)
    when Symbol then super(first)
    when String
      begin
        super(first)
      rescue Exception
        super()
        self.set_text(first)
      end
    when  Gtk::Image, Gdk::Pixbuf, Gdk::PixbufAnimation
      super()
      begin
        initialize_image(first)
      rescue NoMethodError
        self.set_image(Gtk::Image.new(first))
      end
    else
      super()
      raise # did not use first
    end
  rescue RuntimeError, NoMethodError
    parameters.unshift(first)
#     rescue Exception
#       $stderr.puts first.class
#       $stderr.puts first
#       $stderr.puts parameters
#       raise $!
  end
  self.common(parameters, block)
end

- (Object) initialize_image(first)



6
7
8
9
10
11
12
13
14
15
# File 'lib/gtk2applib/widgets/core.rb', line 6

def initialize_image(first)
  case first
  when Gtk::Image
    self.set_image(first)
  when Gdk::Pixbuf
    self.set_pixbuf(first)
  when Gdk::PixbufAnimation
    self.set_pixbuf_animation(first)
  end
end

- (Object) pack(obj, *dummies)

Creates a pack abstraction for :append_page, :add_with_viewport, and :add so that the implemention can always call container.pack(widget). It supports the higher abstraction widget.into(container).



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/gtk2applib/widgets/core.rb', line 78

def pack(obj, *dummies)
  if self.respond_to?(:append_page) then
    if hold = self.hold then # hold defined / used here only
      self.append_page(hold, obj)
      self.hold = nil
    else
      self.hold = obj
    end
  elsif self.respond_to?(:add_with_viewport) then
    self.add_with_viewport(obj)
  else
    self.add(obj)
  end
end

- (Object) set_options(options)



161
162
163
164
165
# File 'lib/gtk2applib/widgets/core.rb', line 161

def set_options(options)
  self.options = KeyValues.new(*options)
  self.execute # execute uses self.options
  self.is = self
end

- (Object) set_signals(signals, block, &blck)



150
151
152
153
154
155
156
157
158
159
# File 'lib/gtk2applib/widgets/core.rb', line 150

def set_signals(signals, block, &blck)
  signals.each do |parameter|
    if block && parameter.kind_of?(String)
      self.connect(parameter, block)
    elsif blck
      # well.. I don't know what to do with this, so spit it back
      blck.call(parameter)
    end
  end
end