+def SalomeConnectToPVServer():
+ """
+ Automatically connect to the right PVServer when not ("inside SALOME GUI" and "already connected").
+ """
+ __my_log("Connecting to PVServer ...")
+ server_url = ""
+ try:
+ isGUIConnected = pvserver.myPVServerService.GetGUIConnected()
+ if isGUIConnected and __getFromGUI():
+ __my_log("Importing pvsimple from GUI and already connected. Won't reconnect.")
+ return
+ server_url = pvserver.myPVServerService.FindOrStartPVServer(0)
+ # Extract host and port from URL:
+ a = server_url.split(':')
+ b = a[1].split('//')
+ host, port = b[-1], int(a[-1])
+ simple.Connect(host, port)
+ __my_log("Connected to %s!" % server_url)
+ if __getFromGUI():
+ pvserver.myPVServerService.SetGUIConnected(True)
+ except Exception as e:
+ __my_log("*******************************************")
+ __my_log("** Could not connect to a running PVServer!")
+ __my_log("*******************************************")
+ raise e
+ pass
+
+if __getFromGUI() < 1:
+ # Only if not in GUI (otherwise the createView will do the connection)
+ SalomeConnectToPVServer()
+del SalomeConnectToPVServer
+
+# Forward namespace of simple into current pvsimple: