12 |
12 |
13 class EricTextSpinBox(QSpinBox): |
13 class EricTextSpinBox(QSpinBox): |
14 """ |
14 """ |
15 Class implementing a spinbox with textual entries. |
15 Class implementing a spinbox with textual entries. |
16 """ |
16 """ |
|
17 |
17 def __init__(self, parent=None): |
18 def __init__(self, parent=None): |
18 """ |
19 """ |
19 Constructor |
20 Constructor |
20 |
21 |
21 @param parent reference to the parent widget (QWidget) |
22 @param parent reference to the parent widget (QWidget) |
22 """ |
23 """ |
23 super().__init__(parent) |
24 super().__init__(parent) |
24 |
25 |
25 self.__items = [] |
26 self.__items = [] |
26 |
27 |
27 self.setMinimum(0) |
28 self.setMinimum(0) |
28 self.setMaximum(0) |
29 self.setMaximum(0) |
29 |
30 |
30 def addItem(self, txt, data=None): |
31 def addItem(self, txt, data=None): |
31 """ |
32 """ |
32 Public method to add an item with item data. |
33 Public method to add an item with item data. |
33 |
34 |
34 @param txt text to be shown (string) |
35 @param txt text to be shown (string) |
35 @param data associated data |
36 @param data associated data |
36 """ |
37 """ |
37 self.__items.append((txt, data)) |
38 self.__items.append((txt, data)) |
38 self.setMaximum(len(self.__items) - 1) |
39 self.setMaximum(len(self.__items) - 1) |
39 |
40 |
40 def itemData(self, index): |
41 def itemData(self, index): |
41 """ |
42 """ |
42 Public method to retrieve the data associated with an item. |
43 Public method to retrieve the data associated with an item. |
43 |
44 |
44 @param index index of the item (integer) |
45 @param index index of the item (integer) |
45 @return associated data |
46 @return associated data |
46 """ |
47 """ |
47 try: |
48 try: |
48 return self.__items[index][1] |
49 return self.__items[index][1] |
49 except IndexError: |
50 except IndexError: |
50 return None |
51 return None |
51 |
52 |
52 def currentIndex(self): |
53 def currentIndex(self): |
53 """ |
54 """ |
54 Public method to retrieve the current index. |
55 Public method to retrieve the current index. |
55 |
56 |
56 @return current index (integer) |
57 @return current index (integer) |
57 """ |
58 """ |
58 return self.value() |
59 return self.value() |
59 |
60 |
60 def textFromValue(self, value): |
61 def textFromValue(self, value): |
61 """ |
62 """ |
62 Public method to convert a value to text. |
63 Public method to convert a value to text. |
63 |
64 |
64 @param value value to be converted (integer) |
65 @param value value to be converted (integer) |
65 @return text for the given value (string) |
66 @return text for the given value (string) |
66 """ |
67 """ |
67 try: |
68 try: |
68 return self.__items[value][0] |
69 return self.__items[value][0] |
69 except IndexError: |
70 except IndexError: |
70 return "" |
71 return "" |
71 |
72 |
72 def valueFromText(self, txt): |
73 def valueFromText(self, txt): |
73 """ |
74 """ |
74 Public method to convert a text to a value. |
75 Public method to convert a text to a value. |
75 |
76 |
76 @param txt text to be converted (string) |
77 @param txt text to be converted (string) |
77 @return value for the given text (integer) |
78 @return value for the given text (integer) |
78 """ |
79 """ |
79 for index in range(len(self.__items)): |
80 for index in range(len(self.__items)): |
80 if self.__items[index][0] == txt: |
81 if self.__items[index][0] == txt: |
81 return index |
82 return index |
82 |
83 |
83 return self.minimum() |
84 return self.minimum() |