Mailing List Archive

CVS: python/dist/src/Mac/Tools/IDE PyEdit.py,1.28,1.29
Update of /cvsroot/python/python/dist/src/Mac/Tools/IDE
In directory usw-pr-cvs1:/tmp/cvs-serv30823

Modified Files:
PyEdit.py
Log Message:
Completely revamped newline handling. PyEdit is now newline-preserving
(if a single newline convention is used in the sourcefile), and the
"save options" has a newline style radio button.

The creator radio button also has the new choices PythonW and None.

Just: just shout (and revert) if you don't agree.


Index: PyEdit.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Tools/IDE/PyEdit.py,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** PyEdit.py 4 Feb 2002 12:50:24 -0000 1.28
--- PyEdit.py 29 Mar 2002 21:26:04 -0000 1.29
***************
*** 52,55 ****
--- 52,56 ----
text = ""
self._creator = W._signature
+ self._eoln = os.linesep
elif os.path.exists(path):
path = resolvealiases(path)
***************
*** 68,83 ****
import EasyDialogs
if string.find(text, '\r\n') >= 0:
! sourceOS = 'DOS'
! searchString = '\r\n'
else:
! sourceOS = 'UNIX'
! searchString = '\n'
! change = EasyDialogs.AskYesNoCancel('"%s" contains %s-style line feeds. '
! 'Change them to MacOS carriage returns?' % (self.title, sourceOS), 1)
! # bug: Cancel is treated as No
! if change > 0:
! text = string.replace(text, searchString, '\r')
else:
change = 0

self.settings = {}
--- 69,80 ----
import EasyDialogs
if string.find(text, '\r\n') >= 0:
! self._eoln = '\r\n'
else:
! self._eoln = '\n'
! text = string.replace(text, self._eoln, '\r')
! change = 0
else:
change = 0
+ self._eoln = '\r'

self.settings = {}
***************
*** 319,326 ****

def domenu_options(self, *args):
! rv = SaveOptions(self._creator)
! if rv:
self.editgroup.editor.selectionchanged() # ouch...
! self._creator = rv

def clicklinefield(self):
--- 316,324 ----

def domenu_options(self, *args):
! rvcreator, rveoln = SaveOptions(self._creator, self._eoln)
! if rvcreator != self._creator or rveoln != self._eoln:
self.editgroup.editor.selectionchanged() # ouch...
! self._creator = rvcreator
! self._eoln = rveoln

def clicklinefield(self):
***************
*** 384,387 ****
--- 382,387 ----
return self.domenu_save_as()
data = self.editgroup.editor.get()
+ if self._eoln != '\r':
+ data = string.replace(data, '\r', self._eoln)
fp = open(self.path, 'wb') # open file in binary mode, data has '\r' line-endings
fp.write(data)
***************
*** 745,757 ****
class _saveoptions:

! def __init__(self, creator):
self.rv = None
! self.w = w = W.ModalDialog((240, 140), 'Save options')
radiobuttons = []
w.label = W.TextBox((8, 8, 80, 18), "File creator:")
w.ide_radio = W.RadioButton((8, 22, 160, 18), "This application", radiobuttons, self.ide_hit)
! w.interp_radio = W.RadioButton((8, 42, 160, 18), "Python Interpreter", radiobuttons, self.interp_hit)
! w.other_radio = W.RadioButton((8, 62, 50, 18), "Other:", radiobuttons)
! w.other_creator = W.EditText((62, 62, 40, 20), creator, self.otherselect)
w.cancelbutton = W.Button((-180, -30, 80, 16), "Cancel", self.cancelbuttonhit)
w.okbutton = W.Button((-90, -30, 80, 16), "Done", self.okbuttonhit)
--- 745,760 ----
class _saveoptions:

! def __init__(self, creator, eoln):
self.rv = None
! self.eoln = eoln
! self.w = w = W.ModalDialog((260, 160), 'Save options')
radiobuttons = []
w.label = W.TextBox((8, 8, 80, 18), "File creator:")
w.ide_radio = W.RadioButton((8, 22, 160, 18), "This application", radiobuttons, self.ide_hit)
! w.interp_radio = W.RadioButton((8, 42, 160, 18), "MacPython Interpreter", radiobuttons, self.interp_hit)
! w.interpx_radio = W.RadioButton((8, 62, 160, 18), "OSX PythonW Interpreter", radiobuttons, self.interpx_hit)
! w.other_radio = W.RadioButton((8, 82, 50, 18), "Other:", radiobuttons)
! w.other_creator = W.EditText((62, 82, 40, 20), creator, self.otherselect)
! w.none_radio = W.RadioButton((8, 102, 160, 18), "None", radiobuttons, self.none_hit)
w.cancelbutton = W.Button((-180, -30, 80, 16), "Cancel", self.cancelbuttonhit)
w.okbutton = W.Button((-90, -30, 80, 16), "Done", self.okbuttonhit)
***************
*** 761,766 ****
--- 764,786 ----
elif creator == W._signature:
w.ide_radio.set(1)
+ elif creator == 'PytX':
+ w.interpx_radio.set(1)
+ elif creator == '\0\0\0\0':
+ w.none_radio.set(1)
else:
w.other_radio.set(1)
+
+ w.eolnlabel = W.TextBox((168, 8, 80, 18), "Newline style:")
+ radiobuttons = []
+ w.unix_radio = W.RadioButton((168, 22, 80, 18), "Unix", radiobuttons, self.unix_hit)
+ w.mac_radio = W.RadioButton((168, 42, 80, 18), "Macintosh", radiobuttons, self.mac_hit)
+ w.win_radio = W.RadioButton((168, 62, 80, 18), "Windows", radiobuttons, self.win_hit)
+ if self.eoln == '\n':
+ w.unix_radio.set(1)
+ elif self.eoln == '\r\n':
+ w.win_radio.set(1)
+ else:
+ w.mac_radio.set(1)
+
w.bind("cmd.", w.cancelbutton.push)
w.open()
***************
*** 772,775 ****
--- 792,801 ----
self.w.other_creator.set("Pyth")

+ def interpx_hit(self):
+ self.w.other_creator.set("PytX")
+
+ def none_hit(self):
+ self.w.other_creator.set("\0\0\0\0")
+
def otherselect(self, *args):
sel_from, sel_to = self.w.other_creator.getselection()
***************
*** 780,793 ****
self.w.other_radio.set(1)

def cancelbuttonhit(self):
self.w.close()

def okbuttonhit(self):
! self.rv = self.w.other_creator.get()[:4]
self.w.close()


! def SaveOptions(creator):
! s = _saveoptions(creator)
return s.rv

--- 806,828 ----
self.w.other_radio.set(1)

+ def mac_hit(self):
+ self.eoln = '\r'
+
+ def unix_hit(self):
+ self.eoln = '\n'
+
+ def win_hit(self):
+ self.eoln = '\r\n'
+
def cancelbuttonhit(self):
self.w.close()

def okbuttonhit(self):
! self.rv = (self.w.other_creator.get()[:4], self.eoln)
self.w.close()


! def SaveOptions(creator, eoln):
! s = _saveoptions(creator, eoln)
return s.rv