Class: Ruber::ExceptionDialog

Inherits:
KDE::Dialog
  • Object
show all
Defined in:
lib/ruber/exception_widgets.rb

Overview

Dialog which displays the content of an exception (that is, the message and the backtrace) to the user.

The backtrace is shown as an extension widget, only if the user clicks the ‘Backtrace’ button.

Direct Known Subclasses

ComponentLoadingErrorDialog

Defined Under Namespace

Classes: ExceptionBacktraceWidget

Instance Method Summary (collapse)

Constructor Details

- (ExceptionDialog) initialize(ex, parent = nil, out = true, msg = 'Ruber raised the following exception:')

A new instance of ExceptionDialog

Parameters:

  • ex (Exception)

    the exception the dialog is for

  • the (Qt::Widget, nil)

    parent widget

  • out (Boolean) (defaults to: true)

    whether to display the exception to standard error when the dialog is executed

  • msg (String) (defaults to: 'Ruber raised the following exception:')

    the text to display in the dialog before the exception message. Note that this will always be treated as rich text. Unless empty, a line break will always be inserted after it



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ruber/exception_widgets.rb', line 92

def initialize ex, parent = nil, out = true, msg = 'Ruber raised the following exception:'
  super parent
  self.caption = KDE::Dialog.make_standard_caption "Exception"
  self.buttons = Ok | Details
  set_button_text Ok, 'Quit Ruber'
  set_button_text Details, 'Backtrace'
  error = ex.message.gsub(/\n/, '<br/>')
  error.gsub!(/[<>]/){|s| s == '<' ? '&lt;' : '&gt;'}
  text = (!msg.empty? ? msg + '<br/>' : '') + '<tt>' + error + '</tt>'
  self.main_widget = Qt::Label.new text, self
  @backtrace_widget = ExceptionBacktraceWidget.new ex, self
  self.details_widget = @backtrace_widget
  @out = out
end

Instance Method Details

- (Integer) exec

Override of KDE::Dialog#exec

If the out parameter passed to the constructor was true, displays the exception message and backtrace on standard error before displaying the dialog

Returns:

  • (Integer)

    the exit code of the dialog



133
134
135
136
137
138
# File 'lib/ruber/exception_widgets.rb', line 133

def exec
  if @out
    $stderr.puts @backtrace_widget.to_plain_text
  end
  super
end

- (nil) show

Override of KDE::Dialog#show

If the out parameter passed to the constructor was true, displays the exception message and backtrace on standard error before displaying the dialog

Returns:

  • (nil)


147
148
149
150
151
152
# File 'lib/ruber/exception_widgets.rb', line 147

def show
  if @out
    $stderr.puts @backtrace_widget.to_plain_text
  end
  super
end

- (Qt::Size) sizeHint

Override of KDE::Dialog#sizeHint

It takes into account the size of the details widget, if shown.

Returns:

  • (Qt::Size)

    the suggested size for the dialog



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ruber/exception_widgets.rb', line 114

def sizeHint
  orig = super
  if defined?(@backtrace_widget) and @backtrace_widget.visible?
    main_width = main_widget.sizeHint.width
    diff = orig.width - main_width
    det_width = @backtrace_widget.sizeHint.width
    w = [det_width, main_width].max + diff
    Qt::Size.new(w, orig.height)
  else orig
  end
end