本文整理汇总了Python中console_editor.EditorTabWidget.newTabEditor方法的典型用法代码示例。如果您正苦于以下问题:Python EditorTabWidget.newTabEditor方法的具体用法?Python EditorTabWidget.newTabEditor怎么用?Python EditorTabWidget.newTabEditor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类console_editor.EditorTabWidget
的用法示例。
在下文中一共展示了EditorTabWidget.newTabEditor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PythonConsoleWidget
# 需要导入模块: from console_editor import EditorTabWidget [as 别名]
# 或者: from console_editor.EditorTabWidget import newTabEditor [as 别名]
#.........这里部分代码省略.........
def runScriptEditor(self):
self.tabEditorWidget.currentWidget().newEditor.runScriptCode()
def commentCode(self):
self.tabEditorWidget.currentWidget().newEditor.commentEditorCode(True)
def uncommentCode(self):
self.tabEditorWidget.currentWidget().newEditor.commentEditorCode(False)
def openScriptFileExtEditor(self):
tabWidget = self.tabEditorWidget.currentWidget()
path = tabWidget.path
import subprocess
try:
subprocess.Popen([os.environ['EDITOR'], path])
except KeyError:
QDesktopServices.openUrl(QUrl.fromLocalFile(path))
def openScriptFile(self):
lastDirPath = self.settings.value("pythonConsole/lastDirPath", QDir.homePath())
openFileTr = QCoreApplication.translate("PythonConsole", "Open File")
fileList = QFileDialog.getOpenFileNames(
self, openFileTr, lastDirPath, "Script file (*.py)")
if fileList:
for pyFile in fileList:
for i in range(self.tabEditorWidget.count()):
tabWidget = self.tabEditorWidget.widget(i)
if tabWidget.path == pyFile:
self.tabEditorWidget.setCurrentWidget(tabWidget)
break
else:
tabName = QFileInfo(pyFile).fileName()
self.tabEditorWidget.newTabEditor(tabName, pyFile)
lastDirPath = QFileInfo(pyFile).path()
self.settings.setValue("pythonConsole/lastDirPath", pyFile)
self.updateTabListScript(pyFile, action='append')
def saveScriptFile(self):
tabWidget = self.tabEditorWidget.currentWidget()
try:
tabWidget.save()
except (IOError, OSError) as error:
msgText = QCoreApplication.translate('PythonConsole',
'The file <b>{0}</b> could not be saved. Error: {1}').format(tabWidget.path,
error.strerror)
self.callWidgetMessageBarEditor(msgText, 2, False)
def saveAsScriptFile(self, index=None):
tabWidget = self.tabEditorWidget.currentWidget()
if not index:
index = self.tabEditorWidget.currentIndex()
if not tabWidget.path:
fileName = self.tabEditorWidget.tabText(index) + '.py'
folder = self.settings.value("pythonConsole/lastDirPath", QDir.home())
pathFileName = os.path.join(folder, fileName)
fileNone = True
else:
pathFileName = tabWidget.path
fileNone = False
saveAsFileTr = QCoreApplication.translate("PythonConsole", "Save File As")
filename = QFileDialog.getSaveFileName(self,
saveAsFileTr,
pathFileName, "Script file (*.py)")
if filename:
示例2: PythonConsoleWidget
# 需要导入模块: from console_editor import EditorTabWidget [as 别名]
# 或者: from console_editor.EditorTabWidget import newTabEditor [as 别名]
#.........这里部分代码省略.........
def toggleEditor(self, checked):
self.splitterObj.show() if checked else self.splitterObj.hide()
self.tabEditorWidget.enableToolBarEditor(checked)
def toggleObjectListWidget(self, checked):
self.listClassMethod.show() if checked else self.listClassMethod.hide()
def findTextEditor(self, checked):
self.widgetFind.show() if checked else self.widgetFind.hide()
def pasteEditor(self):
self.tabEditorWidget.currentWidget().newEditor.paste()
def cutEditor(self):
self.tabEditorWidget.currentWidget().newEditor.cut()
def copyEditor(self):
self.tabEditorWidget.currentWidget().newEditor.copy()
def runScriptEditor(self):
self.tabEditorWidget.currentWidget().newEditor.runScriptCode()
def commentCode(self):
self.tabEditorWidget.currentWidget().newEditor.commentEditorCode(True)
def uncommentCode(self):
self.tabEditorWidget.currentWidget().newEditor.commentEditorCode(False)
# def openScriptFile(self):
# settings = QSettings()
# lastDirPath = settings.value("pythonConsole/lastDirPath").toString()
# scriptFile = QFileDialog.getOpenFileName(
# self, "Open File", lastDirPath, "Script file (*.py)")
# if scriptFile.isEmpty() == False:
# oF = open(scriptFile, 'r')
# listScriptFile = []
# for line in oF:
# if line != "\n":
# listScriptFile.append(line)
# self.shell.insertTextFromFile(listScriptFile)
#
# lastDirPath = QFileInfo(scriptFile).path()
# settings.setValue("pythonConsole/lastDirPath", QVariant(scriptFile))
#
#
# def saveScriptFile(self):
# scriptFile = QFileDialog()
# scriptFile.setDefaultSuffix(".py")
# fName = scriptFile.getSaveFileName(
# self, "Save file", QString(), "Script file (*.py)")
#
# if fName.isEmpty() == False:
# filename = str(fName)
# if not filename.endswith(".py"):
# fName += ".py"
# sF = open(fName,'w')
# listText = self.shellOut.getTextFromEditor()
# is_first_line = True
# for s in listText:
# if s[0:3] in (">>>", "..."):
# s.replace(">>> ", "").replace("... ", "")
# if is_first_line:
# is_first_line = False
# else:
# sF.write('\n')
# sF.write(s)
# sF.close()
# self.callWidgetMessageBar('Script was correctly saved.')
def openScriptFile(self):
settings = QSettings()
lastDirPath = settings.value("pythonConsole/lastDirPath").toString()
openFileTr = QCoreApplication.translate("PythonConsole", "Open File")
filename = QFileDialog.getOpenFileName(
self, openFileTr, lastDirPath, "Script file (*.py)")
if not filename.isEmpty():
for i in range(self.tabEditorWidget.count()):
tabWidget = self.tabEditorWidget.widget(i)
if tabWidget.path == filename:
self.tabEditorWidget.setCurrentWidget(tabWidget)
break
else:
tabName = filename.split('/')[-1]
self.tabEditorWidget.newTabEditor(tabName, filename)
lastDirPath = QFileInfo(filename).path()
settings.setValue("pythonConsole/lastDirPath", QVariant(filename))
self.tabListScript.append(filename)
self.updateTabListScript(script=None)
def saveScriptFile(self):
tabWidget = self.tabEditorWidget.currentWidget()
try:
tabWidget.save()
except (IOError, OSError), e:
errTr = QCoreApplication.translate("PythonConsole", "Save Error")
msgErrTr = QCoreApplication.translate("PythonConsole",
"Failed to save %1: %2").arg(tabWidget.path).arg(e)
QMessageBox.warning(self, errTr, msgErrTr)
示例3: PythonConsoleWidget
# 需要导入模块: from console_editor import EditorTabWidget [as 别名]
# 或者: from console_editor.EditorTabWidget import newTabEditor [as 别名]
#.........这里部分代码省略.........
self.shell.commandConsole('sextante')
def qtCore(self):
self.shell.commandConsole('qtCore')
def qtGui(self):
self.shell.commandConsole('qtGui')
def toggleEditor(self, checked):
self.widgetEditor.show() if checked else self.widgetEditor.hide()
self.openFileButton.setEnabled(checked)
self.saveFileButton.setEnabled(checked)
self.saveAsFileButton.setEnabled(checked)
def pasteEditor(self):
self.tabEditorWidget.currentWidget().newEditor.paste()
def cutEditor(self):
self.tabEditorWidget.currentWidget().newEditor.cut()
def copyEditor(self):
self.tabEditorWidget.currentWidget().newEditor.copy()
def runScriptEditor(self):
self.tabEditorWidget.currentWidget().newEditor.runScriptCode()
def commentCode(self):
self.tabEditorWidget.currentWidget().newEditor.commentEditorCode(True)
def uncommentCode(self):
self.tabEditorWidget.currentWidget().newEditor.commentEditorCode(False)
# def openScriptFile(self):
# settings = QSettings()
# lastDirPath = settings.value("pythonConsole/lastDirPath").toString()
# scriptFile = QFileDialog.getOpenFileName(
# self, "Open File", lastDirPath, "Script file (*.py)")
# if scriptFile.isEmpty() == False:
# oF = open(scriptFile, 'r')
# listScriptFile = []
# for line in oF:
# if line != "\n":
# listScriptFile.append(line)
# self.shell.insertTextFromFile(listScriptFile)
#
# lastDirPath = QFileInfo(scriptFile).path()
# settings.setValue("pythonConsole/lastDirPath", QVariant(scriptFile))
#
#
# def saveScriptFile(self):
# scriptFile = QFileDialog()
# scriptFile.setDefaultSuffix(".py")
# fName = scriptFile.getSaveFileName(
# self, "Save file", QString(), "Script file (*.py)")
#
# if fName.isEmpty() == False:
# filename = str(fName)
# if not filename.endswith(".py"):
# fName += ".py"
# sF = open(fName,'w')
# listText = self.shellOut.getTextFromEditor()
# is_first_line = True
# for s in listText:
# if s[0:3] in (">>>", "..."):
# s.replace(">>> ", "").replace("... ", "")
# if is_first_line:
# is_first_line = False
# else:
# sF.write('\n')
# sF.write(s)
# sF.close()
# self.callWidgetMessageBar('Script was correctly saved.')
def openScriptFile(self):
settings = QSettings()
lastDirPath = settings.value("pythonConsole/lastDirPath").toString()
filename = QFileDialog.getOpenFileName(
self, "Open File", lastDirPath, "Script file (*.py)")
if not filename.isEmpty():
for i in range(self.tabEditorWidget.count()):
tabWidget = self.tabEditorWidget.widget(i)
if tabWidget.path == filename:
self.tabEditorWidget.setCurrentWidget(tabWidget)
break
else:
tabName = filename.split('/')[-1]
self.tabEditorWidget.newTabEditor(tabName, filename)
lastDirPath = QFileInfo(filename).path()
settings.setValue("pythonConsole/lastDirPath", QVariant(filename))
self.tabListScript.append(filename)
self.updateTabListScript(script=None)
def saveScriptFile(self):
tabWidget = self.tabEditorWidget.currentWidget()
try:
tabWidget.save()
except (IOError, OSError), e:
QMessageBox.warning(self, "Save Error",
"Failed to save %s: %s" % (tabWidget.path, e))