def __init__(self, x: int, y: int, radius: int, background_color: tuple, slider_color: tuple, text_color: tuple): self.x = x self.y = y self.radius = radius self.background_color = background_color self.slider_color = slider_color self.text_color = text_color self.white_font = Font(constants.NANUMSQUARE_REGULAR_FONT, radius // 3, (255, 255, 255)) self.black_font = Font(constants.NANUMSQUARE_REGULAR_FONT, radius // 3, (0, 0, 0)) self.background_surface = self.get_colored_font_by_color(self.background_color) \ .render('#%02X%02X%02X' % self.background_color) self.slider_surface = self.get_colored_font_by_color(self.slider_color) \ .render('#%02X%02X%02X' % self.slider_color) self.text_surface = self.get_colored_font_by_color(self.text_color) \ .render('#%02X%02X%02X' % self.text_color) self.background_pos = (int(self.x + self.radius) - self.background_surface.get_width() / 2, int(self.y + self.radius) - self.background_surface.get_height() / 2) self.slider_pos = (int(self.x + self.radius * 3.5) - self.slider_surface.get_width() / 2, int(self.y + self.radius) - self.slider_surface.get_height() / 2) self.text_pos = (int(self.x + self.radius * 6) - self.text_surface.get_width() / 2, int(self.y + self.radius) - self.text_surface.get_height() / 2)
def __init__(self, config, matrix): self.showDuration = config["screens"]["clockScreen"].get( "showDuration") self.matrix = matrix self.font_small = Font(file="CGpixel3x5.ttf", size=5) self.font_big = Font(file="mini_pixel-7.ttf", size=30)
def __init__(self, y): self.y = y self.time = Text( 0, self.y, '', Font(constants.NANUMSQUARE_BOLD_FONT, 72, constants.TEXT_COLOR)) self.millisecond = Text( 0, self.time.y + self.time.font.size, '', Font(constants.NANUMSQUARE_REGULAR_FONT, 32, constants.TEXT_COLOR))
def init(): global keyboard_manager, root_object_manager, state_manager, handler_manager pygame.init() pygame.display.set_caption( f'{constants.PROJECT_NAME} {constants.PROJECT_VERSION}') pygame.display.set_icon(pygame.image.load(constants.PROJECT_ICON)) display.window = pygame.display.set_mode(display.size, pygame.RESIZABLE) keyboard_manager = KeyboardManager() root_object_manager = RootObjectManager() state_manager = StateManager(Clock()) handler_manager = HandlerManager() handler_manager.add(Quit(keyboard_manager, shutdown)) handler_manager.add(RenderStop(keyboard_manager)) handler_manager.add(ResponsiveColor(state_manager)) root_object_manager.add( Terminal( constants.TEXT_COLOR, Font(constants.NANUMSQUARE_REGULAR_FONT, 32, constants.BACKGROUND_COLOR), keyboard_manager, state_manager, root_object_manager, handler_manager, shutdown))
def make_flame(args): """ Use the arguments to make a flame file. """ # Select the padding style pad_char = '█' if args.block_padding else ' ' text = Text(args.text, pad_char) # Read in the font and sanitize the text font = Font() text.sanitize(font.alphabet) print("Making fractal for the following text:") print(text) # The Layout handles positioning each character of text layout = Layout(font, text) # The AffineFinder calculates the necessary transformation # matricies. It returns XForm Objects finder = AffineFinder(layout.bounding_box) xforms = list(finder.find_xforms(layout.geometry)) print("This fractal will use {} xforms + final xform".format(len(xforms))) writer = FlameWriter() writer.write(args.fname, args.flame_name, xforms)
def test_v2x_name_table(self): expected = [ # (langID, nameID, string) (0x409, 0, u'Public domain'), (0x409, 1, u'Wapuro Mincho TateBaikaku'), (0x409, 2, u'Regular'), (0x409, 3, u'1.002;NONE;WapuroMincho-TateBaikaku'), (0x409, 4, u'Wapuro Mincho TateBaikaku'), (0x409, 5, u'Version 1.002'), (0x409, 6, u'WapuroMincho-TateBaikaku'), (0x409, 11, u'https://irori.github.io/wapuro-mincho/'), (0x409, 16, u'Wapuro Mincho'), (0x409, 17, u'TateBaikaku'), (0x411, 1, u'ワープロ明朝 縦倍角'), (0x411, 4, u'ワープロ明朝 縦倍角'), (0x411, 16, u'ワープロ明朝'), (0x411, 17, u'縦倍角'), ] font = Font('bdf/jiskan24-2003-1.bdf') ufo = convert.create_ufo(font, limit=1) convert.v2x(ufo) otf = convert.compile(ufo, 'out.ttf') actual = [] for name in sorted(otf['name'].names): self.assertEqual(name.platformID, 3) self.assertEqual(name.platEncID, 1) actual.append((name.langID, name.nameID, name.toUnicode())) self.assertEqual(expected, actual)
def load_font(self, name, path=None): """ Add a new font to this manager. Parameters ---------- name : :obj:`str` The name of the font. The font's metafile and texture filename's should also be this value with the appropriate file extensions. path : :obj:`str`, optional File path the font files. If not supplied will use the default `res/fonts/` path. """ if path is None: path = self._font_path # Load in the font texture atlas tex_file = path + name + ".png" image = self._app.tex_mgr.load_image(name, tex_file) builder = TextureBuilder().set_filtered(True).set_wrapped( GL_CLAMP_TO_EDGE) texture = self._app.tex_mgr.load_texture(name, image, builder) # Create the font object which automatically loades the font metadata font_file = path + name + ".fnt" font = Font(name, font_file, texture) # Add font to local caches and create loader obj self._fonts[font.name] = font self._loaders[font] = loader = TextLoader(font) self._texts[font] = [] font._loader = loader # Attempting to not expose a set option return font
def setProps(self, props={}, **kwprops): """ If font is given as a string or a dict, convert it into a Font object. If rotation is a string representing a number, convert it. Then call Artist.setProps. """ # A property might be defined in both props and kwprops, # so do all of this twice for d in (props, kwprops): if 'font' in d.keys(): currentFont = Font() if 'font' in self.props().keys(): currentFont = self.props('font') if isinstance(d['font'], str): currentFont.setFamily(d['font']) d['font'] = currentFont elif isinstance(d['font'], dict): currentFont.setProps(d['font']) d['font'] = currentFont if 'rotation' in d.keys(): try: d['rotation'] = float(d['rotation']) except ValueError: pass Artist.setProps(self, props, **kwprops)
def __init__(self, config, matrix): self.showDuration = config["screens"]["scrollScreen"].get( "showDuration") self.matrix = matrix self.font_big = Font(file="mini_pixel-7.ttf", size=40) self.setText("Hello Matrix :)")
def __init__(self, podcast): super(PodcastRow, self).__init__() self.remove_img = get_gtk_image_from_file('./icons/delete.png', 12, 12) self.refresh_img = get_gtk_image_from_file('./icons/update.png', 12, 12) self.refresh = Gtk.Button() self.refresh.set_image(self.refresh_img) self.refresh.set_relief(Gtk.ReliefStyle.NONE) self.remove = Gtk.Button() self.remove.set_image(self.remove_img) self.remove.set_relief(Gtk.ReliefStyle.NONE) hbox1 = Gtk.HBox() hbox1.pack_start(self.refresh, False, True, 0) hbox1.pack_start(self.remove , False, True, 0) self.box_revealer = Gtk.Revealer() self.box_revealer.add(hbox1) self.box_revealer.set_transition_type(Gtk.RevealerTransitionType.NONE) hbox2 = Gtk.HBox(spacing=6) hbox2.pack_start(Gtk.Label(podcast.date, xalign=0), True, True, 0) hbox2.pack_start(self.box_revealer, True, True, 0) self.spinner = Gtk.Spinner() self.load_revealer = Gtk.Revealer.new() self.load_revealer.add(self.spinner) self.load_revealer.set_transition_type(Gtk.RevealerTransitionType.SLIDE_LEFT) font = Font() font.set_weight(FontWeight.BOLD) name = Gtk.Label(podcast.name, xalign=0, yalign=0) name.modify_font(font.to_pango_desc()) revbox = Gtk.HBox(spacing=0) revbox.pack_start(self.load_revealer, False, True, 0) revbox.pack_start(name, True, True, 0) pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(podcast.image, 75, 75, True) image = Gtk.Image.new_from_pixbuf(pixbuf) image.set_alignment(0,0) summary = Gtk.Label(podcast.summary, xalign=0, yalign=0) summary.set_max_width_chars(60) summary.set_lines(4) summary.set_ellipsize(Pango.EllipsizeMode.END) expander = Gtk.Expander.new('Description') expander.add(summary) grid = Gtk.Grid() grid.set_column_spacing(6) grid.attach(image , 0, 0, 1, 3) grid.attach(revbox , 1, 0, 1, 1) grid.attach(expander, 1, 1, 1, 1) grid.attach(hbox2, 1, 2, 1, 1) self.add(grid) self.podcast = podcast self.buttonsConnected = False
def set_font(self, font_file): # get the font f = Font() font = f.load_font(font_file) self.font_width = len(font['i'][Font.CHARACTER_BY_ROWS][Font.ROW]) self.font_height = len(font['i'][Font.CHARACTER_BY_ROWS]) return font
def fonts(self): if not hasattr(self, "__fonts"): from font import Font self.__fonts = {} for row in self.sql.getFontInfos(): self.__fonts[row[0]] = Font(row[0]) return self.__fonts
def __init__(self, **kw): super(DotMatrix, self).__init__(**kw) self.background = kw['background'] if 'background' in kw \ else (.1, .1, .1, 1) self.dot_on = kw['dot_on'] if 'dot_on' in kw else (.1, .9, .1, 1) self.dot_off = kw['dot_off'] if 'dot_off' in kw else (.1, .3, .1, 1) self.dot_style = kw['dot_style'] if 'dot_style' in kw else 'circle' self.rows = kw['rows'] if 'rows' in kw else 2 self.cols = kw['cols'] if 'cols' in kw else 16 curr_dir = os.path.dirname(os.path.realpath(__file__)) if 'font' in kw: self.font = Font(dirname=os.path.join(curr_dir, kw['font'])) else: self.font = Font(dirname=os.path.join(curr_dir, 'font_5x7')) self.spacing = kw['spacing'] if 'spacing' in kw else 1 self.bind(pos=self.draw) self.bind(size=self.draw) self.bind(text=self.draw)
def __init__(self, program, i, iname): py.sprite.Sprite.__init__(self) self.image = py.Surface([140, 40]) self.rect = self.image.get_rect() self.index = i self.program = program self.iname = iname self.namefont = Font(13) self.predraw()
def test_ufo_metrics(self): f = Font('bdf/jiskan24-2003-1.bdf') info = defcon.Info() f.set_ufo_metrics(info) self.assertEqual(info.unitsPerEm, 256) self.assertEqual(info.ascender, 228) self.assertEqual(info.descender, -28) self.assertEqual(info.capHeight, 200) self.assertEqual(info.xHeight, 140)
def __init__(self): super(Player, self).__init__() self.adjustment = Gtk.Adjustment.new(0.0, 0.0, 100.0, 0.5, 10.0, 0.0) self.adjustment.connect('value-changed', self.on_adjustment_changed) self.progress = Gtk.Scale.new(Gtk.Orientation.HORIZONTAL, self.adjustment) self.progress.set_hexpand(True) self.progress.set_sensitive(False) self.progress.set_draw_value(False) self.progress.connect('button-press-event', self.on_mouse_press) self.progress.connect('button-release-event', self.on_mouse_release) font = Font() font.set_size(8) self.current_time = Gtk.Label('00:00:00.00', xalign=0, xpad=6) self.current_time.modify_font(font.to_pango_desc()) self.changing_time = Gtk.Label(' ', xpad=6) self.changing_time.modify_font(font.to_pango_desc()) self.total_time = Gtk.Label('00:00:00.00', xalign=1, xpad=6) self.total_time.modify_font(font.to_pango_desc()) self.track_label = Gtk.Label(' ') self.play_pause_button = Gtk.Button() self.play_pause_button.set_image(self.play_img) self.play_pause_button.connect('clicked', self.play_pause_action) self.stop_button = Gtk.Button() self.stop_button.set_image(self.stop_img) self.stop_button.connect('clicked', self.stop_action) self.set_column_spacing(6) self.set_row_spacing(3) self.attach(self.track_label, 0, 0, 3, 1) self.attach(self.current_time, 0, 1, 1, 1) self.attach(self.changing_time, 1, 1, 1, 1) self.attach(self.total_time, 2, 1, 1, 1) self.attach(self.progress, 0, 2, 3, 1) self.attach(self.play_pause_button, 3, 2, 1, 1) self.attach(self.stop_button, 4, 2, 1, 1) self.duration = 360000000 self.duration_str = '0' self.player_state = PlayerState.STOPPED self.player = AudioStreamer() self.timeout_id = GObject.timeout_add(1000, self.on_timeout, None) self.mouse_moving = False
def _render_fonts(text, font=None, show=False, color='WHITE'): if not font: font = random.choice(Font.get_all_fonts()) if not text: text = 'xart' renderer = Renderer(Font(font)) data = renderer.render(text) sys.stdout.write(Color.dyeing(data, Color.get_color(color))) if show: sys.stdout.write('Font name : {}\n'.format(font))
def __init__(self, spi, scs, extcomin, disp): self.spi = spi self.scs = scs self.extcomin = extcomin self.disp = disp self.data = bytearray(12482) self.font = Font() self.data_reset() self.initialize() self.disp.on()
def __init__(self, start_time=None): super().__init__() self.start_time = start_time if self.start_time is None: self.start_time = datetime.now() self.circle = Circle(0, 0, 190, 20, constants.CIRCLE_COLOR, constants.progress) font = Font(constants.NANUMSQUARE_REGULAR_FONT, 72, constants.TEXT_COLOR) self.elapsed_time = Text(0, 0, '', font) font2 = Font(constants.NANUMSQUARE_LIGHT_FONT, 32, constants.TEXT_COLOR) self.elapsed_microsecond = Text(0, 0, '', font2) self.elapsed_days = Text(0, 0, '', font2) self.days = 0 self.time = Time(0) self.start_text: Text = Text(0, 0, str(self.start_time).split('.')[0], Font(constants.NANUMSQUARE_LIGHT_FONT, 32, constants.TEXT_COLOR)) self.window_resize(*display.size)
def fontDialog(parent, aFont=None): if aFont is not None: aFont = aFont._getFont() result = dialogs.fontDialog(parent, font=aFont) if result.accepted: fontData = result.fontData result.color = result.fontData.GetColour().Get() fontWx = result.fontData.GetChosenFont() result.fontDescription = fontDescription(fontWx) fontWx = None result.font = Font(result.fontDescription) return result
def __init__(self, target: datetime, state_manager: StateManager): super().__init__() self.target = target self.state_manager = state_manager self.start_time = datetime.now() self.circle = ProgressCircle(0, 0, 190, 20, constants.CIRCLE_COLOR, constants.progress) self.last_time = Text( 0, 0, '', Font(constants.NANUMSQUARE_REGULAR_FONT, 16, constants.TEXT_COLOR)) self.time = Time(0) self.target_time: Text = Text( 0, 0, str(self.target).split('.')[0], Font(constants.NANUMSQUARE_LIGHT_FONT, 32, constants.TEXT_COLOR)) self.window_resize(*display.size)
def __init__(self): super().__init__() self.radius = 50 center_x = center(display.size[0], ColorSample.get_width_by_radius(self.radius)) y_offset = center(display.size[1], self.radius * 9.6) self.font = Font(constants.NANUMSQUARE_BOLD_FONT, self.radius // 3 * 2, constants.TEXT_COLOR) for i in range(len(Color.SAMPLE_PALETTES)): x, y = center_x, i * self.radius * 4 + y_offset self.objects.append(ColorSample(x, y, self.radius, *Color.SAMPLE_PALETTES[i])) self.objects.append(Text(x + self.font.size // 3, y - self.font.size * 1.5, chr(i + ord('G')), self.font))
def main(): parser = argparse.ArgumentParser( description='xart : generate art ascii texts.') parser.add_argument('-f', '--font', default='', help='font to render with, default random', metavar='FONT') parser.add_argument('-c', '--color', default='WHITE', choices=Color.all_colors(), metavar='COLOR', help='font color, default WHITE, all : {}'.format( ', '.join(Color.all_colors()))) parser.add_argument('-i', '--info', default=False, help='show information of given font', action='store_true') parser.add_argument('-s', '--show', default=False, help='show random fonts', action='store_true') parser.add_argument('-l', '--list', default=False, help='list all supported fonts', action='store_true') parser.add_argument('-v', '--version', default=False, help='version', action='store_true') parser.add_argument('-o', '--outfile', default='', help='output the text to a file', metavar='OUTFILE') args, text = parser.parse_known_args() text = ''.join(text) if args.version: return _print_version() elif args.list: return _print_all_fonts() elif args.info: return print(Font(args.font).info) _render_fonts(text, args.font, args.show, args.color, args.outfile)
def __init__(self, state_manager: StateManager, root_object_manager: RootObjectManager, keyboard_manager: KeyboardManager, handler_manager: HandlerManager, font_path: str = constants.CONSOLAS_FONT, size: int = 15): self.state_manager = state_manager self.root_object_manager = root_object_manager self.keyboard_manager = keyboard_manager self.handler_manager = handler_manager self.font = Font(font_path, size, constants.TEXT_COLOR) self.surfaces = [] self.last_call = time() self.fps_time = 0 self.real_fps = 0
def _render_fonts(text, font=None, show=False, color='WHITE', outfile=''): if not font: font = random.choice(Font.get_all_fonts()) if not text: text = 'xart' renderer = Renderer(Font(font)) data = renderer.render(text) if outfile: with open(outfile, 'w') as fp: fp.write(data) else: sys.stdout.write(Color.dyeing(data, Color.get_color(color))) if show: sys.stdout.write('Font name : {}\n'.format(font))
def __init__(self): pyxel.init(256, 224, palette=[ 0x000000, 0x1D2B53, 0x7E2553, 0x008751, 0xAB5236, 0x5F574F, 0xC2C3C7, 0xFFF1E8, 0xFF004D, 0xFFA300, 0xFFEC27, 0x00E436, 0x29ADFF, 0x83769C, 0xFF77A8, 0xFFCCAA ]) pyxel.image(0).load(0, 0, os.path.join(os.getcwd(), 'asset/system_neko.bmp')) im = Image.open(os.path.join(os.getcwd(), 'asset/font.png')) rgb_im = im.convert('RGB') self.font = Font(rgb_im) self.scene_manager = SceneManager(self) pyxel.run(self.update, self.draw)
def textCheck(self): for r in self.checkM: for m in r: m.setChecked(False) text_to_render = self.type.text() font = Font(os.path.join('Fonts', self.fonts.currentText()), 8) try: text = repr(font.render_text(text_to_render, 52, 7)) text_by_weekday = text.split('\n') for i in range(7): for j in range(51): if text_by_weekday[i][j] == '#': self.checkM[i][j].setChecked(True) except: self.err.setText('You typed too long :(') self.err.exec()
def __init__(self, parent, text): Frame.__init__(self, parent) self.label = Label( self, text, font=Font(size=8, bold=True, color=(0, 0, 255) # XXX: Use system prefs instead of hardcoded blue )) self.hline = HLine(self) sizer = VBox() sizer.add(Spacer(2, 4)) sizer.add(self.label, border=(4, 0, 0, 0)) sizer.add(Spacer(2, 4)) sizer.add(self.hline) self.sizer = sizer
def value(self, default=False): if default: return self._defaultValue settings = QtCore.QSettings() defaultValue = self._defaultValue if self.type == "font": defaultValue = self._defaultValue.toStorableString() value = settings.value(self._key, defaultValue) if self.type == "font": f = Font() f.fromStorableString(value.toString()) return f elif self.type == "bool": return value.toBool() elif self.type == "int": return value.toInt()[0] return value.toPyObject()
def __init__(self, parent, text): Frame.__init__(self, parent) color = GetSysColor(2 | 0x40000000) r = color & 0xff g = (color >> 8) & 0xff b = (color >> 16) & 0xff color = (r, g, b) self.label = Label( self, text, font=Font(size=8, bold=True, color=color # XXX: Use system prefs instead of hardcoded blue )) self.hline = HLine(self) sizer = VBox() sizer.add(Spacer(2, 4)) sizer.add(self.label, border=(4, 0, 0, 0)) sizer.add(Spacer(2, 4)) sizer.add(self.hline) self.sizer = sizer