Skip to content

Commit

Permalink
Add open in external editor to console
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Aug 17, 2015
1 parent 5fb52fa commit a05a970
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions python/console/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
***************************************************************************/
Some portions of code were taken from https://code.google.com/p/pydee/
"""
import os

from PyQt4.QtCore import Qt, QTimer, QSettings, QCoreApplication, QSize, QByteArray, QFileInfo, SIGNAL
from PyQt4.QtGui import QDockWidget, QToolBar, QToolButton, QWidget, QSplitter, QTreeWidget, QAction, QFileDialog, QCheckBox, QSizePolicy, QMenu, QGridLayout, QApplication
from PyQt4.QtCore import Qt, QTimer, QSettings, QCoreApplication, QSize, QByteArray, QFileInfo, SIGNAL, QUrl
from PyQt4.QtGui import QDockWidget, QToolBar, QToolButton, QWidget,\
QSplitter, QTreeWidget, QAction, QFileDialog, QCheckBox, QSizePolicy, QMenu, QGridLayout, QApplication, \
QDesktopServices
from PyQt4.QtGui import QVBoxLayout
from PyQt4 import pyqtconfig
from qgis.utils import iface
Expand Down Expand Up @@ -168,6 +171,16 @@ def __init__(self, parent=None):
self.openFileButton.setIconVisibleInMenu(True)
self.openFileButton.setToolTip(openFileBt)
self.openFileButton.setText(openFileBt)

openExtEditorBt = QCoreApplication.translate("PythonConsole", "Open in external editor")
self.openInEditorButton = QAction(self)
self.openInEditorButton.setCheckable(False)
self.openInEditorButton.setEnabled(True)
self.openInEditorButton.setIcon(QgsApplication.getThemeIcon("console/iconShowEditorConsole.png"))
self.openInEditorButton.setMenuRole(QAction.PreferencesRole)
self.openInEditorButton.setIconVisibleInMenu(True)
self.openInEditorButton.setToolTip(openExtEditorBt)
self.openInEditorButton.setText(openExtEditorBt)
## Action for Save File
saveFileBt = QCoreApplication.translate("PythonConsole", "Save")
self.saveFileButton = QAction(self)
Expand Down Expand Up @@ -389,6 +402,7 @@ def __init__(self, parent=None):
self.toolBarEditor.setMovable(False)
self.toolBarEditor.setFloatable(False)
self.toolBarEditor.addAction(self.openFileButton)
self.toolBarEditor.addAction(self.openInEditorButton)
self.toolBarEditor.addSeparator()
self.toolBarEditor.addAction(self.saveFileButton)
self.toolBarEditor.addAction(self.saveAsFileButton)
Expand Down Expand Up @@ -519,6 +533,7 @@ def __init__(self, parent=None):
self.loadQtGuiButton.triggered.connect(self.qtGui)
self.runButton.triggered.connect(self.shell.entered)
self.openFileButton.triggered.connect(self.openScriptFile)
self.openInEditorButton.triggered.connect(self.openScriptFileExtEditor)
self.saveFileButton.triggered.connect(self.saveScriptFile)
self.saveAsFileButton.triggered.connect(self.saveAsScriptFile)
self.helpButton.triggered.connect(self.openHelp)
Expand Down Expand Up @@ -602,6 +617,15 @@ def commentCode(self):
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", "")
openFileTr = QCoreApplication.translate("PythonConsole", "Open File")
Expand Down

0 comments on commit a05a970

Please sign in to comment.