set_msg and log buffer

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-04-13 04:22:59 +00:00
parent da47bfaa64
commit 317250c2cc
6 changed files with 29 additions and 14 deletions

View File

@ -146,6 +146,8 @@ class Application(object):
# initialize our buffers
# note that only the first buffer will be initially visible
buffers.append(buffer.about.AboutBuffer())
self.log = buffer.LogBuffer()
buffers.append(self.log)
if self.rcerror:
buffers.insert(0, buffer.data.DataBuffer('*RcError*', self.rcerror))
@ -513,9 +515,12 @@ class Application(object):
window.Window(b, self, height=slot.height, width=slot.width)
# error string handling
def set_error(self, s):
def set_msg(self, s):
self.error_string = s
self.error_timestamp = time.time()
def set_error(self, s):
self.set_msg(s)
self.log.append_lines([s, ""], act=buffer.ACT_NONE, force=True)
def clear_error(self):
self.error_string = ""
self.error_timestamp = None
@ -1051,7 +1056,6 @@ if __name__ == "__main__":
i += 1
import optparse
parser = optparse.OptionParser()
parser.set_defaults(debug=False)
parser.set_defaults(goto=None)

View File

@ -782,3 +782,20 @@ class Binary32Buffer(FileBuffer):
return '\n'.join(lines)
def write_filter(self, data):
return ''.join(self.rawdata)
# log is another singleton
log = None
class LogBuffer(Buffer):
btype = 'log'
def __new__(cls, *args, **kwargs):
global log
if log is None:
log = object.__new__(LogBuffer, *args, **kwargs)
return log
def __init__(self): Buffer.__init__(self)
def clear(self): log.set_data('', force=True)
def name(self): return '*Log*'
def changed(self): return False
def close(self): global log; log = None
def readonly(self): return True

View File

@ -28,6 +28,3 @@ class ConsoleBuffer(Buffer):
def changed(self): return False
def close(self): global console; console = None
def readonly(self): return True
def input_insert_lines(self, p, lines, act=ACT_NORM, force=False): pass
def output_insert_lines(self, p, lines, act=ACT_NORM, force=False): pass
def result_insert_lines(self, p, lines, act=ACT_NORM, force=False): pass

View File

@ -908,7 +908,7 @@ class Cancel(Method):
w.application.close_mini_buffer()
if w.application.completion_window_is_open():
w.application.close_completion_buffer()
w.set_error('Cancel')
w.set_msg('Cancel')
class SplitWindow(Method):
'''Split the main window horizontally into upper and lower windows'''
@ -916,8 +916,6 @@ class SplitWindow(Method):
a = w.application
a.add_slot()
if not w.cursor_is_visible():
#p = w.first
#w.goto(p)
w.center_view(force=True)
n = len(a.bufferlist.slots)
a.set_error('Window has been split into %d windows!' % n)

View File

@ -445,7 +445,7 @@ class Fundamental(Handler):
try:
act = Handler.handle_token(self, t)
if act is None:
self.window.set_error(' '.join(self.curr_tokens))
self.window.set_msg(' '.join(self.curr_tokens))
return
else:
act.execute(self.window)
@ -454,7 +454,7 @@ class Fundamental(Handler):
except ActionError, e:
#XYZ: HACK--should fix
if t in ('C-]', 'C-g'):
self.window.set_error('Cancelled')
self.window.set_msg('Cancelled')
else:
self.window.set_error(str(e))
except Exception, e:

View File

@ -75,10 +75,9 @@ class Window(object):
return os.path.splitext(path)[1].lower()
# some useful pass-through to application
def set_error(self, s):
self.application.set_error(s)
def clear_error(self):
self.application.clear_error()
def set_msg(self, s): self.application.set_msg(s)
def set_error(self, s): self.application.set_error(s)
def clear_error(self): self.application.clear_error()
# mode stuff
def set_mode(self, m):