-
Notifications
You must be signed in to change notification settings - Fork 44
/
Wizard.rb
1863 lines (1661 loc) · 53.6 KB
/
Wizard.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# ***************************************************************************
#
# Copyright (c) 2002 - 2012 Novell, Inc.
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com
#
# ***************************************************************************
# File: Wizard.ycp
# Package: yast2
# Author: Stefan Hundhammer <sh@suse.de>
#
# Provides the wizard dialog (common screen for all YaST2 installation
# modules) and functions to set the contents, to replace and restore
# special widgets.
require "yast"
module Yast
class WizardClass < Module
DEFAULT_ICON_NAME = "yast".freeze
def main
Yast.import "UI"
textdomain "base"
Yast.import "Desktop"
Yast.import "Label"
Yast.import "Popup"
Yast.import "Directory"
Yast.import "OSRelease"
@have_fancy_ui_cache = nil
# this variable is set from Product:: constructor
# to setup correct &product; macro in UI
@product_name = ""
#
# Screenshot Functions
#
# Currently used screenshot name.
# Initially, it must match the UI default, "yast2"
@screenshot_name = "yast2"
# Screenshot names overriden by nested SetScreenShotName calls
@screenshot_name_stack = []
# Handling of relnotes button when creating a wizard over existing one
# Cannot be handled by libyui for NCurses
@relnotes_button_label = ""
@relnotes_button_id = ""
# Current icon name to set.
@icon_name = DEFAULT_ICON_NAME
end
def haveFancyUI
if @have_fancy_ui_cache.nil?
ui_info = UI.GetDisplayInfo
@have_fancy_ui_cache = UI.HasSpecialWidget(:Wizard) == true &&
Ops.greater_or_equal(Ops.get_integer(ui_info, "Depth", 0), 15) &&
Ops.greater_or_equal(Ops.get_integer(ui_info, "DefaultWidth", 0), 800) &&
# some netbooks use such a strange resolution (fate#306298)
Ops.greater_or_equal(
Ops.get_integer(ui_info, "DefaultHeight", 0),
576
)
# have_fancy_ui_cache = false;
UI.SetFunctionKeys(Label.DefaultFunctionKeyMap)
end
@have_fancy_ui_cache
end
# Returns a button box with buttons "Back", "Abort", "Next"
# @return a widget tree
#
def BackAbortNextButtonBox
HBox(
HWeight(
1,
ReplacePoint(
Id(:rep_help),
PushButton(Id(:help), Opt(:key_F1, :helpButton), Label.HelpButton)
)
),
HStretch(),
HWeight(
1,
ReplacePoint(
Id(:rep_back),
PushButton(Id(:back), Opt(:key_F8), Label.BackButton)
)
),
HStretch(),
ReplacePoint(
Id(:rep_abort),
PushButton(Id(:abort), Opt(:key_F9), Label.AbortButton)
),
HStretch(),
HWeight(
1,
ReplacePoint(
Id(:rep_next),
PushButton(Id(:next), Opt(:key_F10, :default), Label.NextButton)
)
)
)
end
# Returns a button box with buttons "Back", "Abort Installation", "Next"
# @return a widget tree
#
def BackAbortInstallationNextButtonBox
HBox(
HWeight(
1,
ReplacePoint(
Id(:rep_help),
PushButton(Id(:help), Opt(:key_F1, :helpButton), Label.HelpButton)
)
),
HStretch(),
HWeight(
1,
ReplacePoint(
Id(:rep_back),
PushButton(Id(:back), Opt(:key_F8), Label.BackButton)
)
),
HStretch(),
ReplacePoint(
Id(:rep_abort),
PushButton(Id(:abort), Opt(:key_F9), Label.AbortInstallationButton)
),
HStretch(),
HWeight(
1,
ReplacePoint(
Id(:rep_next),
PushButton(Id(:next), Opt(:key_F10, :default), Label.NextButton)
)
)
)
end
# Returns a button box with buttons "Back", "Next"
# @return a widget tree
#
def BackNextButtonBox
HBox(
HWeight(
1,
ReplacePoint(
Id(:rep_back),
PushButton(Id(:back), Opt(:key_F8), Label.BackButton)
)
),
HStretch(),
HWeight(
1,
ReplacePoint(
Id(:rep_next),
PushButton(Id(:next), Opt(:key_F10, :default), Label.NextButton)
)
)
)
end
# Returns a button box with buttons "Cancel", "Accept"
# @return a widget tree
#
def CancelAcceptButtonBox
ButtonBox(
PushButton(Id(:cancel), Opt(:key_F9, :cancelButton), Label.CancelButton),
PushButton(
Id(:accept),
Opt(:key_F10, :default, :okButton),
Label.AcceptButton
)
)
end
# Returns a button box with buttons "Cancel", "OK"
# @return a widget tree
#
def CancelOKButtonBox
ButtonBox(
PushButton(Id(:cancel), Opt(:key_F9, :cancelButton), Label.CancelButton),
PushButton(Id(:ok), Opt(:key_F10, :default, :okButton), Label.OKButton)
)
end
# Returns a button box with buttons "Abort", "Accept"
# @return a widget tree
#
def AbortAcceptButtonBox
HBox(
HWeight(1, ReplacePoint(Id(:back_rep), Empty())), # Layout trick to make sure the center button is centered
HStretch(),
HWeight(
1,
ReplacePoint(
Id(:rep_abort), # Make sure HideAbortButton() works (bnc #444176)
PushButton(Id(:abort), Opt(:key_F9), Label.AbortButton)
)
),
HStretch(),
HWeight(
1,
PushButton(Id(:accept), Opt(:key_F10, :default), Label.AcceptButton)
)
)
end
# Returns a button box with buttons "Abort Installation", "Accept"
# @return a widget tree
#
def AbortInstallationAcceptButtonBox
ButtonBox(
PushButton(
Id(:abort),
Opt(:key_F9, :cancelButton),
Label.AbortInstallationButton
),
PushButton(
Id(:accept),
Opt(:key_F10, :okButton, :default),
Label.AcceptButton
)
)
end
# Returns a button box with buttons "Abort", "Apply", "Finish"
# @return a widget tree
#
def AbortApplyFinishButtonBox
ButtonBox(
PushButton(Id(:abort, :cancelButton, :key_F9), Label.AbortButton),
# button text
PushButton(Id(:apply, :applyButton), _("&Apply")),
PushButton(Id(:finish, :okButton, :key_F10), Label.FinishButton)
)
end
# Create a Generic Dialog
#
#
# Returns a term describing a generic wizard dialog with a configurable
# button box.
#
# @note This is a stable API function
#
# @param [Yast::Term] button_box term that contains a `HBox() with buttons in it
# @return [Yast::Term] term describing the dialog.
#
def GenericDialog(button_box)
button_box = deep_copy(button_box)
VBox(
Id(:WizardDialog),
ReplacePoint(Id(:topmenu), Empty()),
VWeight(
1, # Layout trick: Lower layout priority with weight
HBox(
HSpacing(1),
VBox(
VSpacing(0.2),
HBox(
# translators: dialog title to appear before any content is initialized
Heading(Id(:title), Opt(:hstretch), _("Initializing ...")),
HStretch(),
ReplacePoint(Id(:relnotes_rp), Empty())
),
VWeight(
1, # Layout trick: Lower layout priority with weight
HVCenter(Opt(:hvstretch), ReplacePoint(Id(:contents), Empty()))
)
),
HSpacing(1)
)
),
ReplacePoint(Id(:rep_button_box), button_box),
VSpacing(0.2)
)
end
# Create a Generic Tree Dialog
#
#
# Returns a term describing a wizard dialog with left menu tree,
# right contents and a configurable button box.
#
#
# @note This is a stable API function
#
# @param [Yast::Term] button_box term that contains a `HBox() with buttons in it
# @return [Yast::Term] term describing the dialog.
#
def GenericTreeDialog(button_box)
button_box = deep_copy(button_box)
VBox(
Id(:WizardDialog),
ReplacePoint(Id(:topmenu), Empty()),
HBox(
HSpacing(1),
HWeight(
30,
ReplacePoint(
Id(:helpSpace), # `RichText(`id(`HelpText), "")
Empty()
)
),
HSpacing(1),
HWeight(
70,
VBox(
VSpacing(0.2),
HBox(
# translators: dialog title to appear before any content is initialized
Heading(
Id(:title),
Opt(:hstretch),
_("YaST\nInitializing ...\n")
),
HStretch()
),
VWeight(
1, # Layout trick: Lower layout priority with weight
HVCenter(Opt(:hvstretch), ReplacePoint(Id(:contents), Empty()))
)
)
),
HSpacing(1)
),
ReplacePoint(Id(:rep_button_box), button_box),
VSpacing(0.2)
)
end
# Check if the topmost dialog is a wizard dialog
# (i.e. has a widget with `id(`WizardDialog) )
#
# @return [Boolean] True if topmost dialog is a wizard dialog, false otherwise
#
def IsWizardDialog
UI.WidgetExists(Id(:WizardDialog)) == true ||
UI.WidgetExists(:wizard) == true
end
# Open a popup dialog that displays a help text (rich text format).
#
# @note This is a stable API function
#
# @param [String] help_text the text to display
#
def ShowHelp(help_text)
Popup.LongText(
# Heading for help popup window
_("Help"),
RichText(help_text),
50,
20
)
nil
end
# Returns a standard wizard dialog with buttons "Next", "Back", "Abort".
#
# @note This is a stable API function
#
# @return [Yast::Term] describing the dialog.
#
def NextBackDialog
GenericDialog(BackAbortNextButtonBox())
end
# Returns a standard wizard dialog with buttons "Cancel", "Accept"
#
# @note This is a stable API function
#
# @return [Yast::Term] describing the dialog.
#
def AcceptDialog
GenericDialog(CancelAcceptButtonBox())
end
# Returns a standard wizard dialog with buttons "Cancel", "OK"
#
# @note This is a stable API function
#
# @return [Yast::Term] describing the dialog.
#
def OKDialog
GenericDialog(CancelOKButtonBox())
end
# Open any wizard dialog.
#
# @note This is a stable API function
#
# @param [Yast::Term] dialog a wizard dialog, e.g. Wizard::GenericDialog()
#
def OpenDialog(dialog)
dialog = deep_copy(dialog)
set_icon
UI.OpenDialog(Opt(:wizardDialog), dialog)
ShowReleaseNotesButton(@relnotes_button_label, @relnotes_button_id) if !@relnotes_button_id.empty?
nil
end
# Open a dialog with buttons "Next", "Back", "Abort"
# and set the keyboard focus to "Next".
#
def OpenNextBackDialog
if haveFancyUI
open_wizard_dialog(
:back,
Label.BackButton,
:abort,
Label.AbortButton,
:next,
Label.NextButton
)
else
OpenDialog(NextBackDialog())
UI.SetFocus(Id(:next))
end
nil
end
# Open a dialog with "Accept", "Cancel"
# and set the keyboard focus to "Accept".
#
def OpenAcceptDialog
if haveFancyUI
open_wizard_dialog(
:no_back_button,
"",
:cancel,
Label.CancelButton,
:accept,
Label.AcceptButton
)
# Don't let sloppy calls to Wizard::SetContents() disable this button by accident
UI.WizardCommand(term(:ProtectNextButton, true))
else
OpenDialog(AcceptDialog())
UI.SetFocus(Id(:accept))
end
nil
end
# Open a dialog with "OK", "Cancel"
# and set the keyboard focus to "OK".
#
def OpenOKDialog
if haveFancyUI
open_wizard_dialog(
:no_back_button,
"",
:cancel,
Label.CancelButton,
:ok,
Label.OKButton
)
# Don't let sloppy calls to Wizard::SetContents() disable this button by accident
UI.WizardCommand(term(:ProtectNextButton, true))
else
OpenDialog(OKDialog())
UI.SetFocus(Id(:ok))
end
nil
end
# Open a dialog with "Accept", "Cancel"
# and set the keyboard focus to "Accept".
#
def OpenAbortApplyFinishDialog
if haveFancyUI
open_wizard_dialog(
:apply,
_("&Apply"),
:abort,
Label.AbortButton,
:finish,
Label.FinishButton
)
else
OpenDialog(GenericDialog(AbortApplyFinishButtonBox()))
UI.SetFocus(Id(:finish))
end
nil
end
# Open a dialog with "Accept", "Cancel" that will also accept workflow steps.
#
def OpenAcceptStepsDialog
if haveFancyUI
open_wizard_dialog(
Opt(:stepsEnabled),
:no_back_button,
"",
:cancel,
Label.CancelButton,
:accept,
Label.AcceptButton
)
# Don't let sloppy calls to Wizard::SetContents() disable this button by accident
UI.WizardCommand(term(:ProtectNextButton, true))
else
OpenAcceptDialog()
end
nil
end
# Open a dialog with "Accept", "Cancel" that will also accept workflow steps.
#
def OpenAcceptAbortStepsDialog
if haveFancyUI
open_wizard_dialog(
Opt(:stepsEnabled),
:no_back_button,
"",
:abort,
Label.AbortButton,
:accept,
Label.AcceptButton
)
# Don't let sloppy calls to Wizard::SetContents() disable this button by accident
UI.WizardCommand(term(:ProtectNextButton, true))
else
OpenDialog(GenericDialog(AbortAcceptButtonBox()))
end
nil
end
# Open a dialog with "Back", "Next", "Abort" that will also accept workflow steps.
#
def OpenNextBackStepsDialog
if haveFancyUI
open_wizard_dialog(
Opt(:stepsEnabled),
:back,
Label.BackButton,
:abort,
Label.AbortButton,
:next,
Label.NextButton
)
else
OpenNextBackDialog()
end
nil
end
# Open a dialog with "Back", "Next", "Abort"
# that has the title on the left, as wanted by
# the installation visual design
def OpenLeftTitleNextBackDialog
if haveFancyUI
open_wizard_dialog(
Opt(:titleOnLeft),
:back,
Label.BackButton,
:abort,
Label.AbortButton,
:next,
Label.NextButton
)
else
OpenNextBackDialog()
end
nil
end
# Open a new wizard according to the layout configuration
#
# @param layout [::UI::Wizards::Layout]
def OpenWithLayout(layout)
UI.SetProductLogo(layout.banner?)
if layout.mode.steps?
self.OpenNextBackStepsDialog
elsif layout.mode.tree?
self.OpenTreeNextBackDialog
elsif layout.mode.title_on_left?
self.OpenLeftTitleNextBackDialog
elsif layout.mode.title_on_top?
self.OpenNextBackDialog
else
raise "Unknown layout mode: #{layout}"
end
end
# Open a wizard dialog with simple layout
#
# no graphics, no steps,
# only a help widget buttons (by default "Back", "Abort", "Next").
#
# This is the only type of wizard dialog which still allows replacing
# the help space - either already upon opening it or later with
# Wizard::ReplaceCustomHelp().
#
# If help_space_contents is 'nil', the normal help widget will remain.
# If button_box is 'nil', Wizard::BackAbortNextButtonBox() is used.
#
# @see #CloseDialog
#
# @param [Yast::Term] help_space_contents Help space contents
# @param [Yast::Term] button_box Buttom Box
# @return [void]
#
def OpenCustomDialog(help_space_contents, button_box)
help_space_contents = deep_copy(help_space_contents)
button_box = deep_copy(button_box)
button_box = BackAbortNextButtonBox() if button_box.nil?
set_icon
UI.OpenDialog(Opt(:wizardDialog), GenericDialog(button_box))
UI.ReplaceWidget(Id(:helpSpace), help_space_contents) if !help_space_contents.nil?
nil
end
# Replace the help widget for dialogs opened with Wizard::OpenCustomDialog().
# @param [Yast::Term] contents Replace custom help with supplied contents
#
def ReplaceCustomHelp(contents)
contents = deep_copy(contents)
if UI.WidgetExists(Id(:helpSpace))
UI.ReplaceWidget(Id(:helpSpace), contents)
else
Builtins.y2error(
"Wizard::ReplaceHelpSpace() works only for dialogs opened with Wizard::OpenSimpleDialog() !"
)
end
nil
end
# Close a wizard dialog.
#
# @note This is a stable API function
#
def CloseDialog
if IsWizardDialog()
UI.CloseDialog
else
Builtins.y2error(
"Wizard::CloseDialog(): Topmost dialog is not a wizard dialog!"
)
end
nil
end
# Substitute for UI::UserInput
#
# This function transparently handles different variations of the wizard
# layout. Returns `next if `next or `accept were clicked, `back if `back
# or `cancel were clicked. Simply replace
# ret = UI::UserInput()
# with
# ret = Wizard::UserInput()
#
# @return (maybe normalized) widget ID
#
def UserInput
input = UI.UserInput
return :next if input == :accept
return :back if input == :cancel
deep_copy(input)
end
# Substitute for UI::TimeoutUserInput
#
# Analogical to Wizard::UserInput.
#
# @param [Fixnum] timeout_millisec
#
def TimeoutUserInput(timeout_millisec)
input = UI.TimeoutUserInput(timeout_millisec)
return :next if input == :accept
return :back if input == :cancel
deep_copy(input)
end
# Substitute for UI::WaitForEvent
#
# Analog to Wizard::UserInput.
#
def WaitForEvent
input = UI.WaitForEvent
Ops.set(input, "ID", :next) if Ops.get(input, "ID") == :accept
Ops.set(input, "ID", :back) if Ops.get(input, "ID") == :cancel
deep_copy(input)
end
# Substitute for UI::WaitForEvent with timeout
#
# Analog to Wizard::UserInput.
#
def TimeoutWaitForEvent(timeout_millisec)
input = UI.WaitForEvent(timeout_millisec)
Ops.set(input, "ID", :next) if Ops.get(input, "ID") == :accept
Ops.set(input, "ID", :back) if Ops.get(input, "ID") == :cancel
deep_copy(input)
end
# Set a new help text.
# @param [String] help_text Help text
# @example Wizard::SetHelpText("This is a help Text");
#
def SetHelpText(help_text)
UI.ChangeWidget(Id(:WizardDialog), :HelpText, help_text) if UI.WizardCommand(term(:SetHelpText, help_text)) == false
nil
end
# Replace the wizard help subwindow with a custom widget.
#
# @deprecated
# @param [Yast::Term] contents Replace Help with contents
#
def ReplaceHelp(contents)
contents = deep_copy(contents)
if UI.WidgetExists(Id(:helpSpace))
Builtins.y2warning("Wizard::ReplaceHelp() is deprecated!")
UI.ReplaceWidget(Id(:helpSpace), contents)
else
Builtins.y2error(
"Wizard::ReplaceHelp() is not supported by the new Qt wizard!"
)
end
nil
end
# Restore the wizard help subwindow.
# @param [String] help_text Help text
#
def RestoreHelp(help_text)
SetHelpText(help_text)
nil
end
# Create and open a typical installation wizard dialog.
#
# For backwards compatibility only - don't use this any more in new modules.
#
def CreateDialog
# Set productname for help text
@product_name = OSRelease.ReleaseName if @product_name == ""
UI.SetProductName(@product_name)
OpenNextBackDialog()
nil
end
# Set the contents of a wizard dialog and define if to move focus to next button
#
# How the general framework for the installation wizard should
# look like. This function creates and shows a dialog.
#
# @param [String] title Dialog Title
# @param [Yast::Term] contents The Dialog contents
# @param [String] help_text Help text
# @param [Boolean] has_back Is the Back button enabled?
# @param [Boolean] has_next Is the Next button enabled?
# @param [Boolean] set_focus Should the focus be set to Next button?
#
def SetContentsFocus(title, contents, help_text, has_back, has_next, set_focus)
contents = deep_copy(contents)
if UI.WizardCommand(term(:SetDialogHeading, title)) == true
UI.WizardCommand(term(:SetHelpText, help_text))
UI.WizardCommand(term(:EnableNextButton, has_next))
UI.WizardCommand(term(:EnableBackButton, has_back))
UI.WizardCommand(term(:SetFocusToNextButton)) if set_focus
else
if UI.WidgetExists(Id(:next))
UI.ChangeWidget(Id(:next), :Enabled, has_next)
UI.SetFocus(Id(:next))
end
UI.ChangeWidget(Id(:back), :Enabled, has_back) if UI.WidgetExists(Id(:back))
UI.ChangeWidget(Id(:abort), :Enabled, true) if UI.WidgetExists(Id(:abort))
UI.ChangeWidget(Id(:title), :Value, title) if UI.WidgetExists(Id(:title))
UI.SetFocus(Id(:accept)) if set_focus && UI.WidgetExists(Id(:accept))
end
SetHelpText(help_text)
UI.ReplaceWidget(Id(:contents), contents)
nil
end
# Set the contents of a wizard dialog
#
# How the general framework for the installation wizard should
# look like. This function creates and shows a dialog.
#
# @note This is a stable API function
#
# @param [String] title Dialog Title
# @param [Yast::Term] contents The Dialog contents
# @param [String] help_text Help text
# @param [Boolean] has_back Is the Back button enabled?
# @param [Boolean] has_next Is the Next button enabled?
# @see Example file doc/examples/wizard1.rb
# ![screenshots/wizard1.png](../../doc/screenshots/wizard1.png)
#
def SetContents(title, contents, help_text, has_back, has_next)
contents = deep_copy(contents)
SetContentsFocus(title, contents, help_text, has_back, has_next, true)
nil
end
# Clear the wizard contents.
#
# This may sound silly, but it gives much faster feedback to the
# user if used properly: Whenever the user clicks "Next" or
# "Back", call ClearContents() prior to any lengthy
# operation -> the user notices instant response, even though he
# may in fact still have to wait.
#
# @note This is a stable API function
#
def ClearContents
SetContents("", Empty(), "", false, false)
nil
end
# Set the dialog's "Next" button with a new label and a new ID
#
# @note This is a stable API function
#
# @param [Object] id Button ID
# @param [String] label Button Label
#
def SetNextButton(id, label)
id = deep_copy(id)
if UI.WizardCommand(term(:SetNextButtonLabel, label)) == true
UI.WizardCommand(term(:SetNextButtonID, id))
elsif UI.WidgetExists(Id(:rep_next))
UI.ReplaceWidget(
Id(:rep_next),
PushButton(Id(id), Opt(:key_F10, :default), label)
)
end
nil
end
# Set the dialog's "Back" button with a new label and a new ID
#
# @note This is a stable API function
#
# @param [Object] id Button ID
# @param [String] label Button Label
#
def SetBackButton(id, label)
id = deep_copy(id)
if UI.WizardCommand(term(:SetBackButtonLabel, label)) == true
UI.WizardCommand(term(:SetBackButtonID, id))
elsif UI.WidgetExists(Id(:rep_back))
UI.ReplaceWidget(
Id(:rep_back),
PushButton(Id(id), Opt(:key_F8), label)
)
end
nil
end
# Set the dialog's "Abort" button with a new label and a new ID
#
# @note This is a stable API function
#
# @param [Object] id Button ID
# @param [String] label Button Label
#
def SetAbortButton(id, label)
id = deep_copy(id)
if UI.WizardCommand(term(:SetAbortButtonLabel, label)) == true
UI.WizardCommand(term(:SetAbortButtonID, id))
elsif UI.WidgetExists(Id(:rep_abort))
UI.ReplaceWidget(
Id(:rep_abort),
PushButton(Id(id), Opt(:key_F9), label)
)
end
nil
end
# Hide the Wizard's "Next" button.
# Restore it later with RestoreNextButton():
#
# @see #RestoreNextButton
# @note This is a stable API function
#
def HideNextButton
UI.ReplaceWidget(Id(:rep_next), Empty()) if UI.WizardCommand(term(:SetNextButtonLabel, "")) == false && UI.WidgetExists(Id(:rep_next))
nil
end
# Hide the Wizard's "Back" button.
# Restore it later with RestoreBackButton():
#
# @see #RestoreBackButton
# @note This is a stable API function
#
def HideBackButton
UI.ReplaceWidget(Id(:rep_back), Empty()) if UI.WizardCommand(term(:SetBackButtonLabel, "")) == false && UI.WidgetExists(Id(:rep_back))
nil
end
# Overview Dialog
# http://en.opensuse.org/YaST/Style_Guide#Single_Configuration.2FOverview.2FEdit_Dialog
# dialog with Cancel and OK buttons (cancel has function as abort)
#
def OpenCancelOKDialog
if haveFancyUI
open_wizard_dialog(
:back,
Label.BackButton,
:abort,
Label.CancelButton,
:next,
Label.OKButton
)
HideBackButton()
else
OpenDialog(NextBackDialog())
UI.SetFocus(Id(:next))
end
nil
end
# Hide the Wizard's "Abort" button.
# Restore it later with RestoreAbortButton():
#
# @see #RestoreAbortButton
# @note This is a stable API function
#
def HideAbortButton
if UI.WizardCommand(term(:SetAbortButtonLabel, "")) == false
if UI.WidgetExists(Id(:rep_abort))
UI.ReplaceWidget(Id(:rep_abort), Empty())