def __init__(self, batch, groups, on_click, on_enter, on_motion, on_search): # create document self.document = FormattedDocument(' ') self.document.set_style( 0, 1, dict(font_name=FONT_NAME, font_size=FONT_SIZE, color=FONT_COLOR)) # calculate font height and margin font = self.document.get_font(0) self.font_height = font.ascent - font.descent self.margin = self.font_height * TEXT_INPUT_MARGIN # create text input self.input = IncrementalTextLayout(self.document, 100, self.font_height, batch=batch, group=groups[1]) self.input.x = 100 self.input.y = 100 # creating a caret and push it to window handlers self.caret = Caret(self.input, FONT_COLOR[:3], on_click, on_enter, on_motion, on_search) self.clear_text() # create background rectangle self.rect = Rectangle(0, 0, 100, self.font_height + 2 * self.margin, color=TEXT_INPUT_COLOR, batch=batch, group=groups[0])
def on_activate(self): super().on_activate() if not self.document: self.document = FormattedDocument(text=self.license_text) self.document.set_style( 0, len(self.document.text), { 'font_name': 'Arial', 'font_size': get_bottom_bar_height(self.screen_resolution) // 5, 'bold': False, 'italic': False, 'color': (*WHITE_RGB, self.opacity), 'align': 'center' }) if not self.license_layout: self.license_layout = IncrementalTextLayout( document=self.document, width=self.viewport.x2 - self.viewport.x1, height=self.viewport.y2 - self.viewport.y1, multiline=True, batch=BATCHES['ui_batch'], group=GROUPS['button_text']) self.license_layout.x, self.license_layout.y = self.viewport.x1, self.viewport.y1
def _create_text(self): assert self.window is not None self.text_batch = Batch() self.text_document = FormattedDocument() layout = TextLayout(self.text_document, self.window.width, self.window.height, multiline=True, wrap_lines=True, batch=self.text_batch) layout.content_valign = 'bottom'
def __init__(self, width: int, height: int = 0, multiline: bool = False, dpi: object = None, batch: Batch = None, group: Group = None, wrap_lines: bool = True, x: int = 0, y: int = 0, underlined: bool = True, caret_color: tuple = (0, 0, 0), numbers_only: bool = False, font_name=None, font_size=None, font_color=(255, 255, 255, 2555), max_chars=0) -> None: self.document = FormattedDocument() self.layout = IncrementalTextLayout(self.document, width, height, multiline, dpi, batch, group, wrap_lines) self.numbers_only = numbers_only self.style['color'] = font_color self.max_chars = max_chars if font_name: self.style['font_name'] = font_name if font_size: self.style['font_size'] = font_size self.reset_style() if not height: # If the dev didn't specify a height, make the height equal to the height of the font font = pyglet.font.load( font_name or self.document.get_style('font'), font_size or self.document.get_style('font_size')) self.height = font.ascent - font.descent self._hover_cursor = self.get_window().CURSOR_TEXT super().__init__(self.layout, color=caret_color) # TODO: Allow the dev to specify how x and y are treated self.x = x - self.width // 2 self.y = y - self.height // 2 if underlined: self.underline = Rectangle( x=self.x, y=self.y, width=self.width, height=1, )
def __init__(self, caption: str, position: Vector2 = Vector2.zero, size: Vector2 = Vector2.one, document_style=None, font_name: str = 'DisposableDroid BB', font_size: int = 20, color: (int, int, int, int) = ColorHelper.WHITE, hover_color: (int, int, int, int) = ColorHelper.TRANSPARENT): super().__init__(position, size) document_style = {} if document_style is None else document_style document_style.update(dict(font_name=font_name, font_size=font_size)) self._caption = caption self._document = FormattedDocument(caption) self.update_document_style(document_style) self._text_layout = TextLayout(self._document, width=size.x, height=size.y, batch=self.batch, group=OrderedGroup(self.group.order + 1.1), wrap_lines=True, multiline=True) self._text_layout.content_valign = 'center' self.position = position self.color = color self._set_background_color(hover_color) self._set_background_color(self._background_color)
def __init__(self, padding=0): super(MessageQueue, self).__init__() self.font = gui.config.get('control_panel', 'MSG_QUEUE_FONT') self.titleLabelText = gui.config.get('control_panel_strings', 'MSG_QUEUE_TITLE') bgColorStr = gui.config.get('control_panel', 'MSG_QUEUE_BG_COLOR') self.bgColor = list(map(int, tuple(bgColorStr.split(',')))) self.titleLabel = None self.textLayout = None self.dt = 0 self.halfSecs = 0 self.bgRect = None self.border = None self.padding = padding self.currentPos = 0 self.numMsgs = 0 self.doc = FormattedDocument() self.msgs = list()