1515from __future__ import annotations
1616
1717import functools
18- from collections .abc import Callable
1918from contextlib import contextmanager
2019
2120import numpy as np
2221from guidata .env import execenv
23- from guidata .qthelpers import qt_app_context , qt_wait , win32_fix_title_bar_background
24- from qtpy import QtCore as QC
22+ from guidata .qthelpers import qt_app_context , qt_wait
2523from qtpy import QtWidgets as QW
2624
2725from cdlclient import SimpleRemoteProxy
2826from cdlclient .tests .remoteclient_base import AbstractClientWindow
2927from cdlclient .tests .remoteclient_unit import multiple_commands
28+ from cdlclient .widgets import DataLabConnectionDialog
3029
3130APP_NAME = "Remote client test"
3231
@@ -56,80 +55,6 @@ def method_wrapper(*args, **kwargs):
5655 return try_send_command_decorator
5756
5857
59- class DataLabConnectionThread (QC .QThread ):
60- """DataLab Connection thread"""
61-
62- SIG_CONNECTION_OK = QC .Signal ()
63- SIG_CONNECTION_KO = QC .Signal ()
64-
65- def __init__ (self , connect_callback : Callable , parent : QC .QObject = None ) -> None :
66- super ().__init__ (parent )
67- self .connect_callback = connect_callback
68-
69- def run (self ) -> None :
70- """Run thread"""
71- try :
72- self .connect_callback ()
73- self .SIG_CONNECTION_OK .emit ()
74- except ConnectionRefusedError :
75- self .SIG_CONNECTION_KO .emit ()
76-
77-
78- class DataLabConnectionDialog (QW .QDialog ):
79- """DataLab Connection dialog
80-
81- Args:
82- connect_callback: Callback function to connect to DataLab server
83- parent: Parent widget. Defaults to None.
84- """
85-
86- def __init__ (self , connect_callback : Callable , parent : QW .QWidget = None ) -> None :
87- super ().__init__ (parent )
88- win32_fix_title_bar_background (self )
89- self .setWindowTitle ("Connection to DataLab" )
90- self .setMinimumWidth (300 )
91- self .host_label = QW .QLabel ("Host:" )
92- self .progress_bar = QW .QProgressBar ()
93- self .progress_bar .setRange (0 , 0 )
94- self .status_label = QW .QLabel ("Waiting for connection..." )
95- layout = QW .QVBoxLayout ()
96- layout .addWidget (self .host_label )
97- layout .addWidget (self .progress_bar )
98- layout .addWidget (self .status_label )
99- self .setLayout (layout )
100- self .thread = DataLabConnectionThread (connect_callback )
101- self .thread .SIG_CONNECTION_OK .connect (self .on_connection_successful )
102- self .thread .SIG_CONNECTION_KO .connect (self .on_connection_failed )
103- button_box = QW .QDialogButtonBox (QW .QDialogButtonBox .Cancel )
104- button_box .rejected .connect (self .reject )
105- layout .addWidget (button_box )
106-
107- def exec (self ) -> int :
108- """Execute dialog"""
109- self .connect_to_server ()
110- return super ().exec ()
111-
112- def connect_to_server (self ) -> None :
113- """Connect to server"""
114- self .progress_bar .setRange (0 , 0 )
115- self .status_label .setText ("Connecting to server..." )
116- self .thread .start ()
117-
118- def on_connection_successful (self ) -> None :
119- """Connection successful"""
120- self .progress_bar .setRange (0 , 1 )
121- self .progress_bar .setValue (1 )
122- self .status_label .setText ("Connection successful!" )
123- self .accept ()
124-
125- def on_connection_failed (self ) -> None :
126- """Connection failed"""
127- self .progress_bar .setRange (0 , 1 )
128- self .progress_bar .setValue (1 )
129- self .status_label .setText ("Connection failed." )
130- self .reject ()
131-
132-
13358class HostWindow (AbstractClientWindow ):
13459 """Test main view"""
13560
@@ -149,7 +74,6 @@ def init_cdl(self):
14974 if self .cdl is None :
15075 self .cdl : SimpleRemoteProxy = SimpleRemoteProxy ()
15176 connect_dlg = DataLabConnectionDialog (self .cdl .connect , self )
152- connect_dlg .host_label .setText ("Host: DataLab server" )
15377 ok = connect_dlg .exec ()
15478 if ok :
15579 self .host .log ("✨ Initialized DataLab connection ✨" )
0 commit comments