88from typing import Optional
99
1010# PyQGIS
11- from PyQt5 import QtWebSockets # noqa QGS103
1211from qgis .core import Qgis , QgsApplication , QgsJsonExporter , QgsMapLayer , QgsProject
1312from qgis .gui import QgisInterface , QgsDockWidget
1413from qgis .PyQt import uic
2322 QWidget ,
2423)
2524
25+ # plugin
2626from qtribu .__about__ import __title__
2727from qtribu .constants import (
2828 ADMIN_MESSAGES_NICKNAME ,
6464)
6565from qtribu .logic .qchat_websocket import QChatWebsocket
6666from qtribu .tasks .dizzy import DizzyTask
67-
68- # plugin
6967from qtribu .toolbelt import PlgLogger , PlgOptionsManager
7068from qtribu .toolbelt .commons import open_url_in_webviewer , play_resource_sound
7169from qtribu .toolbelt .preferences import PlgSettingsStructure
@@ -88,8 +86,8 @@ class QChatWidget(QgsDockWidget):
8886 def __init__ (
8987 self ,
9088 iface : QgisInterface ,
91- parent : QWidget = None ,
92- auto_reconnect_room : str = None ,
89+ parent : Optional [ QWidget ] = None ,
90+ auto_reconnect_room : Optional [ str ] = None ,
9391 ):
9492 """QWidget to see and post messages on chat
9593
@@ -137,7 +135,7 @@ def __init__(
137135 )
138136 self .twg_chat .itemClicked .connect (self .on_message_clicked )
139137 self .twg_chat .itemDoubleClicked .connect (self .on_message_double_clicked )
140- self .twg_chat .setContextMenuPolicy (Qt .CustomContextMenu )
138+ self .twg_chat .setContextMenuPolicy (Qt .ContextMenuPolicy . CustomContextMenu )
141139 self .twg_chat .customContextMenuRequested .connect (
142140 self .on_custom_context_menu_requested
143141 )
@@ -260,7 +258,7 @@ def on_widget_opened(self) -> None:
260258 self .cbb_room .addItem (room )
261259 except Exception as exc :
262260 self .iface .messageBar ().pushCritical (self .tr ("QChat error" ), str (exc ))
263- self .log (message = str (exc ), log_level = Qgis .Critical )
261+ self .log (message = str (exc ), log_level = Qgis .MessageLevel . Critical )
264262 finally :
265263 self .current_room = MARKER_VALUE
266264
@@ -304,7 +302,7 @@ def on_rules_button_clicked(self) -> None:
304302 )
305303 except Exception as exc :
306304 self .iface .messageBar ().pushCritical (self .tr ("QChat error" ), str (exc ))
307- self .log (message = str (exc ), log_level = Qgis .Critical )
305+ self .log (message = str (exc ), log_level = Qgis .MessageLevel . Critical )
308306
309307 def on_status_button_clicked (self ) -> None :
310308 """
@@ -330,7 +328,7 @@ def on_status_button_clicked(self) -> None:
330328 )
331329 QMessageBox .information (self , self .tr ("QChat instance status" ), text )
332330 except Exception as exc :
333- self .log (message = str (exc ), log_level = Qgis .Critical )
331+ self .log (message = str (exc ), log_level = Qgis .MessageLevel . Critical )
334332
335333 def on_settings_button_clicked (self ) -> None :
336334 """
@@ -367,7 +365,7 @@ def on_room_changed(self) -> None:
367365 message = self .tr (
368366 "QChat nickname not set or too short (between {min} and {max} characters). Please open settings to fix it."
369367 ).format (min = self .min_author_length , max = self .max_author_length ),
370- log_level = Qgis .Warning ,
368+ log_level = Qgis .MessageLevel . Warning ,
371369 push = self .settings .notify_push_info ,
372370 duration = self .settings .notify_push_duration ,
373371 button = True ,
@@ -410,7 +408,7 @@ def on_connect_button_clicked(self) -> None:
410408 message = self .tr (
411409 "QChat nickname not set or too short (between {min} and {max} characters). Please open settings to fix it."
412410 ).format (min = self .min_author_length , max = self .max_author_length ),
413- log_level = Qgis .Warning ,
411+ log_level = Qgis .MessageLevel . Warning ,
414412 push = self .settings .notify_push_info ,
415413 duration = self .settings .notify_push_duration ,
416414 button = True ,
@@ -493,7 +491,7 @@ def on_ws_error(self, error_code: int) -> None:
493491 self .add_admin_message (self .qchat_ws .error_string ())
494492 self .log (
495493 message = f"{ error_code } : { self .qchat_ws .error_string ()} " ,
496- log_level = Qgis .Critical ,
494+ log_level = Qgis .MessageLevel . Critical ,
497495 )
498496
499497 # region websocket message received
@@ -504,7 +502,7 @@ def on_uncompliant_message_received(self, message: QChatUncompliantMessage) -> N
504502 reason = message .reason
505503 ),
506504 application = self .tr ("QChat" ),
507- log_level = Qgis .Critical ,
505+ log_level = Qgis .MessageLevel . Critical ,
508506 push = self .settings .notify_push_info ,
509507 duration = self .settings .notify_push_duration ,
510508 )
@@ -534,7 +532,7 @@ def on_text_message_received(self, message: QChatTextMessage) -> None:
534532 "You were mentionned by {sender}: {message}"
535533 ).format (sender = message .author , message = message .text ),
536534 application = self .tr ("QChat" ),
537- log_level = Qgis .Info ,
535+ log_level = Qgis .MessageLevel . Info ,
538536 push = self .settings .notify_push_info ,
539537 duration = self .settings .notify_push_duration ,
540538 )
@@ -602,7 +600,7 @@ def on_like_message_received(self, message: QChatLikeMessage) -> None:
602600 liker_author = message .liker_author , message = message .message
603601 ),
604602 application = self .tr ("QChat" ),
605- log_level = Qgis .Success ,
603+ log_level = Qgis .MessageLevel . Success ,
606604 push = self .settings .notify_push_info ,
607605 duration = self .settings .notify_push_duration ,
608606 )
@@ -777,7 +775,7 @@ def on_list_users_button_clicked(self) -> None:
777775 )
778776 except Exception as exc :
779777 self .iface .messageBar ().pushCritical (self .tr ("QChat error" ), str (exc ))
780- self .log (message = str (exc ), log_level = Qgis .Critical )
778+ self .log (message = str (exc ), log_level = Qgis .MessageLevel . Critical )
781779
782780 def on_clear_chat_button_clicked (self ) -> None :
783781 """
@@ -798,7 +796,7 @@ def on_send_button_clicked(self) -> None:
798796 if not nickname :
799797 self .log (
800798 message = self .tr ("Nickname not set : please open settings and set it" ),
801- log_level = Qgis .Warning ,
799+ log_level = Qgis .MessageLevel . Warning ,
802800 push = self .settings .notify_push_info ,
803801 duration = self .settings .notify_push_duration ,
804802 button = True ,
@@ -812,7 +810,7 @@ def on_send_button_clicked(self) -> None:
812810 message = self .tr (
813811 "Nickname too short: must be at least 3 characters. Please open settings and set it"
814812 ),
815- log_level = Qgis .Warning ,
813+ log_level = Qgis .MessageLevel . Warning ,
816814 push = self .settings .notify_push_info ,
817815 duration = self .settings .notify_push_duration ,
818816 button = True ,
@@ -950,7 +948,7 @@ def check_cheatcode(self, text: str) -> bool:
950948 self .log (
951949 message = self .tr ("Your QGIS Pro license is about to expire" ),
952950 application = "QGIS Pro" ,
953- log_level = Qgis .Warning ,
951+ log_level = Qgis .MessageLevel . Warning ,
954952 push = self .settings .notify_push_info ,
955953 duration = self .settings .notify_push_duration ,
956954 button = True ,
@@ -968,7 +966,7 @@ def check_cheatcode(self, text: str) -> bool:
968966 def on_renew_clicked (self ) -> None :
969967 msg_box = QMessageBox ()
970968 msg_box .setWindowTitle ("QGIS" )
971- msg_box .setIcon (QMessageBox .Information )
969+ msg_box .setIcon (QMessageBox .Icon . Information )
972970 msg_box .setText (
973971 self .tr (
974972 """No... it was a joke!
@@ -980,9 +978,9 @@ def on_renew_clicked(self) -> None:
980978"""
981979 )
982980 )
983- msg_box .setStandardButtons (QMessageBox .Yes )
981+ msg_box .setStandardButtons (QMessageBox .StandardButton . Yes )
984982 return_value = msg_box .exec ()
985- if return_value == QMessageBox .Yes :
983+ if return_value == QMessageBox .StandardButton . Yes :
986984 open_url_in_webviewer ("https://qgis.org/funding/donate/" , "qgis.org" )
987985
988986 def generate_qaction_send_geojson_layer (self , menu : QMenu ) -> None :
@@ -1002,7 +1000,7 @@ def on_send_layer_to_qchat(self) -> None:
10021000 "Not connected to QChat. Please connect to a room first"
10031001 ),
10041002 application = "QChat" ,
1005- log_level = Qgis .Critical ,
1003+ log_level = Qgis .MessageLevel . Critical ,
10061004 push = self .settings .notify_push_info ,
10071005 duration = self .settings .notify_push_duration ,
10081006 )
@@ -1012,16 +1010,16 @@ def on_send_layer_to_qchat(self) -> None:
10121010 self .log (
10131011 message = self .tr ("No active layer in current QGIS project" ),
10141012 application = self .tr ("QChat" ),
1015- log_level = Qgis .Critical ,
1013+ log_level = Qgis .MessageLevel . Critical ,
10161014 push = self .settings .notify_push_info ,
10171015 duration = self .settings .notify_push_duration ,
10181016 )
10191017 return
1020- if layer .type () != QgsMapLayer .VectorLayer :
1018+ if layer .type () != QgsMapLayer .LayerType . VectorLayer :
10211019 self .log (
10221020 message = self .tr ("Only vector layers can be sent on QChat" ),
10231021 application = self .tr ("QChat" ),
1024- log_level = Qgis .Critical ,
1022+ log_level = Qgis .MessageLevel . Critical ,
10251023 push = self .settings .notify_push_info ,
10261024 duration = self .settings .notify_push_duration ,
10271025 )
0 commit comments