def init_input(self, label, text=None): self.input_label = label self.input = TextArea( self.window, self.font, TextBuffer(text), window_border=(self.window.size[1] - self.height + self.border[0], self.border[1], self.border[2], (self.font.size[0] * len(label)) + (2 * self.border[3])), line_spacing=0)
def run(): (window_size, f) = get_args() tb = TextBuffer() if f: tb.load(f) sdl2.ext.init() window = sdl2.ext.Window(WINDOW_TITLE, size=window_size) window.show() factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE) font_img = factory.from_image(FONT_IMG_PATH) sdl2.SDL_SetColorKey( font_img.surface, sdl2.SDL_TRUE, sdl2.SDL_MapRGB(font_img.surface.format, COLOR_KEY_R, COLOR_KEY_G, COLOR_KEY_B)) font = sdl2.ext.BitmapFont(font_img, FONT_SIZE, mapping=FONT_MAPPING) sb = StatusBar(window, tb, font, STATUS_BAR_COLOR, (STATUS_BAR_BORDER_TOP, STATUS_BAR_BORDER_RIGHT, STATUS_BAR_BORDER_BOTTOM, STATUS_BAR_BORDER_LEFT)) ta = TextArea(window, font, tb, (TEXT_AREA_BORDER_TOP, TEXT_AREA_BORDER_RIGHT, sb.height + TEXT_AREA_BORDER_BOTTOM, TEXT_AREA_BORDER_LEFT), TEXT_AREA_LINE_SPACING) state = EditState(Editor(None, window, ta, sb)) sdl2.SDL_StartTextInput() while True: start = sdl2.SDL_GetTicks() state = state.update(sdl2.ext.get_events()) if state is None: break ticks = sdl2.SDL_GetTicks() - start if ticks < 1000 / FRAMES_PER_SECOND: sdl2.SDL_Delay((1000 / FRAMES_PER_SECOND) - ticks) sdl2.SDL_StopTextInput() sdl2.ext.quit() return 0
def __init__(self): self.textbuffer = TextBuffer(cols, rows) # make the framebuffer we draw into the size of one line of text as that's all we need self.buf = bytearray(screen_width * font_height // 8) # the screen defaults to portrait and we want to use it in landscape so we have to rotate as we go, unfortunately. that's why dimensions look swapped around self.fb = FrameBuffer(self.buf, font_height, screen_width, MONO_HLSB) sck = Pin(18, Pin.OUT) mosi = Pin(23, Pin.OUT) miso = Pin(19, Pin.IN) spi = SPI(2, baudrate=80000000, polarity=0, phase=0, sck=sck, mosi=mosi, miso=miso) cs = Pin(5, Pin.OUT) dc = Pin(17, Pin.OUT) rst = Pin(27, Pin.OUT) busy = Pin(35, Pin.IN) self.epd = EPD(spi, cs, dc, rst, busy) self.epd.init() self.clear_screen() # we were in slow mode for the initial clear on startup, we're now going to fast mode as that's the most likely one we'll need next self.mode = 'slow' self.set_fast() self.running = False self.last_change = None
def setUp(self): self.tb = TextBuffer()
def __init__(self, cols=40, rows=4): self.textbuffer = TextBuffer(cols, rows)