Class: Dialog::KDialog::ProgressBar
- Inherits:
-
Object
- Object
- Dialog::KDialog::ProgressBar
- 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
-
#canceled? ⇒ Boolean
(also: #cancelled?)
If the option to show a cancel button is available, has it been pressed?.
-
#close ⇒ Boolean
Close the progress bar.
-
#initialize(servicename, path, show_cancel: false, label: "Working...", autoclose: true) {|bar| ... } ⇒ ProgressBar
constructor
A new instance of ProgressBar.
-
#label(text) ⇒ ProgressBar
Change the text of the label above the progress bar.
-
#max ⇒ Integer
The maximum value the progress bar go up to.
-
#max=(n) ⇒ ProgressBar
Sets the maximum value the progress bar can go up to.
-
#succ ⇒ ProgressBar
Increments the progress bar by one step.
-
#value ⇒ Integer
Get the current value of the progress bar.
-
#value=(n) ⇒ ProgressBar
Set the current value of the progress bar.
Constructor Details
#initialize(servicename, path, show_cancel: false, label: "Working...", autoclose: true) {|bar| ... } ⇒ ProgressBar
Returns a new instance of ProgressBar.
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?
348 349 350 |
# File 'lib/dialog/kdialog.rb', line 348 def canceled? @progress.wasCancelled.first end |
#close ⇒ Boolean
Close the progress bar
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
397 398 399 400 |
# File 'lib/dialog/kdialog.rb', line 397 def label(text) @progress.setLabelText(text) self end |
#max ⇒ Integer
Returns 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
389 390 391 392 |
# File 'lib/dialog/kdialog.rb', line 389 def max=(n) @progress["maximum"] = n self end |
#succ ⇒ ProgressBar
Increments the progress bar by one step
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 |
#value ⇒ Integer
Get the current value of the progress bar
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.
364 365 366 367 |
# File 'lib/dialog/kdialog.rb', line 364 def value=(n) @progress["value"] = n self end |