forked from fra589/cn5X
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qwkeyboard.py
171 lines (136 loc) · 8.28 KB
/
qwkeyboard.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# -*- coding: utf-8 -*-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' '
' Copyright 2018-2024 Gauthier Brière (gauthier.briere "at" gmail.com) '
' '
' This file is part of cn5X++ '
' '
' cn5X++ is free software: you can redistribute it and/or modify it '
' under the terms of the GNU General Public License as published by '
' the Free Software Foundation, either version 3 of the License, or '
' (at your option) any later version. '
' '
' cn5X++ is distributed in the hope that it will be useful, but '
' WITHOUT ANY WARRANTY; without even the implied warranty of '
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the '
' GNU General Public License for more details. '
' '
' You should have received a copy of the GNU General Public License '
' along with this program. If not, see <http://www.gnu.org/licenses/>. '
' '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
import sys, os
import threading
from PyQt6 import QtCore, QtWidgets, uic
from PyQt6.QtCore import Qt, QCoreApplication, QObject, pyqtSignal, pyqtSlot, QSettings, QEvent
from PyQt6.QtGui import QKeyEvent
from gcodeQLineEdit import gcodeQLineEdit
from PyQt6.QtTest import QTest
class qwKeyboard(QtWidgets.QWidget):
''' Widget personalise construisant le clavier touch screen
'''
def __init__(self, parent=None):
super().__init__()
self.parent = parent
# Initialise l'interface utilisateur du clavier
self.keyboard = QtWidgets.QFrame(parent)
self.keyboard.setStyleSheet(".QFrame{background-color: rgba(192, 192, 192, 192); border: 1px solid #000060; margin: 0px; padding: 0px;}")
self.keyboard.move(5, 265)
self.keyboard.ui = uic.loadUi(os.path.join(os.path.dirname(__file__), "qwKeyboard_ui.ui"), self.keyboard)
self.__txt = None
# Le clavier est masqué au départ
self.keyboard.setVisible(False)
# Connections des evennements clavier
self.keyboard.ui.keybButtonHideL.pressed.connect(self.keyboard_hide)
self.keyboard.ui.keybButtonHideR.pressed.connect(self.keyboard_hide)
self.keyboard.ui.keybButton0.pressed.connect(lambda: self.keyboardKey("0"))
self.keyboard.ui.keybButton1.pressed.connect(lambda: self.keyboardKey("1"))
self.keyboard.ui.keybButton2.pressed.connect(lambda: self.keyboardKey("2"))
self.keyboard.ui.keybButton3.pressed.connect(lambda: self.keyboardKey("3"))
self.keyboard.ui.keybButton4.pressed.connect(lambda: self.keyboardKey("4"))
self.keyboard.ui.keybButton5.pressed.connect(lambda: self.keyboardKey("5"))
self.keyboard.ui.keybButton6.pressed.connect(lambda: self.keyboardKey("6"))
self.keyboard.ui.keybButton7.pressed.connect(lambda: self.keyboardKey("7"))
self.keyboard.ui.keybButton8.pressed.connect(lambda: self.keyboardKey("8"))
self.keyboard.ui.keybButton9.pressed.connect(lambda: self.keyboardKey("9"))
self.keyboard.ui.keybButtonMoins.pressed.connect(lambda: self.keyboardKey("-"))
self.keyboard.ui.keybButtonPoint.pressed.connect(lambda: self.keyboardKey("."))
self.keyboard.ui.keybButtonA.pressed.connect(lambda: self.keyboardKey("A"))
self.keyboard.ui.keybButtonB.pressed.connect(lambda: self.keyboardKey("B"))
self.keyboard.ui.keybButtonC.pressed.connect(lambda: self.keyboardKey("C"))
self.keyboard.ui.keybButtonD.pressed.connect(lambda: self.keyboardKey("D"))
self.keyboard.ui.keybButtonE.pressed.connect(lambda: self.keyboardKey("E"))
self.keyboard.ui.keybButtonF.pressed.connect(lambda: self.keyboardKey("F"))
self.keyboard.ui.keybButtonG.pressed.connect(lambda: self.keyboardKey("G"))
self.keyboard.ui.keybButtonH.pressed.connect(lambda: self.keyboardKey("H"))
self.keyboard.ui.keybButtonI.pressed.connect(lambda: self.keyboardKey("I"))
self.keyboard.ui.keybButtonJ.pressed.connect(lambda: self.keyboardKey("J"))
self.keyboard.ui.keybButtonK.pressed.connect(lambda: self.keyboardKey("K"))
self.keyboard.ui.keybButtonL.pressed.connect(lambda: self.keyboardKey("L"))
self.keyboard.ui.keybButtonM.pressed.connect(lambda: self.keyboardKey("M"))
self.keyboard.ui.keybButtonN.pressed.connect(lambda: self.keyboardKey("N"))
self.keyboard.ui.keybButtonO.pressed.connect(lambda: self.keyboardKey("O"))
self.keyboard.ui.keybButtonP.pressed.connect(lambda: self.keyboardKey("P"))
self.keyboard.ui.keybButtonQ.pressed.connect(lambda: self.keyboardKey("Q"))
self.keyboard.ui.keybButtonR.pressed.connect(lambda: self.keyboardKey("R"))
self.keyboard.ui.keybButtonS.pressed.connect(lambda: self.keyboardKey("S"))
self.keyboard.ui.keybButtonT.pressed.connect(lambda: self.keyboardKey("T"))
self.keyboard.ui.keybButtonU.pressed.connect(lambda: self.keyboardKey("U"))
self.keyboard.ui.keybButtonV.pressed.connect(lambda: self.keyboardKey("V"))
self.keyboard.ui.keybButtonW.pressed.connect(lambda: self.keyboardKey("W"))
self.keyboard.ui.keybButtonX.pressed.connect(lambda: self.keyboardKey("X"))
self.keyboard.ui.keybButtonY.pressed.connect(lambda: self.keyboardKey("Y"))
self.keyboard.ui.keybButtonZ.pressed.connect(lambda: self.keyboardKey("Z"))
self.keyboard.ui.keybButtonSpace.pressed.connect(lambda: self.keyboardKey(" "))
self.keyboard.ui.keybButtonEgal.pressed.connect(lambda: self.keyboardKey("="))
self.keyboard.ui.keybButtonDollar.pressed.connect(lambda: self.keyboardKey("$"))
self.keyboard.ui.keybButtonSharp.pressed.connect(lambda: self.keyboardKey("#"))
self.keyboard.ui.keybButtonQuestion.pressed.connect(lambda: self.keyboardKey("?"))
self.keyboard.ui.keybButtonHome.pressed.connect(lambda: self.keyboardMove("Home"))
self.keyboard.ui.keybButtonLeft.pressed.connect(lambda: self.keyboardMove("Left"))
self.keyboard.ui.keybButtonRight.pressed.connect(lambda: self.keyboardMove("Right"))
self.keyboard.ui.keybButtonEnd.pressed.connect(lambda: self.keyboardMove("End"))
self.keyboard.ui.keybButtonBackSpace.pressed.connect(lambda: self.keyboardDel("Back"))
self.keyboard.ui.keybButtonClear.pressed.connect(lambda: self.keyboardDel("Clear"))
self.keyboard.ui.keybButtonUp.pressed.connect(lambda: self.keyboardUpDown(Qt.Key.Key_Up))
self.keyboard.ui.keybButtonDown.pressed.connect(lambda: self.keyboardUpDown(Qt.Key.Key_Down))
@pyqtSlot(gcodeQLineEdit)
def setLinkedTxt(self, txt):
self.__txt = txt
def keyboard_show(self):
self.keyboard.setVisible(True)
def keyboard_hide(self):
self.keyboard.setVisible(False)
self.parent.ui.btnKeyboard.setText("⇧⌨⇧")
def isKeyboardVisible(self):
return self.keyboard.isVisible()
def keyboardKey(self, key):
if self.__txt is not None:
self.__txt.setFocus()
keyEvent = QKeyEvent(QEvent.Type.KeyPress, ord(key), Qt.KeyboardModifier.NoModifier, key)
QCoreApplication.postEvent(self.__txt, keyEvent)
def keyboardMove(self, action):
if self.__txt is not None:
self.__txt.setFocus()
if action == "Home":
self.__txt.setCursorPosition(0)
elif action == "Left":
if self.__txt.cursorPosition() > 0:
self.__txt.setCursorPosition(self.__txt.cursorPosition()-1)
elif action == "Right":
if self.__txt.cursorPosition() < len(self.__txt.text()):
self.__txt.setCursorPosition(self.__txt.cursorPosition()+1)
elif action == "End":
self.__txt.setCursorPosition(len(self.__txt.text()))
def keyboardDel(self, action):
if self.__txt is not None:
self.__txt.setFocus()
if action == "Back":
self.__txt.backspace()
elif action == "Clear":
self.__txt.clear()
def keyboardUpDown(self, QtKey):
if self.__txt is not None:
self.__txt.setFocus()
keyEvent = QKeyEvent(QEvent.Type.KeyPress, QtKey, Qt.KeyboardModifier.NoModifier)
QCoreApplication.postEvent(self.__txt, keyEvent)