X-Git-Url: https://jfr.im/git/irc/weechat/qweechat.git/blobdiff_plain/02cba1c1c40e9615b07e3ef80b84928db8b19fea..773ee7bb73814319ee9b8fdf8bc43af716b85961:/src/qweechat/buffer.py diff --git a/src/qweechat/buffer.py b/src/qweechat/buffer.py index 4626461..fc12d09 100644 --- a/src/qweechat/buffer.py +++ b/src/qweechat/buffer.py @@ -34,7 +34,7 @@ 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) @@ -52,17 +52,17 @@ class GenericListWidget(QtGui.QListWidget): 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() @@ -70,7 +70,7 @@ class BufferListWidget(GenericListWidget): """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: @@ -98,7 +98,7 @@ class BufferWidget(QtGui.QWidget): # 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: @@ -106,17 +106,13 @@ class BufferWidget(QtGui.QWidget): 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() @@ -134,6 +130,15 @@ class BufferWidget(QtGui.QWidget): 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.""" @@ -145,14 +150,28 @@ class Buffer(QtCore.QObject): 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(self.data['title']) + 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: