Class: Yast::ProgressClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/Progress.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) CloseSuperior

Replaces stages of superior progress by an empty help text.



1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
# File '../../src/modules/Progress.rb', line 1002

def CloseSuperior
  if UI.HasSpecialWidget(:Wizard)
    UI.CloseDialog
  else
    Wizard.RestoreHelp("")
  end
  @super_steps = 0
  @super_step = 0

  nil
end

- (Symbol) CurrentSubprogressType

Get current subprogress type

Returns:

  • (Symbol)

    Current type of the subprogress widget - can be progress,tick or `none



564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
# File '../../src/modules/Progress.rb', line 564

def CurrentSubprogressType
  ret = :none

  return ret if !@visible || Mode.commandline

  # is there the subprogress progress widget?
  if UI.WidgetExists(:subprogress_progress) == true
    ret = :progress
  # or is there the tick subprogress widget?
  elsif UI.WidgetExists(:subprogress_tick) == true
    ret = :tick
  end

  ret
end

- (Object) FallbackIconInvisible



333
334
335
# File '../../src/modules/Progress.rb', line 333

def FallbackIconInvisible
  Ops.add(Directory.icondir, "32x32/apps/yast-sudo.png")
end

- (Object) FallbackIconVisible



337
338
339
# File '../../src/modules/Progress.rb', line 337

def FallbackIconVisible
  Ops.add(Directory.icondir, "32x32/apps/yast-scripts.png")
end

- (Object) Finish

Moves progress bar to the end and marks all stages as completed.



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
# File '../../src/modules/Progress.rb', line 931

def Finish
  return if !@visible || Mode.commandline

  # decrease the reference counter
  @progress_running = Ops.subtract(@progress_running, 1)

  # set the previous state
  if Ops.greater_than(StackSize(), 0)
    PopState()
    return
  end

  if 0 != @stages
    # unwind remaining stages
    NextStage() while Ops.less_than(@current_stage, @stages)
  end
  if 0 != @steps
    @current_step = @steps
    UpdateProgressBar()
  end

  SetProgressBarTitle(" ")

  nil
end

- (Object) GenerateIdleIcons(number_of_stages)



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
# File '../../src/modules/Progress.rb', line 369

def GenerateIdleIcons(number_of_stages)
  display_info = UI.GetDisplayInfo
  can_display_images = Ops.get_boolean(
    display_info,
    "HasImageSupport",
    false
  ) == true

  return Empty() if !can_display_images

  ret = HBox(HSpacing(2))
  i = -1

  number_of_stages = Ops.subtract(number_of_stages, 1)

  while Ops.less_than(i, number_of_stages)
    i = Ops.add(i, 1)

    one_icon = NormalizeIconPath(
      Ops.get(@global_visible_icons_definition, i),
      false
    )
    ret = Builtins.add(
      ret,
      Image(Id(IconId(i)), Opt(:disabled), one_icon, "[X]")
    )
    ret = Builtins.add(ret, HSpacing(2))
  end

  deep_copy(ret)
end

- (Object) HighlightProgressIcon(step_id)

Highlights a progress icon (changes the dimmed one into a normal one).

Parameters:

  • integer

    current step ID



725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
# File '../../src/modules/Progress.rb', line 725

def HighlightProgressIcon(step_id)
  if @has_icon_progress_bar
    @last_highlighted_icon = -1 if @last_highlighted_icon.nil?

    # some steps might have been skipped, change all (not changed yet)
    # icons one by one
    while Ops.less_than(@last_highlighted_icon, step_id)
      @last_highlighted_icon = Ops.add(@last_highlighted_icon, 1)

      icon_id = IconId(@last_highlighted_icon)

      if UI.WidgetExists(Id(icon_id)) == true
        UI.ChangeWidget(Id(icon_id), :Enabled, true)
      end
    end
  end

  nil
end

- (Object) IconId(i)



329
330
331
# File '../../src/modules/Progress.rb', line 329

def IconId(i)
  Builtins.sformat("mark_icon_%1", i)
end

- (Object) IsRunning



152
153
154
155
156
157
158
# File '../../src/modules/Progress.rb', line 152

def IsRunning
  # Check if any progress bar exists. If it does not, we're not running
  # (querying progress counter is not enough, a module ran previously
  # might have failed to reset the counter properly)
  Ops.greater_than(@progress_running, 0) &&
    UI.WidgetExists(:progress_replace_point) == true
end

- (Object) main



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
# File '../../src/modules/Progress.rb', line 93

def main
  Yast.import "UI"

  textdomain "base"

  Yast.import "CommandLine"
  Yast.import "Wizard"
  Yast.import "Mode"
  Yast.import "Directory"
  Yast.import "FileUtils"

  # *******************************************************************
  # // !!! IMPORTANT !!!
  # // If you add here a new variable which is valid only for the current
  # // progress do not forget to add it to PushState() and PopState()
  # // functions which are are used for nested progresses!
  # *******************************************************************

  # Number of stages.
  @stages = 0
  # Number of steps
  @steps = 0
  # Current stage
  @current_stage = 0
  # Current step
  @current_step = 0
  # list of stage-titles
  @titles = []

  # is progress bar used?
  @visible = true

  # superior progress (stages) bar
  @super_steps = 0
  @super_step = 0
  @super_stages = []

  # remember the last max. value of the subprogress bar
  @last_subprogress_max = 0

  @progress_running = 0

  # remember cumulated number of steps for nested progresses
  @progress_max = 0
  @progress_val = 0

  # stack with the running progresses
  # the top of the stack is the end of the list
  @progress_stack = []

  @global_invisible_icons_definition = []
  @global_visible_icons_definition = []

  @use_icons_in_progress = false
  @has_icon_progress_bar = false

  @last_highlighted_icon = -1
end

- (Object) Mark(kind)

Returns UI mark for stages

Parameters:

  • kind (Symbol)

    todo,current or `done

