# Common Encounter Builder Modules

## exporters module

Functions to export program data to other file formats.

`exporters.``_add_actions_to_table`(actions: list, table: PyRTF.Elements.Table, style_sheet: PyRTF.Elements.StyleSheet, shading: PyRTF.PropertySets.AttributedList)

  Adds a set of actions as rows to a table.

  Parameters: | actions – List of ActionPanel objects to add. table – Table to add the action rows to. style_sheet – StyleSheet object associated with the document. shading – AttributedList of ShadingPropertySet objects to help color the table cells.

`exporters.``_export_monster_to_table`(document: PyRTF.Elements.Document, shading: PyRTF.PropertySets.AttributedList, monster: monster_builder.MonsterBuilderPanel) → PyRTF.Elements.Table

  Creates an RTF Table out of a monster’s data, presumably to add into a section of an RTF document.

  Parameters: | document – The Document that will hold the Table. Used to extract style sheet info. shading – An AttributedList of ShadingPropertySets as created by make_dnd_shading(). monster – The MonsterBuilderPanel object whose data should be exported.
  Returns: | An RTF Table object representing the monster’s data, ready to integrate into a Section of a Document.

`exporters.``_process_markup_text`(text: str, paragraph: PyRTF.Elements.Paragraph = None, style: PyRTF.Styles.ParagraphStyle = None) → PyRTF.Elements.Paragraph

  Takes the raw text from a “markup supported” text box (e.g., an action or trait panel) and transform it into an RTF-compatible text block.

  Parameters: | text – The raw text to process. paragraph – If not None, the existing Paragraph to add this text to. If None, will make a new Paragraph. style – If Paragraph is None, this is the ParagraphStyle to apply to the newly created Paragraph.
  Returns: | paragraph updated with the processed contents of text, or a new Paragraph of style if paragraph is None.

`exporters.``export_encounter_to_rtf`(filename: str, encounter: encounter_builder.EncounterBuilderPanel) → bool

  Creates an RTF file containing the given encounter’s data.

  Encounter description and stats will appear as opening paragraphs, and monsters will appear as tables.

  Parameters: | filename – Filename (possibly with path) to export to. Will be overwritten if it already exists. encounter (EncounterBuilderPanel) – An EncounterBuilderPanel object whose data should be exported.
  Returns: | True if the file could be opened and exported to, False otherwise.

`exporters.``export_monster_to_rtf`(filename: str, monster: monster_builder.MonsterBuilderPanel) → bool

  Creates an RTF file containing the given monster’s data as a table.

  Parameters: | filename – Filename (possibly with path) to export to. Will be overwritten if it already exists. monster (MonsterBuilderPanel) – A MonsterBuilderPanel object whose data should be exported.
  Returns: | True if the file could be opened and exported to, False otherwise.

`exporters.``landscape_dimensions`(paper: PyRTF.PropertySets.Paper) → PyRTF.PropertySets.Paper

  Returns inverted dimensions of a PyRTF Paper, effectively “landscaping” it. Still have to set landscape to true in any applicable sections.

`exporters.``make_dnd_shading`(style_sheet) → PyRTF.PropertySets.AttributedList

  Creates a PyRTF.PropertySets.AttributedList of pre-made ShadingPropertySet objects that can be used for shading text and document elements. :param style_sheet: The StyleSheet object for the document.

`exporters.``make_dnd_style_sheet`() → PyRTF.Elements.StyleSheet

  Creates and returns a PyRTF.Elements.StyleSheet object suitable for use when exporting entities to RTF files.

## file_utils module

Functions to load/save monsters from/to files.

