PySide2
This example uses PySide2 to build a custom GUI that can be called from a menu in ADS. PySide2 is the GUI widget toolkit that is by default shipping along with ADS.
# Copyright Keysight Technologies 2023 - 2023
from typing import Union
from keysight.ads import de
from keysight.ads.de import app
from PySide2 import QtCore
from PySide2.QtWidgets import QDialog, QHBoxLayout, QPlainTextEdit, QPushButton, QVBoxLayout, QWidget
def all_lcv() -> list:
import keysight.ads.de as de
wrk = de.active_workspace()
lcvs = []
for lib_name in wrk.writable_library_names:
lib = wrk.open_library(lib_name)
for cell in lib.cells:
for view in cell.views:
lcvs.append((view, view.lcv_name))
return lcvs
class CustomDialog(QDialog):
def __init__(self, workspace: de.Workspace, parent: Union[QWidget, None] = None):
super().__init__(parent)
# Remove question mark, else have to deal with forbidden cursor
self.setWindowFlag(QtCore.Qt.WindowContextHelpButtonHint, False)
# Window title of the dialog
self.setWindowTitle("All Cellviews in Workspace " + workspace.path.name)
# Create the main vertical layout to add widgets into.
main_vertical_layout = QVBoxLayout()
# Text editor to display content
# https://doc.qt.io/qtforpython-5/PySide2/QtWidgets/QPlainTextEdit.html
editor = QPlainTextEdit()
editor.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
editor.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
header_line = "Total number of cellviews - " + str(len(all_lcv())) + "\n"
editor.insertPlainText(header_line)
# Just list the view.lcv_name from (view, view.lcv_name)
editor.appendPlainText("\n".join(lcv[1] for lcv in all_lcv()))
editor.setReadOnly(True)
editor.setLineWrapMode(QPlainTextEdit.NoWrap)
# Place text editor into main layout
main_vertical_layout.addWidget(editor)
# create horizontal layout for button and spacer
horizontal_layout = QHBoxLayout()
ok_button = QPushButton("Ok")
# this essentially dismisses the dialog when the user clicks Ok
ok_button.clicked.connect(self.accept) # type: ignore
# place button in the layout and move it to the left side
horizontal_layout.addWidget(ok_button)
horizontal_layout.addStretch()
# add horizontal layout to main vertical layout
main_vertical_layout.addLayout(horizontal_layout)
# place the layout into the body of the dialog
self.setLayout(main_vertical_layout)
# Create and display the dialog
dlg = CustomDialog(de.active_workspace(), parent=app.window.main_pyside2_widget())
dlg.show()