1919# You should have received a copy of the GNU General Public License
2020# along with this program. If not, see <http://www.gnu.org/licenses/>.
2121
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
2525from core .utils import (interactive , abstract , get_clipboard_text ,
2626 set_clipboard_text , eval_in_emacs , message_to_emacs ,
2727 input_message , get_emacs_var , get_emacs_func_result ,
3434# Build char event.
3535for char in string .ascii_lowercase :
3636 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 ))
3939
4040# Build number event.
4141for 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 ))
4343
4444qt_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
9494})
9595
9696qt_text_dict = {
@@ -183,7 +183,7 @@ def move_cursor_to_corner(self):
183183 '''
184184 Move cursor to bottom right corner of screen.
185185 '''
186- screen = qApp .primaryScreen ()
186+ screen = QApplication . instance () .primaryScreen ()
187187 try :
188188 QCursor ().setPos (screen , screen .size ().width (), screen .size ().height ())
189189 except :
@@ -359,7 +359,7 @@ def send_key(self, event_string):
359359 ''' Fake key event.'''
360360 # Init.
361361 text = event_string
362- modifier = Qt .NoModifier
362+ modifier = Qt .KeyboardModifier . NoModifier
363363
364364 # Get key text.
365365 if event_string in qt_text_dict :
@@ -368,17 +368,17 @@ def send_key(self, event_string):
368368 if event_string in ["TAB" , "<backtab>" ]:
369369 text = ""
370370 if event_string == "<backtab>" :
371- modifier = Qt .ShiftModifier
371+ modifier = Qt .KeyboardModifier . ShiftModifier
372372 elif event_string .isupper ():
373- modifier = Qt .ShiftModifier
373+ modifier = Qt .KeyboardModifier . ShiftModifier
374374
375375 # print("Press: ", event_string)
376376
377377 # NOTE: don't ignore text argument, otherwise QWebEngineView not respond key event.
378378 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 )
380380 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 )
382382
383383 for widget in self .get_key_event_widgets ():
384384 QApplication .sendEvent (widget , key_press )
@@ -396,19 +396,19 @@ def send_key_sequence(self, event_string):
396396 if len (last_char ) == 1 :
397397 last_key = last_char .lower ()
398398
399- modifiers = Qt .NoModifier
399+ modifiers = Qt .KeyboardModifier . NoModifier
400400
401401 for modifier in event_list [0 :- 1 ]:
402402 if modifier == "C" :
403- modifiers |= Qt .ControlModifier
403+ modifiers |= Qt .KeyboardModifier . ControlModifier
404404 elif modifier == "M" :
405- modifiers |= Qt .AltModifier
405+ modifiers |= Qt .KeyboardModifier . AltModifier
406406 elif modifier == "S" :
407- modifiers |= Qt .ShiftModifier
407+ modifiers |= Qt .KeyboardModifier . KeyboardModifier . ShiftModifier
408408 elif modifier == "s" :
409- modifiers |= Qt .MetaModifier
409+ modifiers |= Qt .KeyboardModifier . MetaModifier
410410
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 ))
412412
413413 def get_url (self ):
414414 ''' Get url.'''
@@ -440,7 +440,7 @@ def select_right_tab(self):
440440 def focus_widget (self , event = None ):
441441 '''Focus buffer widget.'''
442442 if event is None :
443- event = QFocusEvent (QEvent .FocusIn , Qt .MouseFocusReason )
443+ event = QFocusEvent (QEvent .Type . FocusIn , Qt . FocusReason .MouseFocusReason )
444444 QApplication .sendEvent (self .buffer_widget .focusProxy (), event )
445445
446446 # Activate emacs window when call focus widget, avoid first char is not
0 commit comments