]>
jfr.im git - irc/weechat/qweechat.git/blob - qweechat/input.py
1 # -*- coding: utf-8 -*-
3 # input.py - input line for chat and debug window
5 # Copyright (C) 2011-2021 Sébastien Helleu <flashcode@flashtux.org>
7 # This file is part of QWeeChat, a Qt remote GUI for WeeChat.
9 # QWeeChat is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # QWeeChat is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
23 from PySide6
import QtCore
24 from PySide6
import QtWidgets
27 class InputLineEdit(QtWidgets
.QLineEdit
):
30 bufferSwitchPrev
= QtCore
.Signal()
31 bufferSwitchNext
= QtCore
.Signal()
32 textSent
= QtCore
.Signal(str)
34 def __init__(self
, scroll_widget
):
35 super().__init
__(scroll_widget
)
36 self
.scroll_widget
= scroll_widget
38 self
._history
_index
= -1
39 self
.returnPressed
.connect(self
._input
_return
_pressed
)
41 def keyPressEvent(self
, event
):
43 modifiers
= event
.modifiers()
44 bar
= self
.scroll_widget
.verticalScrollBar()
45 if modifiers
== QtCore
.Qt
.ControlModifier
:
46 if key
== QtCore
.Qt
.Key_PageUp
:
47 self
.bufferSwitchPrev
.emit()
48 elif key
== QtCore
.Qt
.Key_PageDown
:
49 self
.bufferSwitchNext
.emit()
51 QtWidgets
.QLineEdit
.keyPressEvent(self
, event
)
52 elif modifiers
== QtCore
.Qt
.AltModifier
:
53 if key
in (QtCore
.Qt
.Key_Left
, QtCore
.Qt
.Key_Up
):
54 self
.bufferSwitchPrev
.emit()
55 elif key
in (QtCore
.Qt
.Key_Right
, QtCore
.Qt
.Key_Down
):
56 self
.bufferSwitchNext
.emit()
57 elif key
== QtCore
.Qt
.Key_PageUp
:
58 bar
.setValue(bar
.value() - (bar
.pageStep() / 10))
59 elif key
== QtCore
.Qt
.Key_PageDown
:
60 bar
.setValue(bar
.value() + (bar
.pageStep() / 10))
61 elif key
== QtCore
.Qt
.Key_Home
:
62 bar
.setValue(bar
.minimum())
63 elif key
== QtCore
.Qt
.Key_End
:
64 bar
.setValue(bar
.maximum())
66 QtWidgets
.QLineEdit
.keyPressEvent(self
, event
)
67 elif key
== QtCore
.Qt
.Key_PageUp
:
68 bar
.setValue(bar
.value() - bar
.pageStep())
69 elif key
== QtCore
.Qt
.Key_PageDown
:
70 bar
.setValue(bar
.value() + bar
.pageStep())
71 elif key
== QtCore
.Qt
.Key_Up
:
72 self
._history
_navigate
(-1)
73 elif key
== QtCore
.Qt
.Key_Down
:
74 self
._history
_navigate
(1)
76 QtWidgets
.QLineEdit
.keyPressEvent(self
, event
)
78 def _input_return_pressed(self
):
79 self
._history
.append(self
.text())
80 self
._history
_index
= len(self
._history
)
81 self
.textSent
.emit(self
.text())
84 def _history_navigate(self
, direction
):
86 self
._history
_index
+= direction
87 if self
._history
_index
< 0:
88 self
._history
_index
= 0
90 if self
._history
_index
> len(self
._history
) - 1:
91 self
._history
_index
= len(self
._history
)
94 self
.setText(self
._history
[self
._history
_index
])