Class: Yast::WizardHWClass
- Inherits:
-
Module
- Object
- Module
- Yast::WizardHWClass
- Defined in:
- ../../src/modules/WizardHW.rb
Instance Method Summary (collapse)
-
- (Object) _SetSelectedItem(selected)
Set which item is to be selected.
-
- (Yast::Term) CreateActionsButton(actions)
Create the Push/Menu button for additional actions.
-
- (Object) CreateHWDialog(title, help, headers, actions)
Create the Hardware Wizard dialog Draw the dialog below the widgets (next to other buttons).
-
- (String) CreateRichTextDescription(title, properties)
Create rich text description of a device.
-
- (Object) CreateWidget(headers, actions)
Create CWM widtet for the hardware settings NOTE: The Init and Handle callbacks must be defined.
-
- (String) GetActionLabel(action)
Get the description label for the action.
-
- (Symbol) Handle(_key, event)
Handle function of the widget Used when using the callback interface.
-
- (Object) Init(_key)
Init function of the widget Used when using the callback interface.
- - (Object) main
-
- (Symbol) RunHWDialog(settings)
Draw the dialog, handle all its events via callbacks.
-
- (Object) SelectedItem
Return the id of the currently selected item in the table.
-
- (Object) SetContents(items)
Set the information about hardware.
-
- (Object) SetRichDescription(descr)
Set the rich text description.
-
- (Object) SetSelectedItem(selected)
Set which item is to be selected.
-
- (Object) SimpleStoreReturnValue(selected, event)
Store the event description in internal variable To be used by WizardHW::WaitForEvent function.
-
- (Object) StoreCurrentItems(items)
internal functions.
-
- (Object) UnconfiguredDevice
Get propertly list of an unconfigured device.
-
- (Object) UserInput
Wait for event from the event.
-
- (Object) WaitForEvent
Wait for event from the event.
Instance Method Details
- (Object) _SetSelectedItem(selected)
Set which item is to be selected
98 99 100 101 102 103 104 105 106 107 108 109 |
# File '../../src/modules/WizardHW.rb', line 98 def _SetSelectedItem(selected) if !selected.nil? UI.ChangeWidget(Id(:_hw_items), :CurrentItem, selected) UI.ChangeWidget( Id(:_hw_sum), :Value, Ops.get(@descriptions, selected, "") ) end nil end |
- (Yast::Term) CreateActionsButton(actions)
Create the Push/Menu button for additional actions
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File '../../src/modules/WizardHW.rb', line 188 def CreateActionsButton(actions) actions = deep_copy(actions) sz = Builtins.size(actions) return Empty() if sz == 0 if sz == 1 id = Ops.get(actions, [0, 0]) if id.nil? Builtins.y2error("Unknown ID for button: %1", Ops.get(actions, 0)) id = "nil" end return PushButton(Id(id), GetActionLabel(Ops.get(actions, 0, []))) end items = Builtins.maplist(actions) do |i| id = Ops.get(i, 0) if id.nil? Builtins.y2error("Unknown ID for button: %1", Ops.get(actions, 0)) id = "nil" end Item(Id(id), GetActionLabel(i)) end # menu button MenuButton(_("&Other"), items) end |
- (Object) CreateHWDialog(title, help, headers, actions)
This is a stable API function
Create the Hardware Wizard dialog Draw the dialog below the widgets (next to other buttons)
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File '../../src/modules/WizardHW.rb', line 373 def CreateHWDialog(title, help, headers, actions) headers = deep_copy(headers) actions = deep_copy(actions) # reinitialize internal variables @current_items = [] @descriptions = {} @last_event = {} @get_item_descr_callback = nil @action_callback = fun_ref( method(:SimpleStoreReturnValue), "symbol (string, map)" ) # now create the dialog = CreateWidget(headers, actions) Ops.set(, "help", help) # to suppress error in log w = CWM.CreateWidgets(["wizard_hw"], "wizard_hw" => ) contents = Ops.get_term(w, [0, "widget"], VBox()) Wizard.SetContents(title, contents, help, false, true) nil end |
- (String) CreateRichTextDescription(title, properties)
This is a stable API function
Create rich text description of a device. It can be used for WizardHW::SetContents function for formatting richtext device descriptions
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File '../../src/modules/WizardHW.rb', line 478 def CreateRichTextDescription(title, properties) properties = deep_copy(properties) items = "" if !properties.nil? && Ops.greater_than(Builtins.size(properties), 0) Builtins.foreach(properties) do |prop| items = Ops.add(Ops.add(Ops.add(items, "<LI>"), prop), "</LI>") end end ret = "" if !title.nil? && title != "" ret = Ops.add(Ops.add("<P><B>", title), "</B></P>") end if items != "" ret = Ops.add(Ops.add(Ops.add(ret, "<P><UL>"), items), "</UL></P>") end ret end |
- (Object) CreateWidget(headers, actions)
This is a stable API function
Create CWM widtet for the hardware settings NOTE: The Init and Handle callbacks must be defined
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File '../../src/modules/WizardHW.rb', line 221 def CreateWidget(headers, actions) headers = deep_copy(headers) actions = deep_copy(actions) hdr = Header() Builtins.foreach(headers) { |hi| hdr = Builtins.add(hdr, hi) } item_list = Table(Id(:_hw_items), Opt(:notify, :immediate), hdr) = HBox( PushButton(Id(:add), Label.AddButton), PushButton(Id(:edit), Label.EditButton), PushButton(Id(:delete), Label.DeleteButton), HStretch(), CreateActionsButton(actions) ) item_summary = RichText(Id(:_hw_sum), "") contents = VBox(VWeight(3, item_list), VWeight(1, item_summary), ) handle_events = [:_hw_items, :add, :edit, :delete] extra_events = Builtins.maplist(actions) { |i| Ops.get(i, 1) } extra_events = Builtins.filter(extra_events) { |i| !i.nil? } handle_events = Builtins.merge(handle_events, extra_events) ret = { "widget" => :custom, "custom_widget" => contents, "handle_events" => handle_events } deep_copy(ret) end |
- (String) GetActionLabel(action)
Get the description label for the action
176 177 178 179 180 181 182 183 |
# File '../../src/modules/WizardHW.rb', line 176 def GetActionLabel(action) action = deep_copy(action) fallback = "" if Ops.is_string?(Ops.get(action, 0)) fallback = Ops.get_string(action, 0, "") end Ops.get_string(action, 1, fallback) end |
- (Symbol) Handle(_key, event)
Handle function of the widget Used when using the callback interface
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File '../../src/modules/WizardHW.rb', line 135 def Handle(_key, event) event = deep_copy(event) @last_event = deep_copy(event) current = Convert.to_string(UI.QueryWidget(Id(:_hw_items), :CurrentItem)) if Ops.get(event, "ID") == :_hw_items descr = "" if @get_item_descr_callback.nil? descr = Ops.get(@descriptions, current, "") else descr = @get_item_descr_callback.call(current) end UI.ChangeWidget(Id(:_hw_sum), :Value, descr) return nil end if @action_callback.nil? ret = Ops.get(event, "ID") if Ops.is_symbol?(ret) return Convert.to_symbol(ret) else return nil end else return @action_callback.call(current, event) end end |
- (Object) Init(_key)
Init function of the widget Used when using the callback interface
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File '../../src/modules/WizardHW.rb', line 114 def Init(_key) if !@set_items_callback.nil? @set_items_callback.call else Builtins.y2warning("No initialization callback") end if !@select_initial_item_callback.nil? @select_initial_item_callback.call else _SetSelectedItem(Ops.get_string(@current_items, [0, "id"])) end nil end |
- (Object) main
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File '../../src/modules/WizardHW.rb', line 35 def main Yast.import "UI" textdomain "base" Yast.import "CWM" Yast.import "Label" Yast.import "Report" Yast.import "Popup" Yast.import "Wizard" # local store # List of items in the currently displayed dialog @current_items = [] # Map of rich text descriptions for all items # Contained info can be reachable through current_items, this is for # faster access @descriptions = {} # The last handled UI event @last_event = {} # The return value to be returned by WizardHW::WaitForEvent () @dialog_ret = nil # callbacks # Callback # Perform an action (when an event which is not handled internally occurred) @action_callback = nil # Callback # Get rich text description of an item. # This can be used to set it dynamically @get_item_descr_callback = nil # Callback # Set all the items # Should call the SetContents function of this module @set_items_callback = nil # Callback # Select the initial item # If not set, the first is selected @select_initial_item_callback = nil end |
- (Symbol) RunHWDialog(settings)
This is a stable API function
Draw the dialog, handle all its events via callbacks
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File '../../src/modules/WizardHW.rb', line 291 def RunHWDialog(settings) settings = deep_copy(settings) # reinitialize internal variables @current_items = [] @descriptions = {} @last_event = {} # callbacks @action_callback = Convert.convert( Ops.get(settings, "action_callback"), from: "any", to: "symbol (string, map)" ) @get_item_descr_callback = Convert.convert( Ops.get(settings, "item_descr_callback"), from: "any", to: "string (string)" ) @set_items_callback = Convert.convert( Ops.get(settings, "set_items_callback"), from: "any", to: "void ()" ) @select_initial_item_callback = Convert.convert( Ops.get(settings, "set_initial_item_callback"), from: "any", to: "void ()" ) # other variables actions = Ops.get_list(settings, "actions", []) headers = Ops.get_list(settings, "headers", []) title = Ops.get_string(settings, "title", "") help = Ops.get_string(settings, "help", "HELP") # adapt the widget description map = CreateWidget(headers, actions) = Builtins.remove(, "handle_events") Ops.set(, "help", help) Ops.set(, "init", fun_ref(method(:Init), "void (string)")) Ops.set( , "handle", fun_ref(method(:Handle), "symbol (string, map)") ) = { "wizard_hw" => } # now run the dialog via CWM with handler set CWM.ShowAndRun( "widget_descr" => , "widget_names" => ["wizard_hw"], "contents" => VBox("wizard_hw"), "caption" => title, "abort_button" => Ops.get_string(settings, "abort_button") do Label.AbortButton end, "back_button" => Ops.get_string(settings, "back_button") do Label.BackButton end, "next_button" => Ops.get_string(settings, "next_button") do Label.NextButton end ) end |
- (Object) SelectedItem
This is a stable API function
Return the id of the currently selected item in the table
408 409 410 |
# File '../../src/modules/WizardHW.rb', line 408 def SelectedItem Convert.to_string(UI.QueryWidget(Id(:_hw_items), :CurrentItem)) end |
- (Object) SetContents(items)
This is a stable API function
Set the information about hardware
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
# File '../../src/modules/WizardHW.rb', line 427 def SetContents(items) items = deep_copy(items) term_items = Builtins.maplist(items) do |i| t = Item(Id(Ops.get_string(i, "id", ""))) Builtins.foreach(Ops.get_list(i, "table_descr", [])) do |l| t = Builtins.add(t, l) end deep_copy(t) end UI.ChangeWidget(Id(:_hw_items), :Items, term_items) StoreCurrentItems(items) enabled = Ops.greater_than(Builtins.size(items), 0) UI.ChangeWidget(Id(:edit), :Enabled, enabled) UI.ChangeWidget(Id(:delete), :Enabled, enabled) SetSelectedItem(Ops.get_string(items, [0, "id"], "")) if enabled nil end |
- (Object) SetRichDescription(descr)
This is a stable API function
Set the rich text description.
415 416 417 418 419 |
# File '../../src/modules/WizardHW.rb', line 415 def SetRichDescription(descr) UI.ChangeWidget(Id(:_hw_sum), :Value, descr) nil end |
- (Object) SetSelectedItem(selected)
This is a stable API function
Set which item is to be selected
399 400 401 402 403 |
# File '../../src/modules/WizardHW.rb', line 399 def SetSelectedItem(selected) _SetSelectedItem(selected) nil end |
- (Object) SimpleStoreReturnValue(selected, event)
Store the event description in internal variable To be used by WizardHW::WaitForEvent function
90 91 92 93 94 |
# File '../../src/modules/WizardHW.rb', line 90 def SimpleStoreReturnValue(selected, event) event = deep_copy(event) @dialog_ret = { "event" => event, "selected" => selected } :next # anything but nil end |
- (Object) StoreCurrentItems(items)
internal functions
163 164 165 166 167 168 169 170 171 |
# File '../../src/modules/WizardHW.rb', line 163 def StoreCurrentItems(items) items = deep_copy(items) @current_items = deep_copy(items) @descriptions = Builtins.listmap(items) do |i| { Ops.get_string(i, "id", "") => Ops.get_string(i, "rich_descr", "") } end nil end |
- (Object) UnconfiguredDevice
This is a stable API function
Get propertly list of an unconfigured device. Should be used together with device name in CreateRichTextDescription() function.
505 506 507 508 509 510 511 512 513 514 |
# File '../../src/modules/WizardHW.rb', line 505 def UnconfiguredDevice # translators: message for hardware configuration without any configured # device [ _("The device is not configured"), # translators: message for hardware configuration without any configured # device _("Press <B>Edit</B> to configure") ] end |
- (Object) UserInput
This is a stable API function
Wait for event from the event
465 466 467 468 469 |
# File '../../src/modules/WizardHW.rb', line 465 def UserInput ret = WaitForEvent() Ops.set(ret, "event", Ops.get(ret, ["event", "ID"])) deep_copy(ret) end |
- (Object) WaitForEvent
This is a stable API function
Wait for event from the event
451 452 453 454 455 456 457 458 |
# File '../../src/modules/WizardHW.rb', line 451 def WaitForEvent event = nil while event.nil? event = UI.WaitForEvent event = nil if Handle("wizard_hw", event).nil? end deep_copy(@dialog_ret) end |