Make PEP8 cleanup of line spaces and character distances as well as indents

This commit is contained in:
Griatch 2017-08-19 23:16:36 +02:00
parent 7ff783fea1
commit b278337172
189 changed files with 2039 additions and 1583 deletions

View file

@ -166,6 +166,7 @@ def _to_ansi(obj, regexable=False):
else:
return ANSIString(to_unicode(obj), regexable=regexable)
class EvForm(object):
"""
This object is instantiated with a text file and parses
@ -174,6 +175,7 @@ class EvForm(object):
EvCell or Tables.
"""
def __init__(self, filename=None, cells=None, tables=None, form=None, **kwargs):
"""
Initiate the form
@ -194,7 +196,7 @@ class EvForm(object):
self.filename = filename
self.input_form_dict = form
self.cells_mapping = dict((to_str(key, force_string=True), value) for key, value in cells.items()) if cells else {}
self.cells_mapping = dict((to_str(key, force_string=True), value) for key, value in cells.items()) if cells else {}
self.tables_mapping = dict((to_str(key, force_string=True), value) for key, value in tables.items()) if tables else {}
self.cellchar = "x"
@ -232,7 +234,7 @@ class EvForm(object):
table_coords = {}
# Locate the identifier tags and the horizontal end coords for all forms
re_cellchar = re.compile(r"%s+([^%s%s]+)%s+" % (cellchar, INVALID_FORMCHARS, cellchar, cellchar))
re_cellchar = re.compile(r"%s+([^%s%s]+)%s+" % (cellchar, INVALID_FORMCHARS, cellchar, cellchar))
re_tablechar = re.compile(r"%s+([^%s%s|+])%s+" % (tablechar, INVALID_FORMCHARS, tablechar, tablechar))
for iy, line in enumerate(_to_ansi(form, regexable=True)):
# find cells
@ -262,16 +264,16 @@ class EvForm(object):
# scan up to find top of rectangle
dy_up = 0
if iy > 0:
for i in range(1,iy):
if all(form[iy-i][ix] == cellchar for ix in range(leftix, rightix)):
for i in range(1, iy):
if all(form[iy - i][ix] == cellchar for ix in range(leftix, rightix)):
dy_up += 1
else:
break
# find bottom edge of rectangle
dy_down = 0
if iy < nform-1:
for i in range(1,nform-iy-1):
if all(form[iy+i][ix] == cellchar for ix in range(leftix, rightix)):
if iy < nform - 1:
for i in range(1, nform - iy - 1):
if all(form[iy + i][ix] == cellchar for ix in range(leftix, rightix)):
dy_down += 1
else:
break
@ -284,13 +286,13 @@ class EvForm(object):
# we have all the coordinates we need. Create EvCell.
data = self.cells_mapping.get(key, "")
#if key == "1":
# if key == "1":
options = { "pad_left":0, "pad_right":0, "pad_top":0, "pad_bottom":0, "align":"l", "valign":"t", "enforce_size":True}
options = {"pad_left": 0, "pad_right": 0, "pad_top": 0, "pad_bottom": 0, "align": "l", "valign": "t", "enforce_size": True}
options.update(custom_options)
#if key=="4":
# if key=="4":
mapping[key] = (iyup, leftix, width, height, EvCell(data, width=width, height=height,**options))
mapping[key] = (iyup, leftix, width, height, EvCell(data, width=width, height=height, **options))
# get rectangles and assign Tables
for key, (iy, leftix, rightix) in table_coords.items():
@ -298,16 +300,16 @@ class EvForm(object):
# scan up to find top of rectangle
dy_up = 0
if iy > 0:
for i in range(1,iy):
if all(form[iy-i][ix] == tablechar for ix in range(leftix, rightix)):
for i in range(1, iy):
if all(form[iy - i][ix] == tablechar for ix in range(leftix, rightix)):
dy_up += 1
else:
break
# find bottom edge of rectangle
dy_down = 0
if iy < nform-1:
for i in range(1,nform-iy-1):
if all(form[iy+i][ix] == tablechar for ix in range(leftix, rightix)):
if iy < nform - 1:
for i in range(1, nform - iy - 1):
if all(form[iy + i][ix] == tablechar for ix in range(leftix, rightix)):
dy_down += 1
else:
break
@ -321,8 +323,8 @@ class EvForm(object):
# we have all the coordinates we need. Create Table.
table = self.tables_mapping.get(key, None)
options = { "pad_left":0, "pad_right":0, "pad_top":0, "pad_bottom":0,
"align":"l", "valign":"t", "enforce_size":True}
options = {"pad_left": 0, "pad_right": 0, "pad_top": 0, "pad_bottom": 0,
"align": "l", "valign": "t", "enforce_size": True}
options.update(custom_options)
if table:
@ -343,9 +345,9 @@ class EvForm(object):
# rect is a list of <height> lines, each <width> wide
rect = cell_or_table.get()
for il, rectline in enumerate(rect):
formline = form[iy0+il]
formline = form[iy0 + il]
# insert new content, replacing old
form[iy0+il] = formline[:ix0] + rectline + formline[ix0+width:]
form[iy0 + il] = formline[:ix0] + rectline + formline[ix0 + width:]
return form
def map(self, cells=None, tables=None, **kwargs):
@ -366,7 +368,7 @@ class EvForm(object):
kwargs.pop("width", None)
kwargs.pop("height", None)
new_cells = dict((to_str(key, force_string=True), value) for key, value in cells.items()) if cells else {}
new_cells = dict((to_str(key, force_string=True), value) for key, value in cells.items()) if cells else {}
new_tables = dict((to_str(key, force_string=True), value) for key, value in tables.items()) if tables else {}
self.cells_mapping.update(new_cells)
@ -424,6 +426,7 @@ class EvForm(object):
"prints the form"
return unicode(ANSIString("\n").join([line for line in self.form]))
def _test():
"test evform. This is used by the unittest system."
form = EvForm("evennia.utils.evform_test")
@ -434,18 +437,18 @@ def _test():
3: "A sturdy fellow",
4: 12,
5: 10,
6: 5,
6: 5,
7: 18,
8: 10,
9: 3})
9: 3})
# create the EvTables
tableA = EvTable("HP","MV","MP",
table=[["**"], ["*****"], ["***"]],
border="incols")
tableA = EvTable("HP", "MV", "MP",
table=[["**"], ["*****"], ["***"]],
border="incols")
tableB = EvTable("Skill", "Value", "Exp",
table=[["Shooting", "Herbalism", "Smithing"],
[12,14,9],["550/1200", "990/1400", "205/900"]],
border="incols")
table=[["Shooting", "Herbalism", "Smithing"],
[12, 14, 9], ["550/1200", "990/1400", "205/900"]],
border="incols")
# add the tables to the proper ids in the form
form.map(tables={"A": tableA,
"B": tableB})