|
|
|
@ -19,22 +19,20 @@
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
from pkg_resources import resource_filename
|
|
|
|
|
import qt_compat
|
|
|
|
|
from chat import ChatTextEdit
|
|
|
|
|
from input import InputLineEdit
|
|
|
|
|
import weechat.color as color
|
|
|
|
|
|
|
|
|
|
QtCore = qt_compat.import_module('QtCore')
|
|
|
|
|
QtGui = qt_compat.import_module('QtGui')
|
|
|
|
|
from qweechat.chat import ChatTextEdit
|
|
|
|
|
from qweechat.input import InputLineEdit
|
|
|
|
|
from qweechat.weechat import color
|
|
|
|
|
|
|
|
|
|
from PySide6 import QtCore, QtGui, QtWidgets
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GenericListWidget(QtGui.QListWidget):
|
|
|
|
|
class GenericListWidget(QtWidgets.QListWidget):
|
|
|
|
|
"""Generic QListWidget with dynamic size."""
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args):
|
|
|
|
|
QtGui.QListWidget.__init__(*(self,) + args)
|
|
|
|
|
super().__init__(*args)
|
|
|
|
|
self.setMaximumWidth(100)
|
|
|
|
|
self.setTextElideMode(QtCore.Qt.ElideNone)
|
|
|
|
|
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
|
|
|
@ -52,17 +50,17 @@ class GenericListWidget(QtGui.QListWidget):
|
|
|
|
|
|
|
|
|
|
def clear(self, *args):
|
|
|
|
|
"""Re-implement clear to set dynamic size after clear."""
|
|
|
|
|
QtGui.QListWidget.clear(*(self,) + args)
|
|
|
|
|
QtWidgets.QListWidget.clear(*(self,) + args)
|
|
|
|
|
self.auto_resize()
|
|
|
|
|
|
|
|
|
|
def addItem(self, *args):
|
|
|
|
|
"""Re-implement addItem to set dynamic size after add."""
|
|
|
|
|
QtGui.QListWidget.addItem(*(self,) + args)
|
|
|
|
|
QtWidgets.QListWidget.addItem(*(self,) + args)
|
|
|
|
|
self.auto_resize()
|
|
|
|
|
|
|
|
|
|
def insertItem(self, *args):
|
|
|
|
|
"""Re-implement insertItem to set dynamic size after insert."""
|
|
|
|
|
QtGui.QListWidget.insertItem(*(self,) + args)
|
|
|
|
|
QtWidgets.QListWidget.insertItem(*(self,) + args)
|
|
|
|
|
self.auto_resize()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -70,7 +68,7 @@ class BufferListWidget(GenericListWidget):
|
|
|
|
|
"""Widget with list of buffers."""
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args):
|
|
|
|
|
GenericListWidget.__init__(*(self,) + args)
|
|
|
|
|
super().__init__(*args)
|
|
|
|
|
|
|
|
|
|
def switch_prev_buffer(self):
|
|
|
|
|
if self.currentRow() > 0:
|
|
|
|
@ -85,23 +83,23 @@ class BufferListWidget(GenericListWidget):
|
|
|
|
|
self.setCurrentRow(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BufferWidget(QtGui.QWidget):
|
|
|
|
|
class BufferWidget(QtWidgets.QWidget):
|
|
|
|
|
"""
|
|
|
|
|
Widget with (from top to bottom):
|
|
|
|
|
title, chat + nicklist (optional) + prompt/input.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, display_nicklist=False):
|
|
|
|
|
QtGui.QWidget.__init__(self)
|
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
|
|
# title
|
|
|
|
|
self.title = QtGui.QLineEdit()
|
|
|
|
|
self.title = QtWidgets.QLineEdit()
|
|
|
|
|
self.title.setFocusPolicy(QtCore.Qt.NoFocus)
|
|
|
|
|
|
|
|
|
|
# splitter with chat + nicklist
|
|
|
|
|
self.chat_nicklist = QtGui.QSplitter()
|
|
|
|
|
self.chat_nicklist.setSizePolicy(QtGui.QSizePolicy.Expanding,
|
|
|
|
|
QtGui.QSizePolicy.Expanding)
|
|
|
|
|
self.chat_nicklist = QtWidgets.QSplitter()
|
|
|
|
|
self.chat_nicklist.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
|
|
|
|
|
QtWidgets.QSizePolicy.Expanding)
|
|
|
|
|
self.chat = ChatTextEdit(debug=False)
|
|
|
|
|
self.chat_nicklist.addWidget(self.chat)
|
|
|
|
|
self.nicklist = GenericListWidget()
|
|
|
|
@ -110,16 +108,16 @@ class BufferWidget(QtGui.QWidget):
|
|
|
|
|
self.chat_nicklist.addWidget(self.nicklist)
|
|
|
|
|
|
|
|
|
|
# prompt + input
|
|
|
|
|
self.hbox_edit = QtGui.QHBoxLayout()
|
|
|
|
|
self.hbox_edit = QtWidgets.QHBoxLayout()
|
|
|
|
|
self.hbox_edit.setContentsMargins(0, 0, 0, 0)
|
|
|
|
|
self.hbox_edit.setSpacing(0)
|
|
|
|
|
self.input = InputLineEdit(self.chat)
|
|
|
|
|
self.hbox_edit.addWidget(self.input)
|
|
|
|
|
prompt_input = QtGui.QWidget()
|
|
|
|
|
prompt_input = QtWidgets.QWidget()
|
|
|
|
|
prompt_input.setLayout(self.hbox_edit)
|
|
|
|
|
|
|
|
|
|
# vbox with title + chat/nicklist + prompt/input
|
|
|
|
|
vbox = QtGui.QVBoxLayout()
|
|
|
|
|
vbox = QtWidgets.QVBoxLayout()
|
|
|
|
|
vbox.setContentsMargins(0, 0, 0, 0)
|
|
|
|
|
vbox.setSpacing(0)
|
|
|
|
|
vbox.addWidget(self.title)
|
|
|
|
@ -139,7 +137,7 @@ class BufferWidget(QtGui.QWidget):
|
|
|
|
|
if self.hbox_edit.count() > 1:
|
|
|
|
|
self.hbox_edit.takeAt(0)
|
|
|
|
|
if prompt is not None:
|
|
|
|
|
label = QtGui.QLabel(prompt)
|
|
|
|
|
label = QtWidgets.QLabel(prompt)
|
|
|
|
|
label.setContentsMargins(0, 0, 5, 0)
|
|
|
|
|
self.hbox_edit.insertWidget(0, label)
|
|
|
|
|
|
|
|
|
@ -147,7 +145,7 @@ class BufferWidget(QtGui.QWidget):
|
|
|
|
|
class Buffer(QtCore.QObject):
|
|
|
|
|
"""A WeeChat buffer."""
|
|
|
|
|
|
|
|
|
|
bufferInput = qt_compat.Signal(str, str)
|
|
|
|
|
bufferInput = QtCore.Signal(str, str)
|
|
|
|
|
|
|
|
|
|
def __init__(self, data={}):
|
|
|
|
|
QtCore.QObject.__init__(self)
|
|
|
|
@ -167,15 +165,17 @@ class Buffer(QtCore.QObject):
|
|
|
|
|
"""Update title."""
|
|
|
|
|
try:
|
|
|
|
|
self.widget.set_title(
|
|
|
|
|
color.remove(self.data['title'].decode('utf-8')))
|
|
|
|
|
except: # noqa: E722
|
|
|
|
|
color.remove(self.data['title']))
|
|
|
|
|
except Exception: # noqa: E722
|
|
|
|
|
# TODO: Debug print the exception to be fixed.
|
|
|
|
|
# traceback.print_exc()
|
|
|
|
|
self.widget.set_title(None)
|
|
|
|
|
|
|
|
|
|
def update_prompt(self):
|
|
|
|
|
"""Update prompt."""
|
|
|
|
|
try:
|
|
|
|
|
self.widget.set_prompt(self.data['local_variables']['nick'])
|
|
|
|
|
except: # noqa: E722
|
|
|
|
|
except Exception: # noqa: E722
|
|
|
|
|
self.widget.set_prompt(None)
|
|
|
|
|
|
|
|
|
|
def input_text_sent(self, text):
|
|
|
|
@ -243,6 +243,6 @@ class Buffer(QtCore.QObject):
|
|
|
|
|
pixmap = QtGui.QPixmap(8, 8)
|
|
|
|
|
pixmap.fill()
|
|
|
|
|
icon = QtGui.QIcon(pixmap)
|
|
|
|
|
item = QtGui.QListWidgetItem(icon, nick['name'])
|
|
|
|
|
item = QtWidgets.QListWidgetItem(icon, nick['name'])
|
|
|
|
|
self.widget.nicklist.addItem(item)
|
|
|
|
|
self.widget.nicklist.setVisible(True)
|
|
|
|
|