@@ -64,12 +64,12 @@ def get_handler(self, key, modifier):
64
64
if modifiers == modifier :
65
65
return handler
66
66
return None
67
-
67
+
68
68
def eventFilter (self , obj , event ):
69
69
if event .type () == QEvent .KeyPress and event .key () < 256 :
70
70
handler = self .get_handler (event .key (), event .modifiers ())
71
71
if handler :
72
- handler (self .window , self .tab )
72
+ handler (self .window , self .tab )
73
73
return QObject .eventFilter (self , obj , event )
74
74
75
75
class Editor (QsciScintilla ):
@@ -127,12 +127,12 @@ def __init__(self, parent=None):
127
127
#self.setWrapMode(QsciScintilla.WrapCharacter)
128
128
self .setWhitespaceVisibility (QsciScintilla .WsVisibleAfterIndent )
129
129
#self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
130
-
130
+
131
131
self .settingsEditor ()
132
-
132
+
133
133
# Annotations
134
134
#self.setAnnotationDisplay(QsciScintilla.ANNOTATION_BOXED)
135
-
135
+
136
136
# Indentation
137
137
self .setAutoIndent (True )
138
138
self .setIndentationsUseTabs (False )
@@ -161,7 +161,7 @@ def __init__(self, parent=None):
161
161
self .runScriptScut = QShortcut (QKeySequence (Qt .SHIFT + Qt .CTRL + Qt .Key_E ), self )
162
162
self .runScriptScut .setContext (Qt .WidgetShortcut )
163
163
self .runScriptScut .activated .connect (self .runScriptCode )
164
-
164
+
165
165
self .commentScut = QShortcut (QKeySequence (Qt .CTRL + Qt .Key_3 ), self )
166
166
self .commentScut .setContext (Qt .WidgetShortcut )
167
167
self .commentScut .activated .connect (self .parent .pc .commentCode )
@@ -295,8 +295,8 @@ def contextMenuEvent(self, e):
295
295
menu .addSeparator ()
296
296
commentCodeAction = menu .addAction (iconCommentEditor , "Comment" ,
297
297
self .parent .pc .commentCode , 'Ctrl+3' )
298
- uncommentCodeAction = menu .addAction (iconUncommentEditor , "Uncomment" ,
299
- self .parent .pc .uncommentCode ,
298
+ uncommentCodeAction = menu .addAction (iconUncommentEditor , "Uncomment" ,
299
+ self .parent .pc .uncommentCode ,
300
300
'Shift+Ctrl+3' )
301
301
menu .addSeparator ()
302
302
codePadAction = menu .addAction (iconCodePad ,
@@ -391,7 +391,7 @@ def commentEditorCode(self, commentCheck):
391
391
else :
392
392
if not self .text (line ).trimmed ().startsWith ('#' ):
393
393
continue
394
- self .setSelection (line , self .indentation (line ),
394
+ self .setSelection (line , self .indentation (line ),
395
395
line , self .indentation (line ) + 1 )
396
396
self .removeSelectedText ()
397
397
else :
@@ -401,11 +401,11 @@ def commentEditorCode(self, commentCheck):
401
401
else :
402
402
if not self .text (line ).trimmed ().startsWith ('#' ):
403
403
return
404
- self .setSelection (line , self .indentation (line ),
404
+ self .setSelection (line , self .indentation (line ),
405
405
line , self .indentation (line ) + 1 )
406
406
self .removeSelectedText ()
407
407
self .endUndoAction ()
408
-
408
+
409
409
def createTempFile (self ):
410
410
import tempfile
411
411
fd , path = tempfile .mkstemp ()
@@ -423,10 +423,10 @@ def _runSubProcess(self, filename, tmp=False):
423
423
try :
424
424
## set creationflags for runnning command without shell window
425
425
if sys .platform .startswith ('win' ):
426
- p = subprocess .Popen (['python' , str (filename )], shell = False , stdin = subprocess .PIPE ,
426
+ p = subprocess .Popen (['python' , str (filename )], shell = False , stdin = subprocess .PIPE ,
427
427
stderr = subprocess .PIPE , stdout = subprocess .PIPE , creationflags = 0x08000000 )
428
428
else :
429
- p = subprocess .Popen (['python' , str (filename )], shell = False , stdin = subprocess .PIPE ,
429
+ p = subprocess .Popen (['python' , str (filename )], shell = False , stdin = subprocess .PIPE ,
430
430
stderr = subprocess .PIPE , stdout = subprocess .PIPE )
431
431
out , _traceback = p .communicate ()
432
432
@@ -465,13 +465,14 @@ def _runSubProcess(self, filename, tmp=False):
465
465
466
466
def runScriptCode (self ):
467
467
autoSave = self .settings .value ("pythonConsole/autoSaveScript" ).toBool ()
468
-
468
+
469
469
tabWidget = self .parent .tw .currentWidget ()
470
+
470
471
filename = tabWidget .path
471
-
472
- msgEditorBlank = QCoreApplication .translate ('PythonConsole' ,
472
+
473
+ msgEditorBlank = QCoreApplication .translate ('PythonConsole' ,
473
474
'Hey, type something for running !' )
474
- msgEditorUnsaved = QCoreApplication .translate ('PythonConsole' ,
475
+ msgEditorUnsaved = QCoreApplication .translate ('PythonConsole' ,
475
476
'You have to save the file before running.' )
476
477
if not autoSave :
477
478
if filename is None :
@@ -500,7 +501,7 @@ def getTextFromEditor(self):
500
501
text = self .text ()
501
502
textList = text .split ("\n " )
502
503
return textList
503
-
504
+
504
505
def goToLine (self , objName , linenr ):
505
506
self .SendScintilla (QsciScintilla .SCI_GOTOLINE , linenr - 1 )
506
507
self .SendScintilla (QsciScintilla .SCI_SETTARGETSTART , self .SendScintilla (QsciScintilla .SCI_GETCURRENTPOS ))
@@ -552,7 +553,7 @@ def __init__(self, parent, parentConsole, filename, *args):
552
553
self .newEditor = Editor (self )
553
554
if filename :
554
555
self .path = filename
555
- if os .path .exists (filename ):
556
+ if os .path .exists (filename )
556
557
self .loadFile (filename , False )
557
558
558
559
# Creates layout for message bar
@@ -589,15 +590,15 @@ def loadFile(self, filename, modified):
589
590
590
591
def save (self ):
591
592
if self .path is None :
592
- self .path = str (QFileDialog ().getSaveFileName (self ,
593
+ self .path = str (QFileDialog ().getSaveFileName (self ,
593
594
"Python Console: Save file" ,
594
595
"*.py" ,
595
596
"Script file (*.py)" ))
596
597
# If the user didn't select a file, abort the save operation
597
598
if len (self .path ) == 0 :
598
599
self .path = None
599
600
return
600
- msgText = QCoreApplication .translate ('PythonConsole' ,
601
+ msgText = QCoreApplication .translate ('PythonConsole' ,
601
602
'Script was correctly saved.' )
602
603
self .pc .callWidgetMessageBarEditor (msgText , 0 , True )
603
604
# Rename the original file, if it exists
@@ -706,9 +707,9 @@ def __init__(self, parent):
706
707
707
708
# Menu button list tabs
708
709
self .fileTabMenu = QMenu (self )
709
- self .connect (self .fileTabMenu , SIGNAL ("aboutToShow()" ),
710
+ self .connect (self .fileTabMenu , SIGNAL ("aboutToShow()" ),
710
711
self .showFileTabMenu )
711
- self .connect (self .fileTabMenu , SIGNAL ("triggered(QAction*)" ),
712
+ self .connect (self .fileTabMenu , SIGNAL ("triggered(QAction*)" ),
712
713
self .showFileTabMenuTriggered )
713
714
self .fileTabButton = QToolButton (self )
714
715
self .fileTabButton .setToolTip ('List all tabs' )
@@ -782,7 +783,7 @@ def _removeTab(self, tab, tab2index=False):
782
783
tab = self .indexOf (tab )
783
784
if self .widget (tab ).newEditor .isModified ():
784
785
res = QMessageBox .question ( self , 'Python Console: Save File' ,
785
- 'The file <b>"%s"</b> has been modified, save changes ?'
786
+ 'The file <b>"%s"</b> has been modified, save changes ?'
786
787
% self .tabText (tab ),
787
788
QMessageBox .Save | QMessageBox .Discard | QMessageBox .Cancel )
788
789
if res == QMessageBox .Save :
@@ -920,7 +921,7 @@ def listObject(self, tab):
920
921
s = traceback .format_exc ()
921
922
print '## Error: '
922
923
sys .stderr .write (s )
923
-
924
+
924
925
def refreshSettingsEditor (self ):
925
926
countTab = self .count ()
926
927
for i in range (countTab ):
2 commit comments
nyalldawson commentedon May 1, 2013
Is there an automated command you used to clean all these files? I know about the prepare-commit script, but wasn't aware if there was a similar command for qgis python scripts.
jef-n commentedon May 1, 2013
prepare-commit also works for python files.