210 Private method to get the source extensions of a programming language. |
206 Private method to get the source extensions of a programming language. |
211 |
207 |
212 @param language programming language (string) |
208 @param language programming language (string) |
213 @return source extensions (list of string) |
209 @return source extensions (list of string) |
214 """ |
210 """ |
215 if language == "Python2": |
211 if language == "Python3": |
216 extensions = Preferences.getPython("PythonExtensions") |
|
217 # *.py and *.pyw should always be associated with source files |
|
218 for ext in [".py", ".pyw"]: |
|
219 if ext not in extensions: |
|
220 extensions.append(ext) |
|
221 return extensions |
|
222 elif language == "Python3": |
|
223 extensions = Preferences.getPython("Python3Extensions") |
212 extensions = Preferences.getPython("Python3Extensions") |
224 # *.py and *.pyw should always be associated with source files |
213 # *.py and *.pyw should always be associated with source files |
225 for ext in [".py", ".pyw"]: |
214 for ext in [".py", ".pyw"]: |
226 if ext not in extensions: |
215 if ext not in extensions: |
227 extensions.append(ext) |
216 extensions.append(ext) |
273 self.__fileTypeCallbacks = {} |
262 self.__fileTypeCallbacks = {} |
274 self.__lexerAssociationCallbacks = {} |
263 self.__lexerAssociationCallbacks = {} |
275 self.__binaryTranslationsCallbacks = {} |
264 self.__binaryTranslationsCallbacks = {} |
276 |
265 |
277 self.__projectTypes = { |
266 self.__projectTypes = { |
278 "Qt4": self.tr("PyQt4 GUI (deprecated)"), |
|
279 "Qt4C": self.tr("PyQt4 Console (deprecated)"), |
|
280 "PyQt5": self.tr("PyQt5 GUI"), |
267 "PyQt5": self.tr("PyQt5 GUI"), |
281 "PyQt5C": self.tr("PyQt5 Console"), |
268 "PyQt5C": self.tr("PyQt5 Console"), |
282 "E6Plugin": self.tr("Eric6 Plugin"), |
269 "E6Plugin": self.tr("Eric6 Plugin"), |
283 "Console": self.tr("Console"), |
270 "Console": self.tr("Console"), |
284 "Other": self.tr("Other"), |
271 "Other": self.tr("Other"), |
285 } |
272 } |
286 |
273 |
287 self.__projectProgLanguages = { |
274 self.__projectProgLanguages = { |
288 "Python2": ["Qt4", "Qt4C", "PyQt5", "PyQt5C", |
275 "Python3": ["PyQt5", "PyQt5C", "E6Plugin", "Console", "Other"], |
289 "E6Plugin", "Console", "Other"], |
|
290 "Python3": ["Qt4", "Qt4C", "PyQt5", "PyQt5C", |
|
291 "E6Plugin", "Console", "Other"], |
|
292 "MicroPython": ["Console", "Other"], |
276 "MicroPython": ["Console", "Other"], |
293 "Ruby": ["Qt4", "Qt4C", "Console", "Other"], |
277 "Ruby": ["Console", "Other"], |
294 "JavaScript": ["Other"], |
278 "JavaScript": ["Other"], |
295 } |
279 } |
296 |
280 |
297 pyside_py2, pyside_py3 = Utilities.checkPyside("1") |
281 if Utilities.checkPyside(): |
298 if pyside_py2 or pyside_py3: |
|
299 self.__projectTypes["PySide"] = self.tr("PySide GUI") |
|
300 self.__projectTypes["PySideC"] = self.tr("PySide Console") |
|
301 if pyside_py2: |
|
302 self.__projectProgLanguages["Python2"].extend( |
|
303 ["PySide", "PySideC"]) |
|
304 if pyside_py3: |
|
305 self.__projectProgLanguages["Python3"].extend( |
|
306 ["PySide", "PySideC"]) |
|
307 |
|
308 pyside2_py2, pyside2_py3 = Utilities.checkPyside("2") |
|
309 if pyside2_py2 or pyside2_py3: |
|
310 self.__projectTypes["PySide2"] = self.tr("PySide2 GUI") |
282 self.__projectTypes["PySide2"] = self.tr("PySide2 GUI") |
311 self.__projectTypes["PySide2C"] = self.tr("PySide2 Console") |
283 self.__projectTypes["PySide2C"] = self.tr("PySide2 Console") |
312 if pyside2_py2: |
284 self.__projectProgLanguages["Python3"].extend( |
313 self.__projectProgLanguages["Python2"].extend( |
285 ["PySide2", "PySide2C"]) |
314 ["PySide2", "PySide2C"]) |
|
315 if pyside2_py3: |
|
316 self.__projectProgLanguages["Python3"].extend( |
|
317 ["PySide2", "PySide2C"]) |
|
318 |
286 |
319 def getProjectTypes(self, progLanguage=""): |
287 def getProjectTypes(self, progLanguage=""): |
320 """ |
288 """ |
321 Public method to get the list of supported project types. |
289 Public method to get the list of supported project types. |
322 |
290 |
367 @keyparam progLanguages programming languages supported by the |
335 @keyparam progLanguages programming languages supported by the |
368 project type (list of string) |
336 project type (list of string) |
369 """ |
337 """ |
370 if progLanguages: |
338 if progLanguages: |
371 for progLanguage in progLanguages: |
339 for progLanguage in progLanguages: |
|
340 if progLanguage in ["Python", "Python2"]: |
|
341 # ignore that silently for Python2 |
|
342 return |
|
343 |
372 if progLanguage not in self.__projectProgLanguages: |
344 if progLanguage not in self.__projectProgLanguages: |
373 E5MessageBox.critical( |
345 E5MessageBox.critical( |
374 self.ui, |
346 self.ui, |
375 self.tr("Registering Project Type"), |
347 self.tr("Registering Project Type"), |
376 self.tr( |
348 self.tr( |
377 """<p>The Programming Language <b>{0}</b> is not""" |
349 """<p>The Programming Language <b>{0}</b> is not""" |
378 """ supported.</p>""") |
350 """ supported (project type: {1}).</p>""") |
379 .format(progLanguage) |
351 .format(progLanguage, type_) |
380 ) |
352 ) |
381 return |
353 return |
382 |
354 |
383 if type_ in self.__projectProgLanguages[progLanguage]: |
355 if type_ in self.__projectProgLanguages[progLanguage]: |
384 E5MessageBox.critical( |
356 E5MessageBox.critical( |
614 |
586 |
615 # Protobuf Files |
587 # Protobuf Files |
616 self.pdata["FILETYPES"]["*.proto"] = "PROTOCOLS" |
588 self.pdata["FILETYPES"]["*.proto"] = "PROTOCOLS" |
617 |
589 |
618 # Forms |
590 # Forms |
619 if self.pdata["PROJECTTYPE"] in ["Qt4", "PyQt5", |
591 if self.pdata["PROJECTTYPE"] in ["E6Plugin", |
620 "E6Plugin", "PySide", |
592 "PyQt5", |
621 "PySide2"]: |
593 "PySide2"]: |
622 self.pdata["FILETYPES"]["*.ui"] = "FORMS" |
594 self.pdata["FILETYPES"]["*.ui"] = "FORMS" |
623 |
595 |
624 # Resources |
596 # Resources |
625 if self.pdata["PROJECTTYPE"] in ["Qt4", "Qt4C", |
597 if self.pdata["PROJECTTYPE"] in ["E6Plugin", |
626 "E6Plugin", |
|
627 "PyQt5", "PyQt5C", |
598 "PyQt5", "PyQt5C", |
628 "PySide", "PySideC", |
|
629 "PySide2", "PySide2C"]: |
599 "PySide2", "PySide2C"]: |
630 self.pdata["FILETYPES"]["*.qrc"] = "RESOURCES" |
600 self.pdata["FILETYPES"]["*.qrc"] = "RESOURCES" |
631 |
601 |
632 # Translations |
602 # Translations |
633 if self.pdata["PROJECTTYPE"] in ["Qt4", "Qt4C", |
603 if self.pdata["PROJECTTYPE"] in ["E6Plugin", |
634 "E6Plugin", |
|
635 "PyQt5", "PyQt5C", |
604 "PyQt5", "PyQt5C", |
636 "PySide", "PySideC", |
|
637 "PySide2", "PySide2C"]: |
605 "PySide2", "PySide2C"]: |
638 self.pdata["FILETYPES"]["*.ts"] = "TRANSLATIONS" |
606 self.pdata["FILETYPES"]["*.ts"] = "TRANSLATIONS" |
639 self.pdata["FILETYPES"]["*.qm"] = "TRANSLATIONS" |
607 self.pdata["FILETYPES"]["*.qm"] = "TRANSLATIONS" |
640 |
608 |
641 # Project type specific ones |
609 # Project type specific ones |
652 def updateFileTypes(self): |
620 def updateFileTypes(self): |
653 """ |
621 """ |
654 Public method to update the filetype associations with new default |
622 Public method to update the filetype associations with new default |
655 values. |
623 values. |
656 """ |
624 """ |
657 if self.pdata["PROJECTTYPE"] in ["Qt4", "Qt4C", |
625 if self.pdata["PROJECTTYPE"] in ["E6Plugin", |
658 "E6Plugin", |
|
659 "PyQt5", "PyQt5C", |
626 "PyQt5", "PyQt5C", |
660 "PySide", "PySideC", |
|
661 "PySide2", "PySide2C"]: |
627 "PySide2", "PySide2C"]: |
662 if "*.ts" not in self.pdata["FILETYPES"]: |
628 if "*.ts" not in self.pdata["FILETYPES"]: |
663 self.pdata["FILETYPES"]["*.ts"] = "TRANSLATIONS" |
629 self.pdata["FILETYPES"]["*.ts"] = "TRANSLATIONS" |
664 if "*.qm" not in self.pdata["FILETYPES"]: |
630 if "*.qm" not in self.pdata["FILETYPES"]: |
665 self.pdata["FILETYPES"]["*.qm"] = "TRANSLATIONS" |
631 self.pdata["FILETYPES"]["*.qm"] = "TRANSLATIONS" |
1412 from .AddLanguageDialog import AddLanguageDialog |
1378 from .AddLanguageDialog import AddLanguageDialog |
1413 dlg = AddLanguageDialog(self.parent()) |
1379 dlg = AddLanguageDialog(self.parent()) |
1414 if dlg.exec_() == QDialog.Accepted: |
1380 if dlg.exec_() == QDialog.Accepted: |
1415 lang = dlg.getSelectedLanguage() |
1381 lang = dlg.getSelectedLanguage() |
1416 if self.pdata["PROJECTTYPE"] in [ |
1382 if self.pdata["PROJECTTYPE"] in [ |
1417 "Qt4", "Qt4C", "PyQt5", "PyQt5C", "E6Plugin", |
1383 "PyQt5", "PyQt5C", "E6Plugin", "PySide2", "PySide2C" |
1418 "PySide", "PySideC", "PySide2", "PySide2C" |
|
1419 ]: |
1384 ]: |
1420 langFile = self.pdata["TRANSLATIONPATTERN"].replace( |
1385 langFile = self.pdata["TRANSLATIONPATTERN"].replace( |
1421 "%language%", lang) |
1386 "%language%", lang) |
1422 self.appendFile(langFile) |
1387 self.appendFile(langFile) |
1423 self.projectLanguageAddedByCode.emit(lang) |
1388 self.projectLanguageAddedByCode.emit(lang) |
2383 return |
2348 return |
2384 |
2349 |
2385 # create an empty __init__.py file to make it a Python package |
2350 # create an empty __init__.py file to make it a Python package |
2386 # (only for Python and Python3) |
2351 # (only for Python and Python3) |
2387 if self.pdata["PROGLANGUAGE"] in [ |
2352 if self.pdata["PROGLANGUAGE"] in [ |
2388 "Python", "Python2", "Python3", "MicroPython" |
2353 "Python3", "MicroPython" |
2389 ]: |
2354 ]: |
2390 fn = os.path.join(self.ppath, "__init__.py") |
2355 fn = os.path.join(self.ppath, "__init__.py") |
2391 f = open(fn, "w", encoding="utf-8") |
2356 f = open(fn, "w", encoding="utf-8") |
2392 f.close() |
2357 f.close() |
2393 self.appendFile(fn, True) |
2358 self.appendFile(fn, True) |
2497 self.newProjectAddFiles(ms) |
2462 self.newProjectAddFiles(ms) |
2498 addAllToVcs = res |
2463 addAllToVcs = res |
2499 # create an empty __init__.py file to make it a Python package |
2464 # create an empty __init__.py file to make it a Python package |
2500 # if none exists (only for Python and Python3) |
2465 # if none exists (only for Python and Python3) |
2501 if self.pdata["PROGLANGUAGE"] in [ |
2466 if self.pdata["PROGLANGUAGE"] in [ |
2502 "Python", "Python2", "Python3", "MicroPython" |
2467 "Python3", "MicroPython" |
2503 ]: |
2468 ]: |
2504 fn = os.path.join(self.ppath, "__init__.py") |
2469 fn = os.path.join(self.ppath, "__init__.py") |
2505 if not os.path.exists(fn): |
2470 if not os.path.exists(fn): |
2506 f = open(fn, "w", encoding="utf-8") |
2471 f = open(fn, "w", encoding="utf-8") |
2507 f.close() |
2472 f.close() |
2729 for qm in qmlist: |
2694 for qm in qmlist: |
2730 self.pdata["TRANSLATIONS"].append(qm) |
2695 self.pdata["TRANSLATIONS"].append(qm) |
2731 self.projectLanguageAdded.emit(qm) |
2696 self.projectLanguageAdded.emit(qm) |
2732 if not self.pdata["MAINSCRIPT"] and bool(mainscriptname): |
2697 if not self.pdata["MAINSCRIPT"] and bool(mainscriptname): |
2733 if self.pdata["PROGLANGUAGE"] in [ |
2698 if self.pdata["PROGLANGUAGE"] in [ |
2734 "Python", "Python2", "Python3", "MicroPython" |
2699 "Python3", "MicroPython" |
2735 ]: |
2700 ]: |
2736 self.pdata["MAINSCRIPT"] = '{0}.py'.format(mainscriptname) |
2701 self.pdata["MAINSCRIPT"] = '{0}.py'.format(mainscriptname) |
2737 elif self.pdata["PROGLANGUAGE"] == "Ruby": |
2702 elif self.pdata["PROGLANGUAGE"] == "Ruby": |
2738 self.pdata["MAINSCRIPT"] = '{0}.rb'.format(mainscriptname) |
2703 self.pdata["MAINSCRIPT"] = '{0}.rb'.format(mainscriptname) |
2739 self.setDirty(True) |
2704 self.setDirty(True) |
3442 """ |
3407 """ |
3443 return self.pdata["MIXEDLANGUAGE"] |
3408 return self.pdata["MIXEDLANGUAGE"] |
3444 |
3409 |
3445 def isPythonProject(self): |
3410 def isPythonProject(self): |
3446 """ |
3411 """ |
3447 Public method to check, if this project is a Python2 or Python3 |
3412 Public method to check, if this project is a Python3 or MicroPython |
3448 project. |
3413 project. |
3449 |
3414 |
3450 @return flag indicating a Python project (boolean) |
3415 @return flag indicating a Python project (boolean) |
3451 """ |
3416 """ |
3452 return self.pdata["PROGLANGUAGE"] in ["Python", "Python2", |
3417 return self.pdata["PROGLANGUAGE"] in ["Python3", "MicroPython"] |
3453 "Python3", "MicroPython"] |
|
3454 |
3418 |
3455 def isPy3Project(self): |
3419 def isPy3Project(self): |
3456 """ |
3420 """ |
3457 Public method to check, if this project is a Python3 project. |
3421 Public method to check, if this project is a Python3 project. |
3458 |
3422 |
3459 @return flag indicating a Python3 project (boolean) |
3423 @return flag indicating a Python3 project (boolean) |
3460 """ |
3424 """ |
3461 return self.pdata["PROGLANGUAGE"] == "Python3" |
3425 return self.pdata["PROGLANGUAGE"] == "Python3" |
3462 |
3426 |
3463 def isPy2Project(self): |
|
3464 """ |
|
3465 Public method to check, if this project is a Python2 project. |
|
3466 |
|
3467 @return flag indicating a Python2 project (boolean) |
|
3468 """ |
|
3469 return self.pdata["PROGLANGUAGE"] in ["Python", "Python2"] |
|
3470 |
|
3471 def isMicroPythonProject(self): |
3427 def isMicroPythonProject(self): |
3472 """ |
3428 """ |
3473 Public method to check, if this project is a MicroPython project. |
3429 Public method to check, if this project is a MicroPython project. |
3474 |
3430 |
3475 @return flag indicating a MicroPython project |
3431 @return flag indicating a MicroPython project |
5114 tbasename = os.path.splitext(tfn)[0] |
5070 tbasename = os.path.splitext(tfn)[0] |
5115 self.codeProfileAct.setEnabled( |
5071 self.codeProfileAct.setEnabled( |
5116 os.path.isfile("{0}.profile".format(basename)) or |
5072 os.path.isfile("{0}.profile".format(basename)) or |
5117 os.path.isfile("{0}.profile".format(tbasename))) |
5073 os.path.isfile("{0}.profile".format(tbasename))) |
5118 self.codeCoverageAct.setEnabled( |
5074 self.codeCoverageAct.setEnabled( |
5119 (self.isPy3Project() or self.isPy2Project()) and |
5075 self.isPy3Project() and |
5120 (os.path.isfile("{0}.coverage".format(basename)) or |
5076 (os.path.isfile("{0}.coverage".format(basename)) or |
5121 os.path.isfile("{0}.coverage".format(tbasename)))) |
5077 os.path.isfile("{0}.coverage".format(tbasename)))) |
5122 else: |
5078 else: |
5123 self.codeProfileAct.setEnabled(False) |
5079 self.codeProfileAct.setEnabled(False) |
5124 self.codeCoverageAct.setEnabled(False) |
5080 self.codeCoverageAct.setEnabled(False) |