-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspeChar.py
executable file
·176 lines (144 loc) · 4.11 KB
/
speChar.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
172
173
174
175
176
#!/usr/bin/python3
"""
speChar by Tubbadu
TODO:
* change font
* get screen size automatically
* tidy up
* change scrollbar to the native one (don't know why it's different)
"""
from operator import index
import sys, os, subprocess
#default values
PyQt_VERSION = 5
LANGUAGE = "en"
EMOJI = False
#reading arguments values
args = sys.argv[1:]
if "-l" in args:
LANGUAGE = args[args.index("-l") + 1]
if "-v" in args:
PyQt_VERSION = int(args[args.index("-v") + 1])
if "--emoji" in args:
EMOJI = True
#global variables
path = os.path.abspath(os.path.dirname(__file__))
if EMOJI:
configPath = path + "/emoji_" + LANGUAGE.strip() + ".config"
else:
configPath = path + "/speChar_" + LANGUAGE.strip() + ".config"
iconPath = path + "/speCharIcon.ico"
screenSize = (None, None)
#check if language is supported
if not os.path.isfile(configPath):
print(f"file {configPath} not found: Perhaps \"{LANGUAGE}\" language is not supported yet! Add it yourself in the github page (really easy!): https://github.com/tubbadu/SpeChar/pulls")
exit()
if PyQt_VERSION == 5:
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QWidget, QLineEdit, QListWidget, QListWidgetItem
from PyQt5.QtGui import QFont, QIcon
Key_Escape = Qt.Key_Escape
Key_Enter = Qt.Key_Enter
Key_Return = Qt.Key_Return
Key_Down = Qt.Key_Down
Key_Up = Qt.Key_Up
elif PyQt_VERSION == 6:
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QApplication, QWidget, QLineEdit, QListWidget, QListWidgetItem
from PyQt6.QtGui import QFont, QIcon
Key_Escape = Qt.Key.Key_Escape
Key_Enter = Qt.Key.Key_Enter
Key_Return = Qt.Key.Key_Return
Key_Down = Qt.Key.Key_Down
Key_Up = Qt.Key.Key_Up
else:
print("Error: PyQt_VERSION not supported")
exit(1)
def getConfig():
specialCharacters = list()
with open(configPath, 'r', encoding="utf16") as infile:
for line in infile:
add = line.strip().split('-')
specialCharacters.append([add[0].strip(), add[1].strip()])
return specialCharacters
def write(s):
print(s)
#subprocess.Popen(['xdotool', 'type', s])
from pynput.keyboard import Controller
import pyperclip
keyboard = Controller()
keyboard.type(s)
pyperclip.copy(s)
def refreshList(txt):
ret = []
for element in specialCharacters:
if txt.lower() in element[1].lower():
ret.append(QListWidgetItem(element[0]))
return ret
specialCharacters = getConfig()
lq = refreshList("")
class Main(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def keyPressEvent(self, e):
if e.key() == Key_Escape:
self.close()
elif e.key() == Key_Enter or e.key() == Key_Return:
# print current selection (then closes app)
self.close()
write(self.lbox.currentItem().text())
elif e.key() == Key_Down:
try:
self.lbox.setCurrentRow(self.lbox.currentRow() + 1)
except Exception as e:
print(e)
elif e.key() == Key_Up:
try:
self.lbox.setCurrentRow(self.lbox.currentRow() - 1)
except Exception as e:
print(e)
def initUI(self):
def textchanged():
lbox.clear()
lq = refreshList(str(self.tbox.text()))
for el in lq:
lbox.addItem(el.text())
#now select first element
lbox.setCurrentRow(0)
def itemclicked(item):
self.close()
write(item.text())
self.lbox = QListWidget(self)
lbox = self.lbox
for el in lq:
lbox.addItem(el)
lbox.resize(lbox.sizeHint())
self.lbox.setFont(QFont('Noto Color Emoji'))
lbox.itemClicked.connect(itemclicked)
self.tbox = QLineEdit(self)
tbox = self.tbox
tbox.textChanged.connect(textchanged)
lbox.move(0, 0)
lbox.setGeometry(5, 5, 100, 190)
#tbox.move(115, 85)
tbox.setGeometry(115, 83, 100, 25)
tbox.setFocus()
tbox.setAlignment(Qt.AlignmentFlag.AlignCenter)
lbox.setCurrentRow(0)
self.setGeometry(screenSize[0]//2 - 110, screenSize[1]//2 - 100, 220, 200)
self.setWindowTitle('speChar')
self.setWindowIcon(QIcon(iconPath))
font = QFont()
font.setPixelSize(15)
self.setFont(font)
self.show()
def main():
app = QApplication(sys.argv)
global screenSize
screenSize = (app.primaryScreen().size().width(), app.primaryScreen().size().height())
print(screenSize)
ex = Main()
sys.exit(app.exec())
if __name__ == '__main__':
main()