dialog-fu 0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 546f459f27e812bb284a2afeda60a26995655286
4
- data.tar.gz: b7398666b2b26e12512143fec0afe4c5ae1526b1
3
+ metadata.gz: 8f4a4746fb273f26058ff24e4ea211b81e4483e4
4
+ data.tar.gz: db6d274a13467edfdfbf5c692a56db19411a1bd6
5
5
  SHA512:
6
- metadata.gz: 98327730998009bf20e0302ed6dccba9c7ae3849f64e234fab4024dcd88ea878c8f51fd4cadaf4c6781a17540bddb81b0c6458c93ab9c2bb926cebd650204f62
7
- data.tar.gz: c94b88165cef7049f2a5d1bc618271b4cb83f5d0a05391db06d4738ff9ffa1b4f6a3d74629af8faff6fb57acb6261ce852c81f1e6407e688595e5c182572d5c7
6
+ metadata.gz: a7fd7dd5fd3017d89b9665b480f1f04500190af2653599b58bb818f4cdb60bf1d4e9c16fbae281cc967593646a3709b2e6cdbfcb2fca926c2b5392b2bd2c4258
7
+ data.tar.gz: cbcd2863b35591459157e7f18b7ee77a88cc81ea05ced036a04126c44791d7597c2b443809a1d17fad718632c20124636c6b3a923ebc8a69463170cf80bd6ed1
@@ -2,7 +2,7 @@
2
2
  Chris Riddoch <riddochc@gmail.com>
3
3
  :language: ruby
4
4
 
5
- Version 0.2, 2014-06-27
5
+ Version 0.2.1, 2014-07-07
6
6
 
7
7
  == Description
8
8
 
@@ -1,5 +1,5 @@
1
1
  module Dialog
2
- VERSION='0.2'
2
+ VERSION='0.2.1'
3
3
  end
4
4
 
5
5
  require_relative "dialog/dialog"
@@ -1,5 +1,6 @@
1
1
  require 'open3'
2
2
  require 'tempfile'
3
+ require 'dbus'
3
4
 
4
5
  module Dialog::KDialog
5
6
 
@@ -192,6 +193,8 @@ module Dialog::KDialog
192
193
  selection(choices, label: label, type: :radio, default: default)
193
194
  end
194
195
 
196
+ # Implementation of radiobuttons and checkboxes; user selections.
197
+ #
195
198
  # @macro choiceparam
196
199
  # @macro labelparam
197
200
  # @macro defaultparam
@@ -199,7 +202,6 @@ module Dialog::KDialog
199
202
  # radio buttons, only one selection)
200
203
  # @raise UnknownSelectionType If type is something other than :check or :radio
201
204
  # @macro runreturn
202
- #
203
205
  # @note If +type+ is +:radio+, it's the caller's responsibility to either specify a default,
204
206
  # or make sure only one of the 'choices' attributes is true in the +choices+ parameter.
205
207
  def selection(choices, label: "", type: :check, default: nil)
@@ -290,37 +292,138 @@ module Dialog::KDialog
290
292
  end
291
293
  end
292
294
 
293
- # @todo Implement
294
- # Known groups for iconloader (on my system, anyway):
295
+ # Icon Picker
296
+ #
297
+ # Allows the user to choose an icon among those available to KDE.
295
298
  #
296
- # * Desktop, Toolbar, MainToolbar, Small, Panel, Dialog, User, Action, Application, Device, FileSystem, MimeType, Animation, Category, Emblem, Emote, International, Place, StatusIcon
297
- # * From KDE3: Devices, MimeTypes, Applications, Actions
299
+ # @macro runreturn
298
300
  def icon()
