def __init__(self, window, x=0, y=0, width=100, height=100, anchor_x='left', anchor_y='bottom', style = Default['terminal'], prompt = '> ', banner = ''): '''Create a new console. :Parameters: `window` : pyglet.window.Window Window this console will be embedded in. `x` : int X coordinate of the console. `y` : int Y coordinate of the console. `width` : int Width of the console in pixels, or None `height` : int Height of the console in pixels, or None `anchor_x` : str Anchor point of the X coordinate: one of ``"left"``, ``"center"`` or ``"right"``. `anchor_y` : str Anchor point of the Y coordinate: one of ``"bottom"``, ``"center"`` or ``"top"``. `style` : dict Style dictionnary describing element styles `prompt` : str Console prompt `banner` : str Text to be displayed prior to any input. ''' super(Console, self).__init__() self._window = window self._style = style self._prompt = prompt self._prompt_start, self._prompt_end = 0, 0 batch = pyglet.graphics.Batch() document = Document() margin = self._style['margin'] layout = Layout(document, width=width-2*margin, height=height-2*margin, multiline=True, batch=batch) layout.anchor_x = anchor_x layout.anchor_y = anchor_y layout.x = int(margin) layout.y = int(margin) layout.view_y = 0 layout.selection_color = self._style['selection_fg'] layout.selection_background_color = self._style['selection_bg'] caret = Caret(layout) caret.position = 0 caret.visible = True r,g,b,a = self._style['text_fg'] caret.color = (r,g,b) self._batch = batch self._document = document self._layout = layout self._caret = caret x,y,z = int(layout.x-margin), int(layout.y-margin), -.5 w,h = layout.width+2*margin, layout.height+2*margin self._background = batch.add( 4, pyglet.gl.GL_QUADS, None, ('v3f', (x,y,z, x+w,y,z, x+w,y+h,z, x,y+h,z)), ('c4B', self._style['text_bg']*4)) z += .1 self._border = batch.add( 4, pyglet.gl.GL_LINE_LOOP, None, ('v3f', (x,y,z, x+w,y,z, x+w,y+h,z, x,y+h,z)), ('c4B', self._style['border_fg']*4)) if banner: self.write(banner) if window: self._cursor = window.get_system_mouse_cursor('text') else: self._cursor = None self.resize(width,height)