49
49
from spyder .widgets .helperwidgets import MessageLabel , TipWidget
50
50
51
51
try :
52
- import spyder_env_manager # noqa
52
+ from spyder_env_manager . spyder . widgets . new_environment import NewEnvironment
53
53
ENV_MANAGER = True
54
54
except Exception :
55
55
ENV_MANAGER = False
@@ -707,6 +707,13 @@ def get_name(self):
707
707
return _ ("New connection" )
708
708
709
709
def setup_page (self ):
710
+ # Attributes
711
+ self .env_method_group = QButtonGroup (self )
712
+ self ._radio_buttons_to_info_widgets : dict [
713
+ CreateEnvMethods , QWidget
714
+ ] = {}
715
+
716
+ # Widgets
710
717
self .ssh_info_widget = self .create_ssh_connection_info_widget ()
711
718
jupyterhub_info_widget = self .create_jupyterhub_connection_info_widget ()
712
719
@@ -807,6 +814,29 @@ def is_ssh_info_widget_shown(self) -> bool:
807
814
def selected_env_creation_method (self ) -> CreateEnvMethods :
808
815
return self .env_method_group .checkedId ()
809
816
817
+ def validate_env_creation (self ):
818
+ method_id = self .env_method_group .checkedId ()
819
+ if method_id != CreateEnvMethods .NoEnv :
820
+ env_method_widget = self ._radio_buttons_to_info_widgets [method_id ]
821
+ if env_method_widget .validate_page (env_names = []):
822
+ return True
823
+ else :
824
+ return False
825
+
826
+ return True
827
+
828
+ def get_create_env_info (self ):
829
+ method_id = self .env_method_group .checkedId ()
830
+ env_method_widget = self ._radio_buttons_to_info_widgets [method_id ]
831
+ if method_id == CreateEnvMethods .NewEnv :
832
+ # TODO! Implement later
833
+ pass
834
+ elif method_id == CreateEnvMethods .ImportEnv :
835
+ return (
836
+ env_method_widget .get_zip_file (),
837
+ env_method_widget .get_env_name ()
838
+ )
839
+
810
840
# ---- Private API
811
841
# -------------------------------------------------------------------------
812
842
def _create_env_creation_widget (self ):
@@ -842,7 +872,9 @@ def _create_env_creation_widget(self):
842
872
# Available methods
843
873
methods_group = QGroupBox (_ ("Available methods" ))
844
874
845
- self .env_method_group = QButtonGroup (self )
875
+ self .env_method_group .idToggled .connect (
876
+ self ._on_env_creation_method_changed
877
+ )
846
878
847
879
new_env_radio = self .create_radiobutton (
848
880
_ ("Create a new environment" ),
@@ -863,15 +895,60 @@ def _create_env_creation_widget(self):
863
895
id_ = CreateEnvMethods .NoEnv ,
864
896
)
865
897
866
- new_env_radio .radiobutton .setChecked (True )
867
-
868
898
methods_layout = QVBoxLayout ()
869
899
methods_layout .addSpacing (3 )
870
900
methods_layout .addWidget (new_env_radio )
871
901
methods_layout .addWidget (import_env_radio )
872
902
methods_layout .addWidget (no_env_radio )
873
903
methods_group .setLayout (methods_layout )
874
904
905
+ # Required info
906
+ info_group = QGroupBox (_ ("Required information" ))
907
+
908
+ new_env_info = NewEnvironment (
909
+ self ,
910
+ max_width_for_content = 470 ,
911
+ show_in_remote_connections_dialog = True
912
+ )
913
+ new_env_info .setMaximumWidth (470 )
914
+
915
+ import_env_info = NewEnvironment (
916
+ self ,
917
+ max_width_for_content = 470 ,
918
+ import_env = True ,
919
+ show_in_remote_connections_dialog = True
920
+ )
921
+ import_env_info .setMaximumWidth (470 )
922
+
923
+ no_env_info = QLabel (
924
+ _ (
925
+ "You can set up an environment later by going to the menu "
926
+ "entry <i>Tools > Environment manager</i>."
927
+ )
928
+ )
929
+ no_env_info .setWordWrap (True )
930
+
931
+ info_layout = QVBoxLayout ()
932
+ info_layout .addWidget (new_env_info )
933
+ info_layout .addWidget (import_env_info )
934
+ info_layout .addWidget (no_env_info )
935
+ info_group .setLayout (info_layout )
936
+
937
+ # Hide all info widgets to show
938
+ for widget in [new_env_info , import_env_info , no_env_info ]:
939
+ widget .setVisible (False )
940
+
941
+ # Use the following mapping to show/hide info widgets when the
942
+ # corresponding radio button is toggled
943
+ self ._radio_buttons_to_info_widgets = {
944
+ CreateEnvMethods .NewEnv : new_env_info ,
945
+ CreateEnvMethods .ImportEnv : import_env_info ,
946
+ CreateEnvMethods .NoEnv : no_env_info ,
947
+ }
948
+
949
+ # Set new env as the default method
950
+ new_env_radio .radiobutton .setChecked (True )
951
+
875
952
# Final layout
876
953
layout = QVBoxLayout ()
877
954
layout .setContentsMargins (
@@ -880,13 +957,19 @@ def _create_env_creation_widget(self):
880
957
layout .addLayout (intro_layout )
881
958
layout .addSpacing (8 * AppStyle .MarginSize )
882
959
layout .addWidget (methods_group )
960
+ layout .addWidget (info_group )
883
961
layout .addStretch ()
884
962
885
963
env_creation_widget = QWidget (self )
886
964
env_creation_widget .setLayout (layout )
887
965
888
966
return env_creation_widget
889
967
968
+ def _on_env_creation_method_changed (
969
+ self , id_ : CreateEnvMethods , checked : bool
970
+ ):
971
+ self ._radio_buttons_to_info_widgets [id_ ].setVisible (checked )
972
+
890
973
891
974
class ConnectionPage (BaseConnectionPage ):
892
975
"""Page to display connection status and info for a remote machine."""
0 commit comments