Class: CWM::CustomWidget

Inherits:
AbstractWidget show all
Defined in:
library/cwm/src/lib/cwm/custom_widget.rb

Overview

A custom widget that has its UI content defined in the method #contents. Useful mainly when a specialized widget including more subwidgets should be reusable at more places.

Examples:

custom widget child

class MyWidget < CWM::CustomWidget
  def contents
    HBox(
      MyPushButton.new,
      PushButton(Id(:undo), _("Undo"))
    )
  end

  def handle(event)
    case event["ID"]
    when :undo then ...
    else
      # handle for MyPushButton lives in that PushButton
    end
    nil
  end
end

Direct Known Subclasses

Page, Pager, ProgressBar, ReplacePoint, ServiceWidget, Table, Tree

Instance Attribute Summary

Attributes inherited from AbstractWidget

#handle_all_events, #widget_id

Instance Method Summary collapse

Methods inherited from AbstractWidget

#cleanup, #disable, #displayed?, #enable, #enabled?, #focus, #fun_ref, #handle, #help, #init, #label, #my_event?, #opt, #refresh_help, #store, #validate, widget_type=

Instance Method Details

#contentsWidgetTerm

Must be defined by subclasses

Returns:

  • (WidgetTerm)

    a UI term that can include another AbstractWidgets

See Also:

  • CWM::CustomWidget.example/object_api_nestedexample/object_api_nested.rb


35
# File 'library/cwm/src/lib/cwm/custom_widget.rb', line 35

abstract_method :contents

#cwm_contentsStringTerm (protected)

return contents converted to format understandable by CWM module Basically it replace instance of AbstractWidget by its widget_id

Returns:



51
52
53
54
55
# File 'library/cwm/src/lib/cwm/custom_widget.rb', line 51

def cwm_contents
  Yast.import "CWM"

  Yast::CWM.widgets_contents(contents)
end

#cwm_definitionWidgetHash

Returns:



38
39
40
41
42
43
44
# File 'library/cwm/src/lib/cwm/custom_widget.rb', line 38

def cwm_definition
  res = { "custom_widget" => cwm_contents }

  res["handle_events"] = ids_in_contents unless handle_all_events

  super.merge(res)
end

#find_ids(term) ⇒ Object (protected)



61
62
63
64
65
66
67
68
69
70
71
# File 'library/cwm/src/lib/cwm/custom_widget.rb', line 61

def find_ids(term)
  term.each_with_object([]) do |arg, res|
    next unless arg.is_a? Yast::Term

    if arg.value == :id
      res << arg.params[0]
    else
      res.concat(find_ids(arg))
    end
  end
end

#ids_in_contentsObject (protected)



57
58
59
# File 'library/cwm/src/lib/cwm/custom_widget.rb', line 57

def ids_in_contents
  find_ids(contents) << widget_id
end