-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-run-lintalistAHK-defs.py
291 lines (236 loc) · 11.6 KB
/
run-run-lintalistAHK-defs.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# this file will be (hopefully merged to) ...-all.py
# the following f-keys commands are working:
# keyboard.fake_keypress('<f4>') # edit snippet
# keyboard.fake_keypress('<f5>') # copy snippet
# keyboard.fake_keypress('<f5>') # move snippet
# keyboard.fake_keypress('<f7>') # new snippet
# keyboard.fake_keypress('<f8>') # remove snippet
# keyboard.fake_keypress('<f10>') # manage bundels
# from time import sleep
def slow_send(word, delay):
for c in word:
keyboard.send_keys(c)
time.sleep(delay)
import os, time, datetime, pathlib, subprocess # TODO: one day install: http://omz-software.com/pythonista/docs/ios/clipboard.html
#<<<<<<<<<<<<
# Todo: do this: https://github.com/autokey/autokey/issues/248
#>>>>>>>>>>>>
def popupNotify(text):
subprocess.Popen(['notify-send', text]) # will be showed right top
def popupNotify_howItWorks(text):
global doPopupNotify_howItWorks
if doPopupNotify_howItWorks:
subprocess.Popen(['notify-send', text]) # will be showed right top
def writeAllFile_from_main_defs(path,rewriteAlways = False):
global do_DisableUpdatingThe_all_file
if do_DisableUpdatingThe_all_file:
return
path = home + "/.config/autokey/data/Sample Scripts/"
# global data
data = "# Attention: !!! don`t edit thi file. this file will be result from other files merged."
if not rewriteAlways:
getmtimeConfig = os.path.getmtime(path + 'run-run-lintalistAHK-config.py')
getmtimeDefs = os.path.getmtime(path + 'run-run-lintalistAHK-defs.py')
getmtimeMain = os.path.getmtime(path + 'run-run-lintalistAHK-main.py')
getmtimeAll = os.path.getmtime(path + 'run-run-lintalistAHK-all.py')
if rewriteAlways or (getmtimeAll < getmtimeDefs or getmtimeAll < getmtimeConfig or getmtimeAll < getmtimeMain):
subprocess.Popen(['notify-send', ' need update']) # will be showed right top
# Reading data from file1
with open(path + 'run-run-lintalistAHK-config.py') as fp:
data += "\n" + fp.read()
with open(path + 'run-run-lintalistAHK-defs.py') as fp:
data += "\n" + fp.read()
with open(path + 'run-run-lintalistAHK-main.py') as fp:
data += "\n" + fp.read()
with open(path + 'run-run-lintalistAHK-all.py', 'w') as fp:
fp.write(data)
# from module.run_run_lintalist_fuctions import read_keyword
# HowTo import modules in AutoKey: https://stackoverflow.com/a/23186143/2891692
# not best way: # >~/.config/autokey/autokey.json >Find a line that looks like > "userCodeDir": "", >and put your directory path in manually.
# https://groups.google.com/g/autokey-users/c/ykEoQygDw40?pli=1
# https://stackoverflow.com/questions/16226607/any-way-to-import-autokey-libraries-into-python-script
# https://github.com/autokey/autokey/issues/248#issue-406386345
#################
def beeps(duration=.1, freq=2000, loops=1):
# duration = .8 # second
# freq = 1500 # Hz
for x in range(loops):
os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % (duration, freq))
# <<<<<<<<<< read_keyword
# <<<<<<<<<< read_keyword
# <<<<<<<<<< read_keyword
# <<<<<<<<<< read_keyword
# <<<<<<<<<< read_keyword
# <<<<<<<<<< read_keyword
# <<<<<<<<<< read_keyword
# <<<<<<<<<< read_keyword
# <<<<<<<<<< read_keyword
# <<<<<<<<<< read_keyword
def read_keyword(doReplaceIfPrefixIsThis,do_ifNoPrefix_useFocusedWord_pasteResultRight,keyboard,window,clipboard):
global doPopupNotify_howItWorks, clipboardKey, first_title, duration, freq, doReplace, x, active_title, timeValueInLoopInSec, timeValueForBREAKLoopInSec
if doReplaceIfPrefixIsThis:
# select word and prefix e.g. :test
doSelctWordAndPrefix = True
clipboardBackup = ""
clipboardBackup = ''
try:
clipboardBackup = clipboard.get_clipboard() # .lstrip # found here: https://github.com/autokey/autokey/wiki/Scripting#create-new-abbreviation
except:
clipboardBackup = ""
beeps(duration=.1, freq=2000, loops=1)
popupNotify_howItWorks("get_clipboard except :-O")
# check if its only :
clipboardKey_endChar = check_key_endChar_and_may_replace(clipboard, clipboardBackup, doReplaceIfPrefixIsThis, keyboard)
copy_word_2_clipboard_focusedInTheMiddle(clipboard, keyboard)
clipboardKey = try_read_clipboard_without_visible_errors(clipboard)
# keyboard.release_key('<shift>') # sometimes i got hanging shift key
first_title = window.get_active_title()
popupNotify_howItWorks('get_clipboard')
doReplace = False
popupNotify_howItWorks("clipboardKey = " + clipboardKey)
# time.sleep(1)
# quit() # klkj klkjklkj lklkjlklkjlklkjlklkj
# :seb
firstChar = clipboardKey[0:1]
if not clipboardKey:
popupNotify_howItWorks("NOT clipboardKey = " + clipboardKey + " ==> exit()")
beeps(duration=.1, freq=2000, loops=2)
exit()
if not doReplaceIfPrefixIsThis:
popupNotify_howItWorks("NOT doReplaceIfPrefixIsThis = " + doReplaceIfPrefixIsThis + " ==> exit()")
beeps(duration=.1, freq=2000, loops=3)
exit()
# popupNotify_howItWorks('firstChar = ' + firstChar + ' , clipboardKey = ' + clipboardKey)
# time.sleep(2)
# quit()
if firstChar == doReplaceIfPrefixIsThis: # :test :test ff uihu : :
doReplace = True
popupNotify_howItWorks("found doReplaceIfPrefixIsThis = " + doReplaceIfPrefixIsThis)
# if doPopupNotify_howItWorks: :test
# beeps(duration=.2, freq=1000, loops=2)
else:
try:
popupNotify_howItWorks("NOT found in keyword = >>" + clipboardKey + "<<\n , doReplaceIfPrefixIsThis = >>" + doReplaceIfPrefixIsThis + "<<")
except:
popupNotify_howItWorks("NOT found in keyword")
# asdf
#if doReplaceIfPrefixIsThis == clipboardKey:
# keyboard.send_keys('-' + clipboardKey + '-')
# keyboard.send_keys('-' + clipboardBackup + '-')
# quit() # testk testk : : clipboardBackup : : : clipboardBackup'-' clipboardBackupclipboardBackupclipboardBackup
# keyboard.release_key('<ctrl>')
popupNotify_howItWorks("run run-lintalistAHK.ahk")
# beeps(duration=.25, freq=5000, loops=1)
try:
# subprocess.Popen(["/bin/bash", home + "/Documents/github/Lintalist4Linux/run-run-lintalistAHK.sh"])
# import os :seb
# myCmd = 'wine ' + home + '/.wine/drive_c/Program\ Files/AutoHotkey/AutoHotkey.exe ' + home + '/Documents/github/Lintalist4Linux/run-lintalistAHK.ahk'
myCmd = 'wine ' + home + '/.wine/drive_c/Program\ Files/AutoHotkey/AutoHotkey.exe "' + home + '/.config/autokey/data/Sample Scripts/run-lintalistAHK.ahk"'
# myCmd = 'wine /home/administrator/.wine/drive_c/Program\ Files/AutoHotkey/AutoHotkey.exe ~/Documents/github/Lintalist4Linux/run-lintalistAHK.ahk'
os.system(myCmd)
# test
# myCmd = kotlinc - script home + "/.config/autokey/data/Sample Scripts/PyLink.kts" - - -d. /
# os.system(myCmd)
except subprocess.CalledProcessError:
time.sleep(0.2)
# :lo :Heide
# :tes2016/01t Heide
# 100 line
# php2012/01 cello-technologie.de
for i in range(0, 30):
time.sleep(0.1)
# active_class = window.get_active_class()
active_title = window.get_active_title()
# if active_class != first_class:
if active_title != first_title:
break
timeValueInLoopInSec = 0.3
timeValueForBREAKLoopInSec = 90 # timeOut. Prevention for endless loops
# BREAK x is '101
# time.sleep(2)
# keyboard.send_keys('<ctrl>+v')
return (clipboardKey, doReplace, timeValueForBREAKLoopInSec, timeValueInLoopInSec, first_title)
def try_read_clipboard_without_visible_errors(clipboard):
clipboardKey = ""
for i in range(1, 3):
try:
clipboardKey = clipboard.get_clipboard() # found here: https://github.com/autokey/autokey/wiki/Scripting#create-new-abbreviation
slepSec = i * .1
time.sleep(slepSec)
except:
slepSec = i * .1
time.sleep(slepSec)
if clipboardKey:
break
return clipboardKey # test
def copy_word_2_clipboard_focusedInTheMiddle(clipboard, keyboard):
doSelect1charBefore = True
# read rest for beginning clipboardKey
keyboard.release_key('<ctrl>') # keyboard.press_key('<ctrl>')
time.sleep(.1) # seems importend time while using in pycharm
keyboard.send_keys('<ctrl>+<right>') # not works in every e.g. editor like pycharm
keyboard.send_keys('<ctrl>+<left>') # not works in every e.g. editor like pycharm
if doSelect1charBefore:
keyboard.send_keys('<left>')
keyboard.send_keys('<shift>+<right>')
keyboard.send_keys('<ctrl>+<shift>+<right>')
# time.sleep(.4)
keyboard.send_keys('<ctrl>+c')
time.sleep(.1)
# quit() # asdfasf k Sebastian Sebastian sl5 [email protected]
# test
def check_key_endChar_and_may_replace(clipboard, clipboardBackup, doReplaceIfPrefixIsThis, keyboard):
# this all works not in some websites. for e.g. career5.successfactors.eu
# in some register forms alls specialkey send the form. only letters not
# check if its only dummy_send :
# keyboard.press_key('<shift>')
# quit()
# keyboard.release_key('<shift>')
keyboard.send_keys('<shift>+<left>') # this works not in some websites. for e.g. career5.successfactors.eu
keyboard.send_keys('<ctrl>+c')
time.sleep(0.1)
try:
clipboardKey_endChar = clipboard.get_clipboard() # found here: https://github.com/autokey/autokey/wiki/Scripting#create-new-abbreviation
except:
clipboardKey_endChar = ''
popupNotify_howItWorks("clipboardKey_endChar = " + clipboardKey_endChar)
if clipboardKey_endChar == doReplaceIfPrefixIsThis:
# doReplace = True
popupNotify_howItWorks("found doReplaceIfPrefixIsThis = " + doReplaceIfPrefixIsThis)
keyboard.send_keys(clipboardBackup)
# slow_send(clipboardBackup, 1)
len_clipboardBackup = len(clipboardBackup)
select_text(keyboard, len_clipboardBackup)
keyboard.send_keys('<ctrl>+c') # stay with old clipboard. copy clipboardBackup
quit() #
if clipboardKey_endChar == "²": # special comando. sends it two times with tab beetween
# doReplace = True
popupNotify_howItWorks("found doReplaceIfPrefixIsThis = " + doReplaceIfPrefixIsThis)
keyboard.send_keys(clipboardBackup)
keyboard.send_keys("<tab>")
keyboard.send_keys(clipboardBackup)
# slow_send(clipboardBackup, 1)
len_clipboardBackup = len(clipboardBackup)
select_text(keyboard, len_clipboardBackup)
keyboard.send_keys('<ctrl>+c') # stay with old clipboard. copy clipboardBackup
quit() #
return clipboardKey_endChar
# asdf ² : : asdasdfasdasdfasdasdf Sebastian Sebastian ² Sebastian : Sebastian : Sebastian : Sebastian Sebastian :
def select_text(keyboard, len_clipboardBackup = 0): # 0 if dont know the clipboard/text but try select anyway
keyboard.release_key('<ctrl>')
if not len_clipboardBackup or len_clipboardBackup > 100:
keyboard.send_keys('<ctrl>+<shift>+<left>') # faster but not as exact. forgets special letters.
else:
# keyboard.press_key('<shift>') ### <=== disabled this way of selection 20-08-24 21:23:35
for i in range(0, len_clipboardBackup):
# keyboard.send_keys('<left>') # exact method
keyboard.send_keys('<shift>+<left>') # exact method
# keyboard.release_key('<shift>')
#>>>>>>>>>>>>>> read_keyword
#>>>>>>>>>>>>>> read_keyword
#>>>>>>>>>>>>>> read_keyword
#>>>>>>>>>>>>>> read_keyword
#>>>>>>>>>>>>>> read_keyword
#>>>>>>>>>>>>>> read_keyword
#>>>>>>>>>>>>>> read_keyword
# :umm