Returns:

  • UI mark for stages



316
317
318
319
320
321
# File '../../src/modules/Progress.rb', line 316

def Mark(kind)
  return "-" if kind == :todo
  return UI.Glyph(:BulletArrowRight) if kind == :current
  return UI.Glyph(:CheckMark) if kind == :done
  "?@%!"
end

- (Object) MarkId(i)

Returns widget `id(…) for the marker

Parameters:

  • i (Fixnum)

    stage number

Returns:

  • widget `id(…) for the marker



325
326
327
# File '../../src/modules/Progress.rb', line 325

def MarkId(i)
  Id(Builtins.sformat("mark_stage_%1", i))
end

- (Object) New(window_title, progress_title, length, stg, tits, help_text)

New complex progress bar with stages.

Parameters:

  • window_title (String)

    title of the window

  • progress_title (String)

    title of the progress bar. Pass at least “ ” (one space) if you want some progress bar title.

  • length (Fixnum)

    number of steps. If 0, no progress bar is created, there are only stages and bottom title. THIS IS NOT NUMBER OF STAGES!

  • stg (Array<String>)

    list of strings - stage names. If it is nil, then there are no stages.

  • tits (Array)

    Titles corresponding to stages. When stage changes, progress bar title changes to one of these titles. May be nil/empty.

  • help_text (String)

    help text



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
# File '../../src/modules/Progress.rb', line 414

