@@ -13,11 +13,18 @@ class ConnectionPage(QtWidgets.QFrame):
1313 reboot_clicked = QtCore .pyqtSignal (name = "reboot_clicked" )
1414 restart_klipper_clicked = QtCore .pyqtSignal (name = "restart_klipper_clicked" )
1515 firmware_restart_clicked = QtCore .pyqtSignal (name = "firmware_restart_clicked" )
16+ update_button_clicked = QtCore .pyqtSignal (bool , name = "show-update-page" )
1617
1718 def __init__ (self , parent : QtWidgets .QWidget , ws : MoonWebSocket , / ):
1819 super ().__init__ (parent )
20+ self .setMinimumSize (QtCore .QSize (800 , 480 ))
1921 self .panel = Ui_ConnectivityForm ()
2022 self .panel .setupUi (self )
23+
24+ self .panel .updatepageButton .clicked .connect (
25+ lambda : self .update_button_clicked [bool ].emit (True )
26+ )
27+
2128 self .ws = ws
2229 self ._moonraker_status : str = "disconnected"
2330 self ._klippy_state : str = "closed"
@@ -55,9 +62,16 @@ def show_panel(self, reason: str | None = None):
5562 self .text_update ()
5663 return False
5764
65+ def showEvent (self , a0 : QtCore .QEvent | None ):
66+ """Handle show event"""
67+ self .ws .api .refresh_update_status ()
68+ return super ().showEvent (a0 )
69+
5870 @QtCore .pyqtSlot (bool , name = "on_klippy_connected" )
5971 def on_klippy_connection (self , connected : bool ):
6072 """Handle klippy connection state"""
73+ self .dot_timer .stop ()
74+
6175 self ._klippy_connection = connected
6276 if not connected :
6377 self .panel .connectionTextBox .setText ("Klipper Disconnected" )
@@ -69,6 +83,7 @@ def on_klippy_connection(self, connected: bool):
6983 @QtCore .pyqtSlot (str , name = "on_klippy_state" )
7084 def on_klippy_state (self , state : str ):
7185 """Handle klippy state changes"""
86+ self .dot_timer .stop ()
7287 if state == "error" :
7388 self .panel .connectionTextBox .setText ("Klipper Connection Error" )
7489 if not self .isVisible ():
@@ -87,7 +102,6 @@ def on_klippy_state(self, state: str):
87102 self .panel .connectionTextBox .setText ("Klipper Startup" )
88103 elif state == "ready" :
89104 self .panel .connectionTextBox .setText ("Klipper Ready" )
90- self .hide ()
91105
92106 @QtCore .pyqtSlot (int , name = "on_websocket_connecting" )
93107 @QtCore .pyqtSlot (str , name = "on_websocket_connecting" )
@@ -98,21 +112,22 @@ def on_websocket_connecting(self, attempt: int):
98112 @QtCore .pyqtSlot (name = "on_websocket_connection_achieved" )
99113 def on_websocket_connection_achieved (self ):
100114 """Handle websocket connected state"""
115+ self .dot_timer .stop ()
101116 self .panel .connectionTextBox .setText ("Moonraker Connected\n Klippy not ready" )
102- self .hide ()
103117
104- @QtCore .pyqtSlot (name = "on_websocket_connection_lost " )
118+ @QtCore .pyqtSlot (name = "on_websocket_connection_lzost " )
105119 def on_websocket_connection_lost (self ):
106120 """Handle websocket connection lost state"""
107121 if not self .isVisible ():
108122 self .show ()
123+ self .dot_timer .stop ()
109124 self .text_update (text = "Websocket lost" )
110125
111126 def text_update (self , text : int | str | None = None ):
112127 """Update widget text"""
113128 if self .state == "shutdown" and self .message is not None :
114129 return False
115-
130+ self . dot_timer . stop ()
116131 logging .debug (f"[ConnectionWindowPanel] text_update: { text } " )
117132 if text == "wb lost" :
118133 self .panel .connectionTextBox .setText ("Moonraker connection lost" )
@@ -125,41 +140,34 @@ def text_update(self, text: int | str | None = None):
125140 return True
126141 if isinstance (text , str ):
127142 self .panel .connectionTextBox .setText (
128- f"""
129- Connection to Moonraker unavailable\n Try again by reconnecting or \n restarting klipper\n { text }
130- """
143+ f"""Connection to Moonraker unavailable\n Try again by reconnecting or \n restarting klipper\n { text } """
131144 )
132145 return True
133146 if isinstance (text , int ):
134147 # * Websocket connection messages
148+
149+ self .base_text = f"Attempting to reconnect to Moonraker.\n \n Connection try number: { text } "
150+
135151 if text == 0 :
136- self .dot_timer .stop ()
137152 self .panel .connectionTextBox .setText (
138- "Unable to Connect to Moonraker. \n \n Try again "
153+ "Connection to Moonraker timeout \n \n please retry "
139154 )
140- return False
141-
142- if text == 1 :
143- if self .dot_timer .isActive ():
144- self .dot_timer .stop ()
145- return
146- self .dot_timer .start ()
155+ return
156+ self .dot_count = 0
147157
148- self .text2 = f"Attempting to reconnect to Moonraker.\n \n Connection try number: { text } "
158+ self .dot_timer .start ()
159+ self ._add_dot ()
149160
150161 return False
151162
152163 def _add_dot (self ):
153- if self .state == "shutdown" and self .message is not None :
164+ """Add one dot per second (max 3)."""
165+ self .dot_count += 1
166+ if self .dot_count > 3 :
154167 self .dot_timer .stop ()
155- return False
156-
157- if self .dot_count > 2 :
158- self .dot_count = 1
159- else :
160- self .dot_count += 1
168+ return
161169 dots = "." * self .dot_count + " " * (3 - self .dot_count )
162- self .panel .connectionTextBox .setText (f"{ self .text2 } { dots } " )
170+ self .panel .connectionTextBox .setText (f"{ self .base_text } { dots } " )
163171
164172 @QtCore .pyqtSlot (str , str , name = "webhooks_update" )
165173 def webhook_update (self , state : str , message : str ):
@@ -171,16 +179,19 @@ def webhook_update(self, state: str, message: str):
171179 def eventFilter (self , object : QtCore .QObject , event : QtCore .QEvent ) -> bool :
172180 """Re-implemented method, filter events"""
173181 if event .type () == KlippyDisconnected .type ():
182+ self .dot_timer .stop ()
174183 if not self .isVisible ():
175184 self .panel .connectionTextBox .setText ("Klippy Disconnected" )
176185 self .show ()
177186
178187 elif event .type () == KlippyReady .type ():
188+ self .dot_timer .stop ()
179189 self .panel .connectionTextBox .setText ("Klippy Ready" )
180190 self .hide ()
181191 return False
182192
183193 elif event .type () == KlippyShutdown .type ():
194+ self .dot_timer .stop ()
184195 if not self .isVisible ():
185196 self .panel .connectionTextBox .setText (f"{ self .message } " )
186197 self .show ()
0 commit comments