It looks like you're new here. If you want to get involved, click one of these buttons!
Hi, I do
defaultVal = 5
value = RBA::InputDialog.get_int("Input", "Input an integer", defaultVal)
Now I would like to input more than one parameter on the same input dialog - is this possible or do I have to have multiple input dialogs popping up one after the other?
Thanks!
Comments
Hi David,
that is basically possible, but you'll need to code it in Qt/Ruby. That requires that the Qt binding was enabled upon building KLayout (the binary packages are Qt enabled). Some documentation about the Qt binding can be found here: http://klayout.de/doc/programming/qt_binding.html.
Regards,
Matthias
Matthias,
I found the way to have also radio buttons (see below), but if I want to add in that input box several variables (text or numbers) input, than I am stacked. See variable below : I don't know how to enter a variable.
Thank you for your help, Best regards,
Laurent
It would also be nice to understand how to use the QComboBox.
I am confused on where to put the choice list versus the dialog.
Thanks, Regards,
Laurent
Hi Laurent,
You can use the QComboBox in place of the four QRadioButton objects. So you need just one widget instead of four. The most important methods available for a QComboBox are
Is that answering your question?
Matthias
Fine Matthias,
Now, I can have a multi-inputs window. I join here a theorical example with:
several variables input
radio buttons
check buttons
combo box (list selection input)
action push button
Maybe, there is a better solution for the OK and CANCEL buutons, but I did not find them.
Save the following script in the same directory as klayout exec file as : multi_input.rbm
It will appear in tools menu as : Multiple inputs
Let's try and modify as you need !
Rgds,
Laurent
Hi Laurent,
your sample is actually fine. In particular the Ok button handling is the way KLayout's Qt binding suggests. You could also bind the conventional Qt signals to slots using QObject#connect, but there is not substantial advantage of one method to another.
Let met make a few remarks:
Regards,
Matthias
Matthias,
How to use QDialog with Python ? My macro hangs on :
Thanks, Merry Christmas,
Laurent
Hi Laurent,
The correct Python statement is:
(note the brackets). You don't need "new" - it works too but that is not "pythonic".
If you want to show the dialog you have to use "exec_" instead of "exec" since that is a reserved word in Python:
BTW: there is no specific advantage of Python over Ruby. It's just provided to widen the user community since not everybody is familiar with Ruby and there is a somewhat broader choice of libraries for Python. But on the other hand, Python is in general slower than Ruby and still Ruby is my personal favourite.
Matthias
Matthias,
I'm having trouble extending the above example (the ruby example earlier) to a QTreeView.
In particular I can't tell how to get data back (i.e. get the selected rows) from QTreeView. The difference is, in the previous examples in this thread there was a clearly defined object (like "textbox1") which had a clearly defined method (".text") to get what is inside of it. But in QTreeView there appears to be no such method. There is a .selectedRows(arg) method but it doesn't seem to be for that purpose, as you have to tell it the argument that I actually want to extract!
I know similar functionality to the above can be done using RBA::FileDialog, but the code you see is just a simplified version; I'd like to include more functionality in the future.
Thanks,
David
Hi David,
QTreeView and QFileSystemModel are part of QT's model/view framework. In order to use that you'll have to become familiar with that (see for example http://qt-project.org/doc/qt-4.8/model-view-programming.html.
I have no experience with QFileSystemModel myself but following the general scheme of the model/view framework, you should be able to get the selected files with a code similar to this
But I have not tested that myself.
Best regards,
Matthias
Aha!
Strange thing, and I know why I couldn't find it now.
Your website documentation does indeed list "selectionModel" under "Public methods" of QTreeView. BUT in the Macro IDE when I click the "?" button and search for QTreeView and scroll down, "selectionModel" is not listed!
This is strange -- the MacroIDE's docs do include the one just above where it should be ("selectAll") and the one just below where it should be ("setAllColumnsShowFocus") but not the one I was looking for! Very bizarre. In case you don't believe me :-) here is the raw text, pasted from the Macro IDE's "?" function, showing the one above and below it but not "selectionModel" itself:
I am using KL 0.23.3.
If I'd found it, I would have found the class QItemSelectionModel and its method selectedIndexes...
Anyway, no big deal. I should have searched in the online docs, I just didn't realize there might be a difference.
At first I thought maybe this method is not included in the Qt included with my KL version, which would explain why it's not in the MacroIDE's docs. However it is indeed working as you said, so there are no problems, and "selectionModel" must indeed be listed.
Here is the code for others' future reference
Hi David,
Oh yes .. the Qt part of the documentation is a mess.
The reason is that this method is defined by the base class, QAbstractItemView. You'll find it there.
The Qt documentation was intended as a cross-reference. It's generated automatically from the Qt headers and I did not extract the documentation too (it was difficult enough to parse the signature of the methods ...).
My reasoning was that people would look in the original Qt documentation and then translate the C++ idea to Ruby/Python. The documentation provided was meant to give hints how to do that translation, not more.
Matthias
Ah. Got it.
No problem, it is easy to look at the Qt docs online anyway. And I should have looked to see what was in the base class (or printed it with "print object.methods").
Thanks again,
David
Hello,
I just started to look into the QDialog magic. The last script from Laurent is very interesting. I've got two questions though:
1) How to add a "Cancel" button, and how to put it on the same line as the "OK" button?
2) How to add two separated radio button lists (to be able to select one item of each list)?
Cheers,
Tomas
Hello,
I dug a bit deeper in the Qt designer and it works all nicely but I still cannot make the cancel button to work (the rest of the script is still run). See the code below. I also attached the .ui file. Any idea how to get it working?
Here is what I did so far:
1) Installed https://build-system.fman.io/qt-designer-download: it is very small (only 31Mb) as it only contains the Qt designer.
2) Watched these tutorials (until the Python stuff):
3) KLayout script based on https://www.klayout.de/doc-qt5/programming/qt_binding.html:
Note that I had to remove ".to_i" on line "ui_file.open(QIODevice::ReadOnly.to_i)" to make it work...
4) As mentioned before, the "Cancel" button does not have any canceling effect???
Cheers,
Tomas
In order to see the "cancel effect" you have to check the return value of "dialog.exec". It is an integer and equal to 0 if you pressed "Cancel" and 1 if you pressed "Ok".
And thanks for the note about the "to_i". I'll remove that from the doc.
Matthias
Hi Matthias,
It works fine now... Many thanks!!!
Cheers,
Tomas