def New(window_title, progress_title, length, stg, tits, help_text)
  stg = deep_copy(stg)
  tits = deep_copy(tits)
  return if !@visible

  return if Mode.commandline

  # a progress is already running, remember the current status
  PushState() if IsRunning()

  Builtins.y2milestone(
    "Progress::New(%1, %2, %3)",
    window_title,
    length,
    stg
  )

  orig_current_step = @current_step

  @steps = length
  @stages = Builtins.size(stg)
  @titles = deep_copy(tits)
  @current_step = -1
  @current_stage = -1

  if Ops.less_than(length, Builtins.size(stg))
    Builtins.y2warning(
      "Number of stages (%1) is greater than number of steps (%2)",
      Builtins.size(stg),
      length
    )
  end

  if progress_title == ""
    # Reserve space for future progress bar labels. The ProgressBar
    # widget will suppress the label above the progress bar if the
    # initial label string is empty.
    progress_title = " "
  end

  # do not replace the UI, there is a progress already running
  if IsRunning()
    @progress_max = Ops.multiply(@progress_max, @steps)

    if StackSize() == 1
      @progress_val = Ops.multiply(orig_current_step, @steps)
    else
      prev_state = TopState()
      prev_progress_val = Ops.get_integer(prev_state, "progress_val", 0)

      @progress_val = Ops.multiply(prev_progress_val, @steps)
    end

    # set the maximum value of the progress bar
    UI.ReplaceWidget(
      Id(:progress_replace_point),
      ProgressBar(Id(:pb), progress_title, @progress_max, @progress_val)
    )
    Builtins.y2debug("New progress: %1/%2", @progress_val, @progress_max)

    # increase the reference counter
    @progress_running = Ops.add(@progress_running, 1)
    return
  else
    @progress_max = @steps
  end

  bar = VBox(ProgressBar(Id(:pb), progress_title, length, 0)) # progressbar only
  if 0 != @stages
    bar = VBox(VSpacing(1))
    i = 0
    label_heading = Mark(:todo)

    items = VBox()
    Builtins.foreach(stg) do |item|
      items = Builtins.add(
        items,
        HBox(
          HSpacing(1),
          # check_ycp wants this text to be translatable. I do not know why.
          # HSquash + MinWidth(4) reserves a defined space for 'mark' plus 'emtpy space'
          # see bnc #395752
          HSquash(MinWidth(4, Heading(MarkId(i), label_heading))),
          Label(item),
          HStretch()
        )
      )
      i = Ops.add(i, 1)
    end
    bar = Builtins.add(bar, Left(HBox(HSquash(items))))

    if 0 != @steps
      progress_icons = Empty()
      if @use_icons_in_progress == true
        Builtins.y2milestone("Using icons in progress")
        progress_icons = GenerateIdleIcons(length)
        @has_icon_progress_bar = true
      else
        Builtins.y2milestone("No progress icons defined")
        @has_icon_progress_bar = false
      end

      bar = Builtins.add(
        bar,
        VBox(
          VStretch(),
          progress_icons,
          ReplacePoint(Id(:subprogress_replace_point), Empty()),
          ReplacePoint(
            Id(:progress_replace_point),
            ProgressBar(Id(:pb), progress_title, length, 0)
          ),
          VSpacing(2)
        )
      )
    else
      bar = Builtins.add(
        bar,
        VBox(
          VStretch(),
          ReplacePoint(Id(:subprogress_replace_point), Empty()),
          ReplacePoint(
            Id(:progress_replace_point),
            Label(Id(:pb), Opt(:hstretch), progress_title)
          ),
          VSpacing(2)
        )
      )
    end
  end

  # patch from Michal Srb https://bugzilla.novell.com/show_bug.cgi?id=406890#c7
  if !Mode.test && UI.WidgetExists(Id(:contents))
    UI.ReplaceWidget(Id(:contents), bar)
  end

  if !UI.WizardCommand(term(:SetDialogHeading, window_title))
    UI.ChangeWidget(Id(:title), :Value, window_title)
  end
  Wizard.SetHelpText(help_text) if "" != help_text && nil != help_text
  Wizard.DisableBackButton
  Wizard.DisableNextButton

  @progress_running = Ops.add(@progress_running, 1)

  nil
end

- (Object) NewProgressIcons(window_title, progress_title, length, stg, tits, help_textmap, icons_definition)

Function adds icon-support to progress dialog. Parameters are the same as for Progress::New() function with one parameter added.

Structure:

