Class: CWM::AbstractWidget
- Inherits:
-
Object
- Object
- CWM::AbstractWidget
- Includes:
- Yast::I18n, Yast::Logger, Yast::UIShortcuts
- Defined in:
- library/cwm/src/lib/cwm/abstract_widget.rb
Overview
Represent base for any widget used in CWM. It can be passed as "widget" argument. For more details about usage see Yast::CWM.show
Underneath there is a widget library with a procedural API, using symbol parameters as widget IDs.
The call sequence is:
-
#initializeis called by the Ruby constructor new -
CWM#show builds a widget tree, using
-
#init may initialize the widget state from persistent storage
-
loop:
- {#handle} may update other widgets if this one tells them to - {#validate} may decide whether the user input is valid -
#store may store the widget state to persistent storage
Direct Known Subclasses
CheckBox, ComboBox, CustomWidget, DateField, Empty, InputField, IntField, MenuButton, MultiLineEdit, MultiSelectionBox, Password, PushButton, RadioButtons, RichText, SelectionBox, TimeField, WrapperWidget
Instance Attribute Summary collapse
-
#handle_all_events ⇒ Boolean
By default, #handle has no argument and it is called only for events of its own widget.
-
#widget_id ⇒ String
An ID, unique within a dialog, used for the widget.
Class Method Summary collapse
-
.widget_type=(type) ⇒ void
Declare widget type for Yast::CWMClass.
Instance Method Summary collapse
-
#cleanup ⇒ void
Clean up after the widget is destroyed.
-
#cwm_definition ⇒ WidgetHash
Generate widget definition for Yast::CWMClass.
-
#disable ⇒ void
Closes widget for interaction.
-
#displayed? ⇒ Boolean
Determines whether the widget is currently displayed in the UI.
-
#enable ⇒ void
Opens widget for interaction.
-
#enabled? ⇒ Boolean
Is widget open for interaction?.
-
#focus ⇒ Object
Focus the widget.
-
#fun_ref(*args) ⇒ Yast::FunRef
protected
shortcut from Yast namespace to avoid including whole namespace.
- #handle(*args) ⇒ Object
-
#help ⇒ String
Called only once by default.
-
#init ⇒ void
Initialize the widget: set initial value.
-
#label ⇒ String
Derived classes must override this method to specify a label.
-
#my_event?(event) ⇒ Boolean
protected
A helper to check if an event is invoked by this widget.
-
#opt ⇒ Array<Symbol>
Specifies options passed to widget.
-
#refresh_help ⇒ Object
protected
A widget will need to call this if its #help text has changed,to make the change effective.
-
#store ⇒ void
Store the widget value for further processing.
-
#validate ⇒ Boolean
Validate widgets before ending the loop and storing.
Instance Attribute Details
#handle_all_events ⇒ Boolean
62 63 64 |
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 62 def handle_all_events @handle_all_events.nil? ? false : @handle_all_events end |
#widget_id ⇒ String
Returns An ID, unique within a dialog, used for the widget. By default, the class name is used.
69 70 71 |
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 69 def @widget_id || self.class.to_s end |
Class Method Details
.widget_type=(type) ⇒ void
This method returns an undefined value.
Declare widget type for Yast::CWMClass. Your derived widgets will not need to do this.
77 78 79 |
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 77 def self.(type) define_method(:widget_type) { type } end |
Instance Method Details
#cleanup ⇒ void
This method returns an undefined value.
Clean up after the widget is destroyed
|
|
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 130
|
#cwm_definition ⇒ WidgetHash
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 141 def cwm_definition raise "Widget '#{self.class}' does set its widget type" if !respond_to?(:widget_type) res = {} res["_cwm_key"] = if respond_to?(:help) res["help"] = help_method else res["no_help"] = "" end res["label"] = label if respond_to?(:label) res["opt"] = opt if respond_to?(:opt) if respond_to?(:validate) res["validate_function"] = validate_method res["validate_type"] = :function end res["handle_events"] = [] unless handle_all_events res["init"] = init_method if respond_to?(:init) res["handle"] = handle_method if respond_to?(:handle) res["store"] = store_method if respond_to?(:store) res["cleanup"] = cleanup_method if respond_to?(:cleanup) res["widget"] = res end |
#disable ⇒ void
This method returns an undefined value.
Closes widget for interaction
181 182 183 |
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 181 def disable Yast::UI.ChangeWidget(Id(), :Enabled, false) end |
#displayed? ⇒ Boolean
Determines whether the widget is currently displayed in the UI
193 194 195 |
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 193 def displayed? Yast::UI.WidgetExists(Id()) end |
#enable ⇒ void
This method returns an undefined value.
Opens widget for interaction
175 176 177 |
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 175 def enable Yast::UI.ChangeWidget(Id(), :Enabled, true) end |
#enabled? ⇒ Boolean
Returns Is widget open for interaction?.
169 170 171 |
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 169 def enabled? Yast::UI.QueryWidget(Id(), :Enabled) end |
#focus ⇒ Object
Focus the widget. Useful when validation failed to highlight it.
186 187 188 |
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 186 def focus Yast::UI.SetFocus(Id()) end |
#fun_ref(*args) ⇒ Yast::FunRef (protected)
kill converts in CWM module, to avoid this workaround for funrefs
shortcut from Yast namespace to avoid including whole namespace
215 216 217 |
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 215 def fun_ref(*args) Yast::FunRef.new(*args) end |
#handle ⇒ nil, Symbol #handle(event) ⇒ nil, Symbol
|
|
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 104
|
#help ⇒ String
Called only once by default. Also triggered by #refresh_help.
|
|
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 85
|
#init ⇒ void
This method returns an undefined value.
Initialize the widget: set initial value
|
|
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 100
|
#label ⇒ String
Derived classes must override this method to specify a label.
|
|
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 89
|
#my_event?(event) ⇒ Boolean (protected)
A helper to check if an event is invoked by this widget
201 202 203 |
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 201 def my_event?(event) == event["ID"] end |
#opt ⇒ Array<Symbol>
Specifies options passed to widget. When #handle method is defined, it
is often expected to be immediatelly notified from widget and for that
purpose opt method with [:notify] as return value is needed.
|
|
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 93
|
#refresh_help ⇒ Object (protected)
A widget will need to call this if its #help text has changed,to make the change effective.
206 207 208 209 210 |
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 206 def refresh_help Yast.import "CWM" Yast::CWM.ReplaceWidgetHelp end |
#store ⇒ void
This method returns an undefined value.
Store the widget value for further processing
|
|
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 126
|
#validate ⇒ Boolean
Validate widgets before ending the loop and storing.
|
|
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 121
|