Module: Context::Gtk::Widget
- Included in:
- MainWindow, JLDrill::Gtk::ExampleWindow, JLDrill::Gtk::InfoWindow, JLDrill::Gtk::ItemTableWindow, JLDrill::Gtk::OptionsWindow, JLDrill::Gtk::ProblemPane, JLDrill::Gtk::ProgressBar, JLDrill::Gtk::PromptWindow, JLDrill::Gtk::QuizStatusBar, JLDrill::Gtk::SelectorWindow, JLDrill::Gtk::StatisticsWindow, JLDrill::Gtk::VocabularyHintBox, JLDrill::Gtk::VocabularyWindow
- Defined in:
- lib/Context/Gtk/Widget.rb,
lib/jldrill/spec/Fakes.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 widgets (i.e. if it can act as a container), then
please define the following two methods on your object.
gtkAddWidget(widget) -- simply adds the passed widget 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(widget) -- removes the passed widget from
the correct Gtk container. Again
you will normally implement this
with remove().
The following also need to be defined if your widget is
not derived from a Gtk:Widget.
show_all() -- Displays the widgets.
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
This will turn off the drawing of the widgets in the tests.
-
#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.
32 33 34 |
# File 'lib/Context/Gtk/Widget.rb', line 32 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).
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/Context/Gtk/Widget.rb', line 81 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.
115 116 117 |
# File 'lib/Context/Gtk/Widget.rb', line 115 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.
122 123 124 |
# File 'lib/Context/Gtk/Widget.rb', line 122 def afterWidgetIsRemoved(&block) @gtkWidgetRemovedFromCallback = block end |
#expandWidgetHeight ⇒ Object
When adding the widget, expand it to take up all the allocated vertical height.
54 55 56 |
# File 'lib/Context/Gtk/Widget.rb', line 54 def @gtkWidgetExpandHeight = true end |
#expandWidgetHeight? ⇒ Boolean
Returns true when the the widget should take up all the allocated vertical height.
60 61 62 |
# File 'lib/Context/Gtk/Widget.rb', line 60 def @gtkWidgetExpandHeight end |
#expandWidgetWidth ⇒ Object
When adding the widget, expand it to take up all the allocated horizontal width.
66 67 68 |
# File 'lib/Context/Gtk/Widget.rb', line 66 def @gtkWidgetExpandWidth = true end |
#expandWidgetWidth? ⇒ Boolean
Returns true when the the widget should take up all the allocated horizontal width.
72 73 74 |
# File 'lib/Context/Gtk/Widget.rb', line 72 def @gtkWidgetExpandWidth end |
#gtkAddWidget(widget) ⇒ Object
Default method for adding a widget. Simply logs an warning. It does not add the widget.
150 151 152 153 154 155 |
# File 'lib/Context/Gtk/Widget.rb', line 150 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
157 158 159 160 161 162 |
# File 'lib/Context/Gtk/Widget.rb', line 157 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.
48 49 50 |
# File 'lib/Context/Gtk/Widget.rb', line 48 def isAMainWindow @gtkWidgetMainWindow = self end |
#isInTests? ⇒ Boolean
This will turn off the drawing of the widgets in the tests
144 145 146 |
# File 'lib/Context/Gtk/Widget.rb', line 144 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).
102 103 104 105 106 107 108 109 110 |
# File 'lib/Context/Gtk/Widget.rb', line 102 def removeFromThisWidget() .gtkWidgetMainWindow = nil if !.class.ancestors.include?(Gtk::Window) gtkRemoveWidget() if !isInTests? show_all end end end |
#setupWidget ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/Context/Gtk/Widget.rb', line 35 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
128 129 130 131 132 |
# File 'lib/Context/Gtk/Widget.rb', line 128 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
136 137 138 139 140 |
# File 'lib/Context/Gtk/Widget.rb', line 136 def () if !@gtkWidgetRemovedFromCallback.nil? @gtkWidgetRemovedFromCallback.call() end end |