Skip to content

Commit

Permalink
add clear chat button
Browse files Browse the repository at this point in the history
  • Loading branch information
gounux committed Jul 18, 2024
1 parent eed332f commit 7a982a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
18 changes: 10 additions & 8 deletions qtribu/gui/wdg_qchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
from pathlib import Path
from typing import Any

from qgis.gui import QgsDockWidget

# PyQGIS
from qgis.PyQt import QtWebSockets, uic
#
from PyQt5 import QtWebSockets # noqa QGS103
from qgis.gui import QgsDockWidget
from qgis.PyQt import uic
from qgis.PyQt.QtCore import QUrl
from qgis.PyQt.QtWidgets import QMessageBox, QTreeWidgetItem, QWidget

Expand Down Expand Up @@ -63,6 +64,9 @@ def __init__(self, parent: QWidget = None):
]
)

# clear chat signal listener
self.btn_clear_chat.pressed.connect(self.on_clear_chat_button_clicked)

# initialize websocket client
self.ws_client = QtWebSockets.QWebSocket(
"", QtWebSockets.QWebSocketProtocol.Version13, None
Expand Down Expand Up @@ -110,8 +114,6 @@ def on_connect_button_clicked(self) -> None:
self.connect_to_room(room)

def connect_to_room(self, room: str, log: bool = True) -> None:
messages = self.qchat_client.get_last_messages(room)
messages.reverse()
if log:
self.tw_chat.insertTopLevelItem(
0,
Expand All @@ -124,9 +126,6 @@ def connect_to_room(self, room: str, log: bool = True) -> None:
]
),
)
for message in messages:
qtw_item = self.add_message_to_treeview(room, message)
self.tw_chat.insertTopLevelItem(0, qtw_item)

ws_instance_url = "ws://" + self.settings.qchat_instance_uri.split("://")[-1]
ws_url = f"{ws_instance_url}/room/{room}/ws"
Expand Down Expand Up @@ -182,6 +181,9 @@ def on_ws_message_received(self, message: str) -> None:
0, self.add_message_to_treeview(message["room"], message)
)

def on_clear_chat_button_clicked(self) -> None:
self.tw_chat.clear()

def on_send_button_clicked(self) -> None:
nickname = self.le_nickname.text()
message_text = self.le_message.text()
Expand Down
7 changes: 7 additions & 0 deletions qtribu/gui/wdg_qchat.ui
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@
</column>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_clear_chat">
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 7a982a3

Please sign in to comment.