@@ -485,6 +485,9 @@ def protect_toggle (toggle_widget):
485485 # SMB browser
486486 self .smb_store = Gtk .TreeStore (GObject .TYPE_PYOBJECT )
487487 self .btnSMBBrowse .set_sensitive (True )
488+ if not PYSMB_AVAILABLE :
489+ self .btnSMBBrowse .set_tooltip_text (_ ("Browsing requires pysmbc "
490+ "module" ))
488491 self .tvSMBBrowser .set_model (self .smb_store )
489492
490493 # SMB list columns
@@ -2501,21 +2504,31 @@ def install_python3_smbc_if_needed (self):
25012504 global PYSMB_AVAILABLE
25022505 global pysmb # Make the import of pysmb globally available
25032506 # Does the SMB client library need to be installed?
2504- if not PYSMB_AVAILABLE :
2505- debugprint ("No SMB client library present so attempting install" )
2506- try :
2507- pk = installpackage .PackageKit ()
2508- # The following call means a blocking, synchronous, D-Bus call
2509- pk .InstallPackageName (0 , 0 , "python3-smbc" )
2510- try :
2511- import pysmb
2512- PYSMB_AVAILABLE = True
2513- debugprint ("SMB client successfully installed and set up." )
2514- except :
2515- debugprint ("SMB client setup failed." )
2516- except :
2517- debugprint ("Error during installation/setup of SMB client." )
2518- return PYSMB_AVAILABLE
2507+ if PYSMB_AVAILABLE :
2508+ return True
2509+
2510+ debugprint ("No SMB client library present so attempting install" )
2511+
2512+ try :
2513+ pk = installpackage .PackageKit ()
2514+ # The following call means a blocking, synchronous, D-Bus call
2515+ pk .InstallPackageName (0 , 0 , "python3-smbc" )
2516+ except DBusException as e :
2517+ debugprint ("Error during installation/setup of SMB client." )
2518+ debugprint ("{}" .format (e ))
2519+ return False
2520+
2521+ try :
2522+ import pysmb
2523+ PYSMB_AVAILABLE = True
2524+ except ModuleNotFoundError as e :
2525+ debugprint ("SMB client setup failed." )
2526+ debugprint ("{}" .format (e ))
2527+ return False
2528+
2529+ debugprint ("SMB client successfully installed and set up." )
2530+
2531+ return True
25192532
25202533 def browse_smb_hosts (self ):
25212534 """Initialise the SMB tree store."""
@@ -2723,6 +2736,9 @@ def on_tvSMBBrowser_row_expanded (self, view, iter, path):
27232736
27242737 def set_btnSMBVerify_sensitivity (self , on ):
27252738 self .btnSMBVerify .set_sensitive (on )
2739+ if not PYSMB_AVAILABLE or not on :
2740+ self .btnSMBVerify .set_tooltip_text (_ ("Verification requires the "
2741+ "%s module" ) % "pysmbc" )
27262742
27272743 def on_entSMBURI_changed (self , ent ):
27282744 allowed_chars = string .ascii_letters + string .digits + '_-./:%[]@'
@@ -2760,7 +2776,8 @@ def on_tvSMBBrowser_cursor_changed(self, widget):
27602776 def on_btnSMBBrowse_clicked (self , button ):
27612777 """Check whether the needed SMB client library is available and"""
27622778 """install it if needed"""
2763- if not self .install_python3_smbc_if_needed (): return
2779+ if not self .install_python3_smbc_if_needed ():
2780+ return
27642781
27652782 self .btnSMBBrowseOk .set_sensitive (False )
27662783
@@ -2838,7 +2855,8 @@ def on_rbtnSMBAuthSet_toggled(self, widget):
28382855 def on_btnSMBVerify_clicked (self , button ):
28392856 """Check whether the needed SMB client library is available and"""
28402857 """install it if needed"""
2841- if not self .install_python3_smbc_if_needed (): return
2858+ if not self .install_python3_smbc_if_needed ():
2859+ return
28422860
28432861 uri = self .entSMBURI .get_text ()
28442862 (group , host , share , u , p ) = SMBURI (uri = uri ).separate ()
0 commit comments