icons_definition = $[
   [ // first 'visible'
     "/path/to/icon-highlighted.png"
     "/path/to/another-icon-highlighted.png",
   ]
   [ // then 'invisible'
     "/path/to/icon-gryscale.png",
     nil, // fallback icon will be used
   ],
 ]

Parameters:

  • window_title (String)
  • progress_title (String)
  • length (Fixnum)
  • stg (Array<String>)
  • tits (Array)
  • help_textmap (String)
  • icons_definition (Array<Array<String>>)

See Also:

  • Progress::New()


696
697
698
699
700
701
702
703
704
705
706
707
708
# File '../../src/modules/Progress.rb', line 696

def NewProgressIcons(window_title, progress_title, length, stg, tits, help_textmap, icons_definition)
  stg = deep_copy(stg)
  tits = deep_copy(tits)
  icons_definition = deep_copy(icons_definition)
  @global_visible_icons_definition = Ops.get(icons_definition, 0, [])
  @global_invisible_icons_definition = Ops.get(icons_definition, 1, [])

  @use_icons_in_progress = true
  New(window_title, progress_title, length, stg, tits, help_textmap)
  @use_icons_in_progress = false

  nil
end

- (Object) NextStage

Advance stage, advance step by 1 and set progress bar caption to that defined in New.



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
# File '../../src/modules/Progress.rb', line 812

def NextStage
  return if !@visible
  NextStep()

  if 0 == @stages || Ops.greater_than(@current_stage, @stages)
    Builtins.y2error("Non-existing stage requested.")
    return
  end

  @current_stage = Ops.add(@current_stage, 1)

  # do not update the UI in a nested progress
  return if Ops.greater_than(StackSize(), 0)

  if Mode.commandline
    if Ops.less_than(@current_stage, @stages) &&
        Ops.less_than(@current_stage, Builtins.size(@titles))
      CommandLine.PrintVerbose(Ops.get_string(@titles, @current_stage, ""))
    end
    return
  end

  if Ops.greater_than(@current_stage, 0)
    UI.ChangeWidget(
      MarkId(Ops.subtract(@current_stage, 1)),
      :Value,
      Mark(:done)
    )
  end
  # we may be past the last stage
  if Ops.less_than(@current_stage, @stages)
    if Ops.less_than(@current_stage, Builtins.size(@titles))
      SetProgressBarTitle(Ops.get_string(@titles, @current_stage, ""))
    end
    UI.ChangeWidget(MarkId(@current_stage), :Value, Mark(:current))
  end

  nil
end

- (Object) NextStageStep(st)

Jumps to the next stage and sets step to st.

Parameters:

  • st (Fixnum)

    new progress bar value



914
915
916
917
918
919
920
# File '../../src/modules/Progress.rb', line 914

def NextStageStep(st)
  return if !@visible || Mode.commandline
  NextStage()
  Step(st)

  nil
end

- (Object) NextStep

Some people say it is the best operating system ever. But now to the function. Advances progress bar value by 1.



802
803
804
805
806
807
808
# File '../../src/modules/Progress.rb', line 802

def NextStep
  return if !@visible || Mode.commandline || 0 == @steps
  @current_step = Ops.add(@current_step, 1)
  UpdateProgressBar()

  nil
end

- (Object) NormalizeIconPath(one_icon, visible)



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
# File '../../src/modules/Progress.rb', line 341

def NormalizeIconPath(one_icon, visible)
  if one_icon.nil? || one_icon == ""
    one_icon = visible ? FallbackIconVisible() : FallbackIconInvisible()
  end

  if !Builtins.regexpmatch(one_icon, ".[pP][nN][gG]$") &&
      !Builtins.regexpmatch(one_icon, ".[jJ][pP][gG]$")
    one_icon = Ops.add(one_icon, ".png")
  end

  # relative path (to Directory::icondir)
  if Builtins.regexpmatch(one_icon, "/") &&
      !Builtins.regexpmatch(one_icon, "^/")
    one_icon = Ops.add(Directory.icondir, one_icon)
    # hopefully you know what you do
    # just image name
  elsif !Builtins.regexpmatch(one_icon, "/")
    one_icon = Ops.add(Ops.add(Directory.icondir, "32x32/apps/"), one_icon)
  end

  if !FileUtils.Exists(one_icon)
    Builtins.y2error("Image %1 doesn't exist, using fallback", one_icon)
    one_icon = visible ? FallbackIconVisible() : FallbackIconInvisible()
  end

  one_icon
