Skip to content

Commit 9e754fc

Browse files
committed
250723.4
1 parent c96a227 commit 9e754fc

File tree

6 files changed

+69
-5
lines changed

6 files changed

+69
-5
lines changed
Binary file not shown.

easycoder/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
from .ec_timestamp import *
1212
from .ec_value import *
1313

14-
__version__ = "250723.2"
14+
__version__ = "250723.4"

easycoder/close.png

9.62 KB
Loading

easycoder/ec_keyboard.py

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
import os
23
from .ec_handler import Handler
34
from PySide6.QtWidgets import (
45
QDialog,
@@ -11,11 +12,70 @@
1112
QSizePolicy,
1213
QGraphicsDropShadowEffect
1314
)
14-
from PySide6.QtGui import QFont, QIcon
15-
from PySide6.QtCore import Qt, QTimer
15+
from PySide6.QtGui import QFont, QIcon, QPixmap, QPainter, QColor
16+
from PySide6.QtCore import Qt, QTimer, Signal, QRect
1617

1718
class Keyboard(Handler):
18-
19+
iconClicked = Signal()
20+
21+
class Border(QWidget):
22+
iconClicked = Signal()
23+
24+
def __init__(self):
25+
super().__init__()
26+
self.setFixedHeight(25)
27+
self._drag_active = False
28+
self._drag_start_pos = None
29+
30+
def paintEvent(self, event):
31+
painter = QPainter(self)
32+
painter.setRenderHint(QPainter.Antialiasing)
33+
# Draw the close icon
34+
self.pixmap = QPixmap(f'{os.path.dirname(os.path.abspath(__file__))}/close.png').scaled(25, 25, Qt.KeepAspectRatio, Qt.SmoothTransformation)
35+
x = self.width() - self.pixmap.width()
36+
y = 0
37+
painter.drawPixmap(x, y, self.pixmap)
38+
39+
# Draw the drag bar in the center
40+
bar_width = 100
41+
bar_height = 20
42+
bar_x = (self.width() - bar_width) // 2
43+
bar_y = (self.height() - bar_height) // 2
44+
painter.setBrush(QColor("#bbb"))
45+
painter.setPen(Qt.NoPen)
46+
painter.drawRoundedRect(bar_x, bar_y, bar_width, bar_height, 10, 10)
47+
48+
def mousePressEvent(self, event):
49+
x = self.width() - self.pixmap.width()
50+
y = 0
51+
icon_rect = self.pixmap.rect().translated(x, y)
52+
if icon_rect.contains(event.pos()):
53+
self.iconClicked.emit()
54+
elif self._bar_rect().contains(event.pos()):
55+
self._drag_active = True
56+
self._drag_start_pos = event.globalPosition().toPoint()
57+
self._dialog_start_pos = self.window().pos()
58+
else:
59+
super().mousePressEvent(event)
60+
61+
def mouseMoveEvent(self, event):
62+
if self._drag_active:
63+
delta = event.globalPosition().toPoint() - self._drag_start_pos
64+
self.window().move(self._dialog_start_pos + delta)
65+
else:
66+
super().mouseMoveEvent(event)
67+
68+
def mouseReleaseEvent(self, event):
69+
self._drag_active = False
70+
super().mouseReleaseEvent(event)
71+
72+
def _bar_rect(self):
73+
bar_width = 100
74+
bar_height = 20
75+
bar_x = (self.width() - bar_width) // 2
76+
bar_y = (self.height() - bar_height) // 2
77+
return QRect(bar_x, bar_y, bar_width, bar_height)
78+
1979
def __init__(self, program, receiver, parent=None):
2080
Handler.__init__(self, program.compiler)
2181

@@ -38,6 +98,10 @@ def __init__(self, program, receiver, parent=None):
3898

3999
# Add the keyboard
40100
layout = QVBoxLayout(dialog)
101+
102+
border = self.Border()
103+
border.iconClicked.connect(dialog.reject)
104+
layout.addWidget(border)
41105
layout.addWidget(VirtualKeyboard(42, receiver, dialog.reject))
42106

43107
# Position at bottom of parent window

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies = [
2020
]
2121

2222
[tool.flit.sdist]
23-
include = ["ec_*.py"]
23+
include = ["ec_*.py", "*.png"]
2424

2525
[project.scripts]
2626
easycoder = "easycoder:Main"

0 commit comments

Comments
 (0)