@@ -168,16 +168,14 @@ def __init__(self, parent=None):
168
168
169
169
def autoComplete (self ):
170
170
self .autoCompleteFromAll ()
171
-
172
- #self.modificationChanged.connect(self.textEdited)
173
171
174
172
def on_margin_clicked (self , nmargin , nline , modifiers ):
175
173
# Toggle marker for the line the margin was clicked on
176
174
if self .markersAtLine (nline ) != 0 :
177
175
self .markerDelete (nline , self .ARROW_MARKER_NUM )
178
176
else :
179
177
self .markerAdd (nline , self .ARROW_MARKER_NUM )
180
-
178
+
181
179
def refreshLexerProperties (self ):
182
180
self .setLexers ()
183
181
@@ -217,19 +215,19 @@ def setLexers(self):
217
215
self .lexer .setAPIs (self .api )
218
216
219
217
self .setLexer (self .lexer )
220
-
218
+
221
219
def move_cursor_to_end (self ):
222
220
"""Move cursor to end of text"""
223
221
line , index = self .get_end_pos ()
224
222
self .setCursorPosition (line , index )
225
223
self .ensureCursorVisible ()
226
224
self .ensureLineVisible (line )
227
-
225
+
228
226
def get_end_pos (self ):
229
227
"""Return (line, index) position of the last character"""
230
228
line = self .lines () - 1
231
229
return (line , self .text (line ).length ())
232
-
230
+
233
231
def contextMenuEvent (self , e ):
234
232
menu = QMenu (self )
235
233
iconRun = QgsApplication .getThemeIcon ("console/iconRunConsole.png" )
@@ -302,7 +300,7 @@ def contextMenuEvent(self, e):
302
300
if QApplication .clipboard ().text () != "" :
303
301
pasteAction .setEnabled (True )
304
302
action = menu .exec_ (self .mapToGlobal (e .pos ()))
305
-
303
+
306
304
def codepad (self ):
307
305
import urllib2 , urllib
308
306
listText = self .selectedText ().split ('\n ' )
@@ -336,11 +334,12 @@ def codepad(self):
336
334
except urllib2 .URLError , e :
337
335
msgText = QCoreApplication .translate ('PythonConsole' , 'Connection error: ' )
338
336
self .parent .pc .callWidgetMessageBarEditor (msgText + str (e .args ))
339
-
337
+
340
338
def hideEditor (self ):
341
339
Ed = self .parent .pc .widgetEditor
342
340
Ed .hide ()
343
-
341
+ self .parent .pc .showEditorButton .setChecked (False )
342
+
344
343
def commentEditorCode (self , commentCheck ):
345
344
if self .hasSelectedText ():
346
345
startLine , _ , endLine , _ = self .getSelection ()
@@ -357,7 +356,6 @@ def commentEditorCode(self, commentCheck):
357
356
else :
358
357
self .insert (selCmd )
359
358
self .setCursorPosition (endLine , selCmd .length () - 2 )
360
-
361
359
else :
362
360
line , pos = self .getCursorPosition ()
363
361
selCmd = self .text (line )
@@ -423,36 +421,36 @@ def runScriptCode(self):
423
421
#execfile(unicode(filename))
424
422
except IOError , error :
425
423
print 'Cannot execute file %s. Error: %s' % (filename , error .strerror )
426
-
424
+
427
425
def runSelectedCode (self ):
428
426
cmd = self .selectedText ()
429
427
self .parent .pc .shell .insertFromDropPaste (cmd )
430
428
self .parent .pc .shell .entered ()
431
429
self .setFocus ()
432
-
430
+
433
431
def getTextFromEditor (self ):
434
432
text = self .text ()
435
433
textList = text .split ("\n " )
436
434
return textList
437
-
435
+
438
436
class EditorTab (QWidget ):
439
437
def __init__ (self , parent , parentConsole , filename , * args ):
440
438
QWidget .__init__ (self , parent = None , * args )
441
439
self .mw = parent
442
440
self .pc = parentConsole
443
441
self .path = None
444
-
442
+
445
443
self .fileExcuteList = {}
446
444
self .fileExcuteList = dict ()
447
-
445
+
448
446
self .newEditor = Editor (self )
449
447
self .newEditor .setVerticalScrollBarPolicy (Qt .ScrollBarAsNeeded )
450
448
self .newEditor .modificationChanged .connect (self .modified )
451
449
if filename :
452
450
self .newEditor .setText (open (filename , "r" ).read ())
453
451
self .newEditor .setModified (False )
454
452
self .path = filename
455
-
453
+
456
454
# Creates layout for message bar
457
455
self .layout = QGridLayout (self .newEditor )
458
456
self .layout .setContentsMargins (0 , 0 , 0 , 0 )
@@ -463,28 +461,14 @@ def __init__(self, parent, parentConsole, filename, *args):
463
461
sizePolicy = QSizePolicy (QSizePolicy .Minimum , QSizePolicy .Fixed )
464
462
self .infoBar .setSizePolicy (sizePolicy )
465
463
self .layout .addWidget (self .infoBar , 0 , 0 , 1 , 1 )
466
-
464
+
467
465
self .tabLayout = QGridLayout (self )
468
466
self .tabLayout .setContentsMargins (0 , 0 , 0 , 0 )
469
467
self .tabLayout .addWidget (self .newEditor )
470
-
468
+
471
469
self .keyFilter = KeyFilter (parent , self )
472
470
self .setEventFilter (self .keyFilter )
473
-
474
- # def openFile(self):
475
- # scriptFile = QFileDialog.getOpenFileName(
476
- # self, "Open File", "", "Script file (*.py)")
477
- # if os.path.exists(scriptFile):
478
- # self.newEditor.setText(open(scriptFile, "r").read())
479
- # self.newEditor.setModified(False)
480
- # fN = scriptFile.split('/')[-1]
481
- # if fN:
482
- # self.mw.setTabTitle(self, fN)
483
- # self.path = scriptFile
484
- # index = self.mw.currentIndex()
485
- # idx = unicode(index)
486
- # self.fileExcuteList[idx] = unicode(scriptFile)
487
-
471
+
488
472
def save (self ):
489
473
if self .path is None :
490
474
self .path = str (QFileDialog ().getSaveFileName (self ,
@@ -514,27 +498,27 @@ def save(self):
514
498
self .mw .setTabTitle (self , fN )
515
499
self .newEditor .setModified (False )
516
500
self .pc .updateTabListScript (self .path , action = 'append' )
517
-
501
+
518
502
def changeFont (self ):
519
503
self .newEditor .refreshLexerProperties ()
520
-
504
+
521
505
def modified (self , modified ):
522
506
self .mw .tabModified (self , modified )
523
-
507
+
524
508
def close (self ):
525
509
self .mw ._removeTab (self , tab2index = True )
526
-
510
+
527
511
def setEventFilter (self , filter ):
528
512
self .newEditor .installEventFilter (filter )
529
-
513
+
530
514
def newTab (self ):
531
515
self .mw .newTabEditor ()
532
-
516
+
533
517
class EditorTabWidget (QTabWidget ):
534
518
def __init__ (self , parent ):
535
519
QTabWidget .__init__ (self , parent = None )
536
520
self .parent = parent
537
-
521
+
538
522
# Layout for top frame (restore tabs)
539
523
self .layoutTopFrame = QGridLayout (self )
540
524
self .layoutTopFrame .setContentsMargins (0 , 0 , 0 , 0 )
@@ -549,7 +533,7 @@ def __init__(self, parent):
549
533
label = QCoreApplication .translate ("PythonConsole" ,
550
534
"Click on button to restore all tabs from last session." )
551
535
self .label = QLabel (label )
552
-
536
+
553
537
self .restoreTabsButton = QToolButton ()
554
538
toolTipRestore = QCoreApplication .translate ("PythonConsole" ,
555
539
"Restore tabs" )
@@ -559,7 +543,7 @@ def __init__(self, parent):
559
543
self .restoreTabsButton .setCursor (Qt .PointingHandCursor )
560
544
self .restoreTabsButton .setStyleSheet ('QToolButton:hover{border: none } \
561
545
QToolButton:pressed{border: none}' )
562
-
546
+
563
547
self .clButton = QToolButton ()
564
548
toolTipClose = QCoreApplication .translate ("PythonConsole" ,
565
549
"Close" )
@@ -570,14 +554,14 @@ def __init__(self, parent):
570
554
self .clButton .setStyleSheet ('QToolButton:hover{border: none } \
571
555
QToolButton:pressed{border: none}' )
572
556
self .clButton .setAutoRaise (True )
573
-
557
+
574
558
sizePolicy = QSizePolicy (QSizePolicy .Minimum , QSizePolicy .Fixed )
575
559
self .topFrame .setSizePolicy (sizePolicy )
576
560
self .layoutTopFrame .addWidget (self .topFrame , 0 , 0 , 1 , 1 )
577
561
self .layoutTopFrame2 .addWidget (self .label , 0 , 1 , 1 , 1 )
578
562
self .layoutTopFrame2 .addWidget (self .restoreTabsButton , 0 , 0 , 1 , 1 )
579
563
self .layoutTopFrame2 .addWidget (self .clButton , 0 , 2 , 1 , 1 )
580
-
564
+
581
565
self .topFrame .hide ()
582
566
self .connect (self .restoreTabsButton , SIGNAL ('clicked()' ), self .restoreTabs )
583
567
self .connect (self .clButton , SIGNAL ('clicked()' ), self .closeRestore )
@@ -589,12 +573,12 @@ def __init__(self, parent):
589
573
self .newTabEditor (filename = None )
590
574
if self .restoreTabList :
591
575
self .topFrame .show ()
592
-
576
+
593
577
self .setDocumentMode (True )
594
578
self .setMovable (True )
595
579
#self.setTabsClosable(True)
596
580
self .setTabPosition (QTabWidget .South )
597
-
581
+
598
582
# Menu button list tabs
599
583
self .fileTabMenu = QMenu (self )
600
584
self .connect (self .fileTabMenu , SIGNAL ("aboutToShow()" ),
@@ -608,18 +592,16 @@ def __init__(self, parent):
608
592
self .fileTabButton .setPopupMode (QToolButton .InstantPopup )
609
593
self .fileTabButton .setMenu (self .fileTabMenu )
610
594
self .setCornerWidget (self .fileTabButton , Qt .TopRightCorner )
611
- #self.connect(self.closeTabButton, SIGNAL('clicked()'), self.buttonClosePressed)
612
-
613
595
self .connect (self , SIGNAL ("tabCloseRequested(int)" ), self ._removeTab )
614
-
596
+
615
597
# Open button
616
598
self .newTabButton = QToolButton (self )
617
599
self .newTabButton .setToolTip ('New Tab' )
618
600
self .newTabButton .setAutoRaise (True )
619
601
self .newTabButton .setIcon (QgsApplication .getThemeIcon ("console/iconNewTabEditorConsole.png" ))
620
602
self .setCornerWidget (self .newTabButton , Qt .TopLeftCorner )
621
603
self .connect (self .newTabButton , SIGNAL ('clicked()' ), self .newTabEditor )
622
-
604
+
623
605
def newTabEditor (self , tabName = None , filename = None ):
624
606
nr = self .count ()
625
607
if not tabName :
@@ -633,12 +615,12 @@ def newTabEditor(self, tabName=None, filename=None):
633
615
self .iconTab = QgsApplication .getThemeIcon ('console/iconTabEditorConsole.png' )
634
616
self .addTab (self .tab , self .iconTab , tabName )
635
617
self .setCurrentWidget (self .tab )
636
-
618
+
637
619
def tabModified (self , tab , modified ):
638
620
index = self .indexOf (tab )
639
621
color = Qt .darkGray if modified else Qt .black
640
622
self .tabBar ().setTabTextColor (index , color )
641
-
623
+
642
624
def closeTab (self , tab ):
643
625
# Check if file has been saved
644
626
#if isModified:
0 commit comments