end

- (Object) off

Deprecated.

set

Turns progress bar off. All Progress:: calls return immediatelly.



297
298
299
300
301
302
303
# File '../../src/modules/Progress.rb', line 297

def off
  # no "deprecated" warning
  # because it is ok to use this function in testsuites
  @visible = false

  nil
end

- (Object) on

Deprecated.

set

Turns progress bar on after calling Progress::off.



307
308
309
310
311
312
# File '../../src/modules/Progress.rb', line 307

def on
  Builtins.y2warning(-1, "Deprecated function. Use Progress::set instead")
  @visible = true

  nil
end

- (Object) OpenSuperior(title, stages)

Creates a higher-level progress bar made of stages. Currently it is placed instead of help text.

Parameters:

  • title (String)

    title of the progress…

  • stages (Array<String>)

    list of stage descriptions



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
# File '../../src/modules/Progress.rb', line 961

def OpenSuperior(title, stages)
  stages = deep_copy(stages)
  if UI.HasSpecialWidget(:Wizard)
    Wizard.OpenAcceptAbortStepsDialog
    UI.WizardCommand(term(:AddStepHeading, title))

    idx = 0
    @super_steps = Builtins.size(stages)
    @super_step = -1
    Builtins.foreach(stages) do |s|
      id = Builtins.sformat("super_progress_%1", idx)
      UI.WizardCommand(term(:AddStep, s, id))
    end
    UI.WizardCommand(term(:UpdateSteps)) # old behaviour
  else
    left = VBox(VStretch())
    right = VBox(VStretch())
    idx = 0
    @super_steps = Builtins.size(stages)
    @super_step = -1
    Builtins.foreach(stages) do |i|
      id = Builtins.sformat("super_progress_%1", idx)
      left = Builtins.add(left, Heading(Id(id), "-  "))
      right = Builtins.add(right, Label(Opt(:hstretch), i))
      left = Builtins.add(left, VStretch())
      right = Builtins.add(right, VStretch())
      idx = Ops.add(idx, 1)
    end
    left = Builtins.add(left, HSpacing(4))
    right = Builtins.add(right, HStretch())
    Wizard.ReplaceHelp(
      VBox(
        HBox(HSpacing(1), Frame(title, HBox(HSpacing(1), left, right))),
        VSpacing(0.5)
      )
    )
  end

  nil
end

- (Object) PopState

pop the progress state from the stack and set it



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
# File '../../src/modules/Progress.rb', line 211

def PopState
  # pop the config
  state = Ops.get(
    @progress_stack,
    Ops.subtract(Builtins.size(@progress_stack), 1),
    {}
  )
  @progress_stack = Builtins.remove(
    @progress_stack,
    Ops.subtract(Builtins.size(@progress_stack), 1)
  )

  Builtins.y2milestone("setting up the previous state: %1", state)

  # refresh the variables
  @stages = Ops.get_integer(state, "stages", 0)
  @steps = Ops.get_integer(state, "steps", 0)
  @current_step = Ops.get_integer(state, "current_step", 0)
  @current_stage = Ops.get_integer(state, "current_stage", 0)
  @titles = Ops.get_list(state, "titles", [])
  @last_subprogress_max = Ops.get_integer(state, "last_subprogress_max", 0)
  @progress_max = Ops.get_integer(state, "progress_max", 0)
  @progress_val = Ops.get_integer(state, "progress_val", 0)

  pb_value = Ops.get_integer(state, "progress_value", 0)
  pb_value = Ops.add(pb_value.nil? ? 0 : pb_value, 1)

  # refresh the progress widget, add one step for the embedded progress
  UI.ReplaceWidget(
    Id(:progress_replace_point),
    ProgressBar(
      Id(:pb),
      Ops.get_string(state, "progress_label", ""),
      @steps,
      pb_value
    )
  )

  type = Ops.get_symbol(state, "subprogress_type", :none)
  SubprogressType(type, @last_subprogress_max)

  if type == :progress || type == :tick
    SubprogressTitle(Ops.get_string(state, "subprogress_label", ""))
    SubprogressValue(Ops.get_integer(state, "subprogress_value", 0))
  end

  nil
