require 'Qt' require 'tempfile' # This class implements a dialog with a screenshot display area and a # screenshot button class ScreenshotDialog < Qt::Dialog slots 'button_clicked()' def initialize(parent = nil, name = nil) super setWindowTitle("Screenshot Saver") resize(400, 120) layout = Qt::VBoxLayout.new setLayout(layout) @image = Qt::Label.new("Press the button to fetch a screenshot", self) layout.addWidget(@image) button = Qt::PushButton.new('Screenshot', self) button.setFont(Qt::Font.new('Times', 18, Qt::Font::Bold)) layout.addWidget(button) connect(button, SIGNAL('clicked()'), SLOT('button_clicked()')) end def button_clicked view = RBA::Application.instance.main_window.current_view if view tmp = Tempfile.new("klayout-screenshot") view.save_image(tmp.path, 400, 400) @image.setPixmap(Qt::Pixmap.new(tmp.path)) end end end # Locate the main window's qtruby object: qt_main_window = Qt::Application.topLevelWidgets.select { |w| w.class.to_s == "lay::MainWindow" } [0] # Instantiate the dialog and make it visible initially. # Passing the $main_window will make it stay on top of the main window. $dialog = ScreenshotDialog.new(qt_main_window) $dialog.show # It is important to run the application in the script so that exceptions are caught RBA::Application.instance.exec