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