Class: Interphase::Widget

Inherits:
Object
  • Object
show all
Defined in:
lib/interphase/widgets/basic_widgets.rb

Overview

A basic GTK widget wrapper.

Direct Known Subclasses

Button, Container, Dialog, Entry, Label, ListView, SimpleStatusBar

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gtk_instance, **options, &block) ⇒ Widget

Creates a new widget.

gtk_instance

The GTK widget instance this is wrapping.

name:

This widgets name, allowing it to be referred to after being created.


14
15
16
17
18
19
20
# File 'lib/interphase/widgets/basic_widgets.rb', line 14

def initialize(gtk_instance, **options, &block)
  @gtk_instance = gtk_instance
  @parent = nil
  @name = options[:name]

  instance_eval(&block) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(requested, *args, &block) ⇒ Object

Respond to lookups by name. TODO IMPLEMENT RESPONDS_TO


49
50
51
52
53
54
55
56
57
58
59
# File 'lib/interphase/widgets/basic_widgets.rb', line 49

def method_missing(requested, *args, &block)
  # If any arguments or a block have been given, then this isn't an attr
  if !args.empty? || block_given?
    super
    return
  end

  return self if requested.to_s == name

  super
end

Instance Attribute Details

#gtk_instanceObject

Returns the value of attribute gtk_instance


8
9
10
# File 'lib/interphase/widgets/basic_widgets.rb', line 8

def gtk_instance
  @gtk_instance
end

#nameObject

Returns the value of attribute name


8
9
10
# File 'lib/interphase/widgets/basic_widgets.rb', line 8

def name
  @name
end

#parentObject

Returns the value of attribute parent


8
9
10
# File 'lib/interphase/widgets/basic_widgets.rb', line 8

def parent
  @parent
end

Instance Method Details

#destroyObject

Destroy this widget.


43
44
45
# File 'lib/interphase/widgets/basic_widgets.rb', line 43

def destroy
  gtk_instance.destroy
end

#on(name, &block) ⇒ Object

Associates a block with a signal. The block is invoked whenever the signal occurs.

name

The name of the signal.


38
39
40
# File 'lib/interphase/widgets/basic_widgets.rb', line 38

def on(name, &block)
  gtk_instance.signal_connect(name, &block)
end

#respond_to_missing?Boolean

Returns:

  • (Boolean)

61
62
63
# File 'lib/interphase/widgets/basic_widgets.rb', line 61

def respond_to_missing?
  true
end

#showObject

Shows this widget.


31
32
33
# File 'lib/interphase/widgets/basic_widgets.rb', line 31

def show
  gtk_instance.show
end

#size(width, height) ⇒ Object

Requests that this widget is resized. Note that this is a method, rather than a 'size=' setter, because the request is not guaranteed, and indeed in many cases will not. Only some containers allow their child widgets to be resized.


26
27
28
# File 'lib/interphase/widgets/basic_widgets.rb', line 26

def size(width, height)
  gtk_instance.set_size_request(width, height)
end