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