def handle_say(self, world, input): """ Talk to your fellow mudders!""" if " " in input: text = input.split(" ", 1)[1] self.write(utils.wrap_text("You say: %s" % text, 72, 5, 0) + "\n") world.spamroom(utils.wrap_text("%s says: %s" % (self._name, text), 72, 5, 0) + "\n") else: self.write("say what?\n")
def handle_say(self, world, input): """ Talk to your fellow mudders!""" if " " in input: text = input.split(" ", 1)[1] self.write(utils.wrap_text("You say: %s" % text, 72, 5, 0) + "\n") world.spamroom( utils.wrap_text("%s says: %s" % (self._name, text), 72, 5, 0) + "\n") else: self.write("say what?\n")
def handle_lyntin(self, world, text): """ Returns a paragraph, which coincidentally, is a description of Lyntin.""" output = ("Lyntin is a mud client that is written in Python and uses " + "Python as a scripting language. It strives to be functionally " + "similar to TinTin++ while enhancing that functionality with " + "the ability to call Python functions directly from the input " + "line. It has the advantage of being platform-independent and " + "has multiple interfaces as well--I use Lyntin at home with " + "the Tk interface as well as over telnet using the text " + "interface.\n") output = utils.wrap_text(output, 70, 0, 0) self.write(output)
def handle_lyntin(self, world, text): """ Returns a paragraph, which coincidentally, is a description of Lyntin.""" output = ( "Lyntin is a mud client that is written in Python and uses " + "Python as a scripting language. It strives to be functionally " + "similar to TinTin++ while enhancing that functionality with " + "the ability to call Python functions directly from the input " + "line. It has the advantage of being platform-independent and " + "has multiple interfaces as well--I use Lyntin at home with " + "the Tk interface as well as over telnet using the text " + "interface.\n") output = utils.wrap_text(output, 70, 0, 0) self.write(output)
def __init__(self, Item, pos): self.font = pg.font.SysFont("ubuntumono", 25) self.empty = Item.main_menu_name == "Exit" self.rect = pg.Rect((457, pos[1] - 8), (500, 650)) self.image = self._load_preview(Item.config_params()["preview_file"]) self.border_col = pg.Color(100, 170, 130) self.text_color = pg.Color("#333745") info_text = wrap_text(Item.config_params()["info"], self.font, 500) self.textsurf = self.render_text_list(info_text) print(self.image) new_h = self.textsurf.get_height() + self.image.get_size()[1] + 50 self.rect.h = new_h self.title_pos = ( self.rect.x + 10, self.rect.y + 10, )
def __init__(self, options): self._event_queue = Queue.Queue(0) self._worker = None self._options = options self._ms = None temp = ("Welcome to Neil's Pub--a small tavern of unusual candor. " + "In many ways, this is a dream come true for Neil and it shows " + "in the care he gives to the place. The tavern is both " + "infinitely large and terribly small. There are no exits. " + "Only a long bar and a series of barstools for folks to show " + "up, take a load off, and socialize.") self._desc = wrap_text(temp, 70, 0, 0) self._npcs = [] self._npcs.append(Neil(self))
def __init__(self, options): self._event_queue = Queue.Queue(0) self._worker = None self._options = options self._ms = None temp = ( "Welcome to Neil's Pub--a small tavern of unusual candor. " + "In many ways, this is a dream come true for Neil and it shows " + "in the care he gives to the place. The tavern is both " + "infinitely large and terribly small. There are no exits. " + "Only a long bar and a series of barstools for folks to show " + "up, take a load off, and socialize.") self._desc = wrap_text(temp, 70, 0, 0) self._npcs = [] self._npcs.append(Neil(self))
def look(self, conn, item): if item: for mem in self._npcs: if item == mem._name.lower(): return mem._desc + "\n" for mem in self._ms._conns: if item == mem._name.lower(): return mem._desc + "\n" else: out = self._desc + "\n\n" names = map(lambda x: x._name, self._ms._conns) for mem in self._npcs: names.append(mem._name) out += utils.wrap_text(string.join(names, ', '), 70, 0, 0) out += "\n" return out return "That does not exist.\n"
def look(self, conn, item): if item: for mem in self._npcs: if item == mem._name.lower(): return mem._desc + "\n" for mem in self._ms._conns: if item == mem._name.lower(): return mem._desc + "\n" else: out = self._desc + "\n\n" names = map(lambda x:x._name, self._ms._conns) for mem in self._npcs: names.append(mem._name) out += utils.wrap_text(string.join(names, ', '), 70, 0, 0) out += "\n" return out return "That does not exist.\n"
def set_text(self, text): self.text_flipped = False self.text_surface = self.text_img.copy() sx, sy = self.map_pos() margin = 20 if sy <= 1: margin = 30 self.text_surface = pygame.transform.flip(self.text_surface, False, True) self.text_flipped = True self.text = text size = self.font.size(self.text) max_width = self.text_surface.get_width() - 40; if size[0] > max_width: texts = wrap_text(self.font, self.text, max_width) else: texts = [self.text] for i, t in enumerate(texts): font_surface = self.font.render(t, True, pygame.Color(0, 0, 0)) self.text_surface.blit(font_surface, (20, (i + 1) * margin)) self.text_counter = 100 + len(text) * 3
split_ansi_from_text("\33[1;37mThis is\33[0m text."), ["\33[1;37m", "This is", "\33[0m", " text."]) _pass_fail("split_ansi_from_text 3", split_ansi_from_text("Hi \33[1;37mThis is\33[0m text."), ["Hi ", "\33[1;37m", "This is", "\33[0m", " text."]) _pass_fail("split_ansi_from_text 4", split_ansi_from_text("\33[1;37mThis is\33[0"), ["\33[1;37m", "This is", "\33[0"]) print text = "This is a really long line to see if we're wrapping correctly. Because it's way cool when we write code that works. Yay!" from utils import wrap_text _pass_fail("wrap text 1", wrap_text(text), """This is a really long line to see if we're wrapping correctly. Because it's way cool when we write code that works. Yay!""") _pass_fail("wrap text 2", wrap_text(text, indent=5), """This is a really long line to see if we're wrapping correctly. Because it's way cool when we write code that works. Yay!""") _pass_fail("wrap text 3", wrap_text(text, indent=5, firstline=1), """ This is a really long line to see if we're wrapping correctly. Because it's way cool when we write code that works. Yay!""")
split_ansi_from_text("\33[1;37mThis is\33[0m text."), ["\33[1;37m", "This is", "\33[0m", " text."]) _pass_fail("split_ansi_from_text 3", split_ansi_from_text("Hi \33[1;37mThis is\33[0m text."), ["Hi ", "\33[1;37m", "This is", "\33[0m", " text."]) _pass_fail("split_ansi_from_text 4", split_ansi_from_text("\33[1;37mThis is\33[0"), ["\33[1;37m", "This is", "\33[0"]) print text = "This is a really long line to see if we're wrapping correctly. Because it's way cool when we write code that works. Yay!" from utils import wrap_text _pass_fail( "wrap text 1", wrap_text(text), """This is a really long line to see if we're wrapping correctly. Because it's way cool when we write code that works. Yay!""") _pass_fail( "wrap text 2", wrap_text(text, indent=5), """This is a really long line to see if we're wrapping correctly. Because it's way cool when we write code that works. Yay!""") _pass_fail( "wrap text 3", wrap_text(text, indent=5, firstline=1), """ This is a really long line to see if we're wrapping correctly. Because it's way cool when we write code that works. Yay!""")
def main(): # logging.basicConfig(level=logging.DEBUG, format='%(message)s') logging.basicConfig(level=logging.WARN, format='%(message)s') trans_table = utils.translation_table() max_len = 128 - 4 - 3 with open('/home/michal/dos/PUDR/PUDR/DATA.PAS', mode='w', encoding='latin1', newline='\r\n') as f: print('{generated by tools/encode_texts.py}\n', file=f) # generate texts for section_name, section_texts in data.texts.items(): print( f'{section_name}: array[0..{len(section_texts) - 1}]' f' of string[{max(len(t) for t in section_texts)}] = (', file=f) output = [] for item in section_texts: if isinstance(item, list): output_line = ''.join(chr(n + 48) for n in item) else: wrapped = list(utils.wrap_text(item)) logging.debug('{}\n{}'.format('\n'.join(wrapped), '-' * 27)) if len(wrapped) > 6 or (section_name == 'texts_other' and len(wrapped) > 4): logging.warning('TOO MANY LINES:\n{}'.format( '\n'.join(wrapped))) output_line = '_'.join(wrapped).translate(trans_table) if len(output_line) > max_len: # divide to fit in Turbo Pascal IDE's max line length 128 output_line = f"{output_line[:max_len]}'\n" \ f" + '{output_line[max_len:]}" # because of this, can't use {!r} on the following line output.append(f' \'{output_line}\'') print(',\n'.join(output), file=f) print('\n);\n', file=f) # generate things thing_count = len(data.things) - 1 print(f'things: array[0..{thing_count}] of thing = (', file=f) output = [] for thing in data.things: name = thing['name'].translate(trans_table) img_name = thing['image'][:8] wrapped = list(utils.wrap_text(thing['description'])) logging.debug('{}\n{}'.format('\n'.join(wrapped), '-' * 27)) if len(wrapped) > 4: logging.warning('TOO MANY LINES:\n{}'.format( '\n'.join(wrapped))) desc = '_'.join(wrapped).translate(trans_table) output.append(f" (name: '{name}'; where: {thing['where']};" f" portable: {thing['portable']};" f" slot: {thing['slot']};" f"\n desc: '{desc}';\n image: @{img_name})") print(',\n\n'.join(output), file=f) print('\n);\n', file=f) print(f'thing_count: Byte = {thing_count};\n', file=f)
processed_fund_names = [] if st.button('Adjust Character Width'): ss.max_char_slider = ~ss.max_char_slider if ss.max_char_slider: max_char = st.slider('Character Width', min_value=1, max_value=100, value=ss.max_char) ss.max_char = max_char else: max_char = ss.max_char for fund_name in fund_list: processed_text = wrap_text(fund_name, max_char) processed_fund_names.append(processed_text) # Display Piechart fig1 = plt.figure(figsize=(12, 10)) ax = fig1.gca() ax.pie(x=cur_val_list, autopct='%1.1f%%', labels=processed_fund_names) plt.title('Distribution of funds') fig1.tight_layout() st.pyplot(fig1) # Display barchart fluid and fixed funds expanded_cur_val_list = [] ind = [0, 1] for i, fund_name in enumerate(fund_list): cur_val = cur_val_list[i]
def paint_chat(self): self.screen.blit(self.chat_surface, (0, self.screen.get_height() - self.chat_surface.get_height())) texts = wrap_text(self.font, self.text, self.screen.get_width() - 40) for i, t in enumerate(texts): font_surface = self.font.render(t, True, pygame.Color(0, 0, 0)) self.screen.blit(font_surface, (20, (i * 20) + self.screen.get_height() - self.chat_surface.get_height()))