Thu, 10 Jan 2019 14:18:48 +0100
Updated copyright for 2019.
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 | |
6645
ad476851d7e0
Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6188
diff
changeset
|
3 | # Copyright (c) 2010 - 2019 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 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing a widget to show numbers in different formats. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
3145
a9de05d4a22f
# __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3057
diff
changeset
|
10 | from __future__ import unicode_literals |
2525
8b507a9a2d40
Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2302
diff
changeset
|
11 | |
5736
000ea446ff4b
Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5603
diff
changeset
|
12 | from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QAbstractTableModel |
3656
441956d8fce5
Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3484
diff
changeset
|
13 | from PyQt5.QtWidgets import QWidget, QHeaderView |
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 | from E5Gui.E5Application import e5App |
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 | from .Ui_NumbersWidget import Ui_NumbersWidget |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | import UI.PixmapCache |
5736
000ea446ff4b
Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5603
diff
changeset
|
20 | from Globals import qVersionTuple |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | |
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
22 | |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | class BinaryModel(QAbstractTableModel): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | Class implementing a model for entering binary numbers. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | """ |
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
27 | 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
|
28 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | Constructor |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | @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
|
32 | """ |
2525
8b507a9a2d40
Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2302
diff
changeset
|
33 | super(BinaryModel, self).__init__(parent) |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | self.__bits = 0 |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | self.__value = 0 |
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 | def rowCount(self, parent): |
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 | Public method to get the number of rows of the model. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | @param parent parent index (QModelIndex) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | @return number of columns (integer) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | return 1 |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | def columnCount(self, parent): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | Public method to get the number of columns of the model. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | @param parent parent index (QModelIndex) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | @return number of columns (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.__bits |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | |
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
56 | def data(self, index, role=Qt.DisplayRole): |
372
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 | Public method to get data from the model. |
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 index index to get data for (QModelIndex) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | @param role role of the data to retrieve (integer) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | @return requested data |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | if role == Qt.CheckStateRole: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | return (self.__value >> (self.__bits - index.column() - 1)) & 1 |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | elif role == Qt.DisplayRole: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | return "" |
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 | return None |
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 | def flags(self, index): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | Public method to get flags from the model. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | @param index index to get flags for (QModelIndex) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | @return flags (Qt.ItemFlags) |
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 Qt.ItemIsUserCheckable | Qt.ItemIsEnabled | Qt.ItemIsSelectable |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | |
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
81 | def headerData(self, section, orientation, role=Qt.DisplayRole): |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
82 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | Public method to get header data from the model. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | @param section section number (integer) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
86 | @param orientation orientation (Qt.Orientation) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | @param role role of the data to retrieve (integer) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | @return requested data |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | if orientation == Qt.Horizontal and role == Qt.DisplayRole: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | return str(self.__bits - section - 1) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
92 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | return QAbstractTableModel.headerData(self, section, orientation, role) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | def setBits(self, bits): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | Public slot to set the number of bits. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | @param bits number of bits to show (integer) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | """ |
3656
441956d8fce5
Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3484
diff
changeset
|
101 | self.beginResetModel() |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | self.__bits = bits |
3656
441956d8fce5
Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3484
diff
changeset
|
103 | self.endResetModel() |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | def setValue(self, value): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | Public slot to set the value to show. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | @param value value to show (integer) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | """ |
3656
441956d8fce5
Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3484
diff
changeset
|
111 | self.beginResetModel() |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | self.__value = value |
3656
441956d8fce5
Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3484
diff
changeset
|
113 | self.endResetModel() |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
115 | def setBitsAndValue(self, bits, value): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
116 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
117 | Public slot to set the number of bits and the value to show. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
118 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | @param bits number of bits to show (integer) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
120 | @param value value to show (integer) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
122 | self.__bits = bits |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | self.__value = value |
3656
441956d8fce5
Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3484
diff
changeset
|
124 | self.beginResetModel() |
441956d8fce5
Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3484
diff
changeset
|
125 | self.endResetModel() |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | def getValue(self): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | Public slot to get the current value. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | @return current value of the model (integer) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
132 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
133 | return self.__value |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | |
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
135 | def setData(self, index, value, role=Qt.EditRole): |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
136 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
137 | Public method to set the data of a node cell. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | @param index index of the node cell (QModelIndex) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | @param value value to be set |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
141 | @param role role of the data (integer) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | @return flag indicating success (boolean) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
144 | if role == Qt.CheckStateRole: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
145 | if value == Qt.Checked and not self.data(index, Qt.CheckStateRole): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
146 | # that seems like a hack; Qt 4.6 always sends Qt.Checked |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
147 | self.__value |= (1 << self.__bits - index.column() - 1) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
148 | else: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
149 | self.__value &= ~(1 << self.__bits - index.column() - 1) |
2126
3744863a534e
Reverted the dataChanged signal change due to corrections in PyQt4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2094
diff
changeset
|
150 | self.dataChanged.emit(index, index) |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
151 | return True |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
152 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
153 | return False |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
154 | |
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
155 | |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
156 | class NumbersWidget(QWidget, Ui_NumbersWidget): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
158 | Class implementing a widget to show numbers in different formats. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
160 | @signal insertNumber(str) emitted after the user has entered a number |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
161 | and selected the number format |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
162 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
163 | insertNumber = pyqtSignal(str) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
164 | |
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
165 | 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
|
166 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
167 | Constructor |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
168 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
169 | @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
|
170 | """ |
2525
8b507a9a2d40
Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2302
diff
changeset
|
171 | super(NumbersWidget, self).__init__(parent) |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
172 | self.setupUi(self) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
173 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
174 | self.setWindowIcon(UI.PixmapCache.getIcon("eric.png")) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
175 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | self.__badNumberSheet = "background-color: #ffa0a0;" |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
177 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
178 | self.binInButton.setIcon(UI.PixmapCache.getIcon("2downarrow.png")) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
179 | self.binOutButton.setIcon(UI.PixmapCache.getIcon("2uparrow.png")) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
180 | self.octInButton.setIcon(UI.PixmapCache.getIcon("2downarrow.png")) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
181 | self.octOutButton.setIcon(UI.PixmapCache.getIcon("2uparrow.png")) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
182 | self.decInButton.setIcon(UI.PixmapCache.getIcon("2downarrow.png")) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
183 | self.decOutButton.setIcon(UI.PixmapCache.getIcon("2uparrow.png")) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
184 | self.hexInButton.setIcon(UI.PixmapCache.getIcon("2downarrow.png")) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
185 | self.hexOutButton.setIcon(UI.PixmapCache.getIcon("2uparrow.png")) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
186 | |
3190
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
187 | self.formatBox.addItem(self.tr("Auto"), 0) |
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
188 | self.formatBox.addItem(self.tr("Dec"), 10) |
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
189 | self.formatBox.addItem(self.tr("Hex"), 16) |
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
190 | self.formatBox.addItem(self.tr("Oct"), 8) |
a9a94491c4fd
Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
191 | self.formatBox.addItem(self.tr("Bin"), 2) |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
192 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
193 | self.sizeBox.addItem("8", 8) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
194 | self.sizeBox.addItem("16", 16) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
195 | self.sizeBox.addItem("32", 32) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
196 | self.sizeBox.addItem("64", 64) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
197 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
198 | self.__input = 0 |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
199 | self.__inputValid = True |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
200 | self.__bytes = 1 |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
201 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
202 | self.__model = BinaryModel(self) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
203 | self.binTable.setModel(self.__model) |
5736
000ea446ff4b
Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5603
diff
changeset
|
204 | if qVersionTuple() >= (5, 0, 0): |
2094
88620e11c67c
Made the seventh set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2081
diff
changeset
|
205 | self.binTable.horizontalHeader().setSectionResizeMode( |
88620e11c67c
Made the seventh set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2081
diff
changeset
|
206 | QHeaderView.ResizeToContents) |
88620e11c67c
Made the seventh set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2081
diff
changeset
|
207 | else: |
3776
ccb6eacb50e5
Started adding code to make eric6 usable with PyQt5 and PyQt4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
208 | self.binTable.horizontalHeader().setResizeMode( |
3012
d177226027e2
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
209 | QHeaderView.ResizeToContents) |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
210 | self.__model.setBitsAndValue(self.__bytes * 8, self.__input) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
211 | self.__model.dataChanged.connect(self.__binModelDataChanged) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
212 | |
5603
4f2dd0850803
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
213 | def __formatNumbers(self, numberFormat): |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
214 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
215 | Private method to format the various number inputs. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
216 | |
5603
4f2dd0850803
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
217 | @param numberFormat number format indicator (integer) |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
218 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
219 | self.__block(True) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
220 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
221 | self.binEdit.setStyleSheet("") |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
222 | self.octEdit.setStyleSheet("") |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
223 | self.decEdit.setStyleSheet("") |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
224 | self.hexEdit.setStyleSheet("") |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
225 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
226 | # determine byte count |
5603
4f2dd0850803
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
227 | byteCount = 8 |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
228 | tmp = self.__input |
6188
5a6ae3be31e6
Fixed some loop related coding issues detected by the extended code style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
229 | for _ in range(8): |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
230 | c = (tmp & 0xff00000000000000) >> 7 * 8 |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
231 | if c != 0 and self.__input >= 0: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
232 | break |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
233 | if c != 0xff and self.__input < 0: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
234 | break |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
235 | tmp <<= 8 |
5603
4f2dd0850803
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
236 | byteCount -= 1 |
4f2dd0850803
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
237 | if byteCount == 0: |
4f2dd0850803
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
238 | byteCount = 1 |
4f2dd0850803
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
239 | self.__bytes = byteCount |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
240 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
241 | bytesIn = self.sizeBox.itemData(self.sizeBox.currentIndex()) // 8 |
5603
4f2dd0850803
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
242 | if bytesIn and byteCount > bytesIn: |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
243 | self.sizeBox.setStyleSheet(self.__badNumberSheet) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
244 | else: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
245 | self.sizeBox.setStyleSheet("") |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
246 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
247 | # octal |
5603
4f2dd0850803
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
248 | if numberFormat != 8: |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
249 | self.octEdit.setText("{0:0{1}o}".format(self.__input, bytesIn * 3)) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
250 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
251 | # decimal |
5603
4f2dd0850803
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
252 | if numberFormat != 10: |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
253 | self.decEdit.setText("{0:d}".format(self.__input)) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
254 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
255 | # hexadecimal |
5603
4f2dd0850803
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
256 | if numberFormat != 16: |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
257 | self.hexEdit.setText("{0:0{1}x}".format(self.__input, bytesIn * 2)) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
258 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
259 | # octal |
5603
4f2dd0850803
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
260 | if numberFormat != 8: |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
261 | self.octEdit.setText("{0:0{1}o}".format(self.__input, bytesIn * 3)) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
262 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
263 | # binary |
5603
4f2dd0850803
Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
264 | if numberFormat != 2: |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
265 | num = "{0:0{1}b}".format(self.__input, bytesIn * 8) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
266 | self.binEdit.setText(num) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
267 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
268 | self.__model.setBitsAndValue(len(self.binEdit.text()), self.__input) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
269 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
270 | self.__block(False) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
271 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
272 | def __block(self, b): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
273 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
274 | Private slot to block some signals. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
275 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
276 | @param b flah indicating the blocking state (boolean) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
277 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
278 | self.hexEdit.blockSignals(b) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
279 | self.decEdit.blockSignals(b) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
280 | self.octEdit.blockSignals(b) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
281 | self.binEdit.blockSignals(b) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
282 | self.binTable.blockSignals(b) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
283 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
284 | @pyqtSlot(int) |
2965
d133c7edd88a
Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2302
diff
changeset
|
285 | def on_sizeBox_valueChanged(self, value): |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
286 | """ |
2965
d133c7edd88a
Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2302
diff
changeset
|
287 | Private slot handling a change of the bit size. |
d133c7edd88a
Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2302
diff
changeset
|
288 | |
d133c7edd88a
Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2302
diff
changeset
|
289 | @param value selected bit size (integer) |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
290 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
291 | self.__formatNumbers(10) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
292 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
293 | @pyqtSlot() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
294 | def on_byteOrderButton_clicked(self): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
295 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
296 | Private slot to swap the byte order. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
297 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
298 | bytesIn = self.sizeBox.itemData(self.sizeBox.currentIndex()) // 8 |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
299 | if bytesIn == 0: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
300 | bytesIn = self.__bytes |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
301 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
302 | tmp1 = self.__input |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
303 | tmp2 = 0 |
6188
5a6ae3be31e6
Fixed some loop related coding issues detected by the extended code style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
304 | for _ in range(bytesIn): |
372
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
305 | tmp2 <<= 8 |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
306 | tmp2 |= tmp1 & 0xff |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
307 | tmp1 >>= 8 |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
308 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
309 | self.__input = tmp2 |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
310 | self.__formatNumbers(0) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
311 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
312 | @pyqtSlot() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
313 | def on_binInButton_clicked(self): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
314 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
315 | Private slot to retrieve a binary number from the current editor. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
316 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
317 | number = e5App().getObject("ViewManager").getNumber() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
318 | if number == "": |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
319 | return |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
320 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
321 | self.binEdit.setText(number) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
322 | self.binEdit.setFocus() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
323 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
324 | @pyqtSlot(str) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
325 | def on_binEdit_textChanged(self, txt): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
326 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
327 | Private slot to handle input of a binary number. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
328 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
329 | @param txt text entered (string) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
330 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
331 | try: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
332 | self.__input = int(txt, 2) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
333 | self.__inputValid = True |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
334 | except ValueError: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
335 | self.__inputValid = False |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
336 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
337 | if self.__inputValid: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
338 | self.__formatNumbers(2) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
339 | else: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
340 | self.binEdit.setStyleSheet(self.__badNumberSheet) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
341 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
342 | @pyqtSlot() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
343 | def on_binOutButton_clicked(self): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
344 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
345 | Private slot to send a binary number. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
346 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
347 | self.insertNumber.emit(self.binEdit.text()) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
348 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
349 | def __binModelDataChanged(self, start, end): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
350 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
351 | Private slot to handle a change of the binary model value by the user. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
352 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
353 | @param start start index (QModelIndex) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
354 | @param end end index (QModelIndex) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
355 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
356 | val = self.__model.getValue() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
357 | bytesIn = self.sizeBox.itemData(self.sizeBox.currentIndex()) // 8 |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
358 | num = "{0:0{1}b}".format(val, bytesIn * 8) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
359 | self.binEdit.setText(num) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
360 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
361 | @pyqtSlot() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
362 | def on_octInButton_clicked(self): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
363 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
364 | Private slot to retrieve an octal number from the current editor. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
365 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
366 | number = e5App().getObject("ViewManager").getNumber() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
367 | if number == "": |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
368 | return |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
369 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
370 | self.octEdit.setText(number) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
371 | self.octEdit.setFocus() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
372 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
373 | @pyqtSlot(str) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
374 | def on_octEdit_textChanged(self, txt): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
375 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
376 | Private slot to handle input of an octal number. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
377 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
378 | @param txt text entered (string) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
379 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
380 | try: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
381 | self.__input = int(txt, 8) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
382 | self.__inputValid = True |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
383 | except ValueError: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
384 | self.__inputValid = False |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
385 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
386 | if self.__inputValid: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
387 | self.__formatNumbers(8) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
388 | else: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
389 | self.octEdit.setStyleSheet(self.__badNumberSheet) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
390 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
391 | @pyqtSlot() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
392 | def on_octOutButton_clicked(self): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
393 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
394 | Private slot to send an octal number. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
395 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
396 | self.insertNumber.emit(self.octEdit.text()) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
397 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
398 | @pyqtSlot() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
399 | def on_decInButton_clicked(self): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
400 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
401 | Private slot to retrieve a decimal number from the current editor. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
402 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
403 | number = e5App().getObject("ViewManager").getNumber() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
404 | if number == "": |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
405 | return |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
406 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
407 | self.decEdit.setText(number) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
408 | self.decEdit.setFocus() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
409 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
410 | @pyqtSlot(str) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
411 | def on_decEdit_textChanged(self, txt): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
412 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
413 | Private slot to handle input of a decimal number. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
414 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
415 | @param txt text entered (string) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
416 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
417 | try: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
418 | self.__input = int(txt, 10) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
419 | self.__inputValid = True |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
420 | except ValueError: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
421 | self.__inputValid = False |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
422 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
423 | if self.__inputValid: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
424 | self.__formatNumbers(10) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
425 | else: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
426 | self.decEdit.setStyleSheet(self.__badNumberSheet) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
427 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
428 | @pyqtSlot() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
429 | def on_decOutButton_clicked(self): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
430 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
431 | Private slot to send a decimal number. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
432 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
433 | self.insertNumber.emit(self.decEdit.text()) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
434 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
435 | @pyqtSlot() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
436 | def on_hexInButton_clicked(self): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
437 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
438 | Private slot to retrieve a hexadecimal number from the current editor. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
439 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
440 | number = e5App().getObject("ViewManager").getNumber() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
441 | if number == "": |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
442 | return |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
443 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
444 | self.hexEdit.setText(number) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
445 | self.hexEdit.setFocus() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
446 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
447 | @pyqtSlot(str) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
448 | def on_hexEdit_textChanged(self, txt): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
449 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
450 | Private slot to handle input of a hexadecimal number. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
451 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
452 | @param txt text entered (string) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
453 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
454 | try: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
455 | self.__input = int(txt, 16) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
456 | self.__inputValid = True |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
457 | except ValueError: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
458 | self.__inputValid = False |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
459 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
460 | if self.__inputValid: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
461 | self.__formatNumbers(16) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
462 | else: |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
463 | self.hexEdit.setStyleSheet(self.__badNumberSheet) |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
464 | |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
465 | @pyqtSlot() |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
466 | def on_hexOutButton_clicked(self): |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
467 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
468 | Private slot to send a hexadecimal number. |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
469 | """ |
237c3fe739f5
Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
470 | self.insertNumber.emit(self.hexEdit.text()) |