|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2018 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the name-value pair to define a variable |
|
8 for the IDL compiler. |
|
9 """ |
|
10 |
|
11 from PyQt5.QtCore import pyqtSlot |
|
12 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
13 |
|
14 from .Ui_IdlCompilerDefineNameDialog import Ui_IdlCompilerDefineNameDialog |
|
15 |
|
16 |
|
17 class IdlCompilerDefineNameDialog(QDialog, Ui_IdlCompilerDefineNameDialog): |
|
18 """ |
|
19 Class implementing a dialog to enter the name-value pair to define a |
|
20 variable for the IDL compiler. |
|
21 """ |
|
22 def __init__(self, name="", value="", parent=None): |
|
23 """ |
|
24 Constructor |
|
25 |
|
26 @param name name of the variable |
|
27 @type str |
|
28 @param value value of the variable |
|
29 @type str |
|
30 @param parent reference to the parent widget |
|
31 @type QWidget |
|
32 """ |
|
33 super().__init__(parent) |
|
34 self.setupUi(self) |
|
35 |
|
36 self.nameEdit.setText(name) |
|
37 self.valueEdit.setText(value) |
|
38 |
|
39 msh = self.minimumSizeHint() |
|
40 self.resize(max(self.width(), msh.width()), msh.height()) |
|
41 |
|
42 self.__updateOkButton() |
|
43 |
|
44 def __updateOkButton(self): |
|
45 """ |
|
46 Private slot to update the enable state of the OK button. |
|
47 """ |
|
48 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
|
49 bool(self.nameEdit.text())) |
|
50 |
|
51 @pyqtSlot(str) |
|
52 def on_nameEdit_textChanged(self, txt): |
|
53 """ |
|
54 Private slot to handle changes of the name. |
|
55 |
|
56 @param txt current text of the name edit |
|
57 @type str |
|
58 """ |
|
59 self.__updateOkButton() |
|
60 |
|
61 def getData(self): |
|
62 """ |
|
63 Public method to get the entered data. |
|
64 |
|
65 @return tuple containing the variable name and value |
|
66 @rtype tuple of (str, str) |
|
67 """ |
|
68 return ( |
|
69 self.nameEdit.text().strip(), |
|
70 self.valueEdit.text().strip(), |
|
71 ) |