我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用System.Console()。
def rectangle(self, rect, attr=None, fill=' '): '''Fill Rectangle.''' pass oldtop=self.WindowTop oldpos=self.pos() #raise NotImplementedError x0, y0, x1, y1 = rect if attr is None: attr = self.attr if fill: rowfill=fill[:1]*abs(x1-x0) else: rowfill=' '*abs(x1-x0) for y in range(y0, y1): System.Console.SetCursorPosition(x0,y) self.write_color(rowfill,attr) self.pos(*oldpos)
def install_readline(hook): def hook_wrap(): try: res=hook() except KeyboardInterrupt,x: #this exception does not seem to be caught res="" except EOFError: return None if res[-1:]=="\n": return res[:-1] else: return res class IronPythonWrapper(IronPythonConsole.IConsole): def ReadLine(self,autoIndentSize): return hook_wrap() def Write(self,text, style): System.Console.Write(text) def WriteLine(self,text, style): System.Console.WriteLine(text) IronPythonConsole.PythonCommandLine.MyConsole = IronPythonWrapper()
def rectangle(self, rect, attr=None, fill=' '): '''Fill Rectangle.''' oldtop = self.WindowTop oldpos = self.pos() #raise NotImplementedError x0, y0, x1, y1 = rect if attr is None: attr = self.attr if fill: rowfill = fill[:1] * abs(x1 - x0) else: rowfill = ' ' * abs(x1 - x0) for y in range(y0, y1): System.Console.SetCursorPosition(x0, y) self.write_color(rowfill, attr) self.pos(*oldpos)
def install_readline(hook): def hook_wrap(): try: res = hook() except KeyboardInterrupt as x: #this exception does not seem to be caught res = "" except EOFError: return None if res[-1:] == "\n": return res[:-1] else: return res class IronPythonWrapper(IronPythonConsole.IConsole): def ReadLine(self, autoIndentSize): return hook_wrap() def Write(self, text, style): System.Console.Write(text) def WriteLine(self, text, style): System.Console.WriteLine(text) IronPythonConsole.PythonCommandLine.MyConsole = IronPythonWrapper()
def rectangle(self, rect, attr=None, fill=u' '): u'''Fill Rectangle.''' oldtop = self.WindowTop oldpos = self.pos() #raise NotImplementedError x0, y0, x1, y1 = rect if attr is None: attr = self.attr if fill: rowfill = fill[:1] * abs(x1 - x0) else: rowfill = u' ' * abs(x1 - x0) for y in range(y0, y1): System.Console.SetCursorPosition(x0, y) self.write_color(rowfill, attr) self.pos(*oldpos)
def install_readline(hook): def hook_wrap(): try: res = hook() except KeyboardInterrupt,x: #this exception does not seem to be caught res = u"" except EOFError: return None if res[-1:] == u"\n": return res[:-1] else: return res class IronPythonWrapper(IronPythonConsole.IConsole): def ReadLine(self, autoIndentSize): return hook_wrap() def Write(self, text, style): System.Console.Write(text) def WriteLine(self, text, style): System.Console.WriteLine(text) IronPythonConsole.PythonCommandLine.MyConsole = IronPythonWrapper()
def __init__(self, newbuffer=0): '''Initialize the Console object. newbuffer=1 will allocate a new buffer so the old content will be restored on exit. ''' self.serial=0 self.attr = System.Console.ForegroundColor self.saveattr = winattr[str(System.Console.ForegroundColor).lower()] self.savebg=System.Console.BackgroundColor log('initial attr=%s' % self.attr) log_sock("%s"%self.saveattr)
def _get(self): top=System.Console.WindowTop log_sock("WindowTop:%s"%top,"console") return top
def _set(self,value): top=System.Console.WindowTop log_sock("Set WindowTop:old:%s,new:%s"%(top,value),"console")
def pos(self, x=None, y=None): '''Move or query the window cursor.''' if x is not None: System.Console.CursorLeft=x else: x=System.Console.CursorLeft if y is not None: System.Console.CursorTop=y else: y=System.Console.CursorTop return x,y
def home(self): '''Move to home.''' self.pos(0,0) # Map ANSI color escape sequences into Windows Console Attributes
def page(self, attr=None, fill=' '): '''Fill the entire screen.''' System.Console.Clear()
def clear_to_end_of_window(self): oldtop=self.WindowTop lastline=self.WindowTop+System.Console.WindowHeight pos=self.pos() w,h=self.size() length=w-pos[0]+min((lastline-pos[1]-1),5)*w-1 self.write_color(length*" ") self.pos(*pos) self.WindowTop=oldtop
def scroll_window(self, lines): '''Scroll the window by the indicated number of lines.''' top=self.WindowTop+lines if top<0: top=0 if top+System.Console.WindowHeight>System.Console.BufferHeight: top=System.Console.BufferHeight self.WindowTop=top
def getkeypress(self): '''Return next key press event from the queue, ignoring others.''' ck=System.ConsoleKey while 1: e = System.Console.ReadKey(True) if e.Key == System.ConsoleKey.PageDown: #PageDown self.scroll_window(12) elif e.Key == System.ConsoleKey.PageUp:#PageUp self.scroll_window(-12) elif str(e.KeyChar)=="\000":#Drop deadkeys log_sock("Deadkey: %s"%e) return event(self,e) pass else: return event(self,e)
def size(self, width=None, height=None): '''Set/get window size.''' sc=System.Console if width is not None and height is not None: sc.BufferWidth,sc.BufferHeight=width,height else: return sc.BufferWidth,sc.BufferHeight if width is not None and height is not None: sc.WindowWidth,sc.WindowHeight=width,height else: return sc.WindowWidth-1,sc.WindowHeight-1
def cursor(self, visible=True, size=None): '''Set cursor on or off.''' System.Console.CursorVisible=visible
def bell(self): System.Console.Beep()
def __init__(self, newbuffer=0): '''Initialize the Console object. newbuffer=1 will allocate a new buffer so the old content will be restored on exit. ''' self.serial = 0 self.attr = System.Console.ForegroundColor self.saveattr = winattr[str(System.Console.ForegroundColor).lower()] self.savebg = System.Console.BackgroundColor log('initial attr=%s' % self.attr)
def _get(self): top = System.Console.WindowTop log("WindowTop:%s"%top) return top
def _set(self, value): top = System.Console.WindowTop log("Set WindowTop:old:%s,new:%s"%(top, value))
def pos(self, x=None, y=None): '''Move or query the window cursor.''' if x is not None: System.Console.CursorLeft=x else: x = System.Console.CursorLeft if y is not None: System.Console.CursorTop=y else: y = System.Console.CursorTop return x, y
def home(self): '''Move to home.''' self.pos(0, 0) # Map ANSI color escape sequences into Windows Console Attributes
def clear_to_end_of_window(self): oldtop = self.WindowTop lastline = self.WindowTop+System.Console.WindowHeight pos = self.pos() w, h = self.size() length = w - pos[0] + min((lastline - pos[1] - 1), 5) * w - 1 self.write_color(length * " ") self.pos(*pos) self.WindowTop = oldtop
def scroll_window(self, lines): '''Scroll the window by the indicated number of lines.''' top = self.WindowTop + lines if top < 0: top = 0 if top + System.Console.WindowHeight > System.Console.BufferHeight: top = System.Console.BufferHeight self.WindowTop = top
def getkeypress(self): '''Return next key press event from the queue, ignoring others.''' ck = System.ConsoleKey while 1: e = System.Console.ReadKey(True) if e.Key == System.ConsoleKey.PageDown: #PageDown self.scroll_window(12) elif e.Key == System.ConsoleKey.PageUp:#PageUp self.scroll_window(-12) elif str(e.KeyChar) == "\000":#Drop deadkeys log("Deadkey: %s"%e) return event(self, e) else: return event(self, e)
def size(self, width=None, height=None): '''Set/get window size.''' sc = System.Console if width is not None and height is not None: sc.BufferWidth, sc.BufferHeight = width,height else: return sc.BufferWidth, sc.BufferHeight if width is not None and height is not None: sc.WindowWidth, sc.WindowHeight = width,height else: return sc.WindowWidth - 1, sc.WindowHeight - 1
def cursor(self, visible=True, size=None): '''Set cursor on or off.''' System.Console.CursorVisible = visible
def _get(self): top = System.Console.WindowTop log("WindowTop:%s" % top) return top
def _set(self, value): top = System.Console.WindowTop log("Set WindowTop:old:%s,new:%s" % (top, value))
def pos(self, x=None, y=None): '''Move or query the window cursor.''' if x is not None: System.Console.CursorLeft = x else: x = System.Console.CursorLeft if y is not None: System.Console.CursorTop = y else: y = System.Console.CursorTop return x, y
def clear_to_end_of_window(self): oldtop = self.WindowTop lastline = self.WindowTop + System.Console.WindowHeight pos = self.pos() w, h = self.size() length = w - pos[0] + min((lastline - pos[1] - 1), 5) * w - 1 self.write_color(length * " ") self.pos(*pos) self.WindowTop = oldtop
def getkeypress(self): '''Return next key press event from the queue, ignoring others.''' ck = System.ConsoleKey while 1: e = System.Console.ReadKey(True) if e.Key == System.ConsoleKey.PageDown: #PageDown self.scroll_window(12) elif e.Key == System.ConsoleKey.PageUp: #PageUp self.scroll_window(-12) elif str(e.KeyChar) == "\000": #Drop deadkeys log("Deadkey: %s" % e) return event(self, e) else: return event(self, e)
def size(self, width=None, height=None): '''Set/get window size.''' sc = System.Console if width is not None and height is not None: sc.BufferWidth, sc.BufferHeight = width, height else: return sc.BufferWidth, sc.BufferHeight if width is not None and height is not None: sc.WindowWidth, sc.WindowHeight = width, height else: return sc.WindowWidth - 1, sc.WindowHeight - 1
def __init__(self, newbuffer=0): u'''Initialize the Console object. newbuffer=1 will allocate a new buffer so the old content will be restored on exit. ''' self.serial = 0 self.attr = System.Console.ForegroundColor self.saveattr = winattr[str(System.Console.ForegroundColor).lower()] self.savebg = System.Console.BackgroundColor log(u'initial attr=%s' % self.attr)
def _get(self): top = System.Console.WindowTop log(u"WindowTop:%s"%top) return top