]>
jfr.im git - irc/weechat/qweechat.git/blob - src/qweechat/input.py
2 # -*- coding: utf-8 -*-
4 # Copyright (C) 2011 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
.ControlModifier
and key
== QtCore
.Qt
.Key_PageDown
:
52 self
.bufferSwitchNext
.emit()
53 elif modifiers
== QtCore
.Qt
.AltModifier
and key
== QtCore
.Qt
.Key_PageUp
:
54 bar
.setValue(bar
.value() - (bar
.pageStep() / 10))
55 elif modifiers
== QtCore
.Qt
.AltModifier
and key
== QtCore
.Qt
.Key_PageDown
:
56 bar
.setValue(bar
.value() + (bar
.pageStep() / 10))
57 elif key
== QtCore
.Qt
.Key_PageUp
:
58 bar
.setValue(bar
.value() - bar
.pageStep())
59 elif key
== QtCore
.Qt
.Key_PageDown
:
60 bar
.setValue(bar
.value() + bar
.pageStep())
61 elif modifiers
== QtCore
.Qt
.AltModifier
and key
== QtCore
.Qt
.Key_Home
:
62 bar
.setValue(bar
.minimum())
63 elif modifiers
== QtCore
.Qt
.AltModifier
and key
== QtCore
.Qt
.Key_End
:
64 bar
.setValue(bar
.maximum())
65 elif key
== QtCore
.Qt
.Key_Up
:
66 self
._history
_navigate
(-1)
67 elif key
== QtCore
.Qt
.Key_Down
:
68 self
._history
_navigate
(1)
70 QtGui
.QLineEdit
.keyPressEvent(self
, event
)
72 def _input_return_pressed(self
):
73 self
._history
.append(str(self
.text()))
74 self
._history
_index
= len(self
._history
)
75 self
.textSent
.emit(self
.text())
78 def _history_navigate(self
, direction
):
80 self
._history
_index
+= direction
81 if self
._history
_index
< 0:
82 self
._history
_index
= 0
84 if self
._history
_index
> len(self
._history
) - 1:
85 self
._history
_index
= len(self
._history
)
88 self
.setText(self
._history
[self
._history
_index
])