src/eric7/EricWidgets/EricComboSelectionDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9653
e67609152c5e
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
15 15
16 class EricComboSelectionDialog(QDialog, Ui_E5ComboSelectionDialog): 16 class EricComboSelectionDialog(QDialog, Ui_E5ComboSelectionDialog):
17 """ 17 """
18 Class implementing a dialog to select one entry from a list of strings. 18 Class implementing a dialog to select one entry from a list of strings.
19 """ 19 """
20
20 def __init__(self, entries, title="", message="", parent=None): 21 def __init__(self, entries, title="", message="", parent=None):
21 """ 22 """
22 Constructor 23 Constructor
23 24
24 @param entries list of entries to select from 25 @param entries list of entries to select from
25 @type list of str or list of tuples of (str, any) 26 @type list of str or list of tuples of (str, any)
26 @param title title of the dialog (defaults to "") 27 @param title title of the dialog (defaults to "")
27 @type str (optional) 28 @type str (optional)
28 @param message message to be show in the dialog (defaults to "") 29 @param message message to be show in the dialog (defaults to "")
30 @param parent reference to the parent widget (defaults to None) 31 @param parent reference to the parent widget (defaults to None)
31 @type QWidget (optional) 32 @type QWidget (optional)
32 """ 33 """
33 super().__init__(parent) 34 super().__init__(parent)
34 self.setupUi(self) 35 self.setupUi(self)
35 36
36 for entry in entries: 37 for entry in entries:
37 if isinstance(entry, tuple): 38 if isinstance(entry, tuple):
38 self.selectionComboBox.addItem(*entry) 39 self.selectionComboBox.addItem(*entry)
39 else: 40 else:
40 self.selectionComboBox.addItem(entry) 41 self.selectionComboBox.addItem(entry)
41 42
42 self.on_selectionComboBox_currentTextChanged( 43 self.on_selectionComboBox_currentTextChanged(self.selectionComboBox.itemText(0))
43 self.selectionComboBox.itemText(0)) 44
44
45 msh = self.minimumSizeHint() 45 msh = self.minimumSizeHint()
46 self.resize(max(self.width(), msh.width()), msh.height()) 46 self.resize(max(self.width(), msh.width()), msh.height())
47 47
48 @pyqtSlot(str) 48 @pyqtSlot(str)
49 def on_selectionComboBox_currentTextChanged(self, txt): 49 def on_selectionComboBox_currentTextChanged(self, txt):
50 """ 50 """
51 Private slot to react upon changes of the selected entry. 51 Private slot to react upon changes of the selected entry.
52 52
53 @param txt text of the selected entry 53 @param txt text of the selected entry
54 @type str 54 @type str
55 """ 55 """
56 self.buttonBox.button( 56 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(bool(txt))
57 QDialogButtonBox.StandardButton.Ok).setEnabled(bool(txt)) 57
58
59 def getSelection(self): 58 def getSelection(self):
60 """ 59 """
61 Public method to retrieve the selected item and its data. 60 Public method to retrieve the selected item and its data.
62 61
63 @return tuple containing the selected entry and its associated data 62 @return tuple containing the selected entry and its associated data
64 @rtype tuple of (str, any) 63 @rtype tuple of (str, any)
65 """ 64 """
66 return ( 65 return (
67 self.selectionComboBox.currentText(), 66 self.selectionComboBox.currentText(),
68 self.selectionComboBox.currentData() 67 self.selectionComboBox.currentData(),
69 ) 68 )

eric ide

mercurial