eric6/UI/NumbersWidget.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
child 8143
2c730d5fd177
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

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
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2010 - 2021 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
5736
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5603
diff changeset
10 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
11 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
12
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 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
14
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 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
16
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import UI.PixmapCache
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
19
372
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 class BinaryModel(QAbstractTableModel):
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 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
23 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
24 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
25 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Constructor
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 @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
29 """
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
30 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
31
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 self.__bits = 0
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 self.__value = 0
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 def rowCount(self, parent):
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 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
38
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 @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
40 @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
41 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 return 1
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 def columnCount(self, parent):
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 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
47
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 @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
49 @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
50 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 return self.__bits
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
53 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
54 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 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
56
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 @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
58 @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
59 @return requested data
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 if role == Qt.CheckStateRole:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 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
63
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 elif role == Qt.DisplayRole:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 return ""
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 return None
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 def flags(self, index):
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 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
72
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 @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
74 @return flags (Qt.ItemFlags)
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 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
77
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
78 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
79 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 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
81
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 @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
83 @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
84 @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
85 @return requested data
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 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
88 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
89
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 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
91
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 def setBits(self, bits):
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 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
95
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 @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
97 """
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
98 self.beginResetModel()
372
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 self.__bits = bits
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
100 self.endResetModel()
372
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 def setValue(self, value):
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 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
105
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 @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
107 """
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
108 self.beginResetModel()
372
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 self.__value = value
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
110 self.endResetModel()
372
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 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
113 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 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
115
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 @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
117 @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
118 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 self.__bits = bits
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 self.__value = value
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
121 self.beginResetModel()
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
122 self.endResetModel()
372
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 def getValue(self):
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 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
127
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 @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
129 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 return self.__value
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
132 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
133 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 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
135
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 @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
137 @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
138 @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
139 @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
140 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 if role == Qt.CheckStateRole:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 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
143 # 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
144 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
145 else:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 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
147 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
148 return True
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 return False
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
152
372
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 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
154 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 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
156
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 @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
158 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
159 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 insertNumber = pyqtSignal(str)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
162 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
163 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 Constructor
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 @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
167 """
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
168 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
169 self.setupUi(self)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
171 self.setWindowIcon(UI.PixmapCache.getIcon("eric"))
372
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 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
174
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
175 self.binInButton.setIcon(UI.PixmapCache.getIcon("2downarrow"))
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
176 self.binOutButton.setIcon(UI.PixmapCache.getIcon("2uparrow"))
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
177 self.octInButton.setIcon(UI.PixmapCache.getIcon("2downarrow"))
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
178 self.octOutButton.setIcon(UI.PixmapCache.getIcon("2uparrow"))
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
179 self.decInButton.setIcon(UI.PixmapCache.getIcon("2downarrow"))
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
180 self.decOutButton.setIcon(UI.PixmapCache.getIcon("2uparrow"))
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
181 self.hexInButton.setIcon(UI.PixmapCache.getIcon("2downarrow"))
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
182 self.hexOutButton.setIcon(UI.PixmapCache.getIcon("2uparrow"))
372
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
184 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
185 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
186 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
187 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
188 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
189
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 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
191 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
192 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
193 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
194
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 self.__input = 0
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 self.__inputValid = True
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 self.__bytes = 1
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 self.__model = BinaryModel(self)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 self.binTable.setModel(self.__model)
7198
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
201 self.binTable.horizontalHeader().setSectionResizeMode(
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
202 QHeaderView.ResizeToContents)
372
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 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
204 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
205
5603
4f2dd0850803 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
206 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
207 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 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
209
5603
4f2dd0850803 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
210 @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
211 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 self.__block(True)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 self.binEdit.setStyleSheet("")
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 self.octEdit.setStyleSheet("")
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 self.decEdit.setStyleSheet("")
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 self.hexEdit.setStyleSheet("")
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 # 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
220 byteCount = 8
372
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 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
222 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
223 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
224 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
225 break
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 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
227 break
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 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
229 byteCount -= 1
4f2dd0850803 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
230 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
231 byteCount = 1
4f2dd0850803 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
232 self.__bytes = byteCount
372
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 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
235 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
236 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
237 else:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 self.sizeBox.setStyleSheet("")
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 # octal
5603
4f2dd0850803 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
241 if numberFormat != 8:
372
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 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
243
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 # decimal
5603
4f2dd0850803 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
245 if numberFormat != 10:
372
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 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
247
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 # hexadecimal
5603
4f2dd0850803 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
249 if numberFormat != 16:
372
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 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
251
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 # octal
5603
4f2dd0850803 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
253 if numberFormat != 8:
372
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 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
255
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 # binary
5603
4f2dd0850803 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
257 if numberFormat != 2:
372
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 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
259 self.binEdit.setText(num)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 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
262
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 self.__block(False)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 def __block(self, b):
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 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
268
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 @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
270 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 self.hexEdit.blockSignals(b)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 self.decEdit.blockSignals(b)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 self.octEdit.blockSignals(b)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 self.binEdit.blockSignals(b)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 self.binTable.blockSignals(b)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 @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
278 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
279 """
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
280 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
281
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
282 @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
283 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 self.__formatNumbers(10)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 @pyqtSlot()
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 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
288 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 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
290 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 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
292 if bytesIn == 0:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 bytesIn = self.__bytes
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 tmp1 = self.__input
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 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
297 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
298 tmp2 <<= 8
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 tmp2 |= tmp1 & 0xff
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 tmp1 >>= 8
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 self.__input = tmp2
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 self.__formatNumbers(0)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 @pyqtSlot()
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 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
307 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 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
309 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 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
311 if number == "":
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 return
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 self.binEdit.setText(number)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 self.binEdit.setFocus()
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 @pyqtSlot(str)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 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
319 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 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
321
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 @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
323 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 try:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 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
326 self.__inputValid = True
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 except ValueError:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 self.__inputValid = False
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 if self.__inputValid:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 self.__formatNumbers(2)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 else:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 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
334
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 @pyqtSlot()
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 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
337 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 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
339 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 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
341
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 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
343 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 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
345
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 @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
347 @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
348 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 val = self.__model.getValue()
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 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
351 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
352 self.binEdit.setText(num)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 @pyqtSlot()
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 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
356 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 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
358 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 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
360 if number == "":
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 return
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 self.octEdit.setText(number)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 self.octEdit.setFocus()
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 @pyqtSlot(str)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 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
368 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 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
370
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 @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
372 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 try:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 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
375 self.__inputValid = True
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 except ValueError:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 self.__inputValid = False
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 if self.__inputValid:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 self.__formatNumbers(8)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 else:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 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
383
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 @pyqtSlot()
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 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
386 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 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
388 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 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
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_decInButton_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 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
395 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 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
397 if number == "":
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 return
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 self.decEdit.setText(number)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 self.decEdit.setFocus()
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 @pyqtSlot(str)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 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
405 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 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
407
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 @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
409 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 try:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 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
412 self.__inputValid = True
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413 except ValueError:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
414 self.__inputValid = False
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
415
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416 if self.__inputValid:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417 self.__formatNumbers(10)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418 else:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
419 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
420
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421 @pyqtSlot()
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 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
423 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 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
425 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
426 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
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_hexInButton_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 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
432 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 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
434 if number == "":
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
435 return
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
436
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437 self.hexEdit.setText(number)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
438 self.hexEdit.setFocus()
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 @pyqtSlot(str)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 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
442 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443 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
444
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445 @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
446 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
447 try:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
448 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
449 self.__inputValid = True
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
450 except ValueError:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
451 self.__inputValid = False
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
452
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
453 if self.__inputValid:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
454 self.__formatNumbers(16)
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
455 else:
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
456 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
457
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
458 @pyqtSlot()
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
459 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
460 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
461 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
462 """
237c3fe739f5 Added a numbers viewer to convert numbers into various formats.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
463 self.insertNumber.emit(self.hexEdit.text())

eric ide

mercurial