Class: Cosmos::Splash::SplashDialogBox

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

Overview

Creates a dialog with a message box and a progress bar.

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ SplashDialogBox

Returns a new instance of SplashDialogBox.

Parameters:

  • parent (Qt::Widget)

    The dialog parent



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cosmos/gui/dialogs/splash.rb', line 24

def initialize(parent)
  super(parent, Qt::WindowTitleHint | Qt::CustomizeWindowHint)
  setWindowTitle(parent.windowTitle)
  setModal(true)
  layout = Qt::VBoxLayout.new

  splash_image_filename = File.join(::Cosmos::USERPATH, 'config', 'data', 'splash.gif')
  splash_image_filename = File.join(::Cosmos::PATH, 'data', 'splash.gif') unless File.exist?(splash_image_filename)
  image = Qt::Pixmap.new(splash_image_filename)
  label = Qt::Label.new
  label.setPixmap(image)
  layout.addWidget(label)

  @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

Instance Method Details

#keyPressEvent(event) ⇒ Object

Override keyPressEvent to prevent Esc from closing the splash dialog

Parameters:

  • event (Qt::KeyEvent)

    Pressed key event



81
82
83
84
85
86
87
88
# File 'lib/cosmos/gui/dialogs/splash.rb', line 81

def keyPressEvent(event)
  # Don't allow the Escape key to close this dialog
  if event.key == Qt::Key_Escape
    event.ignore
  else
    super(event)
  end
end

#message=(message) ⇒ Object

Parameters:

  • message (String)

    Text to place in the message box. Text is replaced and not appended.



50
51
52
53
54
55
56
# File 'lib/cosmos/gui/dialogs/splash.rb', line 50

def message=(message)
  unless @complete
    Qt.execute_in_main_thread(false) do
      @message_box.setText(message)
    end
  end
end

#message_callbackMethod

Returns message= method.

Returns:

  • (Method)

    message= method



70
71
72
# File 'lib/cosmos/gui/dialogs/splash.rb', line 70

def message_callback
  method(:message=)
end

#progress=(progress) ⇒ Object

Parameters:

  • progress (Float)

    Set the progress bar to a percentage from 0 to 1



59
60
61
62
63
64
65
66
67
# File 'lib/cosmos/gui/dialogs/splash.rb', line 59

def progress=(progress)
  progress_int = (progress * 100).to_i
  if !@complete && (@progress != progress_int)
    @progress = progress_int
    Qt.execute_in_main_thread(false) do
      @progress_bar.setValue(progress_int)
    end
  end
end

#progress_callbackMethod

Returns progress= method.

Returns:

  • (Method)

    progress= method



75
76
77
# File 'lib/cosmos/gui/dialogs/splash.rb', line 75

def progress_callback
  method(:progress=)
end