-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberPadWidget.py
More file actions
53 lines (47 loc) · 1.61 KB
/
Copy pathNumberPadWidget.py
File metadata and controls
53 lines (47 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import inspect
from typing import Callable, Any
from PyQt5.QtWidgets import QWidget, QGridLayout, QPushButton
from PyQt5.QtCore import Qt, QSize
class NumberPadWidget(QWidget):
def __init__(self, btn_size: QSize, font_size: float = 16, border_size: int=1):
super().__init__()
layout = QGridLayout(self)
layout.setSpacing(0)
layout.setContentsMargins(0,0,0,0)
width = (btn_size.width() * 3)
height = (btn_size.height() * 4)
size = QSize(width, height)
self.setFixedSize(size)
self.setStyleSheet(inspect.cleandoc(
"""\
QPushButton {
font:Segoe UI;
background-color:white;
border: %dpx solid black;
font-size: %dpx;
padding:5px;
font-weight:bold;
}
QPushButton:pressed {background-color: red }
""" % (border_size,font_size)))
self._on_click = lambda _: None
def f(txt: str, r: int, c: int):
btn = QPushButton(txt)
btn.clicked.connect(lambda: self._on_click(btn.text()))
btn.setFixedSize(btn_size)
layout.addWidget(btn, r, c, Qt.AlignCenter)
return btn
button1 = f("1", 0, 0)
button2 = f("2", 0, 1)
button3 = f("3", 0, 2)
button4 = f("4", 1, 0)
button5 = f("5", 1, 1)
button6 = f("6", 1, 2)
button7 = f("7", 2, 0)
button8 = f("8", 2, 1)
button9 = f("9", 2, 2)
button10 = f("*", 3, 0)
button11 = f("0", 3, 1)
button12 = f("#", 3, 2)
def set_on_click(self, fn: Callable[[str], Any]):
self._on_click = fn