RefactoringRope/CodeAssistServer.py

branch
eric7
changeset 394
b34f5dd3db27
parent 392
b9b0a462123d
child 396
933b8fcd854f
equal deleted inserted replaced
393:8b554b390d6f 394:b34f5dd3db27
7 Module implementing the autocompletion interface to rope. 7 Module implementing the autocompletion interface to rope.
8 """ 8 """
9 9
10 import contextlib 10 import contextlib
11 import os 11 import os
12 import shutil
12 import sys 13 import sys
13 import uuid 14 import uuid
14 15
15 from PyQt6.QtCore import pyqtSlot, QCoreApplication, QTimer 16 from PyQt6.QtCore import pyqtSlot, QCoreApplication, QTimer
16 17
186 configfile = None 187 configfile = None
187 if idString in self.__clientConfigs: 188 if idString in self.__clientConfigs:
188 ropedir = self.__clientConfigs[idString] 189 ropedir = self.__clientConfigs[idString]
189 if ropedir: 190 if ropedir:
190 configfile = os.path.join(ropedir, "config.py") 191 configfile = os.path.join(ropedir, "config.py")
191 if not os.path.exists(configfile): 192
192 configfile = None
193 return configfile 193 return configfile
194 194
195 def __configChanged(self, idString): 195 def __configChanged(self, idString):
196 """ 196 """
197 Private slot called, when the rope config file has changed. 197 Private slot called, when the rope config file has changed.
216 editor = MiniEditor(configfile) 216 editor = MiniEditor(configfile)
217 editor.show() 217 editor.show()
218 editor.editorSaved.connect(lambda: self.__configChanged(idString)) 218 editor.editorSaved.connect(lambda: self.__configChanged(idString))
219 self.__editors[idString] = editor 219 self.__editors[idString] = editor
220 return 220 return
221 else:
222 EricMessageBox.critical(
223 self.__ui,
224 self.tr("Configure rope"),
225 self.tr(
226 """The rope configuration file '{0}' does not exist."""
227 ).format(configfile),
228 )
221 else: 229 else:
222 EricMessageBox.critical( 230 EricMessageBox.critical(
223 self.__ui, 231 self.__ui,
224 self.tr("Configure Rope"), 232 self.tr("Configure rope"),
225 self.tr( 233 self.tr(
226 """The Rope configuration file '{0}' does""" """ not exist.""" 234 "The path of the rope configuration file could not be determined."
235 ).format(configfile),
236 )
237
238 def createConfig(self, idString):
239 """
240 Public slot to create a new default rope configuration file.
241
242 @param idString id for which to create the configuration file
243 @type str
244 """
245 configfile = self.__ropeConfigFile(idString)
246 if configfile:
247 defaultConfigFile = os.path.join(
248 os.path.dirname(__file__), "default_config.py"
249 )
250 try:
251 shutil.copyfile(defaultConfigFile, configfile)
252 except OSError as err:
253 EricMessageBox.critical(
254 self.__ui,
255 self.tr("Configure Rope"),
256 self.tr(
257 "<p>A new Rope default configuration could not be written to"
258 " the file '{0}'.</p><p>Reason: {1}</p>"
259 ).format(configfile, str(err)),
260 )
261 else:
262 EricMessageBox.critical(
263 self.__ui,
264 self.tr("Configure rope"),
265 self.tr(
266 "The path of the rope configuration file could not be determined."
227 ).format(configfile), 267 ).format(configfile),
228 ) 268 )
229 269
230 def requestCompletions(self, editor, context, acText): 270 def requestCompletions(self, editor, context, acText):
231 """ 271 """

eric ide

mercurial