From c728febdd5a6f7a1c3cac8637f0df5bc0fd95ad2 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Tue, 20 Dec 2011 11:20:16 +0100 Subject: [PATCH] Add local variables in buffers, update prompt of buffers using local variable "nick" --- src/qweechat/buffer.py | 41 +++++++++++++++++++++++++++++----------- src/qweechat/network.py | 2 +- src/qweechat/qweechat.py | 5 ++++- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/qweechat/buffer.py b/src/qweechat/buffer.py index 4626461..537ed60 100644 --- a/src/qweechat/buffer.py +++ b/src/qweechat/buffer.py @@ -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: diff --git a/src/qweechat/network.py b/src/qweechat/network.py index 2f97fff..e73d58a 100644 --- a/src/qweechat/network.py +++ b/src/qweechat/network.py @@ -29,7 +29,7 @@ QtCore = qt_compat.import_module('QtCore') QtNetwork = qt_compat.import_module('QtNetwork') _PROTO_INIT_CMDS = ['init password=%(password)s,compression=gzip', - '(listbuffers) hdata buffer:gui_buffers(*) number,full_name,short_name,nicklist,title', + '(listbuffers) hdata buffer:gui_buffers(*) number,full_name,short_name,nicklist,title,local_variables', '(listlines) hdata buffer:gui_buffers(*)/own_lines/first_line(*)/data date,displayed,prefix,message', '(nicklist) nicklist', 'sync', diff --git a/src/qweechat/qweechat.py b/src/qweechat/qweechat.py index c3dc0ee..99047c3 100755 --- a/src/qweechat/qweechat.py +++ b/src/qweechat/qweechat.py @@ -315,7 +315,10 @@ class MainWindow(QtGui.QMainWindow): self.buffers[index].data['short_name'] = item['short_name'] elif message.msgid == '_buffer_title_changed': self.buffers[index].data['title'] = item['title'] - self.buffers[index].widget.set_title(item['title']) + self.buffers[index].update_title() + elif message.msgid.startswith('_buffer_localvar_'): + self.buffers[index].data['local_variables'] = item['local_variables'] + self.buffers[index].update_prompt() elif message.msgid == '_buffer_closing': self.remove_buffer(index)