Adding buttons to HTML window

edited October 2017 in Ruby Scripting
Hi Matthias-

Used your screenshot HTML example to create browser dialog.
Can you please provide example how to add button\checkbox etc?

Thanks, Itamar

Comments

  • edited November -1

    Hi Itamar,

    the browser approach is not well suited for doing interactive dialogs with more than just links.

    The "custom dialog" example https://klayout.de/rba_examples.html#example8 shows a simple example. You need some knowledge about Qt however.

    Matthias

  • edited November -1
    Hi Matthias-

    I changed my code to use Qt instead of HTML.
    While most of the Qt is straightforward and manageable, I still have issue adding button with an image icon.
    Maybe you can provide example of how to assign an icon to a Qt button?

    Thanks much,
  • edited November -1

    Hi Itamar,

    where do you want to get the image icon from?

    The usual Qt way is to use resource files. There is a discussion about using resource files and KLayout's Qt binding here in the forum: http://klayout.de/forum/comments.php?DiscussionID=636.

    Regards,

    Matthias

  • edited November -1
    Hi Matthias-

    I would like to get the image icon from a snapshot of main window, then assign it to a certain pushButton.
    After that, get another snapshot and assign it to different pushbutton, etc.

    Thanks,
  • edited November 2017

    Hi,

    If you mean a layout snapshot, then LayoutView#get_image is the method you are looking for.

    I don't know precisely what you plan to do, but here is some code to play with:

    # Shows a dialog with a "Snapshot" button that takes screenshots and
    # lines them up as push buttons
    
    dialog = RBA::QDialog::new
    
    vlayout = RBA::QVBoxLayout::new(dialog)
    
    upper_frame = RBA::QFrame::new(dialog)
    sp = upper_frame.sizePolicy
    sp.setVerticalStretch(1)
    upper_frame.setSizePolicy(sp)
    
    upper_hlayout = RBA::QHBoxLayout::new(lower_frame)
    upper_frame.setLayout(upper_hlayout)
    
    vlayout.addWidget(upper_frame)
    
    lower_frame = RBA::QFrame::new(dialog)
    
    vlayout.addWidget(lower_frame)
    
    lower_hlayout = RBA::QHBoxLayout::new(lower_frame)
    
    snapshot_button = RBA::QPushButton::new(lower_frame)
    snapshot_button.setText("Snapshot")
    lower_hlayout.addWidget(snapshot_button)
    snapshot_button.clicked do 
    
      lv = RBA::LayoutView::current
      if lv
        # Get an image with 100x100 pixels
        snapshot_image = lv.get_image(100, 100)
        snapshot_button = RBA::QPushButton::new(upper_frame)
        snapshot_button.setIconSize(RBA::QSize::new(snapshot_image.width, snapshot_image.height))
        snapshot_button.setIcon(RBA::QIcon::new(RBA::QPixmap::fromImage(snapshot_image)))
        upper_hlayout.addWidget(snapshot_button)
      end
    
    end
    
    lower_hlayout.addStretch(1)
    
    close_button = RBA::QPushButton::new(lower_frame)
    close_button.setText("Close")
    lower_hlayout.addWidget(close_button)
    close_button.clicked do 
      dialog.hide
    end
    
    dialog.show
    

    Matthias

Sign In or Register to comment.