38
38
39
39
_console = None
40
40
41
+
41
42
def show_console ():
42
- """ called from QGIS to open the console """
43
- global _console
44
- if _console is None :
45
- parent = iface .mainWindow () if iface else None
46
- _console = PythonConsole ( parent )
47
- _console .show () # force show even if it was restored as hidden
48
- # set focus to the console so the user can start typing
49
- # defer the set focus event so it works also whether the console not visible yet
50
- QTimer .singleShot (0 , _console .activate )
51
- else :
52
- _console .setVisible (not _console .isVisible ())
53
- # set focus to the console so the user can start typing
54
- if _console .isVisible ():
55
- _console .activate ()
56
- ## Shows help on first launch of the console
57
- settings = QSettings ()
58
- if settings .value ('pythonConsole/contextHelpOnFirstLaunch' , True , type = bool ):
59
- QgsContextHelp .run ( "PythonConsole" )
60
- settings .setValue ('pythonConsole/contextHelpOnFirstLaunch' , False )
43
+ """ called from QGIS to open the console """
44
+ global _console
45
+ if _console is None :
46
+ parent = iface .mainWindow () if iface else None
47
+ _console = PythonConsole (parent )
48
+ _console .show () # force show even if it was restored as hidden
49
+ # set focus to the console so the user can start typing
50
+ # defer the set focus event so it works also whether the console not visible yet
51
+ QTimer .singleShot (0 , _console .activate )
52
+ else :
53
+ _console .setVisible (not _console .isVisible ())
54
+ # set focus to the console so the user can start typing
55
+ if _console .isVisible ():
56
+ _console .activate ()
57
+ ## Shows help on first launch of the console
58
+ settings = QSettings ()
59
+ if settings .value ('pythonConsole/contextHelpOnFirstLaunch' , True , type = bool ):
60
+ QgsContextHelp .run ("PythonConsole" )
61
+ settings .setValue ('pythonConsole/contextHelpOnFirstLaunch' , False )
61
62
62
63
_old_stdout = sys .stdout
63
64
_console_output = None
64
65
65
66
# hook for python console so all output will be redirected
66
67
# and then shown in console
68
+
69
+
67
70
def console_displayhook (obj ):
68
71
global _console_output
69
72
_console_output = obj
70
73
74
+
71
75
class PythonConsole (QDockWidget ):
76
+
72
77
def __init__ (self , parent = None ):
73
78
QDockWidget .__init__ (self , parent )
74
79
self .setObjectName ("PythonConsole" )
75
80
self .setWindowTitle (QCoreApplication .translate ("PythonConsole" , "Python Console" ))
76
81
#self.setAllowedAreas(Qt.BottomDockWidgetArea)
77
82
78
83
self .console = PythonConsoleWidget (self )
79
- self .setWidget ( self .console )
80
- self .setFocusProxy ( self .console )
84
+ self .setWidget (self .console )
85
+ self .setFocusProxy (self .console )
81
86
82
87
# try to restore position from stored main window state
83
88
if iface and not iface .mainWindow ().restoreDockWidget (self ):
@@ -92,7 +97,9 @@ def closeEvent(self, event):
92
97
self .console .saveSettingsConsole ()
93
98
QWidget .closeEvent (self , event )
94
99
100
+
95
101
class PythonConsoleWidget (QWidget ):
102
+
96
103
def __init__ (self , parent = None ):
97
104
QWidget .__init__ (self , parent )
98
105
self .setWindowTitle (QCoreApplication .translate ("PythonConsole" , "Python Console" ))
@@ -113,7 +120,7 @@ def __init__(self, parent=None):
113
120
114
121
self .shellOutWidget = QWidget (self )
115
122
self .shellOutWidget .setLayout (QVBoxLayout ())
116
- self .shellOutWidget .layout ().setContentsMargins (0 ,0 , 0 , 0 )
123
+ self .shellOutWidget .layout ().setContentsMargins (0 , 0 , 0 , 0 )
117
124
self .shellOutWidget .layout ().addWidget (self .shellOut )
118
125
119
126
self .splitter = QSplitter (self .splitterEditor )
@@ -141,7 +148,6 @@ def __init__(self, parent=None):
141
148
self .listClassMethod .setColumnHidden (1 , True )
142
149
self .listClassMethod .setAlternatingRowColors (True )
143
150
144
-
145
151
#self.splitterEditor.addWidget(self.widgetEditor)
146
152
#self.splitterObj.addWidget(self.listClassMethod)
147
153
#self.splitterObj.addWidget(self.widgetEditor)
@@ -477,9 +483,9 @@ def __init__(self, parent=None):
477
483
placeHolderTxt = QCoreApplication .translate ("PythonConsole" , "Enter text to find..." )
478
484
479
485
if pyqtconfig .Configuration ().qt_version >= 0x40700 :
480
- self .lineEditFind .setPlaceholderText (placeHolderTxt )
486
+ self .lineEditFind .setPlaceholderText (placeHolderTxt )
481
487
else :
482
- self .lineEditFind .setToolTip (placeHolderTxt )
488
+ self .lineEditFind .setToolTip (placeHolderTxt )
483
489
self .findNextButton = QToolButton ()
484
490
self .findNextButton .setEnabled (False )
485
491
toolTipfindNext = QCoreApplication .translate ("PythonConsole" , "Find Next" )
@@ -579,13 +585,13 @@ def onClickGoToLine(self, item, column):
579
585
tabEditor .goToLine (objName , linenr )
580
586
581
587
def processing (self ):
582
- self .shell .commandConsole ('processing' )
588
+ self .shell .commandConsole ('processing' )
583
589
584
590
def qtCore (self ):
585
- self .shell .commandConsole ('qtCore' )
591
+ self .shell .commandConsole ('qtCore' )
586
592
587
593
def qtGui (self ):
588
- self .shell .commandConsole ('qtGui' )
594
+ self .shell .commandConsole ('qtGui' )
589
595
590
596
def toggleEditor (self , checked ):
591
597
self .splitterObj .show () if checked else self .splitterObj .hide ()
@@ -650,7 +656,7 @@ def saveScriptFile(self):
650
656
tabWidget = self .tabEditorWidget .currentWidget ()
651
657
try :
652
658
tabWidget .save ()
653
- except (IOError , OSError ), error :
659
+ except (IOError , OSError ) as error :
654
660
msgText = QCoreApplication .translate ('PythonConsole' ,
655
661
'The file <b>{0}</b> could not be saved. Error: {1}' ).format (tabWidget .path ,
656
662
error .strerror )
@@ -663,19 +669,19 @@ def saveAsScriptFile(self, index=None):
663
669
if not tabWidget .path :
664
670
fileName = self .tabEditorWidget .tabText (index ) + '.py'
665
671
folder = self .settings .value ("pythonConsole/lastDirPath" , QDir .home ())
666
- pathFileName = os .path .join (folder ,fileName )
672
+ pathFileName = os .path .join (folder , fileName )
667
673
fileNone = True
668
674
else :
669
675
pathFileName = tabWidget .path
670
676
fileNone = False
671
677
saveAsFileTr = QCoreApplication .translate ("PythonConsole" , "Save File As" )
672
678
filename = QFileDialog .getSaveFileName (self ,
673
- saveAsFileTr ,
674
- pathFileName , "Script file (*.py)" )
679
+ saveAsFileTr ,
680
+ pathFileName , "Script file (*.py)" )
675
681
if filename :
676
682
try :
677
683
tabWidget .save (filename )
678
- except (IOError , OSError ), error :
684
+ except (IOError , OSError ) as error :
679
685
msgText = QCoreApplication .translate ('PythonConsole' ,
680
686
'The file <b>{0}</b> could not be saved. Error: {1}' ).format (tabWidget .path ,
681
687
error .strerror )
@@ -690,7 +696,7 @@ def saveAsScriptFile(self, index=None):
690
696
self .updateTabListScript (pathFileName , action = 'remove' )
691
697
692
698
def openHelp (self ):
693
- QgsContextHelp .run ( "PythonConsole" )
699
+ QgsContextHelp .run ("PythonConsole" )
694
700
695
701
def openSettings (self ):
696
702
if optionsDialog (self ).exec_ ():
0 commit comments