Skip to content

Commit 938b98d

Browse files
committed
TR updates, first round
1 parent 723087b commit 938b98d

File tree

3 files changed

+18
-77
lines changed

3 files changed

+18
-77
lines changed

pyqt-calculator-tutorial/examples/hello.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
# 3. Create an instance of your application's GUI
1919
window = QWidget()
20-
window.setWindowTitle("PyQt6 App")
20+
window.setWindowTitle("PyQt App")
2121
window.setGeometry(WIN_X, WIN_Y, WIDTH, HEIGHT)
2222
helloMsg = QLabel("<h1>Hello World!</h1>", parent=window)
2323
helloMsg.move(LABEL_X, LABEL_Y)

pyqt-calculator-tutorial/examples/signals_slots.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

pyqt-calculator-tutorial/pycalc/pycalc.py

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import sys
44
from functools import partial
5-
from typing import NamedTuple
65

76
from PyQt6.QtCore import Qt
87
from PyQt6.QtWidgets import (
@@ -21,11 +20,6 @@
2120
BUTTON_SIZE = 40
2221

2322

24-
class GridPosition(NamedTuple):
25-
row: int
26-
col: int
27-
28-
2923
class PyCalcWindow(QMainWindow):
3024
"""PyCalc's main window (GUI or view)."""
3125

@@ -34,9 +28,9 @@ def __init__(self):
3428
self.setWindowTitle("PyCalc")
3529
self.setFixedSize(WINDOW_SIZE, WINDOW_SIZE)
3630
self.generalLayout = QVBoxLayout()
37-
self._centralWidget = QWidget(self)
38-
self.setCentralWidget(self._centralWidget)
39-
self._centralWidget.setLayout(self.generalLayout)
31+
centralWidget = QWidget(self)
32+
centralWidget.setLayout(self.generalLayout)
33+
self.setCentralWidget(centralWidget)
4034
self._createDisplay()
4135
self._createButtons()
4236

@@ -50,36 +44,18 @@ def _createDisplay(self):
5044
def _createButtons(self):
5145
self.buttonMap = {}
5246
buttonsLayout = QGridLayout()
53-
# Key Symbol | Key position
54-
keyMap = {
55-
"7": GridPosition(0, 0),
56-
"8": GridPosition(0, 1),
57-
"9": GridPosition(0, 2),
58-
"/": GridPosition(0, 3),
59-
"C": GridPosition(0, 4),
60-
"4": GridPosition(1, 0),
61-
"5": GridPosition(1, 1),
62-
"6": GridPosition(1, 2),
63-
"*": GridPosition(1, 3),
64-
"(": GridPosition(1, 4),
65-
"1": GridPosition(2, 0),
66-
"2": GridPosition(2, 1),
67-
"3": GridPosition(2, 2),
68-
"-": GridPosition(2, 3),
69-
")": GridPosition(2, 4),
70-
"0": GridPosition(3, 0),
71-
"00": GridPosition(3, 1),
72-
".": GridPosition(3, 2),
73-
"+": GridPosition(3, 3),
74-
"=": GridPosition(3, 4),
75-
}
76-
77-
for keySymbol, keyPosition in keyMap.items():
78-
self.buttonMap[keySymbol] = QPushButton(keySymbol)
79-
self.buttonMap[keySymbol].setFixedSize(BUTTON_SIZE, BUTTON_SIZE)
80-
buttonsLayout.addWidget(
81-
self.buttonMap[keySymbol], keyPosition.row, keyPosition.col
82-
)
47+
keyBoard = [
48+
["7", "8", "9", "/", "C"],
49+
["4", "5", "6", "*", "("],
50+
["1", "2", "3", "-", ")"],
51+
["0", "00", ".", "+", "="],
52+
]
53+
54+
for row, keys in enumerate(keyBoard):
55+
for col, key in enumerate(keys):
56+
self.buttonMap[key] = QPushButton(key)
57+
self.buttonMap[key].setFixedSize(BUTTON_SIZE, BUTTON_SIZE)
58+
buttonsLayout.addWidget(self.buttonMap[key], row, col)
8359

8460
self.generalLayout.addLayout(buttonsLayout)
8561

@@ -118,10 +94,10 @@ def _calculateResult(self):
11894
result = self._evaluate(expression=self._view.displayText())
11995
self._view.setDisplayText(result)
12096

121-
def _buildExpression(self, sub_exp):
97+
def _buildExpression(self, subExpression):
12298
if self._view.displayText() == ERROR_MSG:
12399
self._view.clearDisplay()
124-
expression = self._view.displayText() + sub_exp
100+
expression = self._view.displayText() + subExpression
125101
self._view.setDisplayText(expression)
126102

127103
def _connectSignalsAndSlots(self):

0 commit comments

Comments
 (0)