eric7/Debugger/DebugUI.py

branch
eric7
changeset 8529
569623270e29
parent 8524
595547ab8d6f
child 8568
890dfe038613
equal deleted inserted replaced
8528:2175f268ad9b 8529:569623270e29
86 self.editorOpen = False 86 self.editorOpen = False
87 87
88 # read the saved debug info values 88 # read the saved debug info values
89 self.lastUsedVenvName = Preferences.Prefs.settings.value( 89 self.lastUsedVenvName = Preferences.Prefs.settings.value(
90 'DebugInfo/VirtualEnvironment', '') 90 'DebugInfo/VirtualEnvironment', '')
91 self.scriptsHistory = Preferences.toList(
92 Preferences.Prefs.settings.value('DebugInfo/ScriptsHistory'))
91 self.argvHistory = Preferences.toList( 93 self.argvHistory = Preferences.toList(
92 Preferences.Prefs.settings.value('DebugInfo/ArgumentsHistory')) 94 Preferences.Prefs.settings.value('DebugInfo/ArgumentsHistory'))
93 self.wdHistory = Preferences.toList( 95 self.wdHistory = Preferences.toList(
94 Preferences.Prefs.settings.value( 96 Preferences.Prefs.settings.value(
95 'DebugInfo/WorkingDirectoryHistory')) 97 'DebugInfo/WorkingDirectoryHistory'))
632 act.triggered.connect(self.__clearBreakpoints) 634 act.triggered.connect(self.__clearBreakpoints)
633 self.actions.append(act) 635 self.actions.append(act)
634 636
635 self.debugActGrp.setEnabled(False) 637 self.debugActGrp.setEnabled(False)
636 self.dbgSetBpActGrp.setEnabled(False) 638 self.dbgSetBpActGrp.setEnabled(False)
637 self.runAct.setEnabled(False)
638 self.runProjectAct.setEnabled(False) 639 self.runProjectAct.setEnabled(False)
639 self.profileAct.setEnabled(False)
640 self.profileProjectAct.setEnabled(False) 640 self.profileProjectAct.setEnabled(False)
641 self.coverageAct.setEnabled(False)
642 self.coverageProjectAct.setEnabled(False) 641 self.coverageProjectAct.setEnabled(False)
643 self.debugAct.setEnabled(False)
644 self.debugProjectAct.setEnabled(False) 642 self.debugProjectAct.setEnabled(False)
645 self.restartAct.setEnabled(False) 643 self.restartAct.setEnabled(False)
646 self.stopAct.setEnabled(False) 644 self.stopAct.setEnabled(False)
647 645
648 def initMenus(self): 646 def initMenus(self):
729 toolbarManager.addAction(self.coverageProjectAct, 727 toolbarManager.addAction(self.coverageProjectAct,
730 starttb.windowTitle()) 728 starttb.windowTitle())
731 729
732 return [starttb, debugtb] 730 return [starttb, debugtb]
733 731
732 def setScriptsHistory(self, scriptName, clearHistories=False,
733 history=None):
734 """
735 Public slot to initialize the scripts history.
736
737 @param scriptName script name
738 @type str
739 @param clearHistories flag indicating, that the list should
740 be cleared (defaults to False)
741 @type bool (optional)
742 @param history list of history entries to be set (defaults to None)
743 @type list of str (optional)
744 """
745 if clearHistories:
746 del self.scriptsHistory[1:]
747 elif history is not None:
748 self.scriptsHistory = history[:]
749 else:
750 if scriptName in self.scriptsHistory:
751 self.scriptsHistory.remove(scriptName)
752 self.scriptsHistory.insert(0, scriptName)
753
734 def setArgvHistory(self, argsStr, clearHistories=False, history=None): 754 def setArgvHistory(self, argsStr, clearHistories=False, history=None):
735 """ 755 """
736 Public slot to initialize the argv history. 756 Public slot to initialize the argv history.
737 757
738 @param argsStr the commandline arguments (string) 758 @param argsStr the commandline arguments (string)
850 def __lastEditorClosed(self): 870 def __lastEditorClosed(self):
851 """ 871 """
852 Private slot to handle the closeProgram signal. 872 Private slot to handle the closeProgram signal.
853 """ 873 """
854 self.editorOpen = False 874 self.editorOpen = False
855 self.debugAct.setEnabled(False)
856 self.runAct.setEnabled(False)
857 self.profileAct.setEnabled(False)
858 self.coverageAct.setEnabled(False)
859 self.debugActGrp.setEnabled(False) 875 self.debugActGrp.setEnabled(False)
860 self.dbgSetBpActGrp.setEnabled(False) 876 self.dbgSetBpActGrp.setEnabled(False)
861 self.lastAction = -1 877 self.lastAction = -1
862 if not self.projectOpen: 878 if not self.projectOpen:
863 self.restartAct.setEnabled(False) 879 self.restartAct.setEnabled(False)
884 if editor.isPy3File(): 900 if editor.isPy3File():
885 cap = self.debugServer.getClientCapabilities('Python3') 901 cap = self.debugServer.getClientCapabilities('Python3')
886 elif editor.isRubyFile(): 902 elif editor.isRubyFile():
887 cap = self.debugServer.getClientCapabilities('Ruby') 903 cap = self.debugServer.getClientCapabilities('Ruby')
888 904
889 if not self.passive:
890 self.runAct.setEnabled(cap & HasInterpreter)
891 self.coverageAct.setEnabled(cap & HasCoverage)
892 self.profileAct.setEnabled(cap & HasProfiler)
893 self.debugAct.setEnabled(cap & HasDebugger)
894 self.dbgSetBpActGrp.setEnabled(cap & HasDebugger) 905 self.dbgSetBpActGrp.setEnabled(cap & HasDebugger)
895 if editor.curLineHasBreakpoint(): 906 if editor.curLineHasBreakpoint():
896 self.dbgEditBpAct.setEnabled(True) 907 self.dbgEditBpAct.setEnabled(True)
897 else: 908 else:
898 self.dbgEditBpAct.setEnabled(False) 909 self.dbgEditBpAct.setEnabled(False)
901 self.dbgPrevBpAct.setEnabled(True) 912 self.dbgPrevBpAct.setEnabled(True)
902 else: 913 else:
903 self.dbgNextBpAct.setEnabled(False) 914 self.dbgNextBpAct.setEnabled(False)
904 self.dbgPrevBpAct.setEnabled(False) 915 self.dbgPrevBpAct.setEnabled(False)
905 else: 916 else:
906 self.runAct.setEnabled(False)
907 self.coverageAct.setEnabled(False)
908 self.profileAct.setEnabled(False)
909 self.debugAct.setEnabled(False)
910 self.dbgSetBpActGrp.setEnabled(False) 917 self.dbgSetBpActGrp.setEnabled(False)
911 918
912 def __cursorChanged(self, editor): 919 def __cursorChanged(self, editor):
913 """ 920 """
914 Private slot handling the cursorChanged signal of the viewmanager. 921 Private slot handling the cursorChanged signal of the viewmanager.
961 968
962 def clearHistories(self): 969 def clearHistories(self):
963 """ 970 """
964 Public method to clear the various debug histories. 971 Public method to clear the various debug histories.
965 """ 972 """
973 self.scriptsHistory = []
966 self.argvHistory = [] 974 self.argvHistory = []
967 self.wdHistory = [] 975 self.wdHistory = []
968 self.envHistory = [] 976 self.envHistory = []
969 self.multiprocessNoDebugHistory = [] 977 self.multiprocessNoDebugHistory = []
970 978
979 Preferences.Prefs.settings.setValue(
980 'DebugInfo/ScriptsHistory', self.scriptsHistory)
971 Preferences.Prefs.settings.setValue( 981 Preferences.Prefs.settings.setValue(
972 'DebugInfo/ArgumentsHistory', self.argvHistory) 982 'DebugInfo/ArgumentsHistory', self.argvHistory)
973 Preferences.Prefs.settings.setValue( 983 Preferences.Prefs.settings.setValue(
974 'DebugInfo/WorkingDirectoryHistory', self.wdHistory) 984 'DebugInfo/WorkingDirectoryHistory', self.wdHistory)
975 Preferences.Prefs.settings.setValue( 985 Preferences.Prefs.settings.setValue(
983 def shutdown(self): 993 def shutdown(self):
984 """ 994 """
985 Public method to perform shutdown actions. 995 Public method to perform shutdown actions.
986 """ 996 """
987 # Just save the 10 most recent entries 997 # Just save the 10 most recent entries
998 del self.scriptsHistory[10:]
988 del self.argvHistory[10:] 999 del self.argvHistory[10:]
989 del self.wdHistory[10:] 1000 del self.wdHistory[10:]
990 del self.envHistory[10:] 1001 del self.envHistory[10:]
991 1002
992 Preferences.Prefs.settings.setValue( 1003 Preferences.Prefs.settings.setValue(
993 'DebugInfo/VirtualEnvironment', self.lastUsedVenvName) 1004 'DebugInfo/VirtualEnvironment', self.lastUsedVenvName)
1005 Preferences.Prefs.settings.setValue(
1006 'DebugInfo/ScriptsHistory', self.scriptsHistory)
994 Preferences.Prefs.settings.setValue( 1007 Preferences.Prefs.settings.setValue(
995 'DebugInfo/ArgumentsHistory', self.argvHistory) 1008 'DebugInfo/ArgumentsHistory', self.argvHistory)
996 Preferences.Prefs.settings.setValue( 1009 Preferences.Prefs.settings.setValue(
997 'DebugInfo/WorkingDirectoryHistory', self.wdHistory) 1010 'DebugInfo/WorkingDirectoryHistory', self.wdHistory)
998 Preferences.Prefs.settings.setValue( 1011 Preferences.Prefs.settings.setValue(
1687 1700
1688 def __coverageScript(self): 1701 def __coverageScript(self):
1689 """ 1702 """
1690 Private slot to handle the coverage of script action. 1703 Private slot to handle the coverage of script action.
1691 """ 1704 """
1692 self.__doCoverage(False) 1705 self.doCoverage(False)
1693 1706
1694 def __coverageProject(self): 1707 def __coverageProject(self):
1695 """ 1708 """
1696 Private slot to handle the coverage of project action. 1709 Private slot to handle the coverage of project action.
1697 """ 1710 """
1698 self.__compileChangedProjectFiles() 1711 self.__compileChangedProjectFiles()
1699 self.__doCoverage(True) 1712 self.doCoverage(True)
1700 1713
1701 def __doCoverage(self, runProject): 1714 def doCoverage(self, runProject, script=""):
1702 """ 1715 """
1703 Private method to handle the coverage actions. 1716 Public method to handle the coverage actions.
1704 1717
1705 @param runProject flag indicating coverage of the current project 1718 @param runProject flag indicating coverage of the current project
1706 (True) or script (false) 1719 (True) or script (false)
1720 @type bool
1721 @param script name of a script (optional)
1722 @type str
1707 """ 1723 """
1708 from .StartDialog import StartDialog 1724 from .StartDialog import StartDialog
1709 1725
1710 self.__resetUI() 1726 self.__resetUI()
1711 doNotStart = False 1727 doNotStart = False
1715 cap = ( 1731 cap = (
1716 self.tr("Coverage of Project") 1732 self.tr("Coverage of Project")
1717 if runProject else 1733 if runProject else
1718 self.tr("Coverage of Script") 1734 self.tr("Coverage of Script")
1719 ) 1735 )
1736 if runProject:
1737 scriptName = self.project.getMainScript(True)
1738 elif script:
1739 scriptName = script
1740 elif self.lastDebuggedFile:
1741 scriptName = self.lastDebuggedFile
1742 else:
1743 scriptName = ""
1720 dlg = StartDialog( 1744 dlg = StartDialog(
1721 cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory, 1745 cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory,
1722 self.envHistory, self.exceptions, self.ui, 2, 1746 self.envHistory, self.exceptions, self.ui, 2,
1723 autoClearShell=self.autoClearShell, 1747 autoClearShell=self.autoClearShell,
1724 configOverride=self.overrideGlobalConfig) 1748 configOverride=self.overrideGlobalConfig,
1749 forProject=runProject, scriptName=scriptName,
1750 scriptsList=self.scriptsHistory)
1725 if dlg.exec() == QDialog.DialogCode.Accepted: 1751 if dlg.exec() == QDialog.DialogCode.Accepted:
1726 (lastUsedVenvName, argv, wd, env, exceptions, clearShell, 1752 (lastUsedVenvName, scriptName, argv, wd, env, exceptions,
1727 console) = dlg.getData() 1753 clearShell, console) = dlg.getData()
1728 configOverride = dlg.getGlobalOverrideData() 1754 configOverride = dlg.getGlobalOverrideData()
1729 eraseCoverage = dlg.getCoverageData() 1755 eraseCoverage = dlg.getCoverageData()
1730 1756
1731 if runProject: 1757 if runProject:
1732 fn = self.project.getMainScript(True) 1758 fn = self.project.getMainScript(True)
1753 ) 1779 )
1754 1780
1755 self.lastStartAction = 6 1781 self.lastStartAction = 6
1756 self.clientType = self.project.getProjectLanguage() 1782 self.clientType = self.project.getProjectLanguage()
1757 else: 1783 else:
1758 editor = self.viewmanager.activeWindow() 1784 if scriptName:
1759 if editor is None: 1785 fn = scriptName
1760 return 1786 self.clientType = "Python3"
1761 1787 else:
1762 if ( 1788 # run current editor
1763 not self.viewmanager.checkDirty( 1789 editor = self.viewmanager.activeWindow()
1764 editor, Preferences.getDebugger("Autosave")) or 1790 if editor is None:
1765 editor.getFileName() is None 1791 return
1766 ):
1767 return
1768 1792
1769 fn = editor.getFileName() 1793 if (
1794 not self.viewmanager.checkDirty(
1795 editor, Preferences.getDebugger("Autosave")) or
1796 editor.getFileName() is None
1797 ):
1798 return
1799
1800 fn = editor.getFileName()
1801 self.clientType = editor.determineFileType()
1770 self.lastStartAction = 5 1802 self.lastStartAction = 5
1771 self.clientType = editor.determineFileType()
1772 1803
1773 # save the filename for use by the restart method 1804 # save the filename for use by the restart method
1774 self.lastDebuggedFile = fn 1805 self.lastDebuggedFile = fn
1775 self.restartAct.setEnabled(True) 1806 self.restartAct.setEnabled(True)
1776 1807
1777 # save the most recently used virtual environment 1808 # save the most recently used virtual environment
1778 self.lastUsedVenvName = lastUsedVenvName 1809 self.lastUsedVenvName = lastUsedVenvName
1779 1810
1780 # This moves any previous occurrence of these arguments to the head 1811 # This moves any previous occurrence of these arguments to the head
1781 # of the list. 1812 # of the list.
1813 self.setScriptsHistory(scriptName)
1782 self.setArgvHistory(argv) 1814 self.setArgvHistory(argv)
1783 self.setWdHistory(wd) 1815 self.setWdHistory(wd)
1784 self.setEnvHistory(env) 1816 self.setEnvHistory(env)
1785 1817
1786 # Save the exception flags 1818 # Save the exception flags
1818 configOverride=self.overrideGlobalConfig) 1850 configOverride=self.overrideGlobalConfig)
1819 1851
1820 self.stopAct.setEnabled(True) 1852 self.stopAct.setEnabled(True)
1821 1853
1822 if dlg.clearHistories(): 1854 if dlg.clearHistories():
1855 self.setScriptsHistory("", clearHistories=True)
1823 self.setArgvHistory("", clearHistories=True) 1856 self.setArgvHistory("", clearHistories=True)
1824 self.setWdHistory("", clearHistories=True) 1857 self.setWdHistory("", clearHistories=True)
1825 self.setEnvHistory("", clearHistories=True) 1858 self.setEnvHistory("", clearHistories=True)
1826 self.setMultiprocessNoDebugHistory("", clearHistories=True) 1859 self.setMultiprocessNoDebugHistory("", clearHistories=True)
1827 elif dlg.historiesModified(): 1860 elif dlg.historiesModified():
1828 argvHistory, wdHistory, envHistory, _ = dlg.getHistories() 1861 (scriptsHistory, argvHistory, wdHistory, envHistory,
1862 _) = dlg.getHistories()
1863 self.setScriptsHistory("", history=scriptsHistory)
1829 self.setArgvHistory("", history=argvHistory) 1864 self.setArgvHistory("", history=argvHistory)
1830 self.setWdHistory("", history=wdHistory) 1865 self.setWdHistory("", history=wdHistory)
1831 self.setEnvHistory("", history=envHistory) 1866 self.setEnvHistory("", history=envHistory)
1832 1867
1833 def __profileScript(self): 1868 def __profileScript(self):
1834 """ 1869 """
1835 Private slot to handle the profile script action. 1870 Private slot to handle the profile script action.
1836 """ 1871 """
1837 self.__doProfile(False) 1872 self.doProfile(False)
1838 1873
1839 def __profileProject(self): 1874 def __profileProject(self):
1840 """ 1875 """
1841 Private slot to handle the profile project action. 1876 Private slot to handle the profile project action.
1842 """ 1877 """
1843 self.__compileChangedProjectFiles() 1878 self.__compileChangedProjectFiles()
1844 self.__doProfile(True) 1879 self.doProfile(True)
1845 1880
1846 def __doProfile(self, runProject): 1881 def doProfile(self, runProject, script=""):
1847 """ 1882 """
1848 Private method to handle the profile actions. 1883 Public method to handle the profile actions.
1849 1884
1850 @param runProject flag indicating profiling of the current project 1885 @param runProject flag indicating profiling of the current project
1851 (True) or script (False) 1886 (True) or script (False)
1887 @type bool
1888 @param script name of a script (optional)
1889 @type str
1852 """ 1890 """
1853 from .StartDialog import StartDialog 1891 from .StartDialog import StartDialog
1854 1892
1855 self.__resetUI() 1893 self.__resetUI()
1856 doNotStart = False 1894 doNotStart = False
1860 cap = ( 1898 cap = (
1861 self.tr("Profile of Project") 1899 self.tr("Profile of Project")
1862 if runProject else 1900 if runProject else
1863 self.tr("Profile of Script") 1901 self.tr("Profile of Script")
1864 ) 1902 )
1903 if runProject:
1904 scriptName = self.project.getMainScript(True)
1905 elif script:
1906 scriptName = script
1907 elif self.lastDebuggedFile:
1908 scriptName = self.lastDebuggedFile
1909 else:
1910 scriptName = ""
1865 dlg = StartDialog( 1911 dlg = StartDialog(
1866 cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory, 1912 cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory,
1867 self.envHistory, self.exceptions, self.ui, 3, 1913 self.envHistory, self.exceptions, self.ui, 3,
1868 autoClearShell=self.autoClearShell, 1914 autoClearShell=self.autoClearShell,
1869 configOverride=self.overrideGlobalConfig) 1915 configOverride=self.overrideGlobalConfig,
1916 forProject=runProject, scriptName=scriptName,
1917 scriptsList=self.scriptsHistory)
1870 if dlg.exec() == QDialog.DialogCode.Accepted: 1918 if dlg.exec() == QDialog.DialogCode.Accepted:
1871 (lastUsedVenvName, argv, wd, env, exceptions, clearShell, 1919 (lastUsedVenvName, scriptName, argv, wd, env, exceptions,
1872 console) = dlg.getData() 1920 clearShell, console) = dlg.getData()
1873 configOverride = dlg.getGlobalOverrideData() 1921 configOverride = dlg.getGlobalOverrideData()
1874 eraseTimings = dlg.getProfilingData() 1922 eraseTimings = dlg.getProfilingData()
1875 1923
1876 if runProject: 1924 if runProject:
1877 fn = self.project.getMainScript(True) 1925 fn = self.project.getMainScript(True)
1898 ) 1946 )
1899 1947
1900 self.lastStartAction = 8 1948 self.lastStartAction = 8
1901 self.clientType = self.project.getProjectLanguage() 1949 self.clientType = self.project.getProjectLanguage()
1902 else: 1950 else:
1903 editor = self.viewmanager.activeWindow() 1951 if scriptName:
1904 if editor is None: 1952 fn = scriptName
1905 return 1953 self.clientType = "Python3"
1906 1954 else:
1907 if ( 1955 # run current editor
1908 not self.viewmanager.checkDirty( 1956 editor = self.viewmanager.activeWindow()
1909 editor, Preferences.getDebugger("Autosave")) or 1957 if editor is None:
1910 editor.getFileName() is None 1958 return
1911 ):
1912 return
1913 1959
1914 fn = editor.getFileName() 1960 if (
1961 not self.viewmanager.checkDirty(
1962 editor, Preferences.getDebugger("Autosave")) or
1963 editor.getFileName() is None
1964 ):
1965 return
1966
1967 fn = editor.getFileName()
1968 self.clientType = editor.determineFileType()
1915 self.lastStartAction = 7 1969 self.lastStartAction = 7
1916 self.clientType = editor.determineFileType()
1917 1970
1918 # save the filename for use by the restart method 1971 # save the filename for use by the restart method
1919 self.lastDebuggedFile = fn 1972 self.lastDebuggedFile = fn
1920 self.restartAct.setEnabled(True) 1973 self.restartAct.setEnabled(True)
1921 1974
1922 # save the most recently used virtual environment 1975 # save the most recently used virtual environment
1923 self.lastUsedVenvName = lastUsedVenvName 1976 self.lastUsedVenvName = lastUsedVenvName
1924 1977
1925 # This moves any previous occurrence of these arguments to the head 1978 # This moves any previous occurrence of these arguments to the head
1926 # of the list. 1979 # of the list.
1980 self.setScriptsHistory(scriptName)
1927 self.setArgvHistory(argv) 1981 self.setArgvHistory(argv)
1928 self.setWdHistory(wd) 1982 self.setWdHistory(wd)
1929 self.setEnvHistory(env) 1983 self.setEnvHistory(env)
1930 1984
1931 # Save the exception flags 1985 # Save the exception flags
1963 configOverride=self.overrideGlobalConfig) 2017 configOverride=self.overrideGlobalConfig)
1964 2018
1965 self.stopAct.setEnabled(True) 2019 self.stopAct.setEnabled(True)
1966 2020
1967 if dlg.clearHistories(): 2021 if dlg.clearHistories():
2022 self.setScriptsHistory("", clearHistories=True)
1968 self.setArgvHistory("", clearHistories=True) 2023 self.setArgvHistory("", clearHistories=True)
1969 self.setWdHistory("", clearHistories=True) 2024 self.setWdHistory("", clearHistories=True)
1970 self.setEnvHistory("", clearHistories=True) 2025 self.setEnvHistory("", clearHistories=True)
1971 self.setMultiprocessNoDebugHistory("", clearHistories=True) 2026 self.setMultiprocessNoDebugHistory("", clearHistories=True)
1972 elif dlg.historiesModified(): 2027 elif dlg.historiesModified():
1973 argvHistory, wdHistory, envHistory, _ = dlg.getHistories() 2028 (scriptsHistory, argvHistory, wdHistory, envHistory,
2029 _) = dlg.getHistories()
2030 self.setScriptsHistory("", history=scriptsHistory)
1974 self.setArgvHistory("", history=argvHistory) 2031 self.setArgvHistory("", history=argvHistory)
1975 self.setWdHistory("", history=wdHistory) 2032 self.setWdHistory("", history=wdHistory)
1976 self.setEnvHistory("", history=envHistory) 2033 self.setEnvHistory("", history=envHistory)
1977 2034
1978 def __runScript(self): 2035 def __runScript(self):
1979 """ 2036 """
1980 Private slot to handle the run script action. 2037 Private slot to handle the run script action.
1981 """ 2038 """
1982 self.__doRun(False) 2039 self.doRun(False)
1983 2040
1984 def __runProject(self): 2041 def __runProject(self):
1985 """ 2042 """
1986 Private slot to handle the run project action. 2043 Private slot to handle the run project action.
1987 """ 2044 """
1988 self.__compileChangedProjectFiles() 2045 self.__compileChangedProjectFiles()
1989 self.__doRun(True) 2046 self.doRun(True)
1990 2047
1991 def __doRun(self, runProject): 2048 def doRun(self, runProject, script=""):
1992 """ 2049 """
1993 Private method to handle the run actions. 2050 Public method to handle the run actions.
1994 2051
1995 @param runProject flag indicating running the current project (True) 2052 @param runProject flag indicating running the current project (True)
1996 or script (False) 2053 or script (False)
2054 @type bool
2055 @param script name of a script (optional)
2056 @type str
1997 """ 2057 """
1998 from .StartDialog import StartDialog 2058 from .StartDialog import StartDialog
1999 2059
2000 self.__resetUI() 2060 self.__resetUI()
2001 doNotStart = False 2061 doNotStart = False
2005 cap = ( 2065 cap = (
2006 self.tr("Run Project") 2066 self.tr("Run Project")
2007 if runProject else 2067 if runProject else
2008 self.tr("Run Script") 2068 self.tr("Run Script")
2009 ) 2069 )
2070 if runProject:
2071 scriptName = self.project.getMainScript(True)
2072 elif script:
2073 scriptName = script
2074 elif self.lastDebuggedFile:
2075 scriptName = self.lastDebuggedFile
2076 else:
2077 scriptName = ""
2010 dlg = StartDialog( 2078 dlg = StartDialog(
2011 cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory, 2079 cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory,
2012 self.envHistory, self.exceptions, self.ui, 1, 2080 self.envHistory, self.exceptions, self.ui, 1,
2013 autoClearShell=self.autoClearShell, 2081 autoClearShell=self.autoClearShell,
2014 configOverride=self.overrideGlobalConfig) 2082 configOverride=self.overrideGlobalConfig,
2083 forProject=runProject, scriptName=scriptName,
2084 scriptsList=self.scriptsHistory)
2015 if dlg.exec() == QDialog.DialogCode.Accepted: 2085 if dlg.exec() == QDialog.DialogCode.Accepted:
2016 (lastUsedVenvName, argv, wd, env, exceptions, clearShell, 2086 (lastUsedVenvName, scriptName, argv, wd, env, exceptions,
2017 console) = dlg.getData() 2087 clearShell, console) = dlg.getData()
2018 configOverride = dlg.getGlobalOverrideData() 2088 configOverride = dlg.getGlobalOverrideData()
2019 2089
2020 if runProject: 2090 if runProject:
2021 fn = self.project.getMainScript(True) 2091 fn = self.project.getMainScript(True)
2022 if fn is None: 2092 if fn is None:
2042 ) 2112 )
2043 2113
2044 self.lastStartAction = 4 2114 self.lastStartAction = 4
2045 self.clientType = self.project.getProjectLanguage() 2115 self.clientType = self.project.getProjectLanguage()
2046 else: 2116 else:
2047 editor = self.viewmanager.activeWindow() 2117 if scriptName:
2048 if editor is None: 2118 fn = scriptName
2049 return 2119 self.clientType = "Python3"
2050 2120 else:
2051 if ( 2121 # run current editor
2052 not self.viewmanager.checkDirty( 2122 editor = self.viewmanager.activeWindow()
2053 editor, 2123 if editor is None:
2054 Preferences.getDebugger("Autosave")) or 2124 return
2055 editor.getFileName() is None
2056 ):
2057 return
2058 2125
2059 fn = editor.getFileName() 2126 if (
2127 not self.viewmanager.checkDirty(
2128 editor,
2129 Preferences.getDebugger("Autosave")) or
2130 editor.getFileName() is None
2131 ):
2132 return
2133
2134 fn = editor.getFileName()
2135 self.clientType = editor.determineFileType()
2060 self.lastStartAction = 3 2136 self.lastStartAction = 3
2061 self.clientType = editor.determineFileType() 2137
2062
2063 # save the filename for use by the restart method 2138 # save the filename for use by the restart method
2064 self.lastDebuggedFile = fn 2139 self.lastDebuggedFile = fn
2065 self.restartAct.setEnabled(True) 2140 self.restartAct.setEnabled(True)
2066 2141
2067 # save the most recently used virtual environment 2142 # save the most recently used virtual environment
2068 self.lastUsedVenvName = lastUsedVenvName 2143 self.lastUsedVenvName = lastUsedVenvName
2069 2144
2070 # This moves any previous occurrence of these arguments to the head 2145 # This moves any previous occurrence of these arguments to the head
2071 # of the list. 2146 # of the list.
2147 self.setScriptsHistory(scriptName)
2072 self.setArgvHistory(argv) 2148 self.setArgvHistory(argv)
2073 self.setWdHistory(wd) 2149 self.setWdHistory(wd)
2074 self.setEnvHistory(env) 2150 self.setEnvHistory(env)
2075 2151
2076 # Save the exception flags 2152 # Save the exception flags
2104 configOverride=self.overrideGlobalConfig) 2180 configOverride=self.overrideGlobalConfig)
2105 2181
2106 self.stopAct.setEnabled(True) 2182 self.stopAct.setEnabled(True)
2107 2183
2108 if dlg.clearHistories(): 2184 if dlg.clearHistories():
2185 self.setScriptsHistory("", clearHistories=True)
2109 self.setArgvHistory("", clearHistories=True) 2186 self.setArgvHistory("", clearHistories=True)
2110 self.setWdHistory("", clearHistories=True) 2187 self.setWdHistory("", clearHistories=True)
2111 self.setEnvHistory("", clearHistories=True) 2188 self.setEnvHistory("", clearHistories=True)
2112 self.setMultiprocessNoDebugHistory("", clearHistories=True) 2189 self.setMultiprocessNoDebugHistory("", clearHistories=True)
2113 elif dlg.historiesModified(): 2190 elif dlg.historiesModified():
2114 argvHistory, wdHistory, envHistory, _ = dlg.getHistories() 2191 (scriptsHistory, argvHistory, wdHistory, envHistory,
2192 _) = dlg.getHistories()
2193 self.setScriptsHistory("", history=scriptsHistory)
2115 self.setArgvHistory("", history=argvHistory) 2194 self.setArgvHistory("", history=argvHistory)
2116 self.setWdHistory("", history=wdHistory) 2195 self.setWdHistory("", history=wdHistory)
2117 self.setEnvHistory("", history=envHistory) 2196 self.setEnvHistory("", history=envHistory)
2118 2197
2119 def __debugScript(self): 2198 def __debugScript(self):
2120 """ 2199 """
2121 Private slot to handle the debug script action. 2200 Private slot to handle the debug script action.
2122 """ 2201 """
2123 self.__doDebug(False) 2202 self.doDebug(False)
2124 2203
2125 def __debugProject(self): 2204 def __debugProject(self):
2126 """ 2205 """
2127 Private slot to handle the debug project action. 2206 Private slot to handle the debug project action.
2128 """ 2207 """
2129 self.__compileChangedProjectFiles() 2208 self.__compileChangedProjectFiles()
2130 self.__doDebug(True) 2209 self.doDebug(True)
2131 2210
2132 def __doDebug(self, debugProject): 2211 def doDebug(self, debugProject, script=""):
2133 """ 2212 """
2134 Private method to handle the debug actions. 2213 Public method to handle the debug actions.
2135 2214
2136 @param debugProject flag indicating debugging the current project 2215 @param debugProject flag indicating debugging the current project
2137 (True) or script (False) 2216 (True) or script (False)
2217 @type bool
2218 @param script name of a script (optional)
2219 @type str
2138 """ 2220 """
2139 from .StartDialog import StartDialog 2221 from .StartDialog import StartDialog
2140 2222
2141 self.__resetUI() 2223 self.__resetUI()
2142 doNotStart = False 2224 doNotStart = False
2146 cap = ( 2228 cap = (
2147 self.tr("Debug Project") 2229 self.tr("Debug Project")
2148 if debugProject else 2230 if debugProject else
2149 self.tr("Debug Script") 2231 self.tr("Debug Script")
2150 ) 2232 )
2233 if debugProject:
2234 scriptName = self.project.getMainScript(True)
2235 elif script:
2236 scriptName = script
2237 elif self.lastDebuggedFile:
2238 scriptName = self.lastDebuggedFile
2239 else:
2240 scriptName = ""
2151 dlg = StartDialog( 2241 dlg = StartDialog(
2152 cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory, 2242 cap, self.lastUsedVenvName, self.argvHistory, self.wdHistory,
2153 self.envHistory, self.exceptions, self.ui, 0, 2243 self.envHistory, self.exceptions, self.ui, 0,
2154 tracePython=self.tracePython, autoClearShell=self.autoClearShell, 2244 tracePython=self.tracePython, autoClearShell=self.autoClearShell,
2155 autoContinue=self.autoContinue, 2245 autoContinue=self.autoContinue,
2156 enableMultiprocess=self.enableMultiprocess, 2246 enableMultiprocess=self.enableMultiprocess,
2157 multiprocessNoDebugHistory=self.multiprocessNoDebugHistory, 2247 multiprocessNoDebugHistory=self.multiprocessNoDebugHistory,
2158 configOverride=self.overrideGlobalConfig) 2248 configOverride=self.overrideGlobalConfig,
2249 forProject=debugProject, scriptName=scriptName,
2250 scriptsList=self.scriptsHistory)
2159 if dlg.exec() == QDialog.DialogCode.Accepted: 2251 if dlg.exec() == QDialog.DialogCode.Accepted:
2160 (lastUsedVenvName, argv, wd, env, exceptions, clearShell, 2252 (lastUsedVenvName, scriptName, argv, wd, env, exceptions,
2161 console) = dlg.getData() 2253 clearShell, console) = dlg.getData()
2162 configOverride = dlg.getGlobalOverrideData() 2254 configOverride = dlg.getGlobalOverrideData()
2163 (tracePython, autoContinue, enableMultiprocess, 2255 (tracePython, autoContinue, enableMultiprocess,
2164 multiprocessNoDebug) = dlg.getDebugData() 2256 multiprocessNoDebug) = dlg.getDebugData()
2165 2257
2166 if debugProject: 2258 if debugProject:
2191 ) 2283 )
2192 2284
2193 self.lastStartAction = 2 2285 self.lastStartAction = 2
2194 self.clientType = self.project.getProjectLanguage() 2286 self.clientType = self.project.getProjectLanguage()
2195 else: 2287 else:
2196 editor = self.viewmanager.activeWindow() 2288 if scriptName:
2197 if editor is None: 2289 fn = scriptName
2198 return 2290 self.clientType = "Python3"
2199 2291 else:
2200 if ( 2292 # debug current editor
2201 not self.viewmanager.checkDirty( 2293 editor = self.viewmanager.activeWindow()
2202 editor, Preferences.getDebugger("Autosave")) or 2294 if editor is None:
2203 editor.getFileName() is None 2295 return
2204 ):
2205 return
2206 2296
2207 fn = editor.getFileName() 2297 if (
2298 not self.viewmanager.checkDirty(
2299 editor, Preferences.getDebugger("Autosave")) or
2300 editor.getFileName() is None
2301 ):
2302 return
2303
2304 fn = editor.getFileName()
2305 self.clientType = editor.determineFileType()
2208 self.lastStartAction = 1 2306 self.lastStartAction = 1
2209 self.clientType = editor.determineFileType()
2210 2307
2211 # save the filename for use by the restart method 2308 # save the filename for use by the restart method
2212 self.lastDebuggedFile = fn 2309 self.lastDebuggedFile = fn
2213 self.restartAct.setEnabled(True) 2310 self.restartAct.setEnabled(True)
2214 2311
2215 # save the most recently used virtual environment 2312 # save the most recently used virtual environment
2216 self.lastUsedVenvName = lastUsedVenvName 2313 self.lastUsedVenvName = lastUsedVenvName
2217 2314
2218 # This moves any previous occurrence of these arguments to the head 2315 # This moves any previous occurrence of these arguments to the head
2219 # of the list. 2316 # of the list.
2317 self.setScriptsHistory(scriptName)
2220 self.setArgvHistory(argv) 2318 self.setArgvHistory(argv)
2221 self.setWdHistory(wd) 2319 self.setWdHistory(wd)
2222 self.setEnvHistory(env) 2320 self.setEnvHistory(env)
2223 2321
2224 # Save the exception flags 2322 # Save the exception flags
2280 self.debuggingStarted.emit(fn) 2378 self.debuggingStarted.emit(fn)
2281 2379
2282 self.stopAct.setEnabled(True) 2380 self.stopAct.setEnabled(True)
2283 2381
2284 if dlg.clearHistories(): 2382 if dlg.clearHistories():
2383 self.setScriptsHistory("", clearHistories=True)
2285 self.setArgvHistory("", clearHistories=True) 2384 self.setArgvHistory("", clearHistories=True)
2286 self.setWdHistory("", clearHistories=True) 2385 self.setWdHistory("", clearHistories=True)
2287 self.setEnvHistory("", clearHistories=True) 2386 self.setEnvHistory("", clearHistories=True)
2288 self.setMultiprocessNoDebugHistory("", clearHistories=True) 2387 self.setMultiprocessNoDebugHistory("", clearHistories=True)
2289 elif dlg.historiesModified(): 2388 elif dlg.historiesModified():
2290 (argvHistory, wdHistory, envHistory, 2389 (scriptsHistory, argvHistory, wdHistory, envHistory,
2291 noDebugHistory) = dlg.getHistories() 2390 noDebugHistory) = dlg.getHistories()
2391 self.setScriptsHistory("", history=scriptsHistory)
2292 self.setArgvHistory("", history=argvHistory) 2392 self.setArgvHistory("", history=argvHistory)
2293 self.setWdHistory("", history=wdHistory) 2393 self.setWdHistory("", history=wdHistory)
2294 self.setEnvHistory("", history=envHistory) 2394 self.setEnvHistory("", history=envHistory)
2295 self.setMultiprocessNoDebugHistory("", history=noDebugHistory) 2395 self.setMultiprocessNoDebugHistory("", history=noDebugHistory)
2296 2396

eric ide

mercurial