Dialog to select new units. Checks compatibility while typing and does not allow to continue if incompatible. Returns None if cancelled. :param units: current units. :param parent: parent widget. >>> new_units = UnitInputDialog.get_units('ms')
| 1060 | |
| 1061 | |
| 1062 | class UnitInputDialog(QtGui.QDialog): |
| 1063 | """Dialog to select new units. Checks compatibility while typing |
| 1064 | and does not allow to continue if incompatible. |
| 1065 | |
| 1066 | Returns None if cancelled. |
| 1067 | |
| 1068 | :param units: current units. |
| 1069 | :param parent: parent widget. |
| 1070 | |
| 1071 | >>> new_units = UnitInputDialog.get_units('ms') |
| 1072 | """ |
| 1073 | |
| 1074 | def __init__(self, units, parent=None): |
| 1075 | super().__init__(parent) |
| 1076 | self.setupUi(parent) |
| 1077 | self.units = units |
| 1078 | self.source_units.setText(str(units)) |
| 1079 | |
| 1080 | def setupUi(self, parent): |
| 1081 | self.resize(275, 172) |
| 1082 | self.setWindowTitle('Convert units') |
| 1083 | self.layout = QtGui.QVBoxLayout(parent) |
| 1084 | self.layout.setSizeConstraint(QtGui.QLayout.SetFixedSize) |
| 1085 | align = (QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) |
| 1086 | |
| 1087 | self.layout1 = QtGui.QHBoxLayout() |
| 1088 | self.label1 = QtGui.QLabel() |
| 1089 | self.label1.setMinimumSize(QtCore.QSize(100, 0)) |
| 1090 | self.label1.setText('Convert from:') |
| 1091 | self.label1.setAlignment(align) |
| 1092 | |
| 1093 | self.layout1.addWidget(self.label1) |
| 1094 | self.source_units = QtGui.QLineEdit() |
| 1095 | self.source_units.setReadOnly(True) |
| 1096 | self.layout1.addWidget(self.source_units) |
| 1097 | |
| 1098 | self.layout.addLayout(self.layout1) |
| 1099 | |
| 1100 | self.layout2 = QtGui.QHBoxLayout() |
| 1101 | self.label2 = QtGui.QLabel() |
| 1102 | self.label2.setMinimumSize(QtCore.QSize(100, 0)) |
| 1103 | self.label2.setText('to:') |
| 1104 | self.label2.setAlignment(align) |
| 1105 | self.layout2.addWidget(self.label2) |
| 1106 | |
| 1107 | self.destination_units = QtGui.QLineEdit() |
| 1108 | self.layout2.addWidget(self.destination_units) |
| 1109 | |
| 1110 | self.layout.addLayout(self.layout2) |
| 1111 | |
| 1112 | self.message = QtGui.QLabel() |
| 1113 | self.message.setText('') |
| 1114 | self.message.setAlignment(QtCore.Qt.AlignCenter) |
| 1115 | |
| 1116 | self.layout.addWidget(self.message) |
| 1117 | |
| 1118 | self.buttonBox = QtGui.QDialogButtonBox() |
| 1119 | self.buttonBox.setOrientation(QtCore.Qt.Horizontal) |