Skip to content

Commit

Permalink
Merge pull request #2663 from MarkusHackspacher/codestyle
Browse files Browse the repository at this point in the history
Fix E226 missing whitespace around arithmetic operator
  • Loading branch information
squiddy committed May 5, 2017
2 parents d1929ec + 96e1c84 commit 40b1412
Show file tree
Hide file tree
Showing 73 changed files with 183 additions and 183 deletions.
4 changes: 2 additions & 2 deletions development/combat_ai/diplomacy_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def diplomacy_graph():

# always print upper boundary
x = [-10, 10]
y = [upper_boundary]*2
y = [upper_boundary] * 2
pylab.plot (x,y,color='y', marker=None)

functions = []
Expand All @@ -101,7 +101,7 @@ def diplomacy_graph():
functions.append((get_neutral_function(**parameters['neutral']), 'b'))

for f, c in functions:
gen = [(x/10.0, f(x/10.0)) for x in xrange(-100, 100) ]
gen = [(x / 10.0, f(x / 10.0)) for x in xrange(-100, 100) ]
x = [item[0] for item in gen]
y = [item[1] for item in gen]
pylab.plot(x,y, color=c,marker=None)
Expand Down
4 changes: 2 additions & 2 deletions development/compare_string_lengths_in_pos.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@
if trans == "\"\"":
continue

len_ratio = float(len(orig))/len(trans)
len_ratio = float(len(orig)) / len(trans)

if len_ratio > 1.4 or len_ratio < 0.6 and \
abs(len(orig)-len(trans)) > 2:
abs(len(orig) - len(trans)) > 2:
print('string length ratio:', len_ratio)
print(orig)
print(trans)
Expand Down
2 changes: 1 addition & 1 deletion development/extract_strings_from_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def add_line(value, component, sep, key, filename):

if strings:
return ('\n\t"{}" : {'.format(filename) +
(ROWINDENT + '{},'.format(','+ROWINDENT).join(strings)) + ROWINDENT + '},')
(ROWINDENT + '{},'.format(',' + ROWINDENT).join(strings)) + ROWINDENT + '},')
else:
return ''

Expand Down
2 changes: 1 addition & 1 deletion development/extract_strings_from_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

conn.commit()

engine = sqlalchemy.create_engine('sqlite:///'+filename) # must be 4 slashes total, sqlalchemy breaks the unixoid conventions here
engine = sqlalchemy.create_engine('sqlite:///' + filename) # must be 4 slashes total, sqlalchemy breaks the unixoid conventions here

Session = sqlalchemy.orm.sessionmaker(bind=engine)
db_session = Session()
Expand Down
28 changes: 14 additions & 14 deletions development/print_db_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ def get_settler_name(tier):

