Class: Zerenity::Progress

Inherits:
Base
  • Object
show all
Defined in:
lib/zerenity/progress.rb

Overview

:nodoc:

Class Method Summary collapse

Methods inherited from Base

retrieve_selection

Class Method Details

.build(dialog, options, progressProxy) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/zerenity/progress.rb', line 39

def self.build(dialog,options,progressProxy)
  super(dialog,options)
  label = Gtk::Label.new(options[:text])
  progressBar = Gtk::ProgressBar.new
  progressProxy.progressBar = progressBar
  progressBar.pulse_step = 0.02
  !options[:cancellable] ? options[:cancel_button].sensitive = false : nil
  options[:ok_button].sensitive = false
  dialog.vbox.add(label)
  dialog.vbox.add(progressBar)
end

.check(options) ⇒ Object



33
34
35
36
37
# File 'lib/zerenity/progress.rb', line 33

def self.check(options)
  super(options)
  options[:autoClose] ||= false
  options[:cancellable] ||= false
end

.run(options = {}, &block) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/zerenity/progress.rb', line 51

def self.run(options={},&block)
  self.check(options)
  Gtk.init
  dialog = Gtk::Dialog.new(options[:title])
  result = nil
  progressProxy = Zerenity::ProgressProxy.new
  self.build(dialog,options,progressProxy)
  options[:cancel_button].signal_connect(CLICKED) do
    progressProxy.cancel!
  end
  options[:ok_button].signal_connect(CLICKED) do
    result = true
    dialog.destroy
    Gtk.main_quit
  end
  dialog.show_all
  gtkThread = Thread.new do 
    Gtk.main
  end
  block.call(progressProxy)
  if options[:autoClose]
    dialog.destroy
    Gtk.main_quit
    return true 
  end
  options[:ok_button].sensitive = true
  options[:cancel_button].sensitive = false 
  gtkThread.join
  return result
end