19
19
# You should have received a copy of the GNU General Public License
20
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
21
22
- from PyQt5 .QtCore import Qt , QEvent , QThread , pyqtSignal
23
- from PyQt5 .QtGui import QKeyEvent , QCursor , QFocusEvent , QColor
24
- from PyQt5 .QtWidgets import QGraphicsScene , QApplication , qApp
22
+ from PyQt6 .QtCore import Qt , QEvent , QThread , pyqtSignal
23
+ from PyQt6 .QtGui import QKeyEvent , QCursor , QFocusEvent , QColor
24
+ from PyQt6 .QtWidgets import QGraphicsScene , QApplication
25
25
from core .utils import (interactive , abstract , get_clipboard_text ,
26
26
set_clipboard_text , eval_in_emacs , message_to_emacs ,
27
27
input_message , get_emacs_var , get_emacs_func_result ,
34
34
# Build char event.
35
35
for char in string .ascii_lowercase :
36
36
upper_char = char .upper ()
37
- qt_key_dict [char ] = eval ("Qt.Key_{}" .format (upper_char ))
38
- qt_key_dict [upper_char ] = eval ("Qt.Key_{}" .format (upper_char ))
37
+ qt_key_dict [char ] = eval ("Qt.Key. Key_{}" .format (upper_char ))
38
+ qt_key_dict [upper_char ] = eval ("Qt.Key. Key_{}" .format (upper_char ))
39
39
40
40
# Build number event.
41
41
for number in range (0 , 10 ):
42
- qt_key_dict [str (number )] = eval ("Qt.Key_{}" .format (number ))
42
+ qt_key_dict [str (number )] = eval ("Qt.Key. Key_{}" .format (number ))
43
43
44
44
qt_key_dict .update ({
45
- ''':''' : Qt .Key_Colon ,
46
- ''';''' : Qt .Key_Semicolon ,
47
- '''.''' : Qt .Key_Period ,
48
- ''',''' : Qt .Key_Comma ,
49
- '''+''' : Qt .Key_Plus ,
50
- '''-''' : Qt .Key_Minus ,
51
- '''=''' : Qt .Key_Equal ,
52
- '''_''' : Qt .Key_Underscore ,
53
- '''[''' : Qt .Key_BracketLeft ,
54
- ''']''' : Qt .Key_BracketRight ,
55
- '''(''' : Qt .Key_BraceLeft ,
56
- ''')''' : Qt .Key_BraceRight ,
57
- '''{''' : Qt .Key_ParenLeft ,
58
- '''}''' : Qt .Key_ParenRight ,
59
- '''<''' : Qt .Key_Less ,
60
- '''>''' : Qt .Key_Greater ,
61
- '''@''' : Qt .Key_At ,
62
- '''\\ ''' : Qt .Key_Backslash ,
63
- '''|''' : Qt .Key_Bar ,
64
- '''/''' : Qt .Key_Slash ,
65
- '''#''' : Qt .Key_NumberSign ,
66
- '''$''' : Qt .Key_Dollar ,
67
- '''?''' : Qt .Key_Question ,
68
- '''"''' : Qt .Key_QuoteDbl ,
69
- '''`''' : Qt .Key_QuoteLeft ,
70
- '''%''' : Qt .Key_Percent ,
71
- '''^''' : Qt .Key_AsciiCircum ,
72
- '''&''' : Qt .Key_Ampersand ,
73
- '''*''' : Qt .Key_Asterisk ,
74
- '''~''' : Qt .Key_AsciiTilde ,
75
- '''!''' : Qt .Key_Exclam ,
76
- '''\' ''' : Qt .Key_Apostrophe ,
77
- '''SPC''' : Qt .Key_Space ,
78
- '''RET''' : Qt .Key_Return ,
79
- '''DEL''' : Qt .Key_Backspace ,
80
- '''TAB''' : Qt .Key_Tab ,
81
- '''<backtab>''' : Qt .Key_Backtab ,
82
- '''<home>''' : Qt .Key_Home ,
83
- '''<end>''' : Qt .Key_End ,
84
- '''<left>''' : Qt .Key_Left ,
85
- '''<right>''' : Qt .Key_Right ,
86
- '''<up>''' : Qt .Key_Up ,
87
- '''<down>''' : Qt .Key_Down ,
88
- '''<prior>''' : Qt .Key_PageUp ,
89
- '''<next>''' : Qt .Key_PageDown ,
90
- '''<delete>''' : Qt .Key_Delete ,
91
- '''<backspace>''' : Qt .Key_Backspace ,
92
- '''<return>''' : Qt .Key_Return ,
93
- '''<escape>''' : Qt .Key_Escape
45
+ ''':''' : Qt .Key . Key_Colon ,
46
+ ''';''' : Qt .Key . Key_Semicolon ,
47
+ '''.''' : Qt .Key . Key_Period ,
48
+ ''',''' : Qt .Key . Key_Comma ,
49
+ '''+''' : Qt .Key . Key_Plus ,
50
+ '''-''' : Qt .Key . Key_Minus ,
51
+ '''=''' : Qt .Key . Key_Equal ,
52
+ '''_''' : Qt .Key . Key_Underscore ,
53
+ '''[''' : Qt .Key . Key_BracketLeft ,
54
+ ''']''' : Qt .Key . Key_BracketRight ,
55
+ '''(''' : Qt .Key . Key_BraceLeft ,
56
+ ''')''' : Qt .Key . Key_BraceRight ,
57
+ '''{''' : Qt .Key . Key_ParenLeft ,
58
+ '''}''' : Qt .Key . Key_ParenRight ,
59
+ '''<''' : Qt .Key . Key_Less ,
60
+ '''>''' : Qt .Key . Key_Greater ,
61
+ '''@''' : Qt .Key . Key_At ,
62
+ '''\\ ''' : Qt .Key . Key_Backslash ,
63
+ '''|''' : Qt .Key . Key_Bar ,
64
+ '''/''' : Qt .Key . Key_Slash ,
65
+ '''#''' : Qt .Key . Key_NumberSign ,
66
+ '''$''' : Qt .Key . Key_Dollar ,
67
+ '''?''' : Qt .Key . Key_Question ,
68
+ '''"''' : Qt .Key . Key_QuoteDbl ,
69
+ '''`''' : Qt .Key . Key_QuoteLeft ,
70
+ '''%''' : Qt .Key . Key_Percent ,
71
+ '''^''' : Qt .Key . Key_AsciiCircum ,
72
+ '''&''' : Qt .Key . Key_Ampersand ,
73
+ '''*''' : Qt .Key . Key_Asterisk ,
74
+ '''~''' : Qt .Key . Key_AsciiTilde ,
75
+ '''!''' : Qt .Key . Key_Exclam ,
76
+ '''\' ''' : Qt .Key . Key_Apostrophe ,
77
+ '''SPC''' : Qt .Key . Key_Space ,
78
+ '''RET''' : Qt .Key . Key_Return ,
79
+ '''DEL''' : Qt .Key . Key_Backspace ,
80
+ '''TAB''' : Qt .Key . Key_Tab ,
81
+ '''<backtab>''' : Qt .Key . Key_Backtab ,
82
+ '''<home>''' : Qt .Key . Key_Home ,
83
+ '''<end>''' : Qt .Key . Key_End ,
84
+ '''<left>''' : Qt .Key . Key_Left ,
85
+ '''<right>''' : Qt .Key . Key_Right ,
86
+ '''<up>''' : Qt .Key . Key_Up ,
87
+ '''<down>''' : Qt .Key . Key_Down ,
88
+ '''<prior>''' : Qt .Key . Key_PageUp ,
89
+ '''<next>''' : Qt .Key . Key_PageDown ,
90
+ '''<delete>''' : Qt .Key . Key_Delete ,
91
+ '''<backspace>''' : Qt .Key . Key_Backspace ,
92
+ '''<return>''' : Qt .Key . Key_Return ,
93
+ '''<escape>''' : Qt .Key . Key_Escape
94
94
})
95
95
96
96
qt_text_dict = {
@@ -183,7 +183,7 @@ def move_cursor_to_corner(self):
183
183
'''
184
184
Move cursor to bottom right corner of screen.
185
185
'''
186
- screen = qApp .primaryScreen ()
186
+ screen = QApplication . instance () .primaryScreen ()
187
187
try :
188
188
QCursor ().setPos (screen , screen .size ().width (), screen .size ().height ())
189
189
except :
@@ -359,7 +359,7 @@ def send_key(self, event_string):
359
359
''' Fake key event.'''
360
360
# Init.
361
361
text = event_string
362
- modifier = Qt .NoModifier
362
+ modifier = Qt .KeyboardModifier . NoModifier
363
363
364
364
# Get key text.
365
365
if event_string in qt_text_dict :
@@ -368,17 +368,17 @@ def send_key(self, event_string):
368
368
if event_string in ["TAB" , "<backtab>" ]:
369
369
text = ""
370
370
if event_string == "<backtab>" :
371
- modifier = Qt .ShiftModifier
371
+ modifier = Qt .KeyboardModifier . ShiftModifier
372
372
elif event_string .isupper ():
373
- modifier = Qt .ShiftModifier
373
+ modifier = Qt .KeyboardModifier . ShiftModifier
374
374
375
375
# print("Press: ", event_string)
376
376
377
377
# NOTE: don't ignore text argument, otherwise QWebEngineView not respond key event.
378
378
try :
379
- key_press = QKeyEvent (QEvent .KeyPress , qt_key_dict [event_string ], modifier , text )
379
+ key_press = QKeyEvent (QEvent .Type . KeyPress , qt_key_dict [event_string ], modifier , text )
380
380
except :
381
- key_press = QKeyEvent (QEvent .KeyPress , Qt .Key_unknown , modifier , text )
381
+ key_press = QKeyEvent (QEvent .Type . KeyPress , Qt . Key .Key_unknown , modifier , text )
382
382
383
383
for widget in self .get_key_event_widgets ():
384
384
QApplication .sendEvent (widget , key_press )
@@ -396,19 +396,19 @@ def send_key_sequence(self, event_string):
396
396
if len (last_char ) == 1 :
397
397
last_key = last_char .lower ()
398
398
399
- modifiers = Qt .NoModifier
399
+ modifiers = Qt .KeyboardModifier . NoModifier
400
400
401
401
for modifier in event_list [0 :- 1 ]:
402
402
if modifier == "C" :
403
- modifiers |= Qt .ControlModifier
403
+ modifiers |= Qt .KeyboardModifier . ControlModifier
404
404
elif modifier == "M" :
405
- modifiers |= Qt .AltModifier
405
+ modifiers |= Qt .KeyboardModifier . AltModifier
406
406
elif modifier == "S" :
407
- modifiers |= Qt .ShiftModifier
407
+ modifiers |= Qt .KeyboardModifier . KeyboardModifier . ShiftModifier
408
408
elif modifier == "s" :
409
- modifiers |= Qt .MetaModifier
409
+ modifiers |= Qt .KeyboardModifier . MetaModifier
410
410
411
- QApplication .sendEvent (widget , QKeyEvent (QEvent .KeyPress , qt_key_dict [last_key ], modifiers , last_key ))
411
+ QApplication .sendEvent (widget , QKeyEvent (QEvent .Type . KeyPress , qt_key_dict [last_key ], modifiers , last_key ))
412
412
413
413
def get_url (self ):
414
414
''' Get url.'''
@@ -440,7 +440,7 @@ def select_right_tab(self):
440
440
def focus_widget (self , event = None ):
441
441
'''Focus buffer widget.'''
442
442
if event is None :
443
- event = QFocusEvent (QEvent .FocusIn , Qt .MouseFocusReason )
443
+ event = QFocusEvent (QEvent .Type . FocusIn , Qt . FocusReason .MouseFocusReason )
444
444
QApplication .sendEvent (self .buffer_widget .focusProxy (), event )
445
445
446
446
# Activate emacs window when call focus widget, avoid first char is not
0 commit comments