Sun, 01 Apr 2012 11:36:18 +0200
Prepared release 5.2.1 of eric5.
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
1509
c0b5e693b0eb
Updated copyright for 2012.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1131
diff
changeset
|
3 | # Copyright (c) 2010 - 2012 Detlev Offenbach <detlev@die-offenbachs.de> |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | from PyQt4.QtGui import QSpinBox |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | |
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
8 | |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | class E5TextSpinBox(QSpinBox): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
10 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | Class implementing a spinbox with textual entries. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | """ |
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
13 | def __init__(self, parent=None): |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | Constructor |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | @param parent reference to the parent widget (QWidget) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | """ |
1131
7781e396c903
Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
945
diff
changeset
|
19 | super().__init__(parent) |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | self.__items = [] |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | self.setMinimum(0) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | self.setMaximum(0) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | |
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
26 | def addItem(self, txt, data=None): |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | Public method to add an item with item data. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | @param txt text to be shown (string) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | @param data associated data |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | self.__items.append((txt, data)) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | self.setMaximum(len(self.__items) - 1) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | def itemData(self, index): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | Public method to retrieve the data associated with an item. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | @param index index of the item (integer) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | @return associated data |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | try: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | return self.__items[index][1] |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | except IndexError: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | return None |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | def currentIndex(self): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | Public method to retrieve the current index. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | @return current index (integer) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | return self.value() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | def textFromValue(self, value): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | Protected method to convert a value to text. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | @param value value to be converted (integer) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | @return text for the given value (string) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | try: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | return self.__items[value][0] |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | except IndexError: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | return "" |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | def valueFromText(self, txt): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | Protected method to convert a text to a value. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
72 | @param txt text to be converted (string) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | @return value for the given text (integer) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | for index in range(len(self.__items)): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | if self.__items[index][0] == txt: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | return index |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
78 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | return self.minimum() |