2525from PyQt5 .QtWidgets import QPushButton
2626from PyQt5 .QtCore import Qt
2727
28- __version__ = ' 0.1'
29- __author__ = ' Leodanis Pozo Ramos'
28+ __version__ = " 0.1"
29+ __author__ = " Leodanis Pozo Ramos"
3030
31- ERROR_MSG = ' ERROR'
31+ ERROR_MSG = " ERROR"
3232
3333
3434# Create a subclass of QMainWindow to setup the calculator's GUI
@@ -39,7 +39,7 @@ def __init__(self):
3939 """View initializer."""
4040 super ().__init__ ()
4141 # Set some main window's properties
42- self .setWindowTitle (' PyCalc' )
42+ self .setWindowTitle (" PyCalc" )
4343 self .setFixedSize (235 , 235 )
4444 # Create, and set the central widget, and the general layout
4545 self .generalLayout = QVBoxLayout ()
@@ -66,27 +66,28 @@ def _createButtons(self):
6666 self .buttons = {}
6767 buttonsLayout = QGridLayout ()
6868 # Button text | position on the QGridLayout
69- buttons = {'7' : (0 , 0 ),
70- '8' : (0 , 1 ),
71- '9' : (0 , 2 ),
72- '/' : (0 , 3 ),
73- 'C' : (0 , 4 ),
74- '4' : (1 , 0 ),
75- '5' : (1 , 1 ),
76- '6' : (1 , 2 ),
77- '*' : (1 , 3 ),
78- '(' : (1 , 4 ),
79- '1' : (2 , 0 ),
80- '2' : (2 , 1 ),
81- '3' : (2 , 2 ),
82- '-' : (2 , 3 ),
83- ')' : (2 , 4 ),
84- '0' : (3 , 0 ),
85- '00' : (3 , 1 ),
86- '.' : (3 , 2 ),
87- '+' : (3 , 3 ),
88- '=' : (3 , 4 ),
89- }
69+ buttons = {
70+ "7" : (0 , 0 ),
71+ "8" : (0 , 1 ),
72+ "9" : (0 , 2 ),
73+ "/" : (0 , 3 ),
74+ "C" : (0 , 4 ),
75+ "4" : (1 , 0 ),
76+ "5" : (1 , 1 ),
77+ "6" : (1 , 2 ),
78+ "*" : (1 , 3 ),
79+ "(" : (1 , 4 ),
80+ "1" : (2 , 0 ),
81+ "2" : (2 , 1 ),
82+ "3" : (2 , 2 ),
83+ "-" : (2 , 3 ),
84+ ")" : (2 , 4 ),
85+ "0" : (3 , 0 ),
86+ "00" : (3 , 1 ),
87+ "." : (3 , 2 ),
88+ "+" : (3 , 3 ),
89+ "=" : (3 , 4 ),
90+ }
9091 # Create the buttons, and add them to the grid layout
9192 for btn_text , pos in buttons .items ():
9293 self .buttons [btn_text ] = QPushButton (btn_text )
@@ -106,7 +107,7 @@ def displayText(self):
106107
107108 def clearDisplay (self ):
108109 """Clear the display."""
109- self .setDisplayText ('' )
110+ self .setDisplayText ("" )
110111
111112
112113# Create a Model to handle the calculator's operation
@@ -147,12 +148,12 @@ def _buildExpression(self, sub_exp):
147148 def _connectSignals (self ):
148149 """Connect signals, and slots."""
149150 for btn_text , btn in self ._view .buttons .items ():
150- if btn_text not in {'=' , 'C' }:
151+ if btn_text not in {"=" , "C" }:
151152 btn .clicked .connect (partial (self ._buildExpression , btn_text ))
152153
153- self ._view .buttons ['=' ].clicked .connect (self ._calculateResult )
154+ self ._view .buttons ["=" ].clicked .connect (self ._calculateResult )
154155 self ._view .display .returnPressed .connect (self ._calculateResult )
155- self ._view .buttons ['C' ].clicked .connect (self ._view .clearDisplay )
156+ self ._view .buttons ["C" ].clicked .connect (self ._view .clearDisplay )
156157
157158
158159# Client code
@@ -170,5 +171,5 @@ def main():
170171 sys .exit (pycalc .exec_ ())
171172
172173
173- if __name__ == ' __main__' :
174+ if __name__ == " __main__" :
174175 main ()
0 commit comments