Skip to content

Commit

Permalink
[console] Make console action checkable, and bring behaviour into
Browse files Browse the repository at this point in the history
line with style dock/processing toolbox

Where the action is checked only if the dock is open and user visible,
and checking the action brings hidden tabs to the foreground instead
of closing them.
  • Loading branch information
nyalldawson committed Jan 30, 2018
1 parent 3c63e0b commit 77e54d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 10 additions & 7 deletions python/console/console.py
Expand Up @@ -23,7 +23,7 @@
import os

from qgis.PyQt.QtCore import Qt, QTimer, QCoreApplication, QSize, QByteArray, QFileInfo, QUrl, QDir
from qgis.PyQt.QtWidgets import QDockWidget, QToolBar, QToolButton, QWidget, QSplitter, QTreeWidget, QAction, QFileDialog, QCheckBox, QSizePolicy, QMenu, QGridLayout, QApplication, QShortcut
from qgis.PyQt.QtWidgets import QToolBar, QToolButton, QWidget, QSplitter, QTreeWidget, QAction, QFileDialog, QCheckBox, QSizePolicy, QMenu, QGridLayout, QApplication, QShortcut
from qgis.PyQt.QtGui import QDesktopServices, QKeySequence
from qgis.PyQt.QtWidgets import QVBoxLayout
from qgis.utils import iface
Expand All @@ -32,7 +32,7 @@
from .console_editor import EditorTabWidget
from .console_settings import optionsDialog
from qgis.core import QgsApplication, QgsSettings
from qgis.gui import QgsFilterLineEdit, QgsHelp
from qgis.gui import QgsFilterLineEdit, QgsHelp, QgsDockWidget
from functools import partial

import sys
Expand All @@ -46,14 +46,17 @@ def show_console():
if _console is None:
parent = iface.mainWindow() if iface else None
_console = PythonConsole(parent)
if iface:
_console.visibilityChanged.connect(iface.actionShowPythonDialog().setChecked)

_console.show() # force show even if it was restored as hidden
# set focus to the console so the user can start typing
# defer the set focus event so it works also whether the console not visible yet
QTimer.singleShot(0, _console.activate)
else:
_console.setVisible(not _console.isVisible())
_console.setUserVisible(not _console.isUserVisible())
# set focus to the console so the user can start typing
if _console.isVisible():
if _console.isUserVisible():
_console.activate()

return _console
Expand All @@ -70,10 +73,10 @@ def console_displayhook(obj):
_console_output = obj


class PythonConsole(QDockWidget):
class PythonConsole(QgsDockWidget):

def __init__(self, parent=None):
QDockWidget.__init__(self, parent)
super().__init__(parent)
self.setObjectName("PythonConsole")
self.setWindowTitle(QCoreApplication.translate("PythonConsole", "Python Console"))
# self.setAllowedAreas(Qt.BottomDockWidgetArea)
Expand All @@ -89,7 +92,7 @@ def __init__(self, parent=None):
def activate(self):
self.activateWindow()
self.raise_()
QDockWidget.setFocus(self)
QgsDockWidget.setFocus(self)

def closeEvent(self, event):
self.console.saveSettingsConsole()
Expand Down
3 changes: 3 additions & 0 deletions src/ui/qgisapp.ui
Expand Up @@ -1815,6 +1815,9 @@ Ctrl (Cmd) increments by 15 deg.</string>
</property>
</action>
<action name="mActionShowPythonDialog">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/console/mIconRunConsole.svg</normaloff>:/images/themes/default/console/mIconRunConsole.svg</iconset>
Expand Down

0 comments on commit 77e54d3

Please sign in to comment.