Module: Context::Gtk::Widget
- Included in:
- MainWindow
- Defined in:
- lib/Context/Gtk/Widget.rb
Overview
This is a set of routines for translating the requests from Context to the specific widgit set.
Note: If you wish your widget to be able to add and removed
other (i.e. if it can act as a container), then
please define the following two methods on your object.
gtkAddWidget() -- simply adds the passed to
the correct Gtk container. Normally
this can be implemented using add().
However, for some things like tables
you will have to use other methods.
gtkRemoveWidget() -- removes the passed from
the correct Gtk container. Again
you will normally implement this
with remove().
The following also need to be defined if your is
not derived from a Gtk:Widget.
show_all() -- Displays the .
Instance Attribute Summary collapse
-
#gtkWidgetMainWindow ⇒ Object
Returns the value of attribute gtkWidgetMainWindow.
Instance Method Summary collapse
-
#addToThisWidget(widget) ⇒ Object
Use this widget as a container for the passed widget.
-
#afterWidgetIsAdded(&block) ⇒ Object
Set a closure to be run when the widget has been added.
-
#afterWidgetIsRemoved(&block) ⇒ Object
Set a closure to be run when the widget has been removed.
-
#expandWidgetHeight ⇒ Object
When adding the widget, expand it to take up all the allocated vertical height.
-
#expandWidgetHeight? ⇒ Boolean
Returns true when the the widget should take up all the allocated vertical height.
-
#expandWidgetWidth ⇒ Object
When adding the widget, expand it to take up all the allocated horizontal width.
-
#expandWidgetWidth? ⇒ Boolean
Returns true when the the widget should take up all the allocated horizontal width.
-
#gtkAddWidget(widget) ⇒ Object
Default method for adding a widget.
- #gtkRemoveWidget(widget) ⇒ Object
-
#isAMainWindow ⇒ Object
Declares that this widget is a main Window Normally, this will get set for you if the widget you are adding is derived from Gtk::Window.
-
#isInTests? ⇒ Boolean
Helper method for testing.
-
#removeFromThisWidget(widget) ⇒ Object
Remove the passed widget from this object.
- #setupWidget ⇒ Object
-
#widgetWasAddedTo(widget) ⇒ Object
This method is called after the widget has been successfully added to another widget.
-
#widgetWasRemovedFrom(widget) ⇒ Object
This method is called after the widget has been successfully removed from another widget.
Instance Attribute Details
#gtkWidgetMainWindow ⇒ Object
Returns the value of attribute gtkWidgetMainWindow.
31 32 33 |
# File 'lib/Context/Gtk/Widget.rb', line 31 def gtkWidgetMainWindow @gtkWidgetMainWindow end |
Instance Method Details
#addToThisWidget(widget) ⇒ Object
Use this widget as a container for the passed widget. Calls gtkAddWidget, which you must define on the object. Normally this will simply call add() in the correct container. Also calls show_all, which you must define on the object (if it isn’t already).
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/Context/Gtk/Widget.rb', line 80 def addToThisWidget() if !.class.ancestors.include?(Gtk::Window) .gtkWidgetMainWindow = @gtkWidgetMainWindow gtkAddWidget() if !isInTests? show_all end else .isAMainWindow .set_transient_for(@gtkWidgetMainWindow) if !isInTests? .show_all end end end |
#afterWidgetIsAdded(&block) ⇒ Object
Set a closure to be run when the widget has been added. The block must accept the container widget as a parameter.
114 115 116 |
# File 'lib/Context/Gtk/Widget.rb', line 114 def afterWidgetIsAdded(&block) @gtkWidgetAddedToCallback = block end |
#afterWidgetIsRemoved(&block) ⇒ Object
Set a closure to be run when the widget has been removed. The block must accept the container widget as a parameter.
121 122 123 |
# File 'lib/Context/Gtk/Widget.rb', line 121 def afterWidgetIsRemoved(&block) @gtkWidgetRemovedFromCallback = block end |
#expandWidgetHeight ⇒ Object
When adding the widget, expand it to take up all the allocated vertical height.
53 54 55 |
# File 'lib/Context/Gtk/Widget.rb', line 53 def @gtkWidgetExpandHeight = true end |
#expandWidgetHeight? ⇒ Boolean
Returns true when the the widget should take up all the allocated vertical height.
59 60 61 |
# File 'lib/Context/Gtk/Widget.rb', line 59 def @gtkWidgetExpandHeight end |
#expandWidgetWidth ⇒ Object
When adding the widget, expand it to take up all the allocated horizontal width.
65 66 67 |
# File 'lib/Context/Gtk/Widget.rb', line 65 def @gtkWidgetExpandWidth = true end |
#expandWidgetWidth? ⇒ Boolean
Returns true when the the widget should take up all the allocated horizontal width.
71 72 73 |
# File 'lib/Context/Gtk/Widget.rb', line 71 def @gtkWidgetExpandWidth end |
#gtkAddWidget(widget) ⇒ Object
Default method for adding a widget. Simply logs an warning. It does not add the widget.
149 150 151 152 153 154 |
# File 'lib/Context/Gtk/Widget.rb', line 149 def gtkAddWidget() Context::Log::warning("Context::Widget", "Attempted to add a widget " + "to #{self.class} which doesn't define " + "gtkAddWidget(). Ignoring addition.") end |
#gtkRemoveWidget(widget) ⇒ Object
156 157 158 159 160 161 |
# File 'lib/Context/Gtk/Widget.rb', line 156 def gtkRemoveWidget() Context::Log::warning("Context::Widget", "Attempted to remove a widget " + "from #{self.class} which doesn't define " + "gtkRemoveWidget(). Ignoring removal.") end |
#isAMainWindow ⇒ Object
Declares that this widget is a main Window Normally, this will get set for you if the widget you are adding is derived from Gtk::Window. But you can set it explicitly for certain effects if you know what you are doing.
47 48 49 |
# File 'lib/Context/Gtk/Widget.rb', line 47 def isAMainWindow @gtkWidgetMainWindow = self end |
#isInTests? ⇒ Boolean
Helper method for testing. If this method is redefined to return true, then the items will not be shown on the screen.
143 144 145 |
# File 'lib/Context/Gtk/Widget.rb', line 143 def isInTests? false end |
#removeFromThisWidget(widget) ⇒ Object
Remove the passed widget from this object. Calls gtkRemoveWidget, which you must define on the object. Normally this will simply call remove(). Also calls show_all, which you must define on the object (if it isn’t already).
101 102 103 104 105 106 107 108 109 |
# File 'lib/Context/Gtk/Widget.rb', line 101 def removeFromThisWidget() .gtkWidgetMainWindow = nil if !.class.ancestors.include?(Gtk::Window) gtkRemoveWidget() if !isInTests? show_all end end end |
#setupWidget ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/Context/Gtk/Widget.rb', line 34 def setupWidget @gtkWidgetMainWindow = nil # Packing hints for the container @gtkWidgetExpandHeight = false @gtkWidgetExpandWidth = false @gtkWidgetAddedToCallback = nil @gtkWidgetRemovedFromCallback = nil end |
#widgetWasAddedTo(widget) ⇒ Object
This method is called after the widget has been successfully added to another widget
127 128 129 130 131 |
# File 'lib/Context/Gtk/Widget.rb', line 127 def () if !@gtkWidgetAddedToCallback.nil? @gtkWidgetAddedToCallback.call() end end |
#widgetWasRemovedFrom(widget) ⇒ Object
This method is called after the widget has been successfully removed from another widget
135 136 137 138 139 |
# File 'lib/Context/Gtk/Widget.rb', line 135 def () if !@gtkWidgetRemovedFromCallback.nil? @gtkWidgetRemovedFromCallback.call() end end |