Class: RuGUI::FrameworkAdapters::GTK::BaseView

Inherits:
BaseFrameworkAdapter::BaseView show all
Defined in:
lib/rugui/framework_adapters/GTK.rb

Instance Attribute Summary

Attributes inherited from BaseFrameworkAdapter::Base

#adapted_object

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseFrameworkAdapter::Base

#initialize

Constructor Details

This class inherits a constructor from RuGUI::FrameworkAdapters::BaseFrameworkAdapter::Base

Class Method Details

.builder_file_extensionObject

Returns the builder file extension to be used for this view class.



175
176
177
# File 'lib/rugui/framework_adapters/GTK.rb', line 175

def builder_file_extension
  'glade'
end

Instance Method Details

#add_widget_to_container(widget, container_widget) ⇒ Object

Adds a widget to the given container widget.



106
107
108
# File 'lib/rugui/framework_adapters/GTK.rb', line 106

def add_widget_to_container(widget, container_widget)
  container_widget.add(widget)
end

#autoconnect_signals(other_target = nil) ⇒ Object

Autoconnects signals handlers for the view. If other_target is given it is used instead of the view itself.



129
130
131
132
133
134
135
136
# File 'lib/rugui/framework_adapters/GTK.rb', line 129

def autoconnect_signals(other_target = nil)
  if self.adapted_object.use_builder?
    self.adapted_object.glade.signal_autoconnect_full do |source, target, signal_name, handler_name, signal_data, after|
      target ||= other_target
      self.adapted_object.glade.connect(source, target, signal_name, handler_name, signal_data) if target.respond_to?(handler_name)
    end
  end
end

#build_widgets_from(filename) ⇒ Object

Builds widgets from the given filename, using the proper builder.



154
155
156
157
158
159
160
161
# File 'lib/rugui/framework_adapters/GTK.rb', line 154

def build_widgets_from(filename)
  self.adapted_object.glade = GladeXML.new(filename, self.adapted_object.root, nil, nil, GladeXML::FILE)

  self.adapted_object.glade.widget_names.each do |widget_name|
    self.adapted_object.send(:create_attribute_for_widget, widget_name) unless self.adapted_object.glade[widget_name].nil?
  end
  self.adapted_object.root_widget.show if self.adapted_object.display_root? and not self.adapted_object.root_widget.nil?
end

#connect_declared_signal(widget, signal, receiver, method) ⇒ Object

Connects the signal from the widget to the given receiver method.



147
148
149
150
151
# File 'lib/rugui/framework_adapters/GTK.rb', line 147

def connect_declared_signal(widget, signal, receiver, method)
  widget.signal_connect(signal) do |*args|
    receiver.send(method, *args)
  end
end

#connect_declared_signal_block(widget, signal, receiver, block) ⇒ Object

Connects the signal from the widget to the given receiver block. The block is executed in the context of the receiver.



140
141
142
143
144
# File 'lib/rugui/framework_adapters/GTK.rb', line 140

def connect_declared_signal_block(widget, signal, receiver, block)
  widget.signal_connect(signal) do |*args|
    receiver.instance_exec(*args, &block)
  end
end

#queue(&block) ⇒ Object

Queues the block call, so that it is only gets executed in the main thread.



101
102
103
# File 'lib/rugui/framework_adapters/GTK.rb', line 101

def queue(&block)
  Gtk.queue(&block)
end

#register_widgetsObject

Registers widgets as attributes of the view class.



164
165
166
167
168
169
170
171
# File 'lib/rugui/framework_adapters/GTK.rb', line 164

def register_widgets
  self.adapted_object.glade.widget_names.each do |widget_name|
    unless self.adapted_object.glade[widget_name].nil?
      self.adapted_object.send("#{widget_name}=".to_sym, self.adapted_object.glade[widget_name])
      self.adapted_object.widgets[widget_name] = self.adapted_object.glade[widget_name]
    end
  end
end

#remove_all_children(container_widget) ⇒ Object

Removes all children from the given container widget.



116
117
118
119
120
# File 'lib/rugui/framework_adapters/GTK.rb', line 116

def remove_all_children(container_widget)
  container_widget.children.each do |child|
    container_widget.remove(child)
  end
end

#remove_widget_from_container(widget, container_widget) ⇒ Object

Removes a widget from the given container widget.



111
112
113
# File 'lib/rugui/framework_adapters/GTK.rb', line 111

def remove_widget_from_container(widget, container_widget)
  container_widget.remove(widget)
end

#set_widget_name(widget, widget_name) ⇒ Object

Sets the widget name for the given widget if given.



123
124
125
# File 'lib/rugui/framework_adapters/GTK.rb', line 123

def set_widget_name(widget, widget_name)
  widget.name = widget_name.to_s unless widget_name.nil?
end