Class: ProgressBar::KDialog

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

Instance Attribute Summary collapse

Attributes inherited from Base

#i, #max, #startts, #text

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#done_dur, #done_rel, #increment!, #total_dur

Constructor Details

#initialize(max, text = nil, title: nil, **_options) ⇒ KDialog

Returns a new instance of KDialog.



181
182
183
184
185
186
187
188
# File 'lib/progress-bar.rb', line 181

def initialize max, text = nil, title: nil, **_options
	super max, text
	text = @text
	text = nil   if text.nil? or text.empty?
	title = nil  if title.nil? or title.empty?
	@title = title
	@errors = []
end

Instance Attribute Details

#dialog_objectObject (readonly)

Returns the value of attribute dialog_object.



179
180
181
# File 'lib/progress-bar.rb', line 179

def dialog_object
  @dialog_object
end

#dialog_object_pathObject (readonly)

Returns the value of attribute dialog_object_path.



179
180
181
# File 'lib/progress-bar.rb', line 179

def dialog_object_path
  @dialog_object_path
end

#dialog_service_pathObject (readonly)

Returns the value of attribute dialog_service_path.



179
180
181
# File 'lib/progress-bar.rb', line 179

def dialog_service_path
  @dialog_service_path
end

#errorsObject (readonly)

Returns the value of attribute errors.



179
180
181
# File 'lib/progress-bar.rb', line 179

def errors
  @errors
end

Class Method Details

.kdialog(*a) ⇒ Object



216
217
218
219
220
# File 'lib/progress-bar.rb', line 216

def self.kdialog *a
	windowid = ENV['WINDOWID']
	windowid = (windowid.is_a?(String) && !windowid.empty?) ? ['--attach', windowid] : []
	system 'kdialog', *windowid, *a
end

Instance Method Details

#change_progressObject



223
224
225
226
227
228
229
230
# File 'lib/progress-bar.rb', line 223

def change_progress()
	#@dialog_object.Set 'org.kde.kdialog.ProgressDialog', 'value', i
	@dialog_object['value'] = i
	raise Interrupt  if @dialog_object.wasCancelled
rescue DBus::Error
	raise Interrupt  if $!.name == 'org.freedesktop.DBus.Error.ServiceUnknown'
	raise
end

#change_textObject



232
233
234
235
236
237
238
# File 'lib/progress-bar.rb', line 232

def change_text()
	@dialog_object.setLabelText text
	raise Interrupt  if @dialog_object.wasCancelled
rescue DBus::Error
	raise Interrupt  if $!.name == 'org.freedesktop.DBus.Error.ServiceUnknown'
	raise
end

#error(text) ⇒ Object



240
241
242
# File 'lib/progress-bar.rb', line 240

def error text
	kdialog '--error', text
end

#finishObject



244
245
246
247
248
# File 'lib/progress-bar.rb', line 244

def finish()
	return  if @finished
	@dialog_object.close  rescue DBus::Error
	@finished = true
end

#kdialog(*a) ⇒ Object



221
# File 'lib/progress-bar.rb', line 221

def kdialog(*a)  self.class.kdialog *a  end

#max=(val) ⇒ Object



250
251
252
253
# File 'lib/progress-bar.rb', line 250

def max= val
	super val
	@dialog_object['maximum'] = val
end

#possible?Boolean

Returns:

  • (Boolean)


190
191
192
193
# File 'lib/progress-bar.rb', line 190

def possible?
	path = Pathname.new `which kdialog`.chomp
	$?.exitstatus  and  path.executable?
end

#startObject



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/progress-bar.rb', line 195

def start
	@finished = false
	args = ['kdialog', @title ? ['--title', @title] : [], '--progressbar', @text || '.', @max].flatten.compact.map &:to_s
	@dialog_service_path, @dialog_object_path =
		IO.popen( args, 'r', &:readlines).join( "\n").split ' '
	@dialog_bus = DBus.session_bus
	@dialog_service = @dialog_bus[@dialog_service_path]
	@dialog_object = @dialog_service[ @dialog_object_path]
	#STDERR.puts "%p" %
		@dialog_object.introspect
	@dialog_object.showCancelButton 1
	super
	change_text  if text.nil?
	change_progress
	self

rescue DBus::Error
	raise Interrupt  if $!.name == 'org.freedesktop.DBus.Error.ServiceUnknown'
	raise
end