301
+ run(["--geticon", "--help"])
302
+ end
303
+
304
+ # Color Picker
305
+ #
306
+ # @return [Array<Integer> nil] An array of [red, green, blue] 8-bit color components, or nil if 'cancel' pressed.
307
+ def color()
308
+ c = nil
309
+ run(["--getcolor"]) {|out|
310
+ c = [out[1,2].to_i(16),
311
+ out[3,2].to_i(16),
312
+ out[5,2].to_i(16)]
313
+ }
314
+ c
315
+ end
316
+
317
+ # Wraps the ruby-dbus interface to connect to and control a KDE ProgressDialog object.
318
+ # An instance of this object is easily created by the {Dialog::KDialog#progressbar} method, don't try to create it yourself.
319
+ class ProgressBar
320
+ # @param servicename [String] The dbus service to connect to, provided by kdialog's output
321
+ # @param path [String] The path to the progress bar, provided by kdialog's output
322
+ # @!macro [new] pgargs
323
+ # @param show_cancel [Boolean] If true, display a cancel button for the user to request early stop of work
324
+ # @param label [String] Text to display above the progress bar, typically providing information about current activity
325
+ # @param autoclose [Boolean] If true, the window will close when the progress is set to the highest value
326
+ # @yieldparam bar [ProgressBar] An object for manipulating state of the progress bar, ensures proper closing at block exit
327
+ def initialize(servicename, path, show_cancel: false, label: "Working...", autoclose: true)
328
+ bus = DBus::SessionBus.instance
329
+ service = bus.service(servicename)
330
+ dbusobj = service.object(path)
331
+ dbusobj.introspect
332
+ @progress = dbusobj["org.kde.kdialog.ProgressDialog"]
333
+ #@progress["maximum"] = max
334
+ @progress["autoClose"] = autoclose
335
+ @progress.setLabelText(label)
336
+ if block_given?
337
+ begin
338
+ yield(self)
339
+ ensure
340
+ self.close()
341
+ end
342
+ end
343
+ self
344
+ end
345
+
346
+ # If the option to show a cancel button is available, has it been pressed?
347
+ # @return [Boolean]
348
+ def canceled?
349
+ @progress.wasCancelled.first
350
+ end
351
+ alias cancelled? canceled?
352
+
353
+ # Get the current value of the progress bar
354
+ # @return [Integer]
355
+ def value()
356
+ @progress["value"].to_i
357
+ end
358
+
359
+ # Set the current value of the progress bar. The percentage shown is (n / max)
360
+ # Values outside the range of 0..max will be ignored.
361
+ #
362
+ # @param n [Integer] Number to set it to
363
+ # @return [ProgressBar] self, for method chaining
364
+ def value=(n)
365
+ @progress["value"] = n
366
+ self
367
+ end
368
+
369
+ # Increments the progress bar by one step
370
+ # @return [ProgressBar] self, for method chaining
371
+ def succ
372
+ begin
373
+ @progress["value"] += 1
374
+ rescue DBus::Error
375
+ # This could happen...
376
+ end
377
+ self
378
+ end
379
+
380
+ # @return [Integer] The maximum value the progress bar go up to.
381
+ def max()
382
+ @progress["maximum"]
383
+ end
384
+
385
+ # Sets the maximum value the progress bar can go up to
386
+ #
387
+ # @param n [Integer] Number to set it to
388
+ # @return [ProgressBar] self, for method chaining
389
+ def max=(n)
390
+ @progress["maximum"] = n
391
+ self
392
+ end
393
+
394
+ # Change the text of the label above the progress bar
395
+ # @param text [String] New text for label
396
+ # @return [ProgressBar] self, for method chaining
397
+ def label(text)
398
+ @progress.setLabelText(text)
399
+ self
400
+ end
401
+
402
+ # Close the progress bar
403
+ # @return [Boolean] true
404
+ def close()
405
+ begin
406
+ @progress.close
407
+ rescue DBus::Error
408
+ # Already closed, no worries.
409
+ end
410
+ true
411
+ end
299
412
  end
300
413
 
301
- # @todo Design and implement API for using progressbar
302
- def progressbar()
303
- require 'dbus' unless DBus
304
- steps = 10
305
- out, status = Open3.capture2("kdialog", "--progressbar", "Titlebar Text", steps.to_s)
414
+ # Present a progress bar to the user; returns an object to control its desplay
415
+ #
416
+ # @param steps [Integer] Number of increments in the progress bar.
417
+ # @param title [String] Text to display in the titlebar of the window
418
+ # @macro pbargs
419
+ # @return [ProgressBar] An object for manipulating state of the progress bar
420
+ def progressbar(steps: 100, title: "Progress Bar", show_cancel: false, label: "Working...", autoclose: true, &blk)
421
+ out, status = Open3.capture2("kdialog", "--progressbar", title, steps.to_s)
306
422
  if status != 0
307
423
  raise "kdialog exited unexpectedly"
308
424
  end
309
425
  servicename, path = *out.split(/\s+/)
310
-
311
- bus = DBus::SessionBus.instance
312
- dialogservice = bus.service(servicename)
313
- dialogobj = dialogservice.object(path)
314
- d = dialogobj["org.kde.kdialog.ProgressDialog"]
315
-
316
- d.showCancelButton(true) # or false...
317
- r = d.wasCancelled
318
- r.first # the boolean. Why it's in an array? Dunno.
319
- d["maximum"] # => 10
320
- d["autoClose"] # => false, by default
321
- d.setLabelText("Test")
322
- d["value"] # Can be assigned! Yay! Ignored if out of range.
323
- d.close # When done!
426
+ ProgressBar.new(servicename, path, label: label, autoclose: autoclose, &blk)
324
427
  end
325
428
 
326
429
  # @api private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dialog-fu
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Riddoch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-06 00:00:00.000000000 Z
11
+ date: 2014-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake