Starting a Ruby GUI w/out showing the Klayout GUI

edited April 2015 in Ruby Scripting

I am writing an application where I would like to use Klayout-supplied behavior but I don't need the normal Klayout user interface. I have written my GUI in
QT Designer as a .ui file that I load this way:

  module MyMacro
    include RBA

    HERE = File.dirname(__FILE__)
    UI   = File.join(HERE, '..', 'data', 'framebuilder5.ui')

    ui_file = QFile::new(UI)
    ui_file.open(QIODevice::ReadOnly.to_i)
    dialog = QFormBuilder::new.load(ui_file, Application::instance.main_window)
    ui_file.close
    dialog.show
  end

I don't know how to keep the Klayout GUI from appearing without taking away my
application's GUI capability. Can anyone suggest a solution?
My version of Klayout is 0.23.9 compiled with Qt 4.8.5 and Ruby 1.9.3 on RedHat Linux 5.6 (sorry I cannot update my OS).

Thanks,
Dave

Comments

  • edited May 2015

    Hi Dave,

    The "-z" command line option is your friend. You can use it with "-r" to run a script without starting the application:

    Here is a sample:

    include RBA
    
    dialog = QDialog.new(Application.instance.main_window)
    
    dialog.setWindowTitle("Dialog Title")
    
    dialog.resize(350, 300)
    
    grid = QGridLayout.new(dialog)
    
    windowlabel1 = QLabel.new(dialog)
    windowlabel1.setText("Label")
    edit = QTextEdit.new(dialog)
    edit.enabled = false
    
    ok = QPushButton.new("OK", dialog)
    ok.clicked do 
      dialog.hide
    end
    
    grid.addWidget(windowlabel1, 0, 0, 1, 3)
    grid.addWidget(edit, 1, 0, 3, 2)
    grid.addWidget(ok, 4, 3)
    grid.setRowStretch(3, 1)
    grid.setColumnStretch(1, 1)
    
    dialog.exec
    

    Save this to "dialog.rb" and run it this way:

    klayout -z -r dialog.rb
    

    Matthias

  • edited November -1

    That worked! Thank you Matthias!

Sign In or Register to comment.