#!/usr/bin/python
# -*- coding: utf-8 -*-
#
-# Copyright (C) 2011 Sebastien Helleu <flashcode@flashtux.org>
+# buffer.py - management of WeeChat buffers/nicklist
+#
+# Copyright (C) 2011-2013 Sebastien Helleu <flashcode@flashtux.org>
#
# This file is part of QWeeChat, a Qt remote GUI for WeeChat.
#
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
-#
-# Buffers.
-#
-
import qt_compat
QtCore = qt_compat.import_module('QtCore')
QtGui = qt_compat.import_module('QtGui')
from chat import ChatTextEdit
from input import InputLineEdit
+import weechat.color as color
class GenericListWidget(QtGui.QListWidget):
"""Generic QListWidget with dynamic size."""
def __init__(self, *args):
- apply(QtGui.QListWidget.__init__, (self,) + args)
+ QtGui.QListWidget.__init__(*(self,) + args)
self.setMaximumWidth(100)
self.setTextElideMode(QtCore.Qt.ElideNone)
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
def clear(self, *args):
"""Re-implement clear to set dynamic size after clear."""
- apply(QtGui.QListWidget.clear, (self,) + args)
+ QtGui.QListWidget.clear(*(self,) + args)
self.auto_resize()
def addItem(self, *args):
"""Re-implement addItem to set dynamic size after add."""
- apply(QtGui.QListWidget.addItem, (self,) + args)
+ QtGui.QListWidget.addItem(*(self,) + args)
self.auto_resize()
def insertItem(self, *args):
"""Re-implement insertItem to set dynamic size after insert."""
- apply(QtGui.QListWidget.insertItem, (self,) + args)
+ QtGui.QListWidget.insertItem(*(self,) + args)
self.auto_resize()
"""Widget with list of buffers."""
def __init__(self, *args):
- apply(GenericListWidget.__init__, (self,) + args)
+ GenericListWidget.__init__(*(self,) + args)
def switch_prev_buffer(self):
if self.currentRow() > 0:
# splitter with chat + nicklist
self.chat_nicklist = QtGui.QSplitter()
self.chat_nicklist.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
- self.chat = ChatTextEdit()
+ self.chat = ChatTextEdit(debug=False)
self.chat_nicklist.addWidget(self.chat)
self.nicklist = GenericListWidget()
if not display_nicklist:
self.chat_nicklist.addWidget(self.nicklist)
# prompt + input
- hbox_edit = QtGui.QHBoxLayout()
- hbox_edit.setContentsMargins(0, 0, 0, 0)
- hbox_edit.setSpacing(0)
- self.prompt = QtGui.QLabel('FlashCode')
- self.prompt.setContentsMargins(0, 0, 5, 0)
- hbox_edit.addWidget(self.prompt)
+ self.hbox_edit = QtGui.QHBoxLayout()
+ self.hbox_edit.setContentsMargins(0, 0, 0, 0)
+ self.hbox_edit.setSpacing(0)
self.input = InputLineEdit(self.chat)
- hbox_edit.addWidget(self.input)
+ self.hbox_edit.addWidget(self.input)
prompt_input = QtGui.QWidget()
- prompt_input.setLayout(hbox_edit)
- prompt_input.setContentsMargins(0, 0, 0, 0)
+ prompt_input.setLayout(self.hbox_edit)
# vbox with title + chat/nicklist + prompt/input
vbox = QtGui.QVBoxLayout()
if not title is None:
self.title.setText(title)
+ def set_prompt(self, prompt):
+ """Set prompt."""
+ if self.hbox_edit.count() > 1:
+ self.hbox_edit.takeAt(0)
+ if not prompt is None:
+ label = QtGui.QLabel(prompt)
+ label.setContentsMargins(0, 0, 5, 0)
+ self.hbox_edit.insertWidget(0, label)
+
class Buffer(QtCore.QObject):
"""A WeeChat buffer."""
self.data = data
self.nicklist = []
self.widget = BufferWidget(display_nicklist=self.data.get('nicklist', 0))
- if self.data and self.data['title']:
- self.widget.set_title(self.data['title'])
+ self.update_title()
+ self.update_prompt()
self.widget.input.textSent.connect(self.input_text_sent)
def pointer(self):
"""Return pointer on buffer."""
return self.data.get('__path', [''])[0]
+ def update_title(self):
+ """Update title."""
+ try:
+ self.widget.set_title(color.remove(self.data['title'].decode('utf-8')))
+ except:
+ self.widget.set_title(None)
+
+ def update_prompt(self):
+ """Update prompt."""
+ try:
+ self.widget.set_prompt(self.data['local_variables']['nick'])
+ except:
+ self.widget.set_prompt(None)
+
def input_text_sent(self, text):
"""Called when text has to be sent to buffer."""
if self.data: