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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
|
#// auth_ Mohamad Janati
#// Copyright (c) 2019-2021 Mohamad Janati (freaking stupid, right? :|)
from aqt.utils import tooltip
from anki.hooks import wrap
import aqt
from aqt.reviewer import Reviewer
import aqt
from aqt.qt import *
from aqt import mw
from anki import version
anki_version = int(version.replace('.', ''))
if anki_version > 2119:
from typing import Optional
config = mw.addonManager.getConfig(__name__)
tooltip_timer = config["Tooltip Timer"]
tooltip_textColor = config["Tooltip Text Color"]
reviewButton_style = config[" Review_ Buttons Style"]
custom_sizes = config ['Button_ Custom Button Sizes']
buttons_height = config['Button_ Height_ All Bottombar Buttons']
reviewButtons_width = config['Button_ Width_ Review Buttons']
custom_reviewButtonColors = config[' Review_ Custom Colors']
againHover_color = config['Color_ Again on hover']
hardHover_color = config['Color_ Hard on hover']
goodHover_color = config['Color_ Good on hover']
easyHover_color = config['Color_ Easy on hover']
tooltip_style = config['Tooltip Style']
tooltip_position = config['Tooltip Position']
info_position = config["Button_ Position_ Info Button"]
skip_position = config['Button_ Position_ Skip Button']
undo_position = config['Button_ Position_ Undo Button']
info = config['Button_ Info Button']
skip = config['Button_ Skip Button']
undo = config['Button_ Undo Button']
edit_width = config["Button_ Width_ Edit Button"]
info_width = config["Button_ Width_ Info Button"]
skip_width = config["Button_ Width_ Skip Button"]
more_width = config["Button_ Width_ More Button"]
undo_width = config["Button_ Width_ Undo Button"]
if not custom_sizes:
edit_width = 72
info_width = 64
skip_width = 64
undo_width = 64
more_width = 72
if custom_reviewButtonColors:
again_backgroundColor = config['Color_ Again on hover']
hard_backgroundColor = config['Color_ Hard on hover']
good_backgroundColor = config['Color_ Good on hover']
easy_backgroundColor = config['Color_ Easy on hover']
else:
again_backgroundColor = "#FF1111"
hard_backgroundColor = "#FF9814"
good_backgroundColor = "#33FF2D"
easy_backgroundColor = "#21C0FF"
def myTooltip(self, ease): #\\ should i store text, color and position all in this function?? YESSS
button_count = self.mw.col.sched.answerButtons(self.card)
if button_count == 2:
if ease == 1:
button = ["Again", again_backgroundColor, -1, -39]
elif ease == 2:
button = ["Good", good_backgroundColor, 70, -39]
else:
button = ["", "transparent", 20000, 20000]
elif button_count == 3:
if ease == 1:
button = ["Again", again_backgroundColor, -37, -39]
elif ease == 2:
button = ["Good", good_backgroundColor, 35, -39]
elif ease == 3:
button = ["Easy", easy_backgroundColor, 107, -39]
else:
button = ["", "transparent", 20000, 20000]
else:
if ease == 1:
button = ["Again", again_backgroundColor, -73, -39]
elif ease == 2:
button = ["Hard", hard_backgroundColor, -3, -39]
elif ease == 3:
button = ["Good", good_backgroundColor, 70, -39]
elif ease == 4:
button = ["Easy", easy_backgroundColor, 142, -39]
else:
button = ["", "transparent", 20000, 20000]
button_width = 60
button_height = 26
x_offset = button[2]
y_offset = button[3]
text = button[0]
if custom_sizes and reviewButton_style not in [2, 3]:
button_height = buttons_height
button_width = reviewButtons_width
y_offset -= (buttons_height - 30)
if button_count == 2:
if reviewButtons_width < 61:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset += 19
elif ease == 2:
x_offset += reviewButtons_width/4
x_offset -= 15
elif 60 < reviewButtons_width < 81:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset += 14
elif ease == 2:
x_offset += reviewButtons_width/4
x_offset -= 10
elif 80 < reviewButtons_width < 101:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset += 9
elif ease == 2:
x_offset += reviewButtons_width/4
x_offset -= 5
elif 100 < reviewButtons_width < 121:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset += 4
elif ease == 2:
x_offset += reviewButtons_width/4
elif 120 < reviewButtons_width < 141:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset -= 1
elif ease == 2:
x_offset += reviewButtons_width/4
x_offset += 5
elif 140 < reviewButtons_width < 161:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset -= 6
elif ease == 2:
x_offset += reviewButtons_width/4
x_offset += 10
elif 160 < reviewButtons_width < 181:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset -= 11
elif ease == 2:
x_offset += reviewButtons_width/4
x_offset += 15
elif 180 < reviewButtons_width < 201:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset -= 16
elif ease == 2:
x_offset += reviewButtons_width/4
x_offset += 20
elif 200 < reviewButtons_width < 221:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset -= 21
elif ease == 2:
x_offset += reviewButtons_width/4
x_offset += 25
elif 220 < reviewButtons_width < 241:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset -= 26
elif ease == 2:
x_offset += reviewButtons_width/4
x_offset += 30
elif 240 < reviewButtons_width < 261:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset -= 31
elif ease == 2:
x_offset += reviewButtons_width/4
x_offset += 35
elif 260 < reviewButtons_width < 281:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset -= 36
elif ease == 2:
x_offset += reviewButtons_width/4
x_offset += 40
elif 280 < reviewButtons_width < 301:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset -= 41
elif ease == 2:
x_offset += reviewButtons_width/4
x_offset += 45
elif 300 < reviewButtons_width < 321:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset -= 46
elif ease == 2:
x_offset += reviewButtons_width/4
x_offset += 50
elif 320 < reviewButtons_width < 341:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset -= 51
elif ease == 2:
x_offset += reviewButtons_width/4
x_offset += 55
elif 340 < reviewButtons_width < 361:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset -= 56
elif ease == 2:
x_offset += reviewButtons_width/4
x_offset += 60
elif 360 < reviewButtons_width < 381:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset -= 61
elif ease == 2:
x_offset += reviewButtons_width/4
x_offset += 65
elif 380 < reviewButtons_width < 401:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset -= 65
elif ease == 2:
x_offset += reviewButtons_width/4
x_offset += 70
elif button_count == 3:
if ease == 1:
x_offset -= button_width
x_offset += 62
elif ease == 2:
x_offset += 2
elif ease == 3:
x_offset += button_width
x_offset -= 59
elif button_count == 4:
if reviewButtons_width < 61:
if ease == 1:
x_offset -= reviewButtons_width/4
x_offset += 29
elif ease == 2:
x_offset -= reviewButtons_width/4
x_offset += 21
elif ease == 3:
x_offset += reviewButtons_width/4
x_offset -= 15
elif ease == 4:
x_offset += reviewButtons_width/4
x_offset -= 25
elif 60 < reviewButtons_width < 81:
if ease == 1:
x_offset -= reviewButtons_width/2
x_offset += 21
elif ease == 2:
x_offset -= reviewButtons_width/4
x_offset += 15
elif ease == 3:
x_offset += reviewButtons_width/4
x_offset -= 10
elif ease == 4:
x_offset += reviewButtons_width/2
x_offset -= 18
elif 80 < reviewButtons_width < 101:
if ease == 1:
x_offset -= reviewButtons_width/2
elif ease == 2:
x_offset -= reviewButtons_width/4
x_offset += 10
elif ease == 3:
x_offset += reviewButtons_width/4
x_offset -= 5
elif ease == 4:
x_offset += reviewButtons_width/2
x_offset += 2
elif 100 < reviewButtons_width < 121:
if ease == 1:
x_offset -= reviewButtons_width
x_offset += 37
elif ease == 2:
x_offset -= reviewButtons_width/3
x_offset += 15
elif ease == 3:
x_offset += reviewButtons_width/3
x_offset -= 9
elif ease == 4:
x_offset += reviewButtons_width
x_offset -= 33
elif 120 < reviewButtons_width < 141:
if ease == 1:
x_offset -= reviewButtons_width
x_offset += 26
elif ease == 2:
x_offset -= reviewButtons_width/3
x_offset += 13
elif ease == 3:
x_offset += reviewButtons_width/3
x_offset -= 6
elif ease == 4:
x_offset += reviewButtons_width
x_offset -= 23
elif 140 < reviewButtons_width < 161:
if ease == 1:
x_offset -= reviewButtons_width
x_offset += 16
elif ease == 2:
x_offset -= reviewButtons_width/3
x_offset += 7
elif ease == 3:
x_offset += reviewButtons_width/3
x_offset -= 3
elif ease == 4:
x_offset += reviewButtons_width
x_offset -= 13
elif 160 < reviewButtons_width < 181:
if ease == 1:
x_offset -= reviewButtons_width
elif ease == 2:
x_offset -= reviewButtons_width/3
x_offset += 5
elif ease == 3:
x_offset += reviewButtons_width/3
x_offset += 3
elif ease == 4:
x_offset += reviewButtons_width
x_offset -= 3
elif 180 < reviewButtons_width < 201:
if ease == 1:
x_offset -= reviewButtons_width
x_offset -= 5
elif ease == 2:
x_offset -= reviewButtons_width/3
x_offset += 4
elif ease == 3:
x_offset += reviewButtons_width/3
x_offset += 4
elif ease == 4:
x_offset += reviewButtons_width
x_offset += 7
elif 200 < reviewButtons_width < 221:
if ease == 1:
x_offset -= reviewButtons_width
x_offset -= 13
elif ease == 2:
x_offset -= reviewButtons_width/3
x_offset -= 1
elif ease == 3:
x_offset += reviewButtons_width/3
x_offset += 7
elif ease == 4:
x_offset += reviewButtons_width
x_offset += 17
elif 220 < reviewButtons_width < 241:
if ease == 1:
x_offset -= reviewButtons_width
x_offset -= 23
elif ease == 2:
x_offset -= reviewButtons_width/3
x_offset -= 5
elif ease == 3:
x_offset += reviewButtons_width/3
x_offset += 11
elif ease == 4:
x_offset += reviewButtons_width
x_offset += 27
elif 240 < reviewButtons_width < 261:
if ease == 1:
x_offset -= reviewButtons_width
x_offset -= 33
elif ease == 2:
x_offset -= reviewButtons_width/3
x_offset -= 8
elif ease == 3:
x_offset += reviewButtons_width/3
x_offset += 14
elif ease == 4:
x_offset += reviewButtons_width
x_offset += 37
elif 260 < reviewButtons_width < 281:
if ease == 1:
x_offset -= reviewButtons_width
x_offset -= 43
elif ease == 2:
x_offset -= reviewButtons_width/3
x_offset -= 11
elif ease == 3:
x_offset += reviewButtons_width/3
x_offset += 17
elif ease == 4:
x_offset += reviewButtons_width
x_offset += 47
elif 280 < reviewButtons_width < 301:
if ease == 1:
x_offset -= reviewButtons_width
x_offset -= 53
elif ease == 2:
x_offset -= reviewButtons_width/3
x_offset -= 14
elif ease == 3:
x_offset += reviewButtons_width/3
x_offset += 21
elif ease == 4:
x_offset += reviewButtons_width
x_offset += 57
elif 300 < reviewButtons_width < 321:
if ease == 1:
x_offset -= reviewButtons_width
x_offset -= 63
elif ease == 2:
x_offset -= reviewButtons_width/3
x_offset -= 17
elif ease == 3:
x_offset += reviewButtons_width/3
x_offset += 24
elif ease == 4:
x_offset += reviewButtons_width
x_offset += 67
elif 320 < reviewButtons_width < 341:
if ease == 1:
x_offset -= reviewButtons_width
x_offset -= 73
elif ease == 2:
x_offset -= reviewButtons_width/3
x_offset -= 22
elif ease == 3:
x_offset += reviewButtons_width/3
x_offset += 27
elif ease == 4:
x_offset += reviewButtons_width
x_offset += 77
elif 340 < reviewButtons_width < 361:
if ease == 1:
x_offset -= reviewButtons_width
x_offset -= 83
elif ease == 2:
x_offset -= reviewButtons_width/3
x_offset -= 25
elif ease == 3:
x_offset += reviewButtons_width/3
x_offset += 31
elif ease == 4:
x_offset += reviewButtons_width
x_offset += 87
elif 360 < reviewButtons_width < 381:
if ease == 1:
x_offset -= reviewButtons_width
x_offset -= 93
elif ease == 2:
x_offset -= reviewButtons_width/3
x_offset -= 28
elif ease == 3:
x_offset += reviewButtons_width/3
x_offset += 34
elif ease == 4:
x_offset += reviewButtons_width
x_offset += 97
elif 380 < reviewButtons_width < 401:
if ease == 1:
x_offset -= reviewButtons_width
x_offset -= 103
elif ease == 2:
x_offset -= reviewButtons_width/3
x_offset -= 31
elif ease == 3:
x_offset += reviewButtons_width/3
x_offset += 37
elif ease == 4:
x_offset += reviewButtons_width
x_offset += 107
if reviewButton_style in [4, 5, 6, 7]:
y_offset -= 1
if button_count == 2:
if ease == 1:
x_offset -= 4
elif ease == 2:
x_offset += 2
elif button_count == 3:
if ease == 1:
x_offset -= 1
elif ease == 2:
x_offset -= 1
elif button_count == 4:
if ease == 1:
x_offset -= 5
elif ease == 2:
x_offset -= 2
elif ease == 3:
x_offset += 1
elif ease == 4:
x_offset += 5
if reviewButton_style in [4, 5, 6, 7] and not custom_sizes:
button_height = 29
button_width = 72
y_offset += 2
if button_count == 2:
if ease == 1:
x_offset -= 3
elif ease == 2:
x_offset += 4
elif button_count == 3:
if ease == 1:
x_offset -= 10
elif ease == 2:
x_offset += 4
elif ease == 3:
x_offset += 10
elif button_count == 4:
if ease == 1:
x_offset -= 10
elif ease == 2:
x_offset += 4
elif ease == 3:
x_offset += 8
elif ease == 4:
x_offset += 15
if not info or info_position in ['middle left', 'middle right']:
x_offset -= 36
if info and info_position == "left":
x_offset += (info_width-64)/2
if info and info_position == "right":
x_offset -= 72
x_offset -= (info_width-64)/2
if skip and skip_position == "left":
x_offset += 36
x_offset += (skip_width-64)/2
if skip and skip_position == "right":
x_offset -= 36
x_offset -= (skip_width-64)/2
if undo and undo_position == "left":
x_offset += 52
x_offset += (undo_width-86)/2
if undo and undo_position == "right":
x_offset -= 52
x_offset -= (undo_width-86)/2
if reviewButton_style in [4, 5, 6, 7]:
if not info or info_position in ['middle left', 'middle right']:
x_offset -= 8
if info and info_position == "right":
x_offset -= 16
if undo and undo_position == "left":
x_offset +=8
if undo and undo_position == "right":
x_offset -= 17
x_offset -= 7
x_offset -= (more_width-72)/2
x_offset += (edit_width-72)/2
if tooltip_style == 1:
x_offset = tooltip_position[0]
y_offset = -tooltip_position[1]
button_width = 72
button_height = 29
background_color = button[1]
# if self.state == "answer": #// don't show tooltip if user hasn't pressed show answer button (you're really cool for a bug, so, I'm fucking keeping you :D)
showTooltip(text, background_color, tooltip_textColor, button_width, button_height, x_offset, y_offset, period=tooltip_timer)
if anki_version > 2119:
_tooltipTimer: Optional[QTimer] = None
_tooltipLabel: Optional[QLabel] = None
else:
_tooltipTimer = None
_tooltipLabel = None
def showTooltip(text, background_color, tooltip_textColor, button_width, button_height, x_offset, y_offset, period=3000, parent=None):
global _tooltipTimer, _tooltipLabel
class CustomLabel(QLabel):
silentlyClose = True
def mousePressEvent(self, evt):
evt.accept()
self.hide()
closeTooltip()
aw = parent or aqt.mw.app.activeWindow() or aqt.mw
table = """
<table align=center>
<tr>
<td><div style='color: {0};'>{1}</div></td>
</tr>
</table>
""".format(tooltip_textColor, text)
lab = CustomLabel(table, aw)
lab.setFrameStyle(QFrame.Panel)
lab.setLineWidth(2)
lab.setFixedWidth(button_width)
lab.setFixedHeight(button_height)
lab.setWindowFlags(Qt.ToolTip)
p = QPalette()
p.setColor(QPalette.Window, QColor(background_color))
p.setColor(QPalette.WindowText, QColor("transparent"))
lab.setPalette(p)
if tooltip_style == 0:
x_coordinate = int(x_offset+(aw.width()-button_width)/2)
y_coordinate = y_offset+aw.height()
lab.move(aw.mapToGlobal(QPoint(x_coordinate, y_coordinate)))
else:
x_coordinate = min(x_offset, aw.width())
y_coordinate = min(y_offset, aw.height())
lab.move(aw.mapToGlobal(QPoint(x_coordinate, y_coordinate)))
lab.show()
_tooltipTimer = aqt.mw.progress.timer(period, closeTooltip, False, requiresCollection=False)
_tooltipLabel = lab
def closeTooltip():
global _tooltipLabel, _tooltipTimer
if _tooltipLabel:
try:
_tooltipLabel.deleteLater()
except:
# already deleted as parent window closed
pass
_tooltipLabel = None
if _tooltipTimer:
_tooltipTimer.stop()
_tooltipTimer = None
Reviewer._answerCard = wrap(Reviewer._answerCard, myTooltip, 'before')
|