### Start Python Simulacrum GUI Application Source: https://context7.com/dnd5echm/python_simulacrum/llms.txt Launches the main graphical user interface for the Python Simulacrum application. It requires importing the Simulacrum class from the gui module and calling its mainloop() method. The application version is passed during initialization. ```python from gui import Simulacrum # Launch the GUI application VERSION = "1.1.1" gui = Simulacrum(VERSION) gui.mainloop() ``` -------------------------------- ### Open and Save Documents Source: https://context7.com/dnd5echm/python_simulacrum/llms.txt Facilitates opening and saving files with a graphical interface. It supports various formats including HTML, DOC, DOCX, RTF, and TXT. For DOC files, it uses COM automation via Word. HTML files are preprocessed, and content is saved with specified encoding (GBK used in example). ```python from gui.Functions import ask_open_file, ask_save_file # Open file dialog and read content # Supports .htm, .html, .doc, .docx, .rtf, .txt file_content = ask_open_file() if file_content: print(f"Loaded {len(file_content)} characters") # Automatically preprocesses HTML content # Converts .doc to .docx using Word COM interface # Extracts body content from HTML files # Save file dialog success, file_path, file_name = ask_save_file("MyDocument", ".htm") if success: with open(file_path, "w", encoding="GBK", errors="ignore") as f: # Read template with open("template/Empty.htm", "r", encoding="GBK") as template_file: template = template_file.read() # Replace placeholders output = template.replace("{{内容}}", content).replace("{{标题}}", file_name) f.write(output) print(f"Saved to {file_path}") ``` -------------------------------- ### Build Distributable ZIP Package Source: https://context7.com/dnd5echm/python_simulacrum/llms.txt Creates a distributable ZIP archive for the application. It includes the executable, icons, and necessary resource folders. Uses Python's `zipfile` module and a helper function `add_folder_to_zip` to manage directory structures within the archive. Versioning is supported. ```python from Packer import add_folder_to_zip import zipfile import os VERSION = "1.1.1" # Create output directory if not os.path.exists("output"): os.makedirs("output") # Build release package with zipfile.ZipFile(f"output/果园拟像术 {VERSION}.zip", 'w') as zip_file: # Add executable zip_file.write("./dist/Simulacacrum.exe", "./Simulacrum.exe") # Add icon zip_file.write("./icon/icon.ico", "./icon/icon.ico") # Add template folders add_folder_to_zip(zip_file, "template") add_folder_to_zip(zip_file, "trash_styles") print(f"Package created: output/果园拟像术 {VERSION}.zip") ``` -------------------------------- ### Read and Write HTML to Clipboard Source: https://context7.com/dnd5echm/python_simulacrum/llms.txt Manages HTML data on the Windows clipboard. It can read HTML, check for its presence, and write formatted HTML content. Dependencies include the 'module.HTMLClipboard' library. Outputs clipboard content or confirmation messages. ```python import module.HTMLClipboard as hcp # Read HTML from clipboard html_data = hcp.GetHtml() if html_data: print(f"Clipboard contains HTML: {html_data[:100]}...") # Check if clipboard has HTML format if hcp.HasHtml(): print("Clipboard contains HTML data") # Write HTML to clipboard formatted_html = "
Content with formatting
" hcp.PutHtml(formatted_html) print("HTML written to clipboard") # Alternative CHM format (for specific encoding) hcp.PutHtml(formatted_html, test=True) ``` -------------------------------- ### Generate Monster Stat Blocks for Multiple Platforms Source: https://context7.com/dnd5echm/python_simulacrum/llms.txt Creates formatted monster stat blocks from plain text data, tailored for different RPG platforms and formats like Goddess forum BBCode or Notall HTML. It handles styling, color-coding, and layout specific to each target platform, using templates defined within the SummonMonster module. ```python from module.SummonMonster import summon_monster # Monster data in plain text format monster_text = """Ancient Red Dragon 巨型龙类,混乱邪恶 护甲等级 22(天生护甲) 生命值 546(28d20+252) 速度 40尺,攀爬40尺,飞行80尺 力量 30(+10) 敏捷 10(+0) 体质 29(+9) 智力 18(+4) 感知 13(+1) 魅力 23(+6) 豁免 敏捷+7,体质+16,感知+8,魅力+13 技能 察觉+15,隐匿+7 伤害免疫 火焰 感官 盲视60尺,黑暗视觉120尺,被动察觉25 语言 通用语,龙语 挑战等级 24(62000 XP) 传奇抗性(3/日)。若龙在豁免检定中失败,它可以选择改为成功。 多重攻击。龙可以使用其恐惧光环。随后进行三次攻击。 撕咬 Bite。近战武器攻击:命中+17,触及15尺,单一目标。 命中:21(2d10+10)点穿刺伤害加14(4d6)点火焰伤害。""" # Generate for different platforms goddess_bbcode = summon_monster(monster_text, "Goddess5EMonster") notall_html = summon_monster(monster_text, "Notall5EMonster") hedgehog_html = summon_monster(monster_text, "HedgehogMonster") saltmeow_html = summon_monster(monster_text, "SaltymeowMonster", legacy=True) # Each format includes: # - Styled headers and ability names # - Color-coded terms (conditions, cover types) # - Spell highlighting with # markers # - Proper attribute tables with modifiers and saves # - Template-based layout specific to each platform ``` -------------------------------- ### Parse and Traverse HTML Tags Source: https://context7.com/dnd5echm/python_simulacrum/llms.txt Provides functions for navigating and extracting information from HTML structures. It can find tag pairs, extract attributes like styles, determine default page names from HTML, and decode HTML entities. Requires 'module.HTMLTagTraverse'. ```python from module.HTMLTagTraverse import find_tag_pair, htmltag, translate_html_entity html_doc = 'Content...
" filename = get_page_default_name(page_html) print(f"Suggested filename: {filename}.htm") # "Dragon Compendium_ Ancient Dragons.htm" # Decode HTML entities encoded = "Attack & damage: 2d6+4 Range <60ft>" decoded = translate_html_entity(encoded) print(decoded) # "Attack & damage: 2d6+4 Range <60ft>" ``` -------------------------------- ### Convert HTML to BBCode Format Source: https://context7.com/dnd5echm/python_simulacrum/llms.txt Transforms HTML markup into BBCode format, preserving essential formatting like bold, italics, colors, and font sizes. It adapts HTML tags and styles to their corresponding BBCode equivalents, suitable for forum environments. This function is part of the BBCode module. ```python from module.BBCode import morph_html_to_bbcode # Convert HTML content to BBCode html_input = """Dragon
Legendary creature
A powerful beast with blue scales.
""" bbcode_output = morph_html_to_bbcode(html_input) print(bbcode_output) # Output: # [b]Dragon[/b] # [color=#FF0000][size=18pt][b]Legendary creature[/b][/size][/color] # A [i]powerful[/i] beast with [color=#0000FF]blue scales[/color]. ``` -------------------------------- ### Generate HTML Table from Delimited Text Source: https://context7.com/dnd5echm/python_simulacrum/llms.txt Automatically generates a formatted HTML table from text data where columns are separated by tabs or pipes. It supports options like bolding the first line and applies styling such as alternating row colors and centered columns for specific data types like dice notation. This function is part of the AutoTabler module. ```python from module.AutoTabler import make_table # Create table from delimited text table_data = """d20|Result|Effect 1-5|Failure|No damage 6-15|Success|1d6 damage 16-20|Critical|2d6 damage""" html_table = make_table(table_data, first_line_bold=True) # Generates styled HTML table with: # - First row bolded # - Alternating row colors (#eeeeee) # - Centered dice column if detected (d20) # - Proper cell spacing and structure ``` -------------------------------- ### Clean HTML Formatting Source: https://context7.com/dnd5echm/python_simulacrum/llms.txt Removes unnecessary or 'junk' formatting from HTML content, often originating from sources like Word documents or web forums. The function attempts to automatically detect the source and strips extraneous styling while retaining the core structure and content. It's part of the FormatTrashBinner module. ```python from module.FormatTrashBinner import clean_trash_format # Clean HTML copied from Word or web pages messy_html = """Title
Content from forum""" cleaned_html = clean_trash_format(messy_html, using="auto") print(cleaned_html) # Automatically detects source (Word/goddess forum) and removes junk formatting # Output:Title
Content from forum ``` -------------------------------- ### Convert RGB to Hexadecimal Color Source: https://context7.com/dnd5echm/python_simulacrum/llms.txt Converts CSS-style RGB color values (e.g., 'rgb(255, 128, 64)') into their hexadecimal representation suitable for web standards. It also handles direct hexadecimal inputs. Requires 'module.Tools'. ```python from module.Tools import rgb_to_hex # Convert CSS RGB to hex rgb_color = "rgb(255, 128, 64)" hex_color = rgb_to_hex(rgb_color) print(hex_color) # "#FF8040" # Handles edge cases print(rgb_to_hex("rgb(10, 5, 200)")) # "#0A05C8" print(rgb_to_hex("#FF0000")) # "#FF0000" (passes through) ``` -------------------------------- ### Remove BBCode Tags Source: https://context7.com/dnd5echm/python_simulacrum/llms.txt Strips BBCode formatting tags from a given string to extract plain text content. Handles various BBCode tags including basic formatting, colors, sizes, quotes, tables, and inline elements. Requires 'module.Tools'. ```python from module.Tools import purge_bbcode bbcode_content = """ [b]Dragon Attack[/b] [color=#FF0000]Fire damage:[/color] [size=14pt]3d6[/size] [quote] [i]Save:[/i] DC 18 Dexterity [/quote] [table][tr][td]Ability[/td][td]Score[/td][/tr][/table]""" plain_text = purge_bbcode(bbcode_content) print(plain_text) # Output: # Dragon Attack # Fire damage: 3d6 # # Save: DC 18 Dexterity # # Ability Score ``` -------------------------------- ### Extract Plain Text from HTML Source: https://context7.com/dnd5echm/python_simulacrum/llms.txt Strips all HTML tags from a given HTML string, converting it into plain text. It aims to preserve meaningful line breaks and structural elements, making the content more readable without the markup. This utility function is found in the Tools module. ```python from module.Tools import purge_html html_content = """Description text here.
| AC | 15 |
| HP | 45 |