class Dialog::KDialog::ProgressBar

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

Public Class Methods

new(servicename, path, show_cancel: false, label: "Working...", autoclose: true) { |self| ... } click to toggle source

@param servicename [String] The dbus service to connect to, provided by kdialog’s output @param path [String] The path to the progress bar, provided by kdialog’s output @!macro [new] pgargs

@param show_cancel [Boolean] If true, display a cancel button for the user to request early stop of work
@param label [String] Text to display above the progress bar, typically providing information about current activity
@param autoclose [Boolean] If true, the window will close when the progress is set to the highest value
@yieldparam bar [ProgressBar] An object for manipulating state of the progress bar, ensures proper closing at block exit
# 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

Public Instance Methods

canceled?() click to toggle source

If the option to show a cancel button is available, has it been pressed? @return [Boolean]

# File lib/dialog/kdialog.rb, line 348
def canceled?
  @progress.wasCancelled.first
end
Also aliased as: cancelled?
cancelled?()
Alias for: canceled?
close() click to toggle source

Close the progress bar @return [Boolean] true

# File lib/dialog/kdialog.rb, line 404
def close()
  begin
    @progress.close
  rescue DBus::Error
    # Already closed, no worries.
  end
  true
end
label(text) click to toggle source

Change the text of the label above the progress bar @param text [String] New text for label @return [ProgressBar] self, for method chaining

# File lib/dialog/kdialog.rb, line 397
def label(text)
  @progress.setLabelText(text)
  self
end
max() click to toggle source

@return [Integer] The maximum value the progress bar go up to.

# File lib/dialog/kdialog.rb, line 381
def max()
  @progress["maximum"]
end
max=(n) click to toggle source

Sets the maximum value the progress bar can go up to

@param n [Integer] Number to set it to @return [ProgressBar] self, for method chaining

# File lib/dialog/kdialog.rb, line 389
def max=(n)
  @progress["maximum"] = n
  self
end
succ() click to toggle source

Increments the progress bar by one step @return [ProgressBar] self, for method chaining

# File lib/dialog/kdialog.rb, line 371
def succ
  begin
    @progress["value"] += 1
  rescue DBus::Error
    # This could happen...
  end
  self
end
value() click to toggle source

Get the current value of the progress bar @return [Integer]

# File lib/dialog/kdialog.rb, line 355
def value()
  @progress["value"].to_i
end
value=(n) click to toggle source

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

@param n [Integer] Number to set it to @return [ProgressBar] self, for method chaining

# File lib/dialog/kdialog.rb, line 364
def value=(n)
  @progress["value"] = n
  self
end