Add local variables in buffers, update prompt of buffers using local variable "nick"

This commit is contained in:
Sebastien Helleu 2011-12-20 11:20:16 +01:00
parent c738936b1e
commit c728febdd5
3 changed files with 35 additions and 13 deletions

View file

@ -106,17 +106,13 @@ class BufferWidget(QtGui.QWidget):
self.chat_nicklist.addWidget(self.nicklist) self.chat_nicklist.addWidget(self.nicklist)
# prompt + input # prompt + input
hbox_edit = QtGui.QHBoxLayout() self.hbox_edit = QtGui.QHBoxLayout()
hbox_edit.setContentsMargins(0, 0, 0, 0) self.hbox_edit.setContentsMargins(0, 0, 0, 0)
hbox_edit.setSpacing(0) self.hbox_edit.setSpacing(0)
self.prompt = QtGui.QLabel('FlashCode')
self.prompt.setContentsMargins(0, 0, 5, 0)
hbox_edit.addWidget(self.prompt)
self.input = InputLineEdit(self.chat) self.input = InputLineEdit(self.chat)
hbox_edit.addWidget(self.input) self.hbox_edit.addWidget(self.input)
prompt_input = QtGui.QWidget() prompt_input = QtGui.QWidget()
prompt_input.setLayout(hbox_edit) prompt_input.setLayout(self.hbox_edit)
prompt_input.setContentsMargins(0, 0, 0, 0)
# vbox with title + chat/nicklist + prompt/input # vbox with title + chat/nicklist + prompt/input
vbox = QtGui.QVBoxLayout() vbox = QtGui.QVBoxLayout()
@ -134,6 +130,15 @@ class BufferWidget(QtGui.QWidget):
if not title is None: if not title is None:
self.title.setText(title) 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): class Buffer(QtCore.QObject):
"""A WeeChat buffer.""" """A WeeChat buffer."""
@ -145,14 +150,28 @@ class Buffer(QtCore.QObject):
self.data = data self.data = data
self.nicklist = [] self.nicklist = []
self.widget = BufferWidget(display_nicklist=self.data.get('nicklist', 0)) self.widget = BufferWidget(display_nicklist=self.data.get('nicklist', 0))
if self.data and self.data['title']: self.update_title()
self.widget.set_title(self.data['title']) self.update_prompt()
self.widget.input.textSent.connect(self.input_text_sent) self.widget.input.textSent.connect(self.input_text_sent)
def pointer(self): def pointer(self):
"""Return pointer on buffer.""" """Return pointer on buffer."""
return self.data.get('__path', [''])[0] 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): def input_text_sent(self, text):
"""Called when text has to be sent to buffer.""" """Called when text has to be sent to buffer."""
if self.data: if self.data:

View file

@ -29,7 +29,7 @@ QtCore = qt_compat.import_module('QtCore')
QtNetwork = qt_compat.import_module('QtNetwork') QtNetwork = qt_compat.import_module('QtNetwork')
_PROTO_INIT_CMDS = ['init password=%(password)s,compression=gzip', _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', '(listlines) hdata buffer:gui_buffers(*)/own_lines/first_line(*)/data date,displayed,prefix,message',
'(nicklist) nicklist', '(nicklist) nicklist',
'sync', 'sync',

View file

@ -315,7 +315,10 @@ class MainWindow(QtGui.QMainWindow):
self.buffers[index].data['short_name'] = item['short_name'] self.buffers[index].data['short_name'] = item['short_name']
elif message.msgid == '_buffer_title_changed': elif message.msgid == '_buffer_title_changed':
self.buffers[index].data['title'] = item['title'] 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': elif message.msgid == '_buffer_closing':
self.remove_buffer(index) self.remove_buffer(index)