1

Manually in the PythonConsole I can open or close panels but when is executed in code it won't find the dockwidget, this is the line I'm using in my code:

self.iface.mainWindow().findChild(QDockWidget,'PythonConsole').setVisible(True)

and this one works in the PythonConsole:

iface.mainWindow().findChild(QDockWidget,'PythonConsole').setVisible(True)

it is supposed to work but give the error "NoneType" object has no attribute "setVisible" when executed in the code...

  • When is your plugin calling this line? If it's on plugin load, it may be trying to hide the console BEFORE it's been created. – ndawson Dec 3 '18 at 23:48
  • it waits for the a layer to load for first time, once the layer is loaded it calls the line self.iface.mainWindow().findChild(QDockWidget,'PythonConsole').setVisible(True) – Thriskel Dec 4 '18 at 11:22
  • Does it work if you show and then hide the console manually first? – ndawson Dec 4 '18 at 11:30
  • @ndawson yes it does... but why? – Thriskel Dec 4 '18 at 12:52
2

The console is created "on demand", so doesn't exist until a user first clicks the console button.

An alternative way to show the dock is to use:

import console
console.show_console()

This will force creation of the console dock if it hasn't yet been used. Caution: despite it's name, show_console() is more of a "toggle console" action. Calling it when the console is already visible will hide it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.