end

- (Object) PushState

push the current progress into the stack



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
# File '../../src/modules/Progress.rb', line 161

def PushState
  current_subprogress = CurrentSubprogressType()
  state = {
    # global variable
    "stages"               => @stages,
    "steps"                => @steps,
    "current_step"         => @current_step,
    "current_stage"        => @current_stage,
    "titles"               => @titles,
    "last_subprogress_max" => @last_subprogress_max,
    "visible"              => @visible,
    # state of the widgets
    "subprogress_type"     => current_subprogress,
    "progress_label"       => Convert.to_string(
      UI.QueryWidget(Id(:pb), :Label)
    ),
    "progress_value"       => Convert.to_integer(
      UI.QueryWidget(Id(:pb), :Value)
    ),
    "progress_max"         => @progress_max,
    "progress_val"         => @progress_val
  }

  if current_subprogress == :progress
    Ops.set(
      state,
      "subprogress_label",
      Convert.to_string(UI.QueryWidget(Id(:subprogress_progress), :Label))
    )
    Ops.set(
      state,
      "subprogress_value",
      Convert.to_integer(UI.QueryWidget(Id(:subprogress_progress), :Value))
    )
  elsif current_subprogress == :tick
    Ops.set(
      state,
      "subprogress_label",
      Convert.to_string(UI.QueryWidget(Id(:subprogress_tick), :Label))
    )
  end

  Builtins.y2milestone("Current state: %1", state)

  @progress_stack = Builtins.add(@progress_stack, state)

  nil
end

- (Object) set(state)

Sets progress bar state: on = normal operation, off = All Progress:: calls return immediatelly.

Parameters:

  • state (Boolean)

    on or off

Returns:

  • previous state



279
280
281
282
283
# File '../../src/modules/Progress.rb', line 279

def set(state)
  prev = @visible
  @visible = state
  prev
end

- (Object) SetProgressBarTitle(s)

the bar is either ProgressBar orLabel

Parameters:

  • s (String)

    title



794
795
796
797
798
# File '../../src/modules/Progress.rb', line 794

def SetProgressBarTitle(s)
  UI.ChangeWidget(Id(:pb), 0 == @steps ? :Value : :Label, s)

  nil
end

- (Object) Simple(window_title, progress_title, length, help_text)

Create simple progress bar with no stages, only with progress bar.

Parameters:

  • window_title (String)

    Title of the window.

  • progress_title (String)

    Title of the progress bar.

  • length (Fixnum)

    Number of steps.

  • help_text (String)

    Help text.



715
716
717
718
719
# File '../../src/modules/Progress.rb', line 715

def Simple(window_title, progress_title, length, help_text)
  New(window_title, progress_title, length, [], [], help_text)

  nil
end

- (Object) StackSize

return size of the progress stack



261
262
263
# File '../../src/modules/Progress.rb', line 261

def StackSize
  Builtins.size(@progress_stack)
end

- (Object) Stage(st, title, step)

Go to stage st, change progress bar title to title and set progress bar step to step.

Parameters:

  • st (Fixnum)

    New stage.

  • title (String)

    New title for progress bar. If nil, title specified in New is used.

  • step (Fixnum)

    New step or -1 if step should not change.



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
# File '../../src/modules/Progress.rb', line 871

