]>
jfr.im git - irc/weechat/qweechat.git/blob - src/qweechat/buffer.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/>.
27 QtCore
= qt_compat
.import_module('QtCore')
28 QtGui
= qt_compat
.import_module('QtGui')
29 from chat
import ChatTextEdit
30 from input import InputLineEdit
33 class BufferListWidget(QtGui
.QListWidget
):
34 """Widget with list of buffers."""
36 def __init__(self
, *args
):
37 apply(QtGui
.QListWidget
.__init
__, (self
,) + args
)
38 self
.setHorizontalScrollBarPolicy(QtCore
.Qt
.ScrollBarAlwaysOff
)
39 self
.setMinimumWidth(120)
40 self
.setMaximumWidth(200)
41 # TODO: do a dynamic size for widget
42 #self.setMinimumWidth(self.sizeHintForColumn(0))
43 #self.setSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.MinimumExpanding)
44 #self.setResizeMode(QtGui.QListView.Adjust)
45 self
.setFocusPolicy(QtCore
.Qt
.NoFocus
)
47 pal
.setColor(QtGui
.QPalette
.Highlight
, QtGui
.QColor('#ddddff'))
48 pal
.setColor(QtGui
.QPalette
.HighlightedText
, QtGui
.QColor('black'))
51 # TODO: do a dynamic size for widget
54 s
.setHeight(super(BufferListWidget
,self
).sizeHint().height())
55 s
.setWidth(self
.sizeHintForColumn(0))
58 def switch_prev_buffer(self
):
59 if self
.currentRow() > 0:
60 self
.setCurrentRow(self
.currentRow() - 1)
62 self
.setCurrentRow(self
.count() - 1)
64 def switch_next_buffer(self
):
65 if self
.currentRow() < self
.count() - 1:
66 self
.setCurrentRow(self
.currentRow() + 1)
71 class BufferWidget(QtGui
.QWidget
):
72 """Widget with (from top to bottom): title, chat + nicklist (optional) + prompt/input."""
74 def __init__(self
, display_nicklist
=False):
75 QtGui
.QWidget
.__init
__(self
)
78 self
.title
= QtGui
.QLineEdit()
80 # splitter with chat + nicklist
81 self
.chat_nicklist
= QtGui
.QSplitter()
82 self
.chat_nicklist
.setSizePolicy(QtGui
.QSizePolicy
.Expanding
, QtGui
.QSizePolicy
.Expanding
)
83 self
.chat
= ChatTextEdit()
84 self
.chat_nicklist
.addWidget(self
.chat
)
85 self
.nicklist
= QtGui
.QListWidget()
86 self
.nicklist
.setMaximumWidth(100)
87 self
.nicklist
.setFocusPolicy(QtCore
.Qt
.NoFocus
)
88 if not display_nicklist
:
89 self
.nicklist
.setVisible(False)
90 self
.chat_nicklist
.addWidget(self
.nicklist
)
93 hbox_edit
= QtGui
.QHBoxLayout()
94 hbox_edit
.setContentsMargins(0, 0, 0, 0)
95 hbox_edit
.setSpacing(0)
96 self
.prompt
= QtGui
.QLabel('FlashCode')
97 self
.prompt
.setContentsMargins(0, 0, 5, 0)
98 hbox_edit
.addWidget(self
.prompt
)
99 self
.input = InputLineEdit(self
.chat
)
100 hbox_edit
.addWidget(self
.input)
101 prompt_input
= QtGui
.QWidget()
102 prompt_input
.setLayout(hbox_edit
)
103 prompt_input
.setContentsMargins(0, 0, 0, 0)
105 # vbox with title + chat/nicklist + prompt/input
106 vbox
= QtGui
.QVBoxLayout()
107 vbox
.setContentsMargins(0, 0, 0, 0)
109 vbox
.addWidget(self
.title
)
110 vbox
.addWidget(self
.chat_nicklist
)
111 vbox
.addWidget(prompt_input
)
115 def set_title(self
, title
):
116 """Set buffer title."""
118 if not title
is None:
119 self
.title
.setText(title
)
122 class Buffer(QtCore
.QObject
):
123 """A WeeChat buffer."""
125 bufferInput
= qt_compat
.Signal(str, str)
127 def __init__(self
, data
={}):
128 QtCore
.QObject
.__init
__(self
)
130 self
.widget
= BufferWidget(display_nicklist
=self
.data
.get('nicklist', 0))
131 if self
.data
and self
.data
['title']:
132 self
.widget
.set_title(self
.data
['title'])
133 self
.widget
.input.textSent
.connect(self
.input_text_sent
)
136 """Return pointer on buffer."""
137 return self
.data
.get('__path', [''])[0]
139 def input_text_sent(self
, text
):
140 """Called when text has to be sent to buffer."""
142 self
.bufferInput
.emit(self
.data
['full_name'], text
)
144 def add_nick(self
, prefix
, nick
):
145 """Add a nick to nicklist."""
146 self
.widget
.nicklist
.addItem('%s%s' % (prefix
, nick
))