Class: Ruber::CommandPlugin::ToolWidget
- Inherits:
-
Qt::Widget
- Object
- Qt::Widget
- Ruber::CommandPlugin::ToolWidget
- Defined in:
- plugins/command/command.rb
Overview
The tool widget where the user can enter the ruby code to execute.
Instance Method Summary (collapse)
-
- (Boolean) execute_command
slot
Executes the text in the tool widget in the ruby interpreter where Ruber is running in.
-
- (ToolWidget) initialize(parent = nil)
constructor
A new instance of ToolWidget.
-
- (nil) load_settings
slot
Called whenever the global settings change and when the plugin is first loaded.
-
- (nil) output_visible(visible)
slot
private
Shows or hides the output widget and related widgets.
Constructor Details
- (ToolWidget) initialize(parent = nil)
A new instance of ToolWidget
52 53 54 55 56 57 58 59 60 61 |
# File 'plugins/command/command.rb', line 52 def initialize parent = nil super @ui = Ui::CommandToolWidget.new @ui.setup_ui self self.focus_proxy = @ui.editor connect @ui.execute, SIGNAL(:clicked), self, SLOT(:execute_command) connect @ui.show_output, SIGNAL('toggled(bool)'), self, SLOT('output_visible=(bool)') @ui.clear.connect(SIGNAL(:clicked)){@ui.output.clear} self.output_visible = @ui.show_output.checked? end |
Instance Method Details
- (Boolean) execute_command
Executes the text in the tool widget in the ruby interpreter where Ruber is running in. If an exception is raised by the code, it won’t be propagated to Ruber. Instead, it will be displayed on standard error and in a message box.
was raised.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'plugins/command/command.rb', line 71 def execute_command code = @ui.editor.to_plain_text begin old_stdout = $stdout old_stderr = $stderr $stdout = Output.new @ui.output, Ruber[:config][:output_colors, :output], $stdout.fileno $stderr = Output.new @ui.output, Ruber[:config][:output_colors, :error], $stderr.fileno eval code, TOPLEVEL_BINDING, 'COMMAND' true rescue Exception => ex dlg = ExceptionDialog.new ex, Ruber[:main_window], true, 'The command you issued raised the following exception:' dlg. KDE::Dialog::Ok, i18n('Ok') dlg.exec false ensure $stdout = old_stdout $stderr = old_stderr end end |
Slot Signature:
execute_command()
- (nil) load_settings
Called whenever the global settings change and when the plugin is first loaded
Sets the font of the editor to the font chosen by the user as the output font
98 99 100 101 102 103 104 105 106 107 |
# File 'plugins/command/command.rb', line 98 def load_settings font = Ruber[:config][:general, :output_font] metrics = Qt::FontMetrics.new font tab_width = metrics.max_width * 2 @ui.editor.font = font @ui.editor.tab_stop_width = tab_width @ui.output.font = font @ui.output.tab_stop_width = tab_width nil end |
Slot Signature:
load_settings()
- (nil) output_visible=(visible) (private)
Shows or hides the output widget and related widgets
It also changes the text of the Show Output button so that it becomes ‘Hide Output’ if the button is visible.
120 121 122 123 124 125 126 |
# File 'plugins/command/command.rb', line 120 def output_visible= visible @ui.output.visible = visible @ui.clear.visible = visible @ui.output_label.visible = visible @ui.show_output.text = i18n(visible ? '&Hide Output' : '&Show Output') nil end |
Slot Signature:
output_visible=(bool)