RefactoringRope/Refactoring.py

branch
server_client_variant
changeset 167
3c8e875d0326
parent 166
6fc202183b3b
child 168
53d76b4fc1ac
equal deleted inserted replaced
166:6fc202183b3b 167:3c8e875d0326
18 else: 18 else:
19 path = os.path.join(os.path.dirname(__file__), 'rope_py2') 19 path = os.path.join(os.path.dirname(__file__), 'rope_py2')
20 str = unicode # __IGNORE_WARNING__ 20 str = unicode # __IGNORE_WARNING__
21 sys.path.insert(0, path) 21 sys.path.insert(0, path)
22 22
23 import rope
24 import rope.base.libutils 23 import rope.base.libutils
25 import rope.base.exceptions 24 import rope.base.exceptions
26 25
27 from PyQt5.QtWidgets import QMenu, QApplication, QDialog, QAction 26 from PyQt5.QtWidgets import QMenu, QApplication, QDialog, QAction
28 from PyQt5.Qsci import QsciScintilla 27 from PyQt5.Qsci import QsciScintilla
64 self.__helpDialog = None 63 self.__helpDialog = None
65 self.__progressDialog = None 64 self.__progressDialog = None
66 65
67 from FileSystemCommands import E5FileSystemCommands 66 from FileSystemCommands import E5FileSystemCommands
68 self.__fsCommands = E5FileSystemCommands(self.__e5project) 67 self.__fsCommands = E5FileSystemCommands(self.__e5project)
68
69 self.__methodMapping = {
70 "Config": self.__setConfig,
71 "Progress": self.__processProgress,
72 "QueryReferencesResult": self.__queryReferencesResult,
73 "QueryDefinitionResult": self.__queryDefinitionResult,
74 "QueryImplementationsResult": self.__queryImplementationsResult,
75 "SoaFinished": self.__soaFinished,
76
77 "FileSystemCommand": self.__fsCommands.processFileSystemCommand,
78
79 "ClientException": self.__processClientException,
80 }
69 81
70 def initActions(self): 82 def initActions(self):
71 """ 83 """
72 Public method to define the refactoring actions. 84 Public method to define the refactoring actions.
73 """ 85 """
659 self.__editConfig) 671 self.__editConfig)
660 self.refactoringEditConfigAct.setMenuRole(QAction.NoRole) 672 self.refactoringEditConfigAct.setMenuRole(QAction.NoRole)
661 self.actions.append(self.refactoringEditConfigAct) 673 self.actions.append(self.refactoringEditConfigAct)
662 674
663 self.refactoringHelpAct = E5Action( 675 self.refactoringHelpAct = E5Action(
664 self.tr('Rope help'), 676 self.tr('Rope Help'),
665 self.tr('Rope &Help'), 677 self.tr('Rope &Help'),
666 0, 0, 678 0, 0,
667 self, 'refactoring_help') 679 self, 'refactoring_help')
668 self.refactoringHelpAct.setStatusTip(self.tr( 680 self.refactoringHelpAct.setStatusTip(self.tr(
669 'Show help about the rope refactorings')) 681 'Show help about the rope refactorings'))
794 menu.addSeparator() 806 menu.addSeparator()
795 menu.addAction(self.refactoringEditConfigAct) 807 menu.addAction(self.refactoringEditConfigAct)
796 menu.addAction(self.refactoringHelpAct) 808 menu.addAction(self.refactoringHelpAct)
797 809
798 self.__mainMenu = menu 810 self.__mainMenu = menu
811
799 return menu 812 return menu
800 813
801 ################################################################## 814 ##################################################################
802 ## slots below implement general functionality 815 ## slots below implement general functionality
803 ################################################################## 816 ##################################################################
804 817
805 def __ropeInfo(self): 818 def __ropeInfo(self):
806 """ 819 """
807 Private slot to show some info about rope. 820 Private slot to show some info about rope.
808 """ 821 """
809 E5MessageBox.about( 822 if self.__ropeConfig:
810 self.__ui, 823 E5MessageBox.about(
811 self.tr("About rope"), 824 self.__ui,
812 self.tr("{0}\nVersion {1}\n\n{2}".format( 825 self.tr("About rope"),
813 rope.INFO, rope.VERSION, rope.COPYRIGHT))) 826 self.tr("{0}\nVersion {1}\n\n{2}".format(
827 self.__ropeConfig["RopeInfo"],
828 self.__ropeConfig["RopeVersion"],
829 self.__ropeConfig["RopeCopyright"])))
814 830
815 def __canUndo(self): 831 def __canUndo(self):
816 """ 832 """
817 Private slot to check, if there are changes to be undone. 833 Private slot to check, if there are changes to be undone.
818 834
2177 2193
2178 ################################################################## 2194 ##################################################################
2179 ## methods below are private utility methods 2195 ## methods below are private utility methods
2180 ################################################################## 2196 ##################################################################
2181 2197
2198 def __processProgress(self, params):
2199 """
2200 Private method to handle Progress commands.
2201
2202 @param params dictionary containing the progress data
2203 @type dict
2204 """
2205 subcommand = params["Subcommand"]
2206 if subcommand == "Init":
2207 if self.__progressDialog is not None:
2208 self.__progressDialog.reset()
2209
2210 progressDialog = RopeProgressDialog(
2211 self, params["Title"], params["Interruptable"], self.__ui)
2212 progressDialog.show()
2213 self.__progressDialog = progressDialog
2214 QApplication.processEvents()
2215
2216 elif subcommand == "Progress":
2217 if self.__progressDialog is not None:
2218 self.__progressDialog.updateProgress(params)
2219
2220 elif subcommand == "Reset":
2221 if self.__progressDialog is not None:
2222 self.__progressDialog.reset()
2223
2224 def __setConfig(self, params):
2225 """
2226 Private method to set the rope client configuration data.
2227
2228 @param params dictionary containing the configuration data
2229 @type dict
2230 """
2231 self.__ropeConfig = params
2232 # keys: RopeFolderName, DefaultConfig, RopeHelpFile,
2233 # RopeInfo, RopeVersion, RopeCopyright
2234
2182 def __ropeConfigFile(self): 2235 def __ropeConfigFile(self):
2183 """ 2236 """
2184 Private method to get the name of the rope configuration file. 2237 Private method to get the name of the rope configuration file.
2185 2238
2186 @return name of the rope configuration file (string) 2239 @return name of the rope configuration file (string)
2233 2286
2234 self.__projectopen = True 2287 self.__projectopen = True
2235 self.__projectpath = self.__e5project.getProjectPath() 2288 self.__projectpath = self.__e5project.getProjectPath()
2236 self.__projectLanguage = self.__e5project.getProjectLanguage() 2289 self.__projectLanguage = self.__e5project.getProjectLanguage()
2237 2290
2291 ok = False
2292
2238 if self.__projectLanguage.startswith("Python"): 2293 if self.__projectLanguage.startswith("Python"):
2239 if self.__projectLanguage == "Python2": 2294 # get interpreter from project first
2240 interpreter = Preferences.getDebugger("PythonInterpreter") 2295 interpreter = self.__e5project.getDebugProperty("INTERPRETER")
2241 elif self.__projectLanguage == "Python3": 2296 if not interpreter or not Utilities.isinpath(interpreter):
2242 interpreter = Preferences.getDebugger("Python3Interpreter") 2297 # get it from debugger settings second
2243 else: 2298 if self.__projectLanguage == "Python2":
2244 interpreter = "" 2299 interpreter = Preferences.getDebugger("PythonInterpreter")
2300 elif self.__projectLanguage == "Python3":
2301 interpreter = Preferences.getDebugger("Python3Interpreter")
2302 else:
2303 interpreter = ""
2245 if interpreter: 2304 if interpreter:
2246 ok = self.__startRefactoringClient(interpreter) 2305 ok = self.__startRefactoringClient(interpreter)
2247 if not ok: 2306 if not ok:
2248 self.__ui.appendToStderr(self.tr( 2307 self.__ui.appendToStderr(self.tr(
2249 "Project language '{0}' is not supported because" 2308 "Project language '{0}' is not supported because"
2257 self.__ui.appendToStderr(self.tr( 2316 self.__ui.appendToStderr(self.tr(
2258 "Project language '{0}' is not supported because no" 2317 "Project language '{0}' is not supported because no"
2259 " suitable interpreter is configured. Refactoring is" 2318 " suitable interpreter is configured. Refactoring is"
2260 " disabled." 2319 " disabled."
2261 ).format(self.__projectLanguage)) 2320 ).format(self.__projectLanguage))
2321 else:
2322 self.__ui.appendToStderr(self.tr(
2323 "Refactoring for project language '{0}' is not supported."
2324 ).format(self.__projectLanguage))
2325
2326 self.__mainMenu.menuAction().setEnabled(ok)
2262 2327
2263 def projectClosed(self): 2328 def projectClosed(self):
2264 """ 2329 """
2265 Public slot to handle the projectClosed signal. 2330 Public slot to handle the projectClosed signal.
2266 """ 2331 """
2267 for act in self.actions: 2332 for act in self.actions:
2268 act.setEnabled(False) 2333 act.setEnabled(False)
2334 self.__mainMenu.menuAction().setEnabled(False)
2269 2335
2270 self.stopClient() 2336 self.stopClient()
2271 2337
2272 self.__projectopen = False 2338 self.__projectopen = False
2273 self.__projectpath = '' 2339 self.__projectpath = ''
2363 @param method requested method name 2429 @param method requested method name
2364 @type str 2430 @type str
2365 @param params dictionary with method specific parameters 2431 @param params dictionary with method specific parameters
2366 @type dict 2432 @type dict
2367 """ 2433 """
2368 if method == "Config": 2434 self.__methodMapping[method](params)
2369 self.__ropeConfig = params 2435
2370 # keys: RopeFolderName, DefaultConfig 2436 def __processClientException(self, params):
2371 2437 """
2372 elif method == "ClientException": 2438 Private method to handle exceptions of the refactoring client.
2373 if params["ExceptionType"] == "ProtocolError": 2439
2374 E5MessageBox.critical( 2440 @param params dictionary containing the exception data
2375 None, 2441 @type dict
2376 self.tr("Refactoring Protocol Error"), 2442 """
2377 self.tr("""<p>The data received from the refactoring""" 2443 if params["ExceptionType"] == "ProtocolError":
2378 """ server could not be decoded. Please report""" 2444 E5MessageBox.critical(
2379 """ this issue with the received data to the""" 2445 None,
2380 """ eric bugs email address.</p>""" 2446 self.tr("Refactoring Protocol Error"),
2381 """<p>Error: {0}</p>""" 2447 self.tr("""<p>The data received from the refactoring"""
2382 """<p>Data:<br/>{0}</p>""").format( 2448 """ server could not be decoded. Please report"""
2383 params["ExceptionValue"], 2449 """ this issue with the received data to the"""
2384 Utilities.html_encode(params["ProtocolData"])), 2450 """ eric bugs email address.</p>"""
2385 E5MessageBox.StandardButtons( 2451 """<p>Error: {0}</p>"""
2386 E5MessageBox.Ok)) 2452 """<p>Data:<br/>{0}</p>""").format(
2387 else: 2453 params["ExceptionValue"],
2388 E5MessageBox.critical( 2454 Utilities.html_encode(params["ProtocolData"])),
2389 None, 2455 E5MessageBox.StandardButtons(
2390 self.tr("Refactoring Client Error"), 2456 E5MessageBox.Ok))
2391 self.tr("<p>An exception happened in the refactoring" 2457 else:
2392 " client. Please report it to the eric bugs" 2458 E5MessageBox.critical(
2393 " email address.</p>" 2459 None,
2394 "<p>Exception: {0}</p>" 2460 self.tr("Refactoring Client Error"),
2395 "<p>Value: {1}</p>" 2461 self.tr("<p>An exception happened in the refactoring"
2396 "Traceback: {2}</p>").format( 2462 " client. Please report it to the eric bugs"
2397 Utilities.html_encode(params["ExceptionType"]), 2463 " email address.</p>"
2398 params["ExceptionValue"], 2464 "<p>Exception: {0}</p>"
2399 params["Traceback"].replace("\r\n", "<br/>") 2465 "<p>Value: {1}</p>"
2400 .replace("\n", "<br/>").replace("\r", "<br/>"), 2466 "Traceback: {2}</p>").format(
2401 ), 2467 Utilities.html_encode(params["ExceptionType"]),
2402 E5MessageBox.StandardButtons( 2468 params["ExceptionValue"],
2403 E5MessageBox.Ok)) 2469 params["Traceback"].replace("\r\n", "<br/>")
2404 2470 .replace("\n", "<br/>").replace("\r", "<br/>"),
2405 elif method == "FileSystemCommand": 2471 ),
2406 self.__fsCommands.processFileSystemCommand(params) 2472 E5MessageBox.StandardButtons(
2407 2473 E5MessageBox.Ok))
2408 elif method == "ProgressInit":
2409 progressDialog = RopeProgressDialog(
2410 self, params["Title"], params["Interrutable"], self.__ui)
2411 progressDialog.show()
2412 self.__progressDialog = progressDialog
2413 QApplication.processEvents()
2414
2415 elif method == "Progress":
2416 if self.__progressDialog is not None:
2417 self.__progressDialog.updateProgress(params)
2418
2419 elif method == "ProgressReset":
2420 if self.__progressDialog is not None:
2421 self.__progressDialog.reset()
2422
2423 elif method == "QueryReferencesResult":
2424 self.__queryReferencesResult(params)
2425
2426 elif method == "QueryDefinitionResult":
2427 self.__queryDefinitionResult(params)
2428
2429 elif method == "QueryImplementationsResult":
2430 self.__queryImplementationsResult(params)
2431
2432 elif method == "SoaFinished":
2433 self.__soaFinished(params)
2434 2474
2435 def __startRefactoringClient(self, interpreter): 2475 def __startRefactoringClient(self, interpreter):
2436 """ 2476 """
2437 Private method to start the refactoring client. 2477 Private method to start the refactoring client.
2438 2478

eric ide

mercurial