Skip to content

Commit

Permalink
set focus to python console when shown even if in a tabbed dockwidget
Browse files Browse the repository at this point in the history
  • Loading branch information
brushtyler committed Oct 18, 2012
1 parent 9fb0b76 commit 1960bea
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions python/console.py
Expand Up @@ -37,13 +37,16 @@ def show_console():
parent = iface.mainWindow() if iface else None
_console = PythonConsole( parent )
_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())

# set focus to the edit box so the user can start typing
if _console.isVisible():
_console.activateWindow()
_console.setFocus()
# set focus to the console so the user can start typing
if _console.isVisible():
_console.activate()

_old_stdout = sys.stdout
_console_output = None
Expand Down Expand Up @@ -77,11 +80,17 @@ def __init__(self, parent=None):

self.console = PythonConsoleWidget(self)
self.setWidget( self.console )
self.setFocusProxy( self.console )

# try to restore position from stored main window state
if iface and not iface.mainWindow().restoreDockWidget(self):
iface.mainWindow().addDockWidget(Qt.BottomDockWidgetArea, self)

def activate(self):
self.activateWindow()
self.raise_()
QDockWidget.setFocus(self)


class PythonConsoleWidget(QWidget):
def __init__(self, parent=None):
Expand Down Expand Up @@ -257,8 +266,6 @@ def __init__(self, parent=None):

self.e.addWidget(self.widgetButton)
self.e.addWidget(self.edit)

self.edit.setFocus()

self.clearButton.triggered.connect(self.edit.clearConsole)
#self.currentLayerButton.triggered.connect(self.cLayer)
Expand Down

0 comments on commit 1960bea

Please sign in to comment.