Class: Cosmos::Splash

Inherits:
Object show all
Defined in:
lib/cosmos/gui/dialogs/splash.rb

Overview

Provides a single class method which creates a splash screen dialog box. This dialog has both a text message box and progress bar.

Defined Under Namespace

Classes: SplashDialogBox

Class Method Summary collapse

Class Method Details

.execute(parent, wait_for_complete = false) {|dialog| ... } ⇒ Object

Parameters:

  • parent (Qt::Widget)

    Dialog parent

  • wait_for_complete (Boolean) (defaults to: false)

    Whether to call dialog.exec and block other threads from running until this dialog is closed

Yield Parameters:



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/cosmos/gui/dialogs/splash.rb', line 95

def self.execute(parent, wait_for_complete = false, &block)
  # Create the dialog and show it
  dialog = SplashDialogBox.new(parent)
  dialog.show unless wait_for_complete
  dialog.raise

  # 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
  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

      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
  end
  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