`file_utils.``_dict_to_encounter`(encounter_dict: dict, encounter: EncounterBuilderPanel, filename: Union[str, NoneType] = None) → Tuple[[bool, int], int]

  Takes a dictionary equivalent to one generated by _encounter_to_dict() and applies its data to the given EncounterBuilderPanel.

  Parameters: | encounter_dict – Dictionary representation of an encounter as generated by _encounter_to_dict(). encounter – EncounterBuilderPanel that should be populated with the unpacked contents of encounter_dict. filename – The (optional) filename of the encounter file that the dictionary was loaded from. Used for path resolution when loading monster files.
  Returns: | Tuple: (T/F if the dictionary was unpacked successfully, # of monsters unpacked, # of monsters (if any) that had to be unpacked from backup data).

`file_utils.``_dict_to_monster`(monster_dict: dict, monster: monster_builder.MonsterBuilderPanel, filename: Union[str, NoneType] = None) → bool

  Takes a dictionary equivalent to one generated by _monster_to_dict() and applies its data to the given MonsterBuilderPanel.

  Parameters: | monster_dict – Dictionary representation of a monster as generated by _monster_to_dict(). monster – MonsterBuilderPanel that should be populated with the unpacked contents of monster_dict. filename – The (optional) filename of the monster file that the dictionary was loaded from.
  Returns: | True if the dictionary was unpacked successfully, False if not.

`file_utils.``_encounter_to_dict`(encounter: EncounterBuilderPanel, filename: Union[str, NoneType] = None) → dict

  Takes an encounter defined in an EncounterBuilderPanel and returns a dictionary containing its data.

  Parameters: | encounter – EncounterBuilderPanel that should be the source of data for the encounter dictionary. filename – The (optional) filename of the encounter file that the dictionary will be saved to. Used for path resolution when setting monster file names.

`file_utils.``_monster_to_dict`(monster: monster_builder.MonsterBuilderPanel) → dict

  Takes a monster defined in a MonsterBuilderPanel and returns a dictionary containing its data.

`file_utils.``_v_i_dict_from_list`(in_list: list) → dict

  Returns a dictionary whose keys are the elements of in_list and whose values are the indices of each repsective element.

`file_utils.``abs_path`(path: str, *paths) → str

  Converts the given path & path components (joined via os.path.join()) to an absolute path, assuming minimal shenanigans.

`file_utils.``dict_to_monster`(monster_dict: dict, monster: monster_builder.MonsterBuilderPanel, filename: Union[str, NoneType] = None) → bool

  Takes a dictionary equivalent to one generated by _monster_to_dict() and applies its data to the given MonsterBuilderPanel.

  Publicly accessible version of _dict_to_monster().

  Parameters: | monster_dict – Dictionary representation of a monster as generated by _monster_to_dict(). monster – MonsterBuilderPanel that should be populated with the unpacked contents of monster_dict. filename – The (optional) filename of the monster file that the dictionary was loaded from.
  Returns: | True if the dictionary was unpacked successfully, False if not.

`file_utils.``load_encounter`(filename: str, encounter: EncounterBuilderPanel) → Tuple[[bool, int], int]

  Loads the encounter defined in the specified file to the given frame.

  Parameters: | filename – Filename (possibly with path) to load from. encounter (EncounterBuilderPanel) – An EncounterBuilderPanel object whose data should be overridden by the contents of the file.
  Returns: | Tuple: (T/F if the dictionary was unpacked successfully, # of monsters unpacked, # of monsters (if any) that had to be unpacked from backup data).

`file_utils.``load_monster`(filename: str, monster: monster_builder.MonsterBuilderPanel) → bool

  Loads the monster defined in the specified file to the given frame.

  Parameters: | filename – Filename (possibly with path) to load from. monster (MonsterBuilderPanel) – A MonsterBuilderPanel object whose data should be overridden by the contents of the file.
  Returns: | True if the file could be opened and loaded, False otherwise.

`file_utils.``path_rel_to_program`(path: str, *paths) → str

  Given a set of os.path.join()-style args, creates a path from them starting from this file’s current location.

  Used to point to files & resources relative to the program’s installation directory.

`file_utils.``save_encounter`(filename: str, encounter: EncounterBuilderPanel) → bool

  Saves the encounter defined in the given frame to the specified file.

  Parameters: | filename – Filename (possibly with path) to save to. Will be overwritten if it already exists. encounter (EncounterBuilderPanel) – An EncounterBuilderPanel object whose data should be saved.
  Returns: | True if the file could be opened and written, False otherwise.

`file_utils.``save_monster`(filename: str, monster: monster_builder.MonsterBuilderPanel) → bool

  Saves the monster defined in the given frame to the specified file.

  Parameters: | filename – Filename (possibly with path) to save to. Will be overwritten if it already exists. monster (MonsterBuilderPanel) – A MonsterBuilderPanel object whose data should be saved.
  Returns: | True if the file could be opened and written, False otherwise.

## stat_stuff module

Contains stat calculation and manipulation functions.

`stat_stuff.``_calc_attribute_score`(base_attr: int, lvl: int, role_mod: str) → int

  Calculates level-appropriate score for an attribute. If the base attribute is GREAT or higher (i.e., likely a “primary attribute”), adds 1 per 4 levels. Otherwise adds 1 to the attribute per post-Heroic tier. Elite monsters get +2 to everything, Solos get +4 to everything.

  Parameters: | base_attr – Integer base attribute score. lvl – Integer level. role_mod – String name of the current role mod (ROLE_MODS).
  Returns: | Integer level-adjusted attribute score.

`stat_stuff.``_get_def_mod`(mod: str) → int

  Calculates modifier value for a defense.

  Parameters: | mod – String modifier of a defense stat (STAT_MOD_CATEGORIES).
  Returns: | Integer adjustment to apply to the stat.

`stat_stuff.``calc_ac`(role: str, lvl: int, mod: str = 'Normal') → int

  Calculates default AC based on the monster’s role & level.

  Parameters: | role – String role of the monster (ROLES). lvl – Level of the monster. mod – String modifier of AC stat (STAT_MOD_CATEGORIES).
  Returns: | Integer AC.

`stat_stuff.``calc_attribute_mod`(attr: int, lvl: int = 0) → int

  Calculates the modifier of an attribute, including the “+1/2 level” bit. Use 0 for lvl to just get base modifier.

  Parameters: | attr – Integer attribute value. lvl – Integer level.
  Returns: | Integer attribute modifier.

`stat_stuff.``calc_base_hp`(role: str, lvl: int, role_mod: str, mod: str = 'Normal') → int

  Calculates base HP based on the monster’s role & level.

  Parameters: | role – String role of the monster (ROLES). lvl – Level of the monster. role_mod – String name of the current role mod (ROLE_MODS). mod – String modifier of HP stat (STAT_MOD_CATEGORIES).
  Returns: | Integer base HP.

`stat_stuff.``calc_cha`(lvl: int, attribute_role: str, role_mod: str) → int

  Calculates level-appropriate Charisma for a monster based on level and role.

  Parameters: | lvl – Integer level. attribute_role – String name of the monster’s attribute role (key of DEFAULT_ROLE_STATS). role_mod – String name of the current role mod (ROLE_MODS).
  Returns: | Integer Charisma score.

`stat_stuff.``calc_con`(lvl: int, attribute_role: str, role_mod: str) → int

  Calculates level-appropriate Constitution for a monster based on level and role.

  Parameters: | lvl – Integer level. attribute_role – String name of the monster’s attribute role (key of DEFAULT_ROLE_STATS). role_mod – String name of the current role mod (ROLE_MODS).
  Returns: | Integer Constitution score.

`stat_stuff.``calc_dex`(lvl: int, attribute_role: str, role_mod: str) → int

  Calculates level-appropriate Dexterity for a monster based on level and role.

  Parameters: | lvl – Integer level. attribute_role – String name of the monster’s attribute role (key of DEFAULT_ROLE_STATS). role_mod – String name of the current role mod (ROLE_MODS).
  Returns: | Integer Dexterity score.

`stat_stuff.``calc_fort`(role: str, lvl: int, mod: str = 'Normal') → int

  Calculates default Fortitude defense based on the monster’s role & level.

  Parameters: | role – String role of the monster (ROLES). lvl – Level of the monster. mod – String modifier of Fort stat (STAT_MOD_CATEGORIES).
  Returns: | Integer Fort defense.

`stat_stuff.``calc_init`(lvl: int, role: str, dex: int, mod: str = 'Normal') → int

  Calculates Initiative mod based on level, role, & Dex.

  Parameters: | lvl – Integer level. role – String role of the monster (ROLES). dex – Integer Dexterity attribute. mod – String modifier of Init stat (STAT_MOD_CATEGORIES).
  Returns: | Integer Initiative modifier.

`stat_stuff.``calc_int`(lvl: int, attribute_role: str, role_mod: str) → int

  Calculates level-appropriate Intelligence for a monster based on level and role.

  Parameters: | lvl – Integer level. attribute_role – String name of the monster’s attribute role (key of DEFAULT_ROLE_STATS). role_mod – String name of the current role mod (ROLE_MODS).
  Returns: | Integer Intelligence score.

`stat_stuff.``calc_ref`(role: str, lvl: int, mod: str = 'Normal') → int

  Calculates default Reflex defense based on the monster’s role & level.

  Parameters: | role – String role of the monster (ROLES). lvl – Level of the monster. mod – String modifier of Ref stat (STAT_MOD_CATEGORIES).
  Returns: | Integer Ref defense.

`stat_stuff.``calc_str`(lvl: int, attribute_role: str, role_mod: str) → int

  Calculates level-appropriate Strength for a monster based on level and role.

  Parameters: | lvl – Integer level. attribute_role – String name of the monster’s attribute role (key of DEFAULT_ROLE_STATS). role_mod – String name of the current role mod (ROLE_MODS).
  Returns: | Integer Strength score.

`stat_stuff.``calc_will`(role: str, lvl: int, mod: str = 'Normal') → int

  Calculates default Will defense based on the monster’s role & level.

  Parameters: | role – String role of the monster (ROLES). lvl – Level of the monster. mod – String modifier of Will stat (STAT_MOD_CATEGORIES).
  Returns: | Integer Will defense.

`stat_stuff.``calc_wis`(lvl: int, attribute_role: str, role_mod: str) → int

  Calculates level-appropriate Wisdom for a monster based on level and role.

  Parameters: | lvl – Integer level. attribute_role – String name of the monster’s attribute role (key of DEFAULT_ROLE_STATS). role_mod – String name of the current role mod (ROLE_MODS).
  Returns: | Integer Wisdom score.

`stat_stuff.``calc_xp`(lvl: int, role_mod: str) → int

  Calculates normal monster XP based on current level & role mod.

  Parameters: | lvl – Integer level. role_mod – String name of the current role mod (ROLE_MODS).
  Returns: | Integer XP value.

`stat_stuff.``is_recharge_numeric`(recharge_str: str) → tuple

  Checks if recharge frequency is a reasonable subset of d6 faces.

  Parameters: | recharge_str – The raw string the user entered for recharge frequency.
  Returns: | Tuple. First element True/False if it’s a set of d6 faces. Second element either array of faces or raw text if can’t be parsed.

`stat_stuff.``signed_value`(val: int) → str

  Checks if a given integer is positive or negative, prepends ‘+’ or ‘-‘ to a string representation of it (respectively).

## ui_helpers module

Contains helper data, functions, and classes for UI creation & management.

class `ui_helpers.``BuilderFrame`

  Bases: `wx._core.Frame`

  Abstract base class of any Frame used in the application.

  This way children of the application’s frame can guarantee their parent has certain methods, regardless of which style of builder is being presented.

  `__metaclass__`

    alias of `abc.ABCMeta`

  `__module__` = 'ui_helpers'
  `_initialize`()
  `_setup_ui`()
  `clear_status`()
  `repaint`()
  `resize`()
  `set_status`(status_text: str, clear_later: bool = True)

`ui_helpers.``basic_button`(parent: wx._core.Window, label: str, sizer: wx._core.Sizer, style: int = 0, proportion: int = 0, flag: int = 240, border: int = 4) → wx._core.Button

  Creates a wx.Button object with “normal” parameters and adds it to the given sizer.

  Parameters: | parent – wx.Window serving as the parent. label – The initial text of the button. sizer – wx.Sizer supporting an Add() method similar to wx.BoxSizer. style – OR’d set of Style flags. proportion – Proportion argument for the sizer. flag – Flags to pass to the sizer when adding the control. border – Size of the padding between this and other controls.
  Returns: | A wx.StaticText object set up with the appropriate parent & label.

`ui_helpers.``basic_checkbox`(parent: wx._core.Window, label: str, sizer: wx._core.Sizer, style: int = 0, proportion: int = 0, flag: int = 240, border: int = 4) → wx._core.CheckBox

  Creates a wx.CheckBox object with “normal” parameters and adds it to the given sizer.

  Parameters: | parent – wx.Window serving as the parent. label – The caption of the checkbox. sizer – wx.Sizer supporting an Add() method similar to wx.BoxSizer. style – OR’d set of Style flags. proportion – Proportion argument for the sizer. flag – Flags to pass to the sizer when adding the control. border – Size of the padding between this and other controls.
  Returns: | A wx.CheckBox object set up with the appropriate parent & value.

`ui_helpers.``basic_checklist`(parent: wx._core.Window, choices: list, sizer: wx._core.Sizer, minsize: wx._core.Size = None, style: int = 0, proportion: int = 0, flag: int = 240, border: int = 4) → wx._core.CheckListBox

  Creates a wx.CheckListBox object with “normal” parameters and adds it to the given sizer.

  Parameters: | parent – wx.Window serving as the parent. choices – A list of initial choices for the dropdown. sizer – wx.Sizer supporting an Add() method similar to wx.BoxSizer. minsize – If not None, a wx.Size object to apply to the minimum size of the checklist. style – OR’d set of Style flags. proportion – Proportion argument for the sizer. flag – Flags to pass to the sizer when adding the control. border – Size of the padding between this and other controls.
  Returns: | A wx.CheckListBox object set up with the appropriate parent & value.

`ui_helpers.``basic_dropdown`(parent: wx._core.Window, choices: list, sizer: wx._core.Sizer, minsize: wx._core.Size = None, style: int = 0, proportion: int = 0, flag: int = 240, border: int = 4) → wx._core.Choice

  Creates a wx.Choice object with “normal” parameters and adds it to the given sizer.

  Parameters: | parent – wx.Window serving as the parent. choices – A list of initial choices for the dropdown. sizer – wx.Sizer supporting an Add() method similar to wx.BoxSizer. minsize – If not None, a wx.Size object to apply to the minimum size of the dropdown. style – OR’d set of Style flags. proportion – Proportion argument for the sizer. flag – Flags to pass to the sizer when adding the control. border – Size of the padding between this and other controls.
  Returns: | A wx.Choice object set up with the appropriate parent & value.

`ui_helpers.``basic_label`(parent: wx._core.Window, label: str, sizer: wx._core.Sizer, style: int = 0, proportion: int = 0, flag: int = 240, border: int = 4) → wx._core.StaticText

  Creates a wx.StaticText object with “normal” parameters and adds it to the given sizer.

  Parameters: | parent – wx.Window serving as the parent. label – The initial text of the label. sizer – wx.Sizer supporting an Add() method similar to wx.BoxSizer. style – OR’d set of Style flags. proportion – Proportion argument for the sizer. flag – Flags to pass to the sizer when adding the control. border – Size of the padding between this and other controls.
  Returns: | A wx.StaticText object set up with the appropriate parent & label.

`ui_helpers.``basic_radiobutton`(parent: wx._core.Window, label: str, sizer: wx._core.Sizer, group_start: bool = False, style: int = 0, proportion: int = 0, flag: int = 240, border: int = 4) → wx._core.RadioButton

  Creates a wx.RadioButton object with “normal” parameters and adds it to the given sizer.

  Parameters: | parent – wx.Window serving as the parent. label – The caption of the radio button. sizer – wx.Sizer supporting an Add() method similar to wx.BoxSizer. group_start – True to include RB_GROUP in style and start a new radio group, False to include with last group. style – OR’d set of Style flags. proportion – Proportion argument for the sizer. flag – Flags to pass to the sizer when adding the control. border – Size of the padding between this and other controls.
  Returns: | A wx.CheckBox object set up with the appropriate parent & value.

`ui_helpers.``basic_textbox`(parent: wx._core.Window, value: str, sizer: wx._core.Sizer, minsize: wx._core.Size = None, style: int = 0, proportion: int = 0, flag: int = 240, border: int = 4) → wx._core.TextCtrl

  Creates a wx.TextCtrl object with “normal” parameters and adds it to the given sizer.

  Parameters: | parent – wx.Window serving as the parent. value – The initial contents of the text box. sizer – wx.Sizer supporting an Add() method similar to wx.BoxSizer. minsize – If not None, a wx.Size object to apply to the minimum size of the text box. style – OR’d set of Style flags. proportion – Proportion argument for the sizer. flag – Flags to pass to the sizer when adding the control. border – Size of the padding between this and other controls.
  Returns: | A wx.StaticText object set up with the appropriate parent & value.

`ui_helpers.``get_dropdown_str`(dropdown: wx._core.Choice) → str

  Convenience function to grab the string value of a dropdown’s selection.

  Parameters: | dropdown – wx.Choice object.
  Returns: | The string value of the current selection of the dropdown box.

`ui_helpers.``get_textbox_attribute`(textbox: wx._core.TextCtrl) → int

  Convenience function to get the integer value of an attribute text box.

  Parameters: | textbox – wx.TextCtrl object.
  Returns: | Integer value of the textbox, or DEFAULT_ATTR_VAL if the text box’s value can’t be parsed as an int.

`ui_helpers.``get_textbox_int`(textbox: Union[wx._core.TextEntry, wx._core.SpinCtrl]) → int

  Convenience function to get the integer value of a text box.

  Parameters: | textbox – wx.TextCtrl object, or something that supports GetValue().
  Returns: | Integer value of the textbox, or 0 if the text box’s value can’t be parsed as an int.

`ui_helpers.``labeled_textbox`(parent: wx._core.Window, label: str, value: str, sizer: wx._core.Sizer, minsize: wx._core.Size = None, label_style: int = 0, text_style: int = 0, label_prop: int = 0, text_prop: int = 0, label_flag: int = 240, text_flag: int = 240, label_border: int = 4, text_border: int = 4) → tuple

  Creates wx.StaticText and wx.TextCtrl objects with “normal” parameters and adds them to the given sizer. The StaticText object will come before the TextCtrl object and serve as its label.

  Parameters: | parent – wx.Window serving as the parent. label – The text for the label. value – The initial contents of the text box. sizer – wx.Sizer supporting an Add() method similar to wx.BoxSizer. minsize – If not None, a wx.Size object to apply to the minimum size of the text box. label_style – OR’d set of Style flags for the label. text_style – OR’d set of Style flags for the text box. label_prop – Proportion argument for the sizer for the label. text_prop – Proportion argument for the sizer for the text box. label_flag – Flags to pass to the sizer when adding the label. text_flag – Flags to pass to the sizer when adding the text box. label_border – Size of the padding between the label and other controls. text_border – Size of the padding between the text box and other controls.
  Returns: | A tuple of the wx.StaticText object and wx.TextCtrl objects set up with appropriate values.

`ui_helpers.``log_error`(message, *args)

  Logs a message to stderr.

  Parameters: | message – The message to output. May use str.format()-style items, args will be applied to message accordingly. args – Arguments to apply to message via a call to str.format().

`ui_helpers.``log_info`(message, *args)

  Logs a message to stdout.

  Parameters: | message – The message to output. May use str.format()-style items, args will be applied to message accordingly. args – Arguments to apply to message via a call to str.format().

`ui_helpers.``setup_ui_helper_constants`(char_width: int, char_height: int)

  Initializes the “constant” global control size and font variables in this module if they haven’t been yet.

  Parameters: | char_width – Integer average character width as reported by the calling window’s GetCharWidth(). char_height – Integer character height as reported by the calling window’s GetCharHeight().