Class: CWM::AbstractWidget

Inherits:
Object
  • Object
show all
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:

  • `#initialize` is called by the Ruby constructor new

  • CWM#show builds a widget tree, using

    - the AbstractWidget concrete class
    - {#opt} widget options: `[:notify]` is needed if {#handle} is defined
    - {#label}
    - {#help}
  • #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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#handle_all_eventsBoolean

By default, #handle has no argument and it is called only for events of its own widget. If true, #handle(event) is called for events of any widget.

Returns:

  • (Boolean)


60
61
62
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 60

def handle_all_events
  @handle_all_events.nil? ? false : @handle_all_events
end

#widget_idString

Returns An ID, unique within a dialog, used for the widget. By default, the class name is used.

Returns:

  • (String)

    An ID, unique within a dialog, used for the widget. By default, the class name is used.



67
68
69
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 67

def widget_id
  @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.

Parameters:

  • type (Symbol)


76
77
78
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 76

def self.widget_type=(type)
  define_method(:widget_type) { type }
end

Instance Method Details

#cleanupvoid

This method returns an undefined value.

Clean up after the widget is destroyed



# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 129

#cwm_definitionWidgetHash

Generate widget definition for Yast::CWMClass. It refers to #help, #label, #opt #validate, #init, #handle, #store, #cleanup.

Returns:

Raises:

  • (RuntimeError)

    if a required method is not implemented or widget_type is not set.



140
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
167
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 140

def cwm_definition
  if !respond_to?(:widget_type)
    raise "Widget '#{self.class}' does set its widget type"
  end

  res = {}

  res["_cwm_key"] = widget_id
  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"] = [widget_id] 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"] = widget_type

  res
end

#disablevoid

This method returns an undefined value.

Closes widget for interaction



182
183
184
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 182

def disable
  Yast::UI.ChangeWidget(Id(widget_id), :Enabled, false)
end

#enablevoid

This method returns an undefined value.

Opens widget for interaction



176
177
178
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 176

def enable
  Yast::UI.ChangeWidget(Id(widget_id), :Enabled, true)
end

#enabled?Boolean

Returns Is widget open for interaction?

Returns:

  • (Boolean)

    Is widget open for interaction?



170
171
172
# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 170

def enabled?
  Yast::UI.QueryWidget(Id(widget_id), :Enabled)
end

#handlenil, Symbol #handle(event) ⇒ nil, Symbol

Overloads:

  • #handlenil, Symbol
    Note:

    defining #handle itself does not pass `:notify` to widget. It has to be done with #opt method.

    Process an event generated by this widget. This method is invoked if #handle_all_events is `false`.

    Returns:

    • (nil, Symbol)

      what to return from the dialog, or `nil` to continue processing

  • #handle(event) ⇒ nil, Symbol
    Note:

    defining #handle itself does not pass `:notify` to widget. It has to be done with #opt method.

    Process an event generated a widget. This method is invoked if #handle_all_events is `true`.

    Parameters:

    • event (Hash)

      see CWMClass

    Returns:

    • (nil, Symbol)

      what to return from the dialog, or `nil` to continue processing



# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 103

#helpString

Called only once by default. Also triggered by #refresh_help.

Returns:

  • (String)

    translated help text for the widget



# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 84

#initvoid

This method returns an undefined value.

Initialize the widget: set initial value



# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 99

#labelString

Derived classes must override this method to specify a label.

Returns:

  • (String)

    translated label text for the widget



# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 88

#optArray<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.

Returns:

  • (Array<Symbol>)

    options passed to widget like `[:hstretch, :vstretch]`



# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 92

#storevoid

This method returns an undefined value.

Store the widget value for further processing



# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 125

#validateBoolean

Validate widgets before ending the loop and storing.

Returns:

  • (Boolean)

    validate widget value. If it fails (`false`) the dialog will not return yet.



# File 'library/cwm/src/lib/cwm/abstract_widget.rb', line 120