def format_prodline(line_list, depth):
for res, amount in line_list:
print(' '*depth, '{amount:>4} {name:16} ({id:2})'.format(
print(' ' * depth, '{amount:>4} {name:16} ({id:2})'.format(
amount=abs(amount), name=get_res_name(res), id=res))

def print_production_lines():
print('Production lines per building:')
for b in Entities.buildings.itervalues():
print('\n', b.name, '\n', '='*len(b.name))
print('\n', b.name, '\n', '=' * len(b.name))
for comp in b.component_templates:
if not isinstance(comp, dict):
continue
Expand All @@ -110,7 +110,7 @@ def print_production_lines():
disabled_by_default = dct.get('enabled_by_default') is not None
enabled_text = (disabled_by_default and 'not ' or '') + 'enabled by default'
time = dct.get('time') or 1
print('{time:>3}s'.format(time=time), '('+changes_anim_text+',', enabled_text+')')
print('{time:>3}s'.format(time=time), '(' + changes_anim_text + ',', enabled_text + ')')
consumes = dct.get('consumes')
if consumes:
print(' consumes')
Expand Down Expand Up @@ -236,13 +236,13 @@ def print_collector_restrictions():
def print_tier_data():
print('Data has been moved, this view is unavailable for now')
return
upgrade_tiers = xrange(1, TIER.CURRENT_MAX+1)
upgrade_tiers = xrange(1, TIER.CURRENT_MAX + 1)
print('{:15s} {} {} {}'.format('tier', 'max_inh', 'base_tax', 'upgrade_prod_line'))
print('=' * 64)
for inc, name, inh, tax in db('SELECT level, name, inhabitants_max, tax_income FROM tier'):
str = '{:3s} {:11s} {:5s} {:4s}'.format((inc+1), name, inh, tax)
if inc+1 in upgrade_tiers:
line = db("SELECT production_line FROM upgrade_material WHERE level = ?", inc+1)[0][0]
str = '{:3s} {:11s} {:5s} {:4s}'.format((inc + 1), name, inh, tax)
if inc + 1 in upgrade_tiers:
line = db("SELECT production_line FROM upgrade_material WHERE level = ?", inc + 1)[0][0]
str += 5 * ' ' + '{:2s}: '.format(line)
(consumption, _) = get_prod_line(line, list)
for (res, amount) in consumption:
Expand All @@ -255,7 +255,7 @@ def print_colors():
print('=' * 45)
for id_, name, R, G, B, alpha in db("SELECT id, name, red, green, blue, alpha FROM colors"):
print('{:2s}: {:12s} {:3s} {:3s} {:3s} {:3s} #'
.format(id_, name, R, G, B, alpha) + 3*'{:02x}'.format(R, G, B))
.format(id_, name, R, G, B, alpha) + 3 * '{:02x}'.format(R, G, B))

def print_scenario_actions():
print('Available scenario actions and their arguments:')
Expand Down Expand Up @@ -293,14 +293,14 @@ def print_settler_needs():
print("Needed resources per tier")
pprint.pprint(data)
print('\nChanges per level:')
for i in xrange(len(data)-2):
s = str(i)+"/"+str(i+1)+": "
for r in data[i+1]:
for i in xrange(len(data) - 2):
s = str(i) + "/" + str(i + 1) + ": "
for r in data[i + 1]:
if r not in data[i]:
s += "+"+r+", "
s += "+" + r + ", "
for r in data[i]:
if r not in data[i+1]:
s += "-"+r+", "
if r not in data[i + 1]:
s += "-" + r + ", "
print(s)


Expand Down
6 changes: 3 additions & 3 deletions horizons/ai/aiplayer/combat/combatmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def close_range(cls, ship):
"""
Range used when wanting to get close to ships.
"""
return (2*ship._max_range + ship._min_range)/3 + 1
return (2 * ship._max_range + ship._min_range) / 3 + 1

@classmethod
def fallback_range(cls, ship):
Expand Down Expand Up @@ -173,8 +173,8 @@ def _highlight_points(self, points, color):

def _highlight_circle(self, position, radius, color):
points = set(self.session.world.get_points_in_radius(position, radius))
points2 = set(self.session.world.get_points_in_radius(position, radius-1))
self._highlight_points(list(points-points2), color)
points2 = set(self.session.world.get_points_in_radius(position, radius - 1))
self._highlight_points(list(points - points2), color)

def display(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion horizons/ai/aiplayer/strategy/strategymanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def calculate_player_balance(self, player, trimming_factor=10.0, linear_boundary
'power':power_balance,
'terrain':terrain_balance,
}
balance = {key: trim_value(value, 1./trimming_factor, trimming_factor) for key, value in balance.items()}
balance = {key: trim_value(value, 1. / trimming_factor, trimming_factor) for key, value in balance.items()}
balance = {key: map_balance(value, trimming_factor, linear_boundary) for key, value in balance.items()}

return collections.namedtuple('Balance', 'wealth, power, terrain')(**balance)
Expand Down
2 changes: 1 addition & 1 deletion horizons/component/healthcomponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def deal_damage(self, weapon_id, damage):
scaling_factor = 1
self.health -= scaling_factor * damage
self.health = max(self.health, 0.0) # don't go below 0
self.log.debug("dealing damage %s to %s; new health: %s", scaling_factor*damage, self.instance, self.health)
self.log.debug("dealing damage %s to %s; new health: %s", scaling_factor * damage, self.instance, self.health)
self.on_damage_dealt()

def check_if_alive(self, caller=None):
Expand Down
4 changes: 2 additions & 2 deletions horizons/component/tradepostcomponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def buy(self, res, amount, price, player_id):
assert remnant == 0
self.trade_history.append((Scheduler().cur_tick, player_id, res, amount, -price))
self.buy_history[ Scheduler().cur_tick ] = (res, amount, price)
self.total_expenses += amount*price
self.total_expenses += amount * price
self._changed()
return True
assert False
Expand All @@ -175,7 +175,7 @@ def sell(self, res, amount, price, player_id):
assert remnant == 0
self.trade_history.append((Scheduler().cur_tick, player_id, res, -amount, price))
self.sell_history[ Scheduler().cur_tick ] = (res, amount, price)
self.total_income += amount*price
self.total_income += amount * price
self._changed()
return True
assert False
Expand Down
8 changes: 4 additions & 4 deletions horizons/editor/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ def __init__(self, world_editor, ingame_gui):
image.capture(Callback(self._set_cursor_tile, tile))

self.widget.mapEvents({
self.widget.name+'/mouseEntered/cursor': self._cursor_inside,
self.widget.name+'/mouseExited/cursor': self._cursor_outside,
self.widget.name + '/mouseEntered/cursor': self._cursor_inside,
self.widget.name + '/mouseExited/cursor': self._cursor_outside,
})

self._ingame_gui.mainhud.mapEvents({
self._ingame_gui.mainhud.name+'/mouseEntered/cursor': self._cursor_inside,
self._ingame_gui.mainhud.name+'/mouseExited/cursor': self._cursor_outside,
self._ingame_gui.mainhud.name + '/mouseEntered/cursor': self._cursor_inside,
self._ingame_gui.mainhud.name + '/mouseExited/cursor': self._cursor_outside,
})

def _set_cursor_tile(self, tile):
Expand Down
12 changes: 6 additions & 6 deletions horizons/engine/pychan_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def text2gui(text):
# Drop unicode encoding for now.
#unicodePolicy = horizons.globals.fife.pychan.manager.unicodePolicy
#return text.encode("utf8",*unicodePolicy).replace("\t"," "*4).replace("[br]","\n")
return text.replace("\t"," "*4).replace("[br]","\n")
return text.replace("\t"," " * 4).replace("[br]","\n")

pychan.widgets.textfield.text2gui = text2gui
pychan.widgets.basictextwidget.text2gui = text2gui
Expand All @@ -167,17 +167,17 @@ def make_cursor_change_on_hover_class(cls):
# this can't be a regular class since vanilla TextFields should have it by default
def disable_cursor_change_on_hover(self):
self.mapEvents({
self.name+'/mouseEntered/cursor' : None,
self.name+'/mouseExited/cursor' : None,
self.name + '/mouseEntered/cursor' : None,
self.name + '/mouseExited/cursor' : None,
})

def enable_cursor_change_on_hover(self):
self.mapEvents({
self.name+'/mouseEntered/cursor' : set_cursor,
self.name+'/mouseExited/cursor' : unset_cursor,
self.name + '/mouseEntered/cursor' : set_cursor,
self.name + '/mouseExited/cursor' : unset_cursor,
# this changes the cursor if the widget is hidden while the
# cursor is still above the textfield
self.name+'/ancestorHidden/cursor': unset_cursor
self.name + '/ancestorHidden/cursor': unset_cursor
})

def add_cursor_change_on_hover_init(func):
Expand Down
2 changes: 1 addition & 1 deletion horizons/extscheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ExtScheduler(object, metaclass=ManualConstructionSingleton):
@param pump: pump list the scheduler registers itself with.
"""

NOOP = _ExtCallbackObject(lambda : 42*1337-3.14, None)
NOOP = _ExtCallbackObject(lambda : 42 * 1337 - 3.14, None)

def __init__(self, pump):
super(ExtScheduler, self).__init__()
Expand Down
2 changes: 1 addition & 1 deletion horizons/gui/ingamegui.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def _display_speed(self, tps):
down_icon.set_inactive()
else:
if tps != GAME_SPEED.TICKS_PER_SECOND:
text = "{0:1g}x".format(tps * 1.0/GAME_SPEED.TICKS_PER_SECOND)
text = "{0:1g}x".format(tps * 1.0 / GAME_SPEED.TICKS_PER_SECOND)
#%1g: displays 0.5x, but 2x instead of 2.0x
index = GAME_SPEED.TICK_RATES.index(tps)
if index + 1 >= len(GAME_SPEED.TICK_RATES):
Expand Down
2 changes: 1 addition & 1 deletion horizons/gui/modules/playerdataselection.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, color_palette=None):
# right now there are 14 different colors to choose from.
for i in range(0, len(colorlabels), 5):
hbox = HBox(name='line_{index}'.format(index=i))
hbox.addChildren(colorlabels[i:i+5])
hbox.addChildren(colorlabels[i:i + 5])
self.colors.addChild(hbox)

playertextfield = self.gui.findChild(name='playername')
Expand Down
6 changes: 3 additions & 3 deletions horizons/gui/mousetools/navigationtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def mouseMoved(self, evt):
# Status menu update
current = self.get_exact_world_location(evt)

distance_ge = lambda a, b, epsilon : abs((a.x-b.x)**2 + (a.y-b.y)**2) >= epsilon**2
distance_ge = lambda a, b, epsilon : abs((a.x - b.x) ** 2 + (a.y - b.y) ** 2) >= epsilon ** 2

if distance_ge(current, self.last_exact_world_location, 4): # update every 4 tiles for settlement info
self.last_exact_world_location = current
Expand All @@ -162,11 +162,11 @@ def mouseMoved(self, evt):
x, y = 0, 0
if mousepoint.x < VIEW.AUTOSCROLL_WIDTH:
x -= VIEW.AUTOSCROLL_WIDTH - mousepoint.x
elif mousepoint.x > (self.session.view.cam.getViewPort().right()-VIEW.AUTOSCROLL_WIDTH):
elif mousepoint.x > (self.session.view.cam.getViewPort().right() - VIEW.AUTOSCROLL_WIDTH):
x += VIEW.AUTOSCROLL_WIDTH + mousepoint.x - self.session.view.cam.getViewPort().right()
if mousepoint.y < VIEW.AUTOSCROLL_WIDTH:
y -= VIEW.AUTOSCROLL_WIDTH - mousepoint.y
elif mousepoint.y > (self.session.view.cam.getViewPort().bottom()-VIEW.AUTOSCROLL_WIDTH):
elif mousepoint.y > (self.session.view.cam.getViewPort().bottom() - VIEW.AUTOSCROLL_WIDTH):
y += VIEW.AUTOSCROLL_WIDTH + mousepoint.y - self.session.view.cam.getViewPort().bottom()
x *= 10
y *= 10
Expand Down
2 changes: 1 addition & 1 deletion horizons/gui/tabs/barrackstabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def init_widget(self):

def build_groundunit_info(self, index, groundunit, prodline):
size = (260, 90)
widget = Container(name='showcase_{}'.format(index), position=(0, 20 + index*90),
widget = Container(name='showcase_{}'.format(index), position=(0, 20 + index * 90),
min_size=size, max_size=size, size=size)
bg_icon = Icon(image='content/gui/images/background/square_80.png', name='bg_{}'.format(index))
widget.addChild(bg_icon)
Expand Down
6 changes: 3 additions & 3 deletions horizons/gui/tabs/boatbuildertabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ def update_queue(self, container_active):
image = self.__class__.UNIT_THUMBNAIL.format(type_id=unit_type)
helptext = T("{ship} (place in queue: {place})").format(
ship=self.instance.session.db.get_unit_type_name(unit_type),
place=place_in_queue+1)
place=place_in_queue + 1)
# people don't count properly, always starting at 1..
icon_name = "queue_elem_"+str(place_in_queue)
icon_name = "queue_elem_" + str(place_in_queue)

try:
icon = Icon(name=icon_name, image=image, helptext=helptext)
Expand Down Expand Up @@ -234,7 +234,7 @@ def init_widget(self):

def build_ship_info(self, index, ship, prodline):
size = (260, 90)
widget = Container(name='showcase_%s' % index, position=(0, 20 + index*90),
widget = Container(name='showcase_%s' % index, position=(0, 20 + index * 90),
min_size=size, max_size=size, size=size)
bg_icon = Icon(image='content/gui/images/background/square_80.png', name='bg_{}'.format(index))
widget.addChild(bg_icon)
Expand Down
6 changes: 3 additions & 3 deletions horizons/gui/tabs/buildtabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ def _set_entry(button, icon, building_id):
res_overview = self.session.ingame_gui.resource_overview
show_costs = Callback(res_overview.set_construction_mode, settlement, building.costs)
button.mapEvents({
button.name+"/mouseEntered/buildtab" : show_costs,
button.name+"/mouseExited/buildtab" : res_overview.close_construction_mode
button.name + "/mouseEntered/buildtab" : show_costs,
button.name + "/mouseExited/buildtab" : res_overview.close_construction_mode
})

(enough_res, missing_res) = Build.check_resources({}, building.costs, settlement.owner, [settlement])
Expand All @@ -183,7 +183,7 @@ def _set_entry(button, icon, building_id):
column = -1 # can't use enumerate, not always incremented
for entry in row:
column += 1
position = (10*column) + (row_num+1) # legacy code, first row is 1, 11, 21
position = (10 * column) + (row_num + 1) # legacy code, first row is 1, 11, 21
if entry is None:
continue
elif (column + 1) > self.MAX_COLS:
Expand Down
2 changes: 1 addition & 1 deletion horizons/gui/tabs/buyselltab.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def add_resource(self, resource_id, slot_id, value=None):
inventory = self.trade_post.get_inventory()
filled = (100 * inventory[resource_id]) // inventory.get_limit(resource_id)
fillbar.position = (icon.width - fillbar.width - 1,
icon.height - int(icon.height*filled))
icon.height - int(icon.height * filled))
# reuse code from toggle to finish setup (must switch state before, it will reset it)
slot.action = "sell" if slot.action == "buy" else "buy"
self.toggle_buysell(slot_id, keep_hint=keep_hint)
Expand Down
12 changes: 6 additions & 6 deletions horizons/gui/tabs/mainsquaretabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def refresh(self):
self.widget.child_finder('running_costs').text = str(running_costs)
self.widget.child_finder('buying').text = str(buy_expenses)
self.widget.child_finder('sale').text = str(sell_income)
self.widget.child_finder('balance').text = str(sign+' '+str(abs(balance)))
self.widget.child_finder('balance').text = str(sign + ' ' + str(abs(balance)))
self.widget.child_finder('headline').text = self.settlement.get_component(NamedComponent).name
rename = Callback(self.instance.session.ingame_gui.show_change_name_dialog, self.settlement)
self.widget.mapEvents({'headline': rename})
Expand Down Expand Up @@ -213,14 +213,14 @@ def refresh(self):
houses += house_count
residents += house_count * number
position_x = (space_per_label * (column - 1)) + 10
if not container.findChild(name="resident_"+str(column)):
label = Label(name="resident_"+str(column), position=(position_x, 0), text=str(number))
if not container.findChild(name="resident_" + str(column)):
label = Label(name="resident_" + str(column), position=(position_x, 0), text=str(number))
container.addChild(label)
count_label = Label(name="resident_count_"+str(column), position=(position_x - 1, 20), text=str(house_count))
count_label = Label(name="resident_count_" + str(column), position=(position_x - 1, 20), text=str(house_count))
container.addChild(count_label)
else:
container.findChild(name="resident_"+str(column)).text = str(number)
container.findChild(name="resident_count_"+str(column)).text = str(house_count)
container.findChild(name="resident_" + str(column)).text = str(number)
container.findChild(name="resident_count_" + str(column)).text = str(house_count)

sad = self.instance.session.db.get_lower_happiness_limit()
happy = self.instance.session.db.get_upper_happiness_limit()
Expand Down
2 changes: 1 addition & 1 deletion horizons/gui/tabs/productiontabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def refresh(self):
centered_container.addChild(toggle_icon)
anim = PychanAnimation(toggle_icon, self.__class__.ACTIVE_PRODUCTION_ANIM_DIR)
centered_container.anim = anim
anim.start(1.0/12, -1) # always start anew, people won't notice
anim.start(1.0 / 12, -1) # always start anew, people won't notice
self._animations.append(weakref.ref(anim))

# fill it with input and output resources
Expand Down
2 changes: 1 addition & 1 deletion horizons/gui/tabs/tabwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def on_tab_removal(tabwidget):
container.addChild(background)
container.addChild(button)
self.content.addChild(container)
self.widget.size = (54, 55*len(self._tabs))
self.widget.size = (54, 55 * len(self._tabs))
self.widget.adaptLayout()

self._apply_layout_hack()
Expand Down
4 changes: 2 additions & 2 deletions horizons/gui/widgets/icongroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def _set_tile_amount(self, amount):
start_img = Icon(image=self.start_img, name=self.name + '0')
self.addChild(start_img)
for i in range(self.amount):
mid = Icon(image=self.tiles_img, name=self.name + str(i+1))
mid = Icon(image=self.tiles_img, name=self.name + str(i + 1))
self.addChild(mid)
self.addChild(Icon(image=self.final_img, name=self.name + str(self.amount+1)))
self.addChild(Icon(image=self.final_img, name=self.name + str(self.amount + 1)))

amount = property(_get_tile_amount, _set_tile_amount)

Expand Down

0 comments on commit 40b1412

Please sign in to comment.