@@ -34,14 +34,16 @@ def show_console():
34
34
""" called from QGIS to open the console """
35
35
global _console
36
36
if _console is None :
37
- _console = PythonConsole (iface .mainWindow ())
37
+ parent = iface .mainWindow () if iface else None
38
+ _console = PythonConsole ( parent )
38
39
_console .show () # force show even if it was restored as hidden
39
40
else :
40
41
_console .setVisible (not _console .isVisible ())
42
+
41
43
# set focus to the edit box so the user can start typing
42
44
if _console .isVisible ():
43
45
_console .activateWindow ()
44
- _console .edit . setFocus ()
46
+ _console .setFocus ()
45
47
46
48
_old_stdout = sys .stdout
47
49
_console_output = None
@@ -70,10 +72,23 @@ class PythonConsole(QDockWidget):
70
72
def __init__ (self , parent = None ):
71
73
QDockWidget .__init__ (self , parent )
72
74
self .setObjectName ("PythonConsole" )
73
- #self.setAllowedAreas(Qt.BottomDockWidgetArea)
75
+ self .setWindowTitle (QCoreApplication .translate ("PythonConsole" , "Python Console" ))
76
+ #self.setAllowedAreas(Qt.BottomDockWidgetArea)
77
+
78
+ self .console = PythonConsoleWidget (self )
79
+ self .setWidget ( self .console )
80
+
81
+ # try to restore position from stored main window state
82
+ if iface and not iface .mainWindow ().restoreDockWidget (self ):
83
+ iface .mainWindow ().addDockWidget (Qt .BottomDockWidgetArea , self )
84
+
85
+
86
+ class PythonConsoleWidget (QWidget ):
87
+ def __init__ (self , parent = None ):
88
+ QWidget .__init__ (self , parent )
89
+ self .setWindowTitle (QCoreApplication .translate ("PythonConsole" , "Python Console" ))
74
90
75
91
self .widgetButton = QWidget ()
76
- self .widgetEdit = QWidget ()
77
92
78
93
self .toolBar = QToolBar ()
79
94
self .toolBar .setEnabled (True )
@@ -90,7 +105,7 @@ def __init__(self, parent=None):
90
105
#self.toolBar.setObjectName(_fromUtf8("toolMappa"))
91
106
92
107
self .b = QVBoxLayout (self .widgetButton )
93
- self .e = QHBoxLayout (self . widgetEdit )
108
+ self .e = QHBoxLayout (self )
94
109
95
110
self .e .setMargin (0 )
96
111
self .e .setSpacing (0 )
@@ -238,15 +253,13 @@ def __init__(self, parent=None):
238
253
239
254
self .b .addWidget (self .toolBar )
240
255
self .edit = PythonEdit ()
241
-
242
- self .setWidget (self .widgetEdit )
256
+ self .setFocusProxy ( self .edit )
243
257
244
258
self .e .addWidget (self .widgetButton )
245
259
self .e .addWidget (self .edit )
246
260
247
261
self .edit .setFocus ()
248
262
249
- self .setWindowTitle (QCoreApplication .translate ("PythonConsole" , "Python Console" ))
250
263
self .clearButton .triggered .connect (self .edit .clearConsole )
251
264
#self.currentLayerButton.triggered.connect(self.cLayer)
252
265
self .loadIfaceButton .triggered .connect (self .iface )
@@ -257,9 +270,6 @@ def __init__(self, parent=None):
257
270
self .openFileButton .triggered .connect (self .openScriptFile )
258
271
self .saveFileButton .triggered .connect (self .saveScriptFile )
259
272
self .helpButton .triggered .connect (self .openHelp )
260
- # try to restore position from stored main window state
261
- if not iface .mainWindow ().restoreDockWidget (self ):
262
- iface .mainWindow ().addDockWidget (Qt .BottomDockWidgetArea , self )
263
273
264
274
def cLayer (self ):
265
275
self .edit .commandConsole ('cLayer' )
@@ -327,5 +337,6 @@ def closeEvent(self, event):
327
337
328
338
if __name__ == '__main__' :
329
339
a = QApplication (sys .argv )
330
- show_console ()
340
+ console = PythonConsoleWidget ()
341
+ console .show ()
331
342
a .exec_ ()
0 commit comments