commit
32ae069a0c
4 changed files with 21 additions and 21 deletions
|
|
@ -15,6 +15,7 @@ user.
|
||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
from src.utils import utils
|
from src.utils import utils
|
||||||
|
from src.utils.utils import to_str
|
||||||
|
|
||||||
# ANSI definitions
|
# ANSI definitions
|
||||||
|
|
||||||
|
|
@ -355,7 +356,7 @@ class ANSIString(unicode):
|
||||||
string to be handled as already decoded. It is important not to double
|
string to be handled as already decoded. It is important not to double
|
||||||
decode strings, as escapes can only be respected once.
|
decode strings, as escapes can only be respected once.
|
||||||
"""
|
"""
|
||||||
string = args[0]
|
string = to_str(args[0], force_string=True)
|
||||||
if not isinstance(string, basestring):
|
if not isinstance(string, basestring):
|
||||||
string = str(string)
|
string = str(string)
|
||||||
parser = kwargs.get('parser', ANSI_PARSER)
|
parser = kwargs.get('parser', ANSI_PARSER)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
"""
|
"""
|
||||||
Evform - a way to create advanced ascii forms
|
Mudform - a way to create advanced ascii forms
|
||||||
|
|
||||||
|
|
||||||
This is intended for creating advanced ascii game forms, such as a
|
This is intended for creating advanced ascii game forms, such as a
|
||||||
large pretty character sheet or info document.
|
large pretty character sheet or info document.
|
||||||
|
|
@ -68,11 +67,11 @@ Use as follows:
|
||||||
7: 18,
|
7: 18,
|
||||||
8: 10,
|
8: 10,
|
||||||
9: 3})
|
9: 3})
|
||||||
# create the MudTables
|
# create the EvTables
|
||||||
tableA = mudform.MudTable("HP","MV","MP",
|
tableA = mudform.EvTable("HP","MV","MP",
|
||||||
table=[["**"], ["*****"], ["***"]],
|
table=[["**"], ["*****"], ["***"]],
|
||||||
border="incols")
|
border="incols")
|
||||||
tableB = mudform.MudTable("Skill", "Value", "Exp",
|
tableB = mudform.EvTable("Skill", "Value", "Exp",
|
||||||
table=[["Shooting", "Herbalism", "Smithing"],
|
table=[["Shooting", "Herbalism", "Smithing"],
|
||||||
[12,14,9],["550/1200", "990/1400", "205/900"]],
|
[12,14,9],["550/1200", "990/1400", "205/900"]],
|
||||||
border="incols")
|
border="incols")
|
||||||
|
|
@ -102,10 +101,10 @@ This produces the following result:
|
||||||
| |**|* | Herbalism |14 |990/1400 |
|
| |**|* | Herbalism |14 |990/1400 |
|
||||||
| |* | | Smithing |9 |205/900 |
|
| |* | | Smithing |9 |205/900 |
|
||||||
| | |
|
| | |
|
||||||
------------------------------------------------
|
`----------------------------------------------´
|
||||||
|
|
||||||
The marked forms have been replaced with Cells of text and with
|
The marked forms have been replaced with Cells of text and with
|
||||||
MudTables. The form can be updated by simply re-applying form.map()
|
EvTables. The form can be updated by simply re-applying form.map()
|
||||||
with the updated data.
|
with the updated data.
|
||||||
|
|
||||||
When working with the template ascii file, you can use form.reload()
|
When working with the template ascii file, you can use form.reload()
|
||||||
|
|
@ -121,7 +120,7 @@ form will raise an error.
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import copy
|
import copy
|
||||||
from src.utils.mudtable import Cell, MudTable
|
from src.utils.evtable import Cell, EvTable
|
||||||
from src.utils.utils import all_from_module, to_str, to_unicode
|
from src.utils.utils import all_from_module, to_str, to_unicode
|
||||||
|
|
||||||
# non-valid form-identifying characters (which can thus be
|
# non-valid form-identifying characters (which can thus be
|
||||||
|
|
@ -131,7 +130,7 @@ from src.utils.utils import all_from_module, to_str, to_unicode
|
||||||
INVALID_FORMCHARS = r"\s\/\|\\\*\_\-\#\<\>\~\^\:\;\.\,"
|
INVALID_FORMCHARS = r"\s\/\|\\\*\_\-\#\<\>\~\^\:\;\.\,"
|
||||||
|
|
||||||
|
|
||||||
class MudForm(object):
|
class EvForm(object):
|
||||||
"""
|
"""
|
||||||
This object is instantiated with a text file and parses
|
This object is instantiated with a text file and parses
|
||||||
it for rectangular form fields. It can then be fed a
|
it for rectangular form fields. It can then be fed a
|
||||||
|
|
@ -151,10 +150,10 @@ class MudForm(object):
|
||||||
"FORM":templatestring}
|
"FORM":templatestring}
|
||||||
if this is given, filename is not read.
|
if this is given, filename is not read.
|
||||||
cells - a dictionary mapping of {id:text}
|
cells - a dictionary mapping of {id:text}
|
||||||
tables - dictionary mapping of {id:MudTable}
|
tables - dictionary mapping of {id:EvTable}
|
||||||
|
|
||||||
other kwargs are fed as options to the Cells and MudTablets
|
other kwargs are fed as options to the Cells and EvTables
|
||||||
(see mudtablet.Cell and mudtablet.MudTablet for more info).
|
(see evtablet.Cell and evtable.EvTable for more info).
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
|
@ -304,7 +303,7 @@ class MudForm(object):
|
||||||
if table:
|
if table:
|
||||||
table.reformat(width=width, height=height, **options)
|
table.reformat(width=width, height=height, **options)
|
||||||
else:
|
else:
|
||||||
table = MudTable(width=width, height=height, **options)
|
table = EvTable(width=width, height=height, **options)
|
||||||
mapping[key] = (iyup, leftix, width, height, table)
|
mapping[key] = (iyup, leftix, width, height, table)
|
||||||
|
|
||||||
return mapping
|
return mapping
|
||||||
|
|
@ -331,7 +330,7 @@ class MudForm(object):
|
||||||
tables - a dictionary of {identifier:table}
|
tables - a dictionary of {identifier:table}
|
||||||
|
|
||||||
kwargs will be forwarded to tables/cells. See
|
kwargs will be forwarded to tables/cells. See
|
||||||
mudtable.Cell and mudtable.MudTable for info.
|
evtable.Cell and evtable.EvTable for info.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# clean kwargs (these cannot be overridden)
|
# clean kwargs (these cannot be overridden)
|
||||||
|
|
@ -7,7 +7,7 @@ FORMCHAR = "x"
|
||||||
TABLECHAR = "c"
|
TABLECHAR = "c"
|
||||||
|
|
||||||
FORM = """
|
FORM = """
|
||||||
.------------------------------------------------.
|
{c.------------------------------------------------.
|
||||||
| |
|
| |
|
||||||
| Name: xxxxx1xxxxx Player: xxxxxxx2xxxxxxx |
|
| Name: xxxxx1xxxxx Player: xxxxxxx2xxxxxxx |
|
||||||
| xxxxxxxxxxx |
|
| xxxxxxxxxxx |
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Mudtable
|
EvTable
|
||||||
|
|
||||||
This is an advanced ASCII table creator. It was inspired
|
This is an advanced ASCII table creator. It was inspired
|
||||||
by prettytable but shares no code.
|
by prettytable but shares no code.
|
||||||
|
|
@ -9,7 +9,7 @@ by prettytable but shares no code.
|
||||||
|
|
||||||
Example usage:
|
Example usage:
|
||||||
|
|
||||||
table = MudTable("Heading1", "Heading2", table=[[1,2,3],[4,5,6],[7,8,9]], border="cells")
|
table = EvTable("Heading1", "Heading2", table=[[1,2,3],[4,5,6],[7,8,9]], border="cells")
|
||||||
table.add_column("This is long data", "This is even longer data")
|
table.add_column("This is long data", "This is even longer data")
|
||||||
table.add_row("This is a single row")
|
table.add_row("This is a single row")
|
||||||
print table
|
print table
|
||||||
|
|
@ -78,7 +78,7 @@ def make_iter(obj):
|
||||||
return not hasattr(obj, '__iter__') and [obj] or obj
|
return not hasattr(obj, '__iter__') and [obj] or obj
|
||||||
|
|
||||||
|
|
||||||
# Cell class (see further down for the MudTable itself)
|
# Cell class (see further down for the EvTable itself)
|
||||||
|
|
||||||
class Cell(object):
|
class Cell(object):
|
||||||
"""
|
"""
|
||||||
|
|
@ -446,9 +446,9 @@ class Cell(object):
|
||||||
return "\n".join(self.formatted)
|
return "\n".join(self.formatted)
|
||||||
|
|
||||||
|
|
||||||
# Main Mudtable class
|
# Main Evtable class
|
||||||
|
|
||||||
class MudTable(object):
|
class EvTable(object):
|
||||||
"""
|
"""
|
||||||
Table class.
|
Table class.
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue