MainWindow tabs in ruby script

edited May 2015 in Ruby Scripting
I am running a ruby script invoked by:
klayout -z -rx -rm ruby_script.rb

The script loads a ui file that generates an RBA::MainWindow

I then try and generate a layout and layout view on the main_window (this is following the examples provided here: http://www.klayout.de/doc/programming/database_api.html ) [note that an error occurs when I try to do cell.index in the basic sample as index is not a known method of the cell]


When I run the script from my GUI, however, nothing is displayed. (the script runs fine and as expected when invoked as a menu item script from within klayout).

This leads me to wonder, does a tab of some sort need to be generated in MainWindow, or is it supposed to generate when create_layout is run on the MainWindow object?

In examining the object, it is not nil, and the layout and layout_view are being created, but they're not displaying. Am I missing something in my GUI that exists in klayout that sets where the view will be drawn?

Comments

  • edited November -1

    Hi,

    Thanks for the hint about the typo in the sample code. It's supposed to be "cell_index", not "index".

    I'm a bit confused about your request. Actually you don't create a MainWindow object - it's already there. You can obtain it from "RBA::Application::instance.main_window". When you call "create_layout" a new tab should be opened automatically.

    Matthias

  • edited November -1
    Hi Matthias,

    We are creating our own custom GUI with its own windows separate from Klayout's GUI. The script is still being run by Klayout, but Klayout windows are not being started. Thus, we do our own RBA calls.

    The script being run is identical to the one provided in your example, but when I do the create_layout, I do not see it being displayed. However, it is successful in the object creation. Do you have an idea of how to track down/troubleshoot whether it is being created correctly or where it is trying to display?
  • edited November -1

    Hi,

    can you give some sample code illustrating your approach? I have no clue what you're doing.

    Matthias

  • edited November -1

    I'll try and examine it more closely. I didn't write the actual GUI portion...

    From my end:

    main_window = FrameBuilder::Application::instance.main_window

    >

    layout = main_window.create_layout(0).layout
    layout_view = main_window.current_view

    >

    layout.dbu = 0.001
    cell = layout.create_cell("TOP")
    layer_index = layout.insert_layer(RBA::LayerInfo::new(10,0))
    cell.shapes(layer_index).insert(RBA::Box::new(0,0,1000,2000))
    layout_view.select_cell(0,0)
    layout_view.add_missing_layers
    layout_view.zoom_fit

    This code works as a script invoked within klayout, but it doesn't seem to do it from our custom gui.

    I am working with davei. He is invoking klayout to load the gui from a UI file. The GUI generates, and the above ruby code runs, but it doesn't seem to actually create a tab that is visible. Do you have any ideas on what I should look for within the UI file or loading that may indicate what is going on?

  • edited May 2015

    Hi,

    since the code above works I can't say a lot, except that it looks fine ... I still don't know what you're doing. Can you give a sample of non-working code? And give instructions how to run it and what is the expected and actual result? What is that "custom gui" doing?

    Matthias

  • edited November -1
    Given a GUI created by loading a .ui file from QtDesigner. That GUI has
    many items including one QGraphicsView_Native widget. It is this widget
    to which we want layout data to be drawn. There seems to be two ways one
    might accomplish this:
    1. Pass the GUI's QGraphicsView_Native instance to KLayout such that
    the output layout will appear in our custom GUI.
    2. Replace our GUI's QGraphicView_Native instance with another object
    instance create from KLayout.
    Perhaps there is another way. In any case, I need one working solution.

    Invocation of the program is done this way right now:
    % klayout -z -rx -rm some_ruby_file.rb
    The above will load a .ui file with QFormBuilder and run .exec on the top
    level to bring up the GUI.

    We are using:
    klayout 0.23.9
    ruby 1.9.3
    Qt 4.8.5dd
  • edited November -1
    ui file:

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>Dialog</class>
    <widget class="QDialog" name="Dialog">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>300</width>
    <height>250</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>Dialog</string>
    </property>
    <widget class="QGraphicsView" name="frame_layout_view">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>580</width>
    <height>873</height>
    </rect>
    </property>
    <property name="sizePolicy">
    <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
    <horstretch>0</horstretch>
    <verstretch>0</verstretch>
    </sizepolicy>
    </property>
    <property name="focusPolicy">
    <enum>Qt::ClickFocus</enum>
    </property>
    <property name="frameShape">
    <enum>QFrame::Panel</enum>
    </property>
    <property name="lineWidth">
    <number>2</number>
    </property>
    </widget>
    </widget>
    <resources>
    <include location="data/icons.qrc"/>
    <include location="../../../../../icons.qrc"/>
    </resources>
    <connections/>
    </ui>
  • edited November -1
    some_ruby_file.rb:

    include RBA

    ui_path = "./example.ui"
    parent = Application.instance.main_window
    ui_file = QFile::new(ui_path)
    ui_file.open(QIODevice::ReadOnly.to_i)
    dialog = QFormBuilder::new.load(ui_file, parent)
    ui_file.close

    # we want to generate a layout in dialog.frame_layout_view

    dialog.exec
  • edited November -1

    Hi,

    I'm sorry, but the program is not built for that kind of application. I don't know how to redirect output to a graphics view. You may be able to reuse the LayoutView component - but right now it won't work properly without being embedded into a main window.

    To be frank, I'm a bit scared about what you're planning. Even if you find a way to implement your application, I cannot guarantee in any way that this will work in the next release.

    What you're looking for is probably something like GUI components for layout viewing. But KLayout is an application, not a component framework.

    Matthias

  • edited November -1
    Thanks, Matthias, for the response.

    Since the GUI is invoked through klayout using the -z option to hide klayout, is it possible to invoke a command from within the ruby script to make the klayout window visible?
  • edited June 2015

    Hi,

    I haven't tried running KLayout with the -z option set, but you can control the visibility of the main window using this:

    mw = RBA::Application.instance.main_window # get the main window reference
    mw.setVisible(false) # hide the main window
    mw.setVisible(true)  # show the main window
    

    If this doesn't work with the -z option set, you might be able to work around that by having a script which runs at startup and hides the main window immediately until you want to show it.

    Hope this helps!

    Regards, Chris

  • edited November -1
    That does help.

    Thanks, Chris!
Sign In or Register to comment.