]> jfr.im git - irc/weechat/qweechat.git/blob - src/qweechat/chat.py
Initial commit
[irc/weechat/qweechat.git] / src / qweechat / chat.py
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright (C) 2011 Sebastien Helleu <flashcode@flashtux.org>
5 #
6 # This file is part of QWeeChat, a Qt remote GUI for WeeChat.
7 #
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.
12 #
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.
17 #
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/>.
20 #
21
22 #
23 # Chat area.
24 #
25
26 import datetime
27 import qt_compat
28 QtCore = qt_compat.import_module('QtCore')
29 QtGui = qt_compat.import_module('QtGui')
30
31
32 class ChatTextEdit(QtGui.QTextEdit):
33 """Chat area."""
34
35 def __init__(self, *args):
36 apply(QtGui.QTextEdit.__init__, (self,) + args)
37 self.readOnly = True
38 self.setFocusPolicy(QtCore.Qt.NoFocus)
39 self.setFontFamily('monospace')
40
41 def display(self, time, prefix, text, color=None):
42 oldcolor = self.textColor()
43 if time == 0:
44 d = datetime.datetime.now()
45 else:
46 d = datetime.datetime.fromtimestamp(float(time))
47 self.setTextColor(QtGui.QColor('#999999'))
48 self.insertPlainText(d.strftime('%H:%M '))
49 self.setTextColor(oldcolor)
50 if prefix:
51 self.insertPlainText(str(prefix).decode('utf-8') + ' ')
52 if color:
53 self.setTextColor(QtGui.QColor(color))
54 self.insertPlainText(str(text).decode('utf-8'))
55 if text[-1:] != '\n':
56 self.insertPlainText('\n')
57 if color:
58 self.setTextColor(oldcolor)
59 self.scroll_bottom()
60
61 def scroll_bottom(self):
62 bar = self.verticalScrollBar()
63 bar.setValue(bar.maximum())