@@ -79,7 +79,7 @@ def __init__(self, parent=None):
79
79
super (Editor ,self ).__init__ (parent )
80
80
self .parent = parent
81
81
## recent modification time
82
- self .mtime = 0
82
+ self .lastModified = 0
83
83
self .opening = ['(' , '{' , '[' , "'" , '"' ]
84
84
self .closing = [')' , '}' , ']' , "'" , '"' ]
85
85
@@ -349,7 +349,7 @@ def contextMenuEvent(self, e):
349
349
undoAction .setEnabled (True )
350
350
if self .isRedoAvailable ():
351
351
redoAction .setEnabled (True )
352
- if QApplication .clipboard ().text () != "" :
352
+ if QApplication .clipboard ().text ():
353
353
pasteAction .setEnabled (True )
354
354
action = menu .exec_ (self .mapToGlobal (e .pos ()))
355
355
@@ -502,7 +502,7 @@ def _runSubProcess(self, filename, tmp=False):
502
502
except IOError , error :
503
503
IOErrorTr = QCoreApplication .translate ('PythonConsole' ,
504
504
'Cannot execute file %1. Error: %2\n ' ) \
505
- .arg (str (filename )).arg (error .strerror )
505
+ .arg (unicode (filename )).arg (error .strerror )
506
506
print '## Error: ' + IOErrorTr
507
507
except :
508
508
s = traceback .format_exc ()
@@ -624,10 +624,10 @@ def focusInEvent(self, e):
624
624
if not os .path .exists (pathfile ):
625
625
msgText = QCoreApplication .translate ('PythonConsole' ,
626
626
'The file <b>"%1"</b> has been deleted or is not accessible' ) \
627
- .arg (pathfile )
627
+ .arg (unicode ( pathfile ) )
628
628
self .parent .pc .callWidgetMessageBarEditor (msgText , 2 , False )
629
629
return
630
- if pathfile and self .mtime != os . stat (pathfile ).st_mtime :
630
+ if pathfile and self .lastModified != QFileInfo (pathfile ).lastModified () :
631
631
self .beginUndoAction ()
632
632
self .selectAll ()
633
633
#fileReplaced = self.selectedText()
@@ -643,16 +643,18 @@ def focusInEvent(self, e):
643
643
self .endUndoAction ()
644
644
645
645
self .parent .tw .listObject (self .parent .tw .currentWidget ())
646
- self .mtime = os . stat (pathfile ).st_mtime
646
+ self .lastModified = QFileInfo (pathfile ).lastModified ()
647
647
msgText = QCoreApplication .translate ('PythonConsole' ,
648
648
'The file <b>"%1"</b> has been changed and reloaded' ) \
649
- .arg (pathfile )
649
+ .arg (unicode ( pathfile ) )
650
650
self .parent .pc .callWidgetMessageBarEditor (msgText , 1 , False )
651
651
QsciScintilla .focusInEvent (self , e )
652
652
653
653
def fileReadOnly (self ):
654
+ tabWidget = self .parent .tw .currentWidget ()
654
655
msgText = QCoreApplication .translate ('PythonConsole' ,
655
- 'Read only file, please save to different file first.' )
656
+ 'The file <b>"%1"</b> is read only, please save to different file first.' ) \
657
+ .arg (unicode (tabWidget .path ))
656
658
self .parent .pc .callWidgetMessageBarEditor (msgText , 1 , False )
657
659
658
660
class EditorTab (QWidget ):
@@ -700,10 +702,12 @@ def loadFile(self, filename, modified):
700
702
self .newEditor .setReadOnly (self .readOnly )
701
703
QApplication .restoreOverrideCursor ()
702
704
self .newEditor .setModified (modified )
703
- self .newEditor .mtime = os . stat (filename ).st_mtime
705
+ self .newEditor .lastModified = QFileInfo (filename ).lastModified ()
704
706
self .newEditor .recolor ()
705
707
706
- def save (self ):
708
+ def save (self , fileName = None ):
709
+ if fileName :
710
+ self .path = fileName
707
711
if self .path is None :
708
712
index = self .tw .currentIndex ()
709
713
saveTr = QCoreApplication .translate ('PythonConsole' ,
@@ -723,6 +727,13 @@ def save(self):
723
727
path = unicode (self .path )
724
728
overwrite = os .path .exists (path )
725
729
if overwrite :
730
+ try :
731
+ permis = os .stat (path ).st_mode
732
+ #self.newEditor.lastModified = QFileInfo(path).lastModified()
733
+ os .chmod (path , permis )
734
+ except :
735
+ raise
736
+
726
737
temp_path = path + "~"
727
738
if os .path .exists (temp_path ):
728
739
os .remove (temp_path )
@@ -732,13 +743,14 @@ def save(self):
732
743
f .write (self .newEditor .text ())
733
744
if overwrite :
734
745
os .remove (temp_path )
746
+ if self .newEditor .isReadOnly ():
747
+ self .newEditor .setReadOnly (False )
735
748
fN = path .split ('/' )[- 1 ]
736
- if not self .newEditor .isReadOnly ():
737
- self .tw .setTabTitle (self , fN )
749
+ self .tw .setTabTitle (self .tw .currentIndex (), fN )
738
750
self .tw .setTabToolTip (self .tw .currentIndex (), path )
739
751
self .newEditor .setModified (False )
740
752
self .pc .saveFileButton .setEnabled (False )
741
- self .newEditor .mtime = os . stat (path ).st_mtime
753
+ self .newEditor .lastModified = QFileInfo (path ).lastModified ()
742
754
self .pc .updateTabListScript (path , action = 'append' )
743
755
self .tw .listObject (self )
744
756
@@ -865,23 +877,23 @@ def contextMenuEvent(self, e):
865
877
tabBar = self .tabBar ()
866
878
self .idx = tabBar .tabAt (e .pos ())
867
879
if self .widget (self .idx ):
868
- cW = self .currentWidget ( )
880
+ cW = self .widget ( self . idx )
869
881
menu = QMenu (self )
870
882
menu .addSeparator ()
871
883
newTabAction = menu .addAction ("New Editor" ,
872
- self .newTabEditor )
884
+ self .newTabEditor )
873
885
menu .addSeparator ()
874
886
closeTabAction = menu .addAction ("Close Tab" ,
875
887
cW .close )
876
888
closeAllTabAction = menu .addAction ("Close All" ,
877
- self .closeAll )
889
+ self .closeAll )
878
890
closeOthersTabAction = menu .addAction ("Close Others" ,
879
- self .closeOthers )
891
+ self .closeOthers )
880
892
menu .addSeparator ()
881
893
saveAction = menu .addAction ("Save" ,
882
- cW .save )
894
+ cW .save )
883
895
saveAsAction = menu .addAction ("Save As" ,
884
- self .parent .saveAsScriptFile )
896
+ self .parent .saveAsScriptFile )
885
897
closeTabAction .setEnabled (False )
886
898
closeAllTabAction .setEnabled (False )
887
899
closeOthersTabAction .setEnabled (False )
@@ -929,7 +941,7 @@ def newTabEditor(self, tabName=None, filename=None):
929
941
except IOError , error :
930
942
IOErrorTr = QCoreApplication .translate ('PythonConsole' ,
931
943
'The file %1 could not be opened. Error: %2\n ' ) \
932
- .arg (str (filename )).arg (error .strerror )
944
+ .arg (unicode (filename )).arg (error .strerror )
933
945
print '## Error: '
934
946
sys .stderr .write (IOErrorTr )
935
947
return
@@ -961,32 +973,33 @@ def closeTab(self, tab):
961
973
self .currentWidget ().setFocus (Qt .TabFocusReason )
962
974
963
975
def setTabTitle (self , tab , title ):
964
- self .setTabText (self . indexOf ( tab ) , title )
976
+ self .setTabText (tab , title )
965
977
966
978
def _removeTab (self , tab , tab2index = False ):
967
979
if tab2index :
968
980
tab = self .indexOf (tab )
969
- if self .widget (tab ).newEditor .isModified ():
981
+ tabWidget = self .widget (tab )
982
+ if tabWidget .newEditor .isModified ():
970
983
txtSaveOnRemove = QCoreApplication .translate ("PythonConsole" ,
971
984
"Python Console: Save File" )
972
985
txtMsgSaveOnRemove = QCoreApplication .translate ("PythonConsole" ,
973
- "The file <b>'%1'</b> has been modified, save changes ?" ).arg (self .tabText (tab ))
986
+ "The file <b>'%1'</b> has been modified, save changes ?" ) \
987
+ .arg (self .tabText (tab ))
974
988
res = QMessageBox .question ( self , txtSaveOnRemove ,
975
989
txtMsgSaveOnRemove ,
976
990
QMessageBox .Save | QMessageBox .Discard | QMessageBox .Cancel )
977
991
if res == QMessageBox .Save :
978
- self . widget ( tab ) .save ()
992
+ tabWidget .save ()
979
993
elif res == QMessageBox .Cancel :
980
994
return
981
- else :
982
- self .parent .updateTabListScript (self . widget ( tab ). path )
983
- self .removeTab (tab )
984
- if self .count () <= 1 :
985
- self .newTabEditor ()
995
+ if tabWidget . path :
996
+ self .parent .updateTabListScript (tabWidget . path , action = 'remove' )
997
+ self .removeTab (tab )
998
+ if self .count () < 1 :
999
+ self .newTabEditor ()
986
1000
else :
987
- if self .widget (tab ).path is not None or \
988
- self .widget (tab ).path in self .restoreTabList :
989
- self .parent .updateTabListScript (self .widget (tab ).path )
1001
+ if tabWidget .path :
1002
+ self .parent .updateTabListScript (tabWidget .path , action = 'remove' )
990
1003
if self .count () <= 1 :
991
1004
self .removeTab (tab )
992
1005
self .newTabEditor ()
@@ -1005,7 +1018,7 @@ def closeCurrentWidget(self):
1005
1018
if currWidget :
1006
1019
currWidget .setFocus (Qt .TabFocusReason )
1007
1020
if currWidget .path in self .restoreTabList :
1008
- self .parent .updateTabListScript (currWidget .path )
1021
+ self .parent .updateTabListScript (currWidget .path , action = 'remove' )
1009
1022
1010
1023
def restoreTabs (self ):
1011
1024
for script in self .restoreTabList :
@@ -1016,19 +1029,19 @@ def restoreTabs(self):
1016
1029
else :
1017
1030
errOnRestore = QCoreApplication .translate ("PythonConsole" ,
1018
1031
"Unable to restore the file: \n %1\n " ) \
1019
- .arg (pathFile )
1032
+ .arg (unicode ( pathFile ) )
1020
1033
print '## Error: '
1021
1034
s = errOnRestore
1022
1035
sys .stderr .write (s )
1023
- self .parent .updateTabListScript (pathFile )
1036
+ self .parent .updateTabListScript (pathFile , action = 'remove' )
1024
1037
if self .count () < 1 :
1025
1038
self .newTabEditor (filename = None )
1026
1039
self .topFrame .close ()
1027
1040
self .enableToolBarEditor (True )
1028
1041
self .currentWidget ().newEditor .setFocus (Qt .TabFocusReason )
1029
1042
1030
1043
def closeRestore (self ):
1031
- self .parent .updateTabListScript ('empty' )
1044
+ self .parent .updateTabListScript (None )
1032
1045
self .topFrame .close ()
1033
1046
self .newTabEditor (filename = None )
1034
1047
self .enableToolBarEditor (True )
0 commit comments