def Stage(st, title, step)
  return if !@visible

  Step(step) if -1 != step

  # another progress is running
  # do not change the current stage, calculate the target step
  if Ops.greater_than(StackSize(), 0)
    UpdateProgressBar()
    return
  end

  if !Mode.commandline && Ops.greater_or_equal(@current_stage, 0)
    UI.ChangeWidget(
      MarkId(@current_stage),
      :Value,
      Mark(Ops.greater_than(st, @current_stage) ? :done : :todo)
    )
  end

  @current_stage = st
  s = ""
  if Ops.less_than(@current_stage, Builtins.size(@titles))
    s = Ops.get_string(@titles, @current_stage, "")
  end
  s = title if nil != title
  if Ops.less_than(@current_stage, Builtins.size(@titles))
    if Mode.commandline
      CommandLine.PrintVerbose(s)
      return
    else
      SetProgressBarTitle(s)
    end
  end
  if Ops.less_than(@current_stage, @stages)
    UI.ChangeWidget(MarkId(@current_stage), :Value, Mark(:current))
  end

  nil
end

- (Boolean) status

Returns currently selected visibility status of all UI-modifying Progress:: functions.

Returns:

  • (Boolean)

    whether the progress bar is used

See Also:

  • Yast::ProgressClass#Progress#Progress::set
  • Yast::ProgressClass#Progress#Progress::off
  • Yast::ProgressClass#Progress#Progress::on


291
292
293
# File '../../src/modules/Progress.rb', line 291

def status
  @visible
end

- (Object) Step(st)

Changes progress bar value to st.

Parameters:

  • st (Fixnum)

    new value



853
854
855
856
857
858
859
860
861
862
863
# File '../../src/modules/Progress.rb', line 853

def Step(st)
  return if !@visible || Mode.commandline || 0 == @steps

  return if Ops.less_than(st, 0) || Ops.greater_than(st, @steps)

  @current_step = st

  UpdateProgressBar()

  nil
end

- (Object) StepSuperior

Make one step in a superior progress bar.



1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
# File '../../src/modules/Progress.rb', line 1014

def StepSuperior
  if Ops.greater_or_equal(@super_step, 0) &&
      Ops.less_than(@super_step, @super_steps)
    if !UI.HasSpecialWidget(:Wizard)
      UI.ChangeWidget(
        Id(Builtins.sformat("super_progress_%1", @super_step)),
        :Value,
        UI.Glyph(:CheckMark)
      )
    end
  end
  @super_step = Ops.add(@super_step, 1)
  return if Ops.greater_or_equal(@super_step, @super_steps)
  if UI.HasSpecialWidget(:Wizard)
    UI.WizardCommand(
      term(
        :SetCurrentStep,
        Builtins.sformat("super_progress_%1", @super_step)
      )
    )
  else
    UI.ChangeWidget(
      Id(Builtins.sformat("super_progress_%1", @super_step)),
      :Value,
      UI.Glyph(:BulletArrowRight)
    )
  end

  nil
end

- (Object) SubprogressTitle(title)

Set the label of the subprogress

Parameters:

  • title (String)

    New label for the subprogress



653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
# File '../../src/modules/Progress.rb', line 653

def SubprogressTitle(title)
  return if !@visible || Mode.commandline

  current_type = CurrentSubprogressType()

  if current_type == :progress
    UI.ChangeWidget(Id(:subprogress_progress), :Label, title)
  elsif current_type == :tick
    UI.ChangeWidget(Id(:subprogress_tick), :Label, title)
  else
    Builtins.y2warning("No subprogress is defined, cannot set the label!")
  end

  nil
end

- (Object) SubprogressType(type, max_value)

Create (or remove) a new subprogress above the progress bar, can be use for detailed progress of the current task tick (tick progress) ornone (no subprogress, intended for removing the progress bar from the dialog)

Parameters:

  • type (Symbol)

    type of the subprogress widget, can be `progress (standard progress),

  • max_value (Fixnum)

    maximum value for `progress type, for the other types it is not relevant (use any integer value or nil)



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
# File '../../src/modules/Progress.rb', line 604

