Class: Dialog::KDialog::ProgressBar

Inherits:
Object
  • Object
show all
Defined in:
lib/dialog/kdialog.rb

Overview

Wraps the ruby-dbus interface to connect to and control a KDE ProgressDialog object. An instance of this object is easily created by the #progressbar method, don’t try to create it yourself.

Instance Method Summary collapse

Constructor Details

#initialize(servicename, path, show_cancel: false, label: "Working...", autoclose: true) {|bar| ... } ⇒ ProgressBar

Returns a new instance of ProgressBar.

Parameters:

  • servicename (String)

    The dbus service to connect to, provided by kdialog’s output

  • path (String)

    The path to the progress bar, provided by kdialog’s output

  • show_cancel (Boolean) (defaults to: false)

    If true, display a cancel button for the user to request early stop of work

  • label (String) (defaults to: "Working...")

    Text to display above the progress bar, typically providing information about current activity

  • autoclose (Boolean) (defaults to: true)

    If true, the window will close when the progress is set to the highest value

Yield Parameters:

  • bar (ProgressBar)

    An object for manipulating state of the progress bar, ensures proper closing at block exit



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/dialog/kdialog.rb', line 327

def initialize(servicename, path, show_cancel: false, label: "Working...", autoclose: true)
  bus = DBus::SessionBus.instance
  service = bus.service(servicename)
  dbusobj =  service.object(path)
  dbusobj.introspect
  @progress = dbusobj["org.kde.kdialog.ProgressDialog"]
  #@progress["maximum"] = max
  @progress["autoClose"] = autoclose
  @progress.setLabelText(label)
  if block_given?
    begin
      yield(self)
    ensure
      self.close()
    end
  end
  self
end

Instance Method Details

#canceled?Boolean Also known as: cancelled?

If the option to show a cancel button is available, has it been pressed?

Returns:

  • (Boolean)


348
349
350
# File 'lib/dialog/kdialog.rb', line 348

def canceled?
  @progress.wasCancelled.first
end

#closeBoolean

Close the progress bar

Returns:

  • (Boolean)

    true



404
405
406
407
408
409
410
411
# File 'lib/dialog/kdialog.rb', line 404

def close()
  begin
    @progress.close
  rescue DBus::Error
    # Already closed, no worries.
  end
  true
end

#label(text) ⇒ ProgressBar

Change the text of the label above the progress bar

Parameters:

  • text (String)

    New text for label

Returns:



397
398
399
400
# File 'lib/dialog/kdialog.rb', line 397

def label(text)
  @progress.setLabelText(text)
  self
end

#maxInteger

Returns The maximum value the progress bar go up to.

Returns:

  • (Integer)

    The maximum value the progress bar go up to.



381
382
383
# File 'lib/dialog/kdialog.rb', line 381

def max()
  @progress["maximum"]
end

#max=(n) ⇒ ProgressBar

Sets the maximum value the progress bar can go up to

Parameters:

  • n (Integer)

    Number to set it to

Returns:



389
390
391
392
# File 'lib/dialog/kdialog.rb', line 389

def max=(n)
  @progress["maximum"] = n
  self
end

#succProgressBar

Increments the progress bar by one step

Returns:



371
372
373
374
375
376
377
378
# File 'lib/dialog/kdialog.rb', line 371

def succ
  begin
    @progress["value"] += 1
  rescue DBus::Error
    # This could happen...
  end
  self
end

#valueInteger

Get the current value of the progress bar

Returns:

  • (Integer)


355
356
357
# File 'lib/dialog/kdialog.rb', line 355

def value()
  @progress["value"].to_i
end

#value=(n) ⇒ ProgressBar

Set the current value of the progress bar. The percentage shown is (n / max) Values outside the range of 0..max will be ignored.

Parameters:

  • n (Integer)

    Number to set it to

Returns:



364
365
366
367
# File 'lib/dialog/kdialog.rb', line 364

def value=(n)
  @progress["value"] = n
  self
end