lib/cosmos/gui/dialogs/splash.rb in cosmos-3.2.1 vs lib/cosmos/gui/dialogs/splash.rb in cosmos-3.3.0

- old
+ new

@@ -35,23 +35,31 @@ @message_box = Qt::LineEdit.new @message_box.setReadOnly(true) layout.addWidget(@message_box) @progress_bar = Qt::ProgressBar.new layout.addWidget(@progress_bar) - setLayout(layout) + + @progress = 0 + @complete = false end def message=(message) - Qt.execute_in_main_thread(true) do - @message_box.setText(message) + unless @complete + Qt.execute_in_main_thread(false) do + @message_box.setText(message) + end end end def progress=(progress) - Qt.execute_in_main_thread(true) do - @progress_bar.setValue(progress * 100) + progress_int = (progress * 100).to_i + if !@complete and @progress != progress_int + @progress = progress_int + Qt.execute_in_main_thread(false) do + @progress_bar.setValue(progress_int) + end end end def message_callback method(:message=) @@ -80,34 +88,48 @@ # Create a new thread to run the block # WARNING! If you need to update your own gui you must wrap it with: # Qt.execute_in_main_thread(true) do # < Update the GUI > # end - complete = false Thread.new do error = nil begin yield dialog rescue Exception => e error = e end + @complete = true + # If the block threw an error show it before allowing the application to crash if error Qt.execute_in_main_thread(true) do ExceptionDialog.new(parent, error, "Error During Startup") end end Qt.execute_in_main_thread(true) do # Once the block has completed we hide and dispose the dialog to allow the main application to take over dialog.hide - dialog.dispose unless wait_for_complete + + unless wait_for_complete + # Need to make sure all Qt.execute_in_main_thread() have completed before disposing or + # we will segfault + Qt::RubyThreadFix.queue.pop.call until Qt::RubyThreadFix.queue.empty? + + dialog.dispose + end end - complete = true end - dialog.exec if wait_for_complete - dialog.dispose if wait_for_complete + if wait_for_complete + dialog.exec + + # Need to make sure all Qt.execute_in_main_thread() have completed before disposing or + # we will segfault + Qt::RubyThreadFix.queue.pop.call until Qt::RubyThreadFix.queue.empty? + + dialog.dispose + end end end end # module Cosmos