@@ -58,6 +58,16 @@ PythonCodeCompletion::~PythonCodeCompletion()
5858{
5959}
6060
61+ wxString PythonCodeCompletion::GetExtraFile (const wxString &short_name, ConfigManager *mgr)
62+ {
63+ wxString fullname=mgr->GetDataFolder (false )+short_name;
64+ if (wxFileName::FileExists (fullname))
65+ return fullname;
66+ fullname=mgr->GetDataFolder (true )+short_name;
67+ return fullname;
68+ return wxEmptyString;
69+ }
70+
6171void PythonCodeCompletion::OnAttach ()
6272{
6373 // do whatever initialization you need for your plugin
@@ -67,6 +77,8 @@ void PythonCodeCompletion::OnAttach()
6777 // is FALSE, it means that the application did *not* "load"
6878 // (see: does not need) this plugin...
6979 // hook to editors
80+ py_server=NULL ;
81+ m_pImageList=NULL ;
7082 EditorHooks::HookFunctorBase* myhook = new EditorHooks::HookFunctor<PythonCodeCompletion>(this , &PythonCodeCompletion::EditorEventHook);
7183 m_EditorHookId = EditorHooks::RegisterHook (myhook);
7284
@@ -82,18 +94,26 @@ void PythonCodeCompletion::OnAttach()
8294
8395 int port = -1 ; // Port == -1 uses pipe to do RPC over redirected stdin/stdout of the process, otherwise uses a socket
8496
85- #ifdef __WXMSW__
86- wxString script = mgr->GetDataFolder (false )+_T (" \\ python\\ python_completion_server.py" );
87- #else
88- wxString script = mgr->GetDataFolder (false )+_T (" /python/python_completion_server.py" );
89- #endif
97+ #ifdef __WXMSW__
98+ wxString script = GetExtraFile (_T (" /python/python_completion_server.py" ),mgr);
99+ wxString stdlib = GetExtraFile (_T (" /python/STDLIB" ),mgr);
100+ #else
101+ wxString script = GetExtraFile (_T (" /python/python_completion_server.py" ),mgr);
102+ wxString stdlib = GetExtraFile (_T (" /python/STDLIB" ),mgr);
103+ #endif
104+ if (script==wxEmptyString || stdlib == wxEmptyString)
105+ {
106+ Manager::Get ()->GetLogManager ()->Log (_T (" PyCC: Missing python scripts. Try reinstalling the plugin." ));
107+ return ;
108+ }
90109 wxString command = wxString::Format (_T (" python -u %s %i" ),script.c_str (),port);
91110 Manager::Get ()->GetLogManager ()->Log (_T (" PYCC: Launching python on " )+script);
92111 Manager::Get ()->GetLogManager ()->Log (_T (" PYCC: with command " )+command);
93112 py_server = XmlRpcMgr::Get ().LaunchInterpreter (command,port);
94113 if (py_server->IsDead ())
95114 {
96- wxMessageBox (_ (" Error Starting Python Code Completion Server" ));
115+ Manager::Get ()->GetLogManager ()->Log (_ (" Error Starting Python Code Completion Server" ));
116+ return ;
97117 }
98118
99119
@@ -191,11 +211,6 @@ void PythonCodeCompletion::OnAttach()
191211
192212 if (port!=-1 )
193213 ::wxSleep (2 ); // need a delay to allow the xmlrpc server time to start
194- #ifdef __WXMSW__
195- wxString stdlib = mgr->GetDataFolder (false )+_T (" \\ python\\ STDLIB" );
196- #else
197- wxString stdlib = mgr->GetDataFolder (false )+_T (" /python/STDLIB" );
198- #endif
199214 Manager::Get ()->GetLogManager ()->Log (_ (" Loading stdlib" ));
200215
201216// Load the symbol lib synchronously
@@ -227,21 +242,22 @@ void PythonCodeCompletion::OnRelease(bool appShutDown)
227242 // NOTE: after this function, the inherited member variable
228243 // m_IsAttached will be FALSE...
229244 EditorHooks::UnregisterHook (m_EditorHookId, true );
230- if (!py_server->IsDead ()) // TODO: Really should wait until serverr is no longer busy and request it to terminate via XMLRPC
245+ if (py_server && !py_server->IsDead ()) // TODO: Really should wait until serverr is no longer busy and request it to terminate via XMLRPC
231246 py_server->KillProcess (true );
232- delete m_pImageList;
247+ if (m_pImageList)
248+ delete m_pImageList;
233249}
234250
235251void PythonCodeCompletion::OnStdLibLoaded (XmlRpcResponseEvent &event)
236252{
237253 if (event.GetState ()==XMLRPC_STATE_RESPONSE )
238254 {
239255 m_libs_loaded=true ;
240- Manager::Get ()->GetLogManager ()->Log (_ (" Python CC Initialized" ));
256+ Manager::Get ()->GetLogManager ()->Log (_ (" PyCC: Completion Library is Initialized" ));
241257 }
242258 if (event.GetState ()==XMLRPC_STATE_REQUEST_FAILED )
243259 {
244- Manager::Get ()->GetLogManager ()->Log (_ (" Python CC failed to initialize" ));
260+ Manager::Get ()->GetLogManager ()->Log (_ (" PyCC: Completion Library Failed to initialize" ));
245261 }
246262}
247263
0 commit comments