def SubprogressType(type, max_value)
  return if !@visible || Mode.commandline

  Builtins.y2debug(
    "SubprogressType: type: %1, max_value: %2",
    type,
    max_value
  )

  if type == CurrentSubprogressType()
    if type == :progress
      # just reset the current value of the progress bar if the requested progress is the same
      if max_value == @last_subprogress_max
        Builtins.y2milestone("Resetting the subprogressbar...")
        SubprogressValue(0)
        return
      end
    elsif type == :tick
      # just restart the animation
      UI.ChangeWidget(Id(:subprogress_tick), :Alive, true)
    else
      Builtins.y2milestone("Subprogress initialization skipped")
      return
    end
  end

  widget = Empty()

  if type == :progress
    widget = ProgressBar(Id(:subprogress_progress), " ", max_value, 0)
  elsif type == :tick
    widget = BusyIndicator(Id(:subprogress_tick), " ", 3000)
  elsif type == :none
    widget = Empty()
  else
    Builtins.y2error("Unknown subprogress type: %1", type)
  end

  Builtins.y2debug("widget: %1", widget)
  UI.ReplaceWidget(Id(:subprogress_replace_point), widget)

  # remember the max. value
  @last_subprogress_max = max_value

  nil
end

- (Object) SubprogressValue(value)

Set value of the subprogress

Parameters:

  • value (Fixnum)

    Current value of the subprogress, if a tick subprogress is running the value is ignored and the next tick is displayed



582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
# File '../../src/modules/Progress.rb', line 582

def SubprogressValue(value)
  return if !@visible || Mode.commandline

  current_type = CurrentSubprogressType()

  # normal progress
  if current_type == :progress
    UI.ChangeWidget(Id(:subprogress_progress), :Value, value)
  # tick progress
  elsif current_type == :tick
    UI.ChangeWidget(Id(:subprogress_tick), :Alive, true)
  else
    Builtins.y2warning("No subprogress is defined, cannot set the value!")
  end

  nil
end

- (Object) Title(t)

Change progress bar title.

Parameters:

  • t (String)

    new title. Use “”(empty string) if you want an empty progress bar.



924
925
926
927
928
# File '../../src/modules/Progress.rb', line 924

def Title(t)
  SetProgressBarTitle(t) if @visible && !Mode.commandline

  nil
end

- (Object) TopState

return the value on the top of the stack the stack is not changed



267
268
269
270
271
272
273
# File '../../src/modules/Progress.rb', line 267

def TopState
  Ops.get(
    @progress_stack,
    Ops.subtract(Builtins.size(@progress_stack), 1),
    {}
  )
end

- (Object) UpdateProgressBar

Uses current_step



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
# File '../../src/modules/Progress.rb', line 746

def UpdateProgressBar
  if Ops.greater_than(@current_step, @steps)
    Builtins.y2error(
      -2,
      "Progress bar has only %1 steps, not %2.",
      @steps,
      @current_step
    )
    return
  end

  progress_value = @current_step

  # do not change icons in a nested progress
  if StackSize() == 0
    HighlightProgressIcon(@current_step)
  else
    # recalculate the progress bar value according to the parent progress
    prev_state = TopState()
    prev_step = Ops.get_integer(prev_state, "current_step", 0)

    progress_value = Ops.add(
      Ops.multiply(prev_step, @steps),
      Ops.greater_than(@current_step, 0) ? @current_step : 0
    )
  end

  Builtins.y2debug(
    "New progress value: %1, current_step: %2/%3 (%4%%)",
    progress_value,
    @current_step,
    @steps,
    Ops.divide(
      Ops.multiply(
        100.0,
        Convert.convert(progress_value, from: "integer", to: "float")
      ),
      Convert.convert(@progress_max, from: "integer", to: "float")
    )
  )

  UI.ChangeWidget(Id(:pb), :Value, progress_value)

  nil
end