Tweak console shortcut behavior

This commit is contained in:
karxi 2017-01-09 17:20:03 -05:00
parent bd4bc95258
commit e78bb31249

View file

@ -1179,16 +1179,16 @@ class PesterWindow(MovingWindow):
self.console.window = None self.console.window = None
self.console.action = QtGui.QAction("Console", self) self.console.action = QtGui.QAction("Console", self)
self.connect(self.console.action, QtCore.SIGNAL('triggered()'), self.connect(self.console.action, QtCore.SIGNAL('triggered()'),
self, QtCore.SLOT('showConsole()')) self, QtCore.SLOT('toggleConsole()'))
self.console.shortcut = QtGui.QShortcut( self.console.shortcut = QtGui.QShortcut(
QtGui.QKeySequence("Ctrl+`"), self) QtGui.QKeySequence("Ctrl+`"), self)
# Make sure the shortcut works anywhere. # Make sure the shortcut works anywhere.
# karxi: There's something wrong with the inheritance scheme here. # karxi: There's something wrong with the inheritance scheme here.
self.console.shortcut.setContext(QtCore.Qt.ApplicationShortcut) self.console.shortcut.setContext(QtCore.Qt.ApplicationShortcut)
self.connect(self.console.shortcut, QtCore.SIGNAL('activated()'), self.connect(self.console.shortcut, QtCore.SIGNAL('activated()'),
self, QtCore.SLOT('showConsole()')) self, QtCore.SLOT('toggleConsole()'))
#~# Use new-style connections #~# Use new-style connections
#~self.console.shortcut.activated.connect(self.showConsole) #~self.console.shortcut.activated.connect(self.toggleConsole)
# Apparently those can crash sometimes...c'est la vie. Can't use 'em. # Apparently those can crash sometimes...c'est la vie. Can't use 'em.
self.console.is_open = False self.console.is_open = False
@ -1568,7 +1568,7 @@ class PesterWindow(MovingWindow):
self, QtCore.SLOT('memoTabsClosed()')) self, QtCore.SLOT('memoTabsClosed()'))
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def showConsole(self): def toggleConsole(self):
if not _CONSOLE: if not _CONSOLE:
# We don't have the module file for this at the moment. # We don't have the module file for this at the moment.
return return
@ -1581,7 +1581,21 @@ class PesterWindow(MovingWindow):
self.connect(win, QtCore.SIGNAL('windowClosed()'), self.connect(win, QtCore.SIGNAL('windowClosed()'),
self, QtCore.SLOT('consoleWindowClosed()')) self, QtCore.SLOT('consoleWindowClosed()'))
if self.console.is_open: if self.console.is_open:
# Already open - hide the console. if not (win.hasFocus() or win.text.area.hasFocus() or
win.text.input.hasFocus()):
# The console is open, but not in focus. Bring it to the fore.
# NOTE: This is a bit of a kludgy method - it may not work
# properly on Windows. Need to look into workarounds.
#
# karxi: I *think* that Windows doesn't mind if the
# process/window that 'owns' this one changes our focus, since
# the application ultimately already *has* our focus - but I'm
# not sure.
win.raise_()
win.show()
win.activateWindow()
else:
# The console is open and in focus, so hide it for now.
win.hide() win.hide()
self.console.is_open = False self.console.is_open = False
else: else: