@@ -44,6 +44,11 @@ def txt_message_enter(self):
4444 def txt_username_enter (self ):
4545 self .btn_connect_clicked ()
4646
47+ def btn_pm_send_clicked (self , ui ):
48+ message = ui .txt_message .text ()
49+ self .client .talk (message , ui .username )
50+ ui .txt_message .setText ('' )
51+
4752 QtCore .pyqtSlot (str )
4853 def on_message (self , msg ):
4954 self .ui .txt_chat .append (msg )
@@ -121,14 +126,21 @@ def on_user_list(self, obj):
121126 model .appendRow (item )
122127
123128 self .ui .lst_users .setModel (model )
129+
130+ self .ui .lbl_sbar_user_count .setText ('{0}' .format (model .rowCount ()))
124131
125132 QtCore .pyqtSlot ()
126133 def on_connect (self ):
127134 self .ui .btn_connect .setVisible (False )
128135 self .ui .actionConnect .setVisible (False )
129136 self .ui .actionDisconnect .setVisible (True )
130137 self .ui .btn_disconnect .setVisible (True )
131- self .ui .statusbar .showMessage ('Connected' )
138+ self .ui .lbl_sbar_conn .setStyleSheet ('color: green' )
139+ self .ui .lbl_sbar_conn .setText ('Connected' )
140+ self .ui .lbl_sbar_login .setText ('Logged as <b>{0}</b>' .format (self .client .username ))
141+
142+ self .chat_windows_status (True )
143+
132144 self .ui .txt_message .setReadOnly (False )
133145 self .ui .txt_username .setReadOnly (True )
134146 self .ui .txt_message .setFocus ()
@@ -139,7 +151,13 @@ def on_disconnect(self):
139151 self .ui .actionDisconnect .setVisible (False )
140152 self .ui .actionConnect .setVisible (True )
141153 self .ui .btn_connect .setVisible (True )
142- self .ui .statusbar .showMessage ('Disconnected' )
154+ self .ui .lbl_sbar_conn .setStyleSheet ('color: red' )
155+ self .ui .lbl_sbar_conn .setText ('Disconnected' )
156+ self .ui .lbl_sbar_login .setText ('' )
157+ self .ui .lbl_sbar_user_count .setText ('0' )
158+
159+ self .chat_windows_status (False )
160+
143161 self .ui .txt_message .setReadOnly (True )
144162 self .ui .txt_username .setReadOnly (False )
145163 self .ui .txt_username .setFocus ()
@@ -149,6 +167,19 @@ def on_clear_user_list(self):
149167 model = QStandardItemModel (self .ui .lst_users )
150168 self .ui .lst_users .setModel (model )
151169
170+ QtCore .pyqtSlot (str , str , str )
171+ def show_dialog_box (self , title , message , mb_type ):
172+ if mb_type == 'c' :
173+ QMessageBox .critical (self .window , title , message )
174+ elif mb_type == 'i' :
175+ QMessageBox .information (self .window , title , message )
176+ elif mb_type == 'q' :
177+ QMessageBox .question (self .window , title , message )
178+ elif mb_type == 'w' :
179+ QMessageBox .warning (self .window , title , message )
180+ else :
181+ QMessageBox .information (self .window , title , message )
182+
152183 def on_close (self ):
153184 self .app .closeAllWindows ()
154185
@@ -178,24 +209,6 @@ def appQuitEvent(self):
178209 self .client .stop ()
179210 self .app .quit ()
180211
181- QtCore .pyqtSlot (str , str , str )
182- def show_dialog_box (self , title , message , mb_type ):
183- if mb_type == 'c' :
184- QMessageBox .critical (self .window , title , message )
185- elif mb_type == 'i' :
186- QMessageBox .information (self .window , title , message )
187- elif mb_type == 'q' :
188- QMessageBox .question (self .window , title , message )
189- elif mb_type == 'w' :
190- QMessageBox .warning (self .window , title , message )
191- else :
192- QMessageBox .information (self .window , title , message )
193-
194- def pm_btn_send_clicked (self , ui ):
195- message = ui .txt_message .text ()
196- self .client .talk (message , ui .username )
197- ui .txt_message .setText ('' )
198-
199212 def create_chat_window (self , username ):
200213 if not hasattr (self .ui , 'windows' ):
201214 self .ui .windows = dict ()
@@ -212,14 +225,19 @@ def create_chat_window(self, username):
212225 tmp_ui .setupUi (tmp_window )
213226 tmp_ui .username = username
214227
215- tmp_ui .btn_send .clicked .connect (partial (self .pm_btn_send_clicked , tmp_ui ))
216- tmp_ui .txt_message .returnPressed .connect (partial (self .pm_btn_send_clicked , tmp_ui ))
228+ tmp_ui .btn_send .clicked .connect (partial (self .btn_pm_send_clicked , tmp_ui ))
229+ tmp_ui .txt_message .returnPressed .connect (partial (self .btn_pm_send_clicked , tmp_ui ))
230+
231+ tmp_ui .statusbar .addPermanentWidget (tmp_ui .lbl_sbar_conn , 2 )
232+ tmp_ui .statusbar .addPermanentWidget (tmp_ui .lbl_sbar_login , 8 )
217233
218234 tmp_window .setWindowIcon (icon )
219235 tmp_window .setWindowTitle ('{} - Chat' .format (username ))
220236
221237 self .ui .windows ['chat' ][username ] = [tmp_window , tmp_ui ]
222238
239+ self .chat_windows_status (True )
240+
223241 def lst_users_double_clicked (self , item : QModelIndex ):
224242 username = item .data ()
225243
@@ -239,12 +257,6 @@ def lst_users_double_clicked(self, item: QModelIndex):
239257 msg = self .client .user_chat_queue [username ].get ()
240258 print (msg )
241259 self .ui .windows ['chat' ][username ][1 ].txt_chat .append (msg )
242-
243- def sys_tray_icon_activated (self , reason ):
244- if reason == QSystemTrayIcon .DoubleClick :
245- self .window .tray_icon .contextMenu ().exec_ (QCursor ().pos ())
246- elif reason == QSystemTrayIcon .Trigger :
247- self .window .show ()
248260
249261 def load_settings_form (self ):
250262 ui = self .ui .windows ['settings' ][1 ]
@@ -293,3 +305,23 @@ def open_preferences(self):
293305
294306 self .load_settings_form ()
295307 self .ui .windows ['settings' ][0 ].show ()
308+
309+ def sys_tray_icon_activated (self , reason ):
310+ if reason == QSystemTrayIcon .DoubleClick :
311+ self .window .tray_icon .contextMenu ().exec_ (QCursor ().pos ())
312+ elif reason == QSystemTrayIcon .Trigger :
313+ self .window .show ()
314+
315+ def chat_windows_status (self , status ):
316+ if status :
317+ if hasattr (self .ui , 'windows' ) and 'chat' in self .ui .windows :
318+ for key , val in self .ui .windows ['chat' ].items ():
319+ val [1 ].lbl_sbar_conn .setStyleSheet ('color: green' )
320+ val [1 ].lbl_sbar_conn .setText ('Connected' )
321+ val [1 ].lbl_sbar_login .setText ('Logged as <b>{0}</b>' .format (self .client .username ))
322+ else :
323+ if hasattr (self .ui , 'windows' ) and 'chat' in self .ui .windows :
324+ for key , val in self .ui .windows ['chat' ].items ():
325+ val [1 ].lbl_sbar_conn .setStyleSheet ('color: red' )
326+ val [1 ].lbl_sbar_conn .setText ('Disconnected' )
327+ val [1 ].lbl_sbar_login .setText ('' )
0 commit comments