Commit c618ed98 authored by Guido van Rossum's avatar Guido van Rossum

Use disabled state to enforce read-only state (bit painful since it means

switching states each time we insert some text but has to be done this way
since else class bindings might allow editing...)
parent 3e395be1
...@@ -81,7 +81,10 @@ class EditableManPage(ScrolledText): ...@@ -81,7 +81,10 @@ class EditableManPage(ScrolledText):
self.ok = 0 self.ok = 0
self.empty = 0 self.empty = 0
self.buffer = None self.buffer = None
savestate = self['state']
self['state'] = 'normal'
self.delete('1.0', 'end') self.delete('1.0', 'end')
self['state'] = savestate
# End parsing -- must be busy, need not be at EOF # End parsing -- must be busy, need not be at EOF
def _endparser(self): def _endparser(self):
...@@ -128,6 +131,8 @@ class EditableManPage(ScrolledText): ...@@ -128,6 +131,8 @@ class EditableManPage(ScrolledText):
self.ok = 0 self.ok = 0
self.empty = 0 self.empty = 0
return return
savestate = self['state']
self['state'] = 'normal'
if self.empty: if self.empty:
# One or more previous lines were empty # One or more previous lines were empty
# -- insert one blank line in the text # -- insert one blank line in the text
...@@ -137,19 +142,19 @@ class EditableManPage(ScrolledText): ...@@ -137,19 +142,19 @@ class EditableManPage(ScrolledText):
if not propline: if not propline:
# No properties # No properties
self._insert_prop(textline) self._insert_prop(textline)
self.lineno = self.lineno + 1 else:
return # Search for properties
# Search for properties p = ''
p = '' j = 0
j = 0 for i in range(min(len(propline), len(textline))):
for i in range(min(len(propline), len(textline))): if propline[i] != p:
if propline[i] != p: if j < i:
if j < i: self._insert_prop(textline[j:i], p)
self._insert_prop(textline[j:i], p) j = i
j = i p = propline[i]
p = propline[i] self._insert_prop(textline[j:])
self._insert_prop(textline[j:])
self.lineno = self.lineno + 1 self.lineno = self.lineno + 1
self['state'] = savestate
# Insert a string at the end, with at most one property (tag) # Insert a string at the end, with at most one property (tag)
def _insert_prop(self, str, prop = ' '): def _insert_prop(self, str, prop = ' '):
...@@ -166,21 +171,8 @@ class ReadonlyManPage(EditableManPage): ...@@ -166,21 +171,8 @@ class ReadonlyManPage(EditableManPage):
# Initialize instance # Initialize instance
def __init__(self, master=None, cnf={}): def __init__(self, master=None, cnf={}):
# Initialize base class EditableManPage.__init__(self, master,
EditableManPage.__init__(self, master, cnf) (cnf, {'state': 'disabled'}))
# Make the text readonly
self.bind('<Any-KeyPress>', self.modify_cb)
self.bind('<Return>', self.modify_cb)
self.bind('<BackSpace>', self.modify_cb)
self.bind('<Delete>', self.modify_cb)
self.bind('<Control-h>', self.modify_cb)
self.bind('<Control-d>', self.modify_cb)
self.bind('<Control-v>', self.modify_cb)
# You could override this to ring the bell, etc.
def modify_cb(self, e):
pass
# Alias # Alias
ManPage = ReadonlyManPage ManPage = ReadonlyManPage
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment