From 0076a317a1012954e4f557b129284d5554145e9c Mon Sep 17 00:00:00 2001 From: Alexandru-Paul Copil Date: Wed, 9 Aug 2017 19:28:31 +0300 Subject: [PATCH] Improvements to code health --- landscape.yaml | 2 ++ stargateRL/launcher/elements.py | 6 +++--- stargateRL/launcher/main.py | 10 +++++++--- stargateRL/objects/ftext.py | 12 ++++++++---- stargateRL/objects/stext.py | 8 ++++---- stargateRL/world/exports.py | 7 ++++--- 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/landscape.yaml b/landscape.yaml index 4c25e74..7590294 100644 --- a/landscape.yaml +++ b/landscape.yaml @@ -14,7 +14,9 @@ pylint: - C0103 - R0903 - R0913 + - R0901 - MC0001 + - D203 pep8: full: true doc-warnings: true diff --git a/stargateRL/launcher/elements.py b/stargateRL/launcher/elements.py index c95940c..595f4ef 100644 --- a/stargateRL/launcher/elements.py +++ b/stargateRL/launcher/elements.py @@ -37,7 +37,7 @@ def __init__(self, master, label): self.options = {} header_font = tkFont.Font(family='Serif', size=18, weight=tkFont.BOLD) - self._label = tk.Label(master=self, text='# '+label, anchor=tk.NW, + self._label = tk.Label(master=self, text='# '+ label, anchor=tk.NW, padx=25, font=header_font, bg=HEADER_COLORS[0], fg=HEADER_COLORS[1]) self._label.pack(fill=tk.X) @@ -51,7 +51,7 @@ def __init__(self, master, label): tk.Frame.__init__(self, master, bg=SUBFRAME_COLORS[0]) self.pack(side=tk.TOP, fill=tk.X) - self._label = tk.Label(master=self, text=label+':', anchor=tk.W, + self._label = tk.Label(master=self, text=label + ':', anchor=tk.W, padx=30, width=10, bg=SUBFRAME_COLORS[0]) self._label.pack(fill=tk.X, side=tk.LEFT) @@ -130,7 +130,7 @@ def __init__(self, master, label, value, values): self._is_int = isinstance(value, int) - self._entry = tk.OptionMenu(self, self._value, *values) + self._entry = tk.OptionMenu(self, self._value, * values) self._entry.config(bg=SUBFRAME_COLORS[0], relief=tk.FLAT, highlightbackground=SUBFRAME_COLORS[0], fg=VALUE_COLORS[1]) diff --git a/stargateRL/launcher/main.py b/stargateRL/launcher/main.py index d13d3fa..ee96d95 100644 --- a/stargateRL/launcher/main.py +++ b/stargateRL/launcher/main.py @@ -64,6 +64,7 @@ def close(): popup.mainloop() try: popup.destroy() +# TODO: Restrain which type of exception is thrown here >.> except Exception: sys.exit() @@ -71,8 +72,8 @@ def close(): # Check for special flag to launch the game without the config menu if len(sys.argv) > 1: if sys.argv[1] == '--launch': - import stargateRL.main - stargateRL.main.main() + import stargateRL.main as game + game.main() sys.exit() @@ -91,7 +92,9 @@ def close(): FONT_PATH = DirectoryPaths.FONTS.value TILESETS = [tile for tile in os.listdir(TILE_PATH) if tile.endswith('.png')] -FONTS = [font.replace('_', ' ')[:-4] for font in os.listdir(FONT_PATH) if font.endswith('.ttf')] +FONTS = [ + font.replace('_', ' ')[:-4] + for font in os.listdir(FONT_PATH) if font.endswith('.ttf')] SIZES = [16, 20, 32, 64] # Fill the sections with options @@ -144,5 +147,6 @@ def close(): root.mainloop() try: root.destroy() +# TODO: Restrain which type of exception is thrown here >.> except Exception: sys.exit() diff --git a/stargateRL/objects/ftext.py b/stargateRL/objects/ftext.py index 3abfb3b..6d700bd 100644 --- a/stargateRL/objects/ftext.py +++ b/stargateRL/objects/ftext.py @@ -19,12 +19,15 @@ def __init__(self, text, color, position, dimensions, align='left', self._batch = batch self._group = group + # TODO: Simplify number of local variables and this entire mammoth! self._label = Label(text=text, font_name=DEFAULT_FONT, - font_size=TILE_SIZE+fsdt, bold=False, italic=False, + font_size=TILE_SIZE + fsdt, + bold=False, italic=False, color=color.value.rgba, - x=x*TILE_SIZE, y=y*TILE_SIZE, - width=x_tiles*TILE_SIZE, height=y_tiles*TILE_SIZE, + x=x * TILE_SIZE, y=y * TILE_SIZE, + width=x_tiles * TILE_SIZE, + height=y_tiles * TILE_SIZE, anchor_x=anchor_x, anchor_y=anchor_y, align=align, multiline=False, dpi=None, batch=batch, group=group) @@ -65,7 +68,8 @@ def __init__(self, strings, position, dimensions, colors, for index, string in enumerate(strings): self._labels.append( Text(string, default, - position=(x_tiles/2+x, y_tiles/2+y_tiles/4+y-index), + position=(x_tiles / 2 + x, + y_tiles / 2 + y_tiles / 4 + y - index), dimensions=(x_tiles, TILE_SIZE), align=align, anchor=anchor, fsdt=0, batch=batch, group=group)) diff --git a/stargateRL/objects/stext.py b/stargateRL/objects/stext.py index ca6cfc3..8ec2b49 100644 --- a/stargateRL/objects/stext.py +++ b/stargateRL/objects/stext.py @@ -26,7 +26,7 @@ def __init__(self, string, position, dimensions=(None, None), self._string = string x, y = position - x_tiles, y_tiles = dimensions + x_tiles, _ = dimensions # Create sprites from string self._sprites = [] @@ -45,12 +45,12 @@ def __init__(self, string, position, dimensions=(None, None), self._sprites.append( Sprite( GX_TILESETS['MAIN'].get_colored(letter_ord, tile_color), - (x+x_mod)*TILE_SIZE, (y+y_mod)*TILE_SIZE, + (x + x_mod) * TILE_SIZE, (y + y_mod) * TILE_SIZE, batch=self._batch, group=self._group_order)) def set_color(self, tile_color=TileColor(), start=0, end=None): """Change the color of the text or part of the text.""" for index, sprite in enumerate(self._sprites[start:end]): sprite.image =\ - GX_TILESETS['MAIN'].get_colored(ord(self._string[index+start]), - tile_color) + GX_TILESETS['MAIN'].get_colored( + ord(self._string[index + start]), tile_color) diff --git a/stargateRL/world/exports.py b/stargateRL/world/exports.py index 41f814e..836f0ad 100644 --- a/stargateRL/world/exports.py +++ b/stargateRL/world/exports.py @@ -20,15 +20,16 @@ def monochrome(map_data, file_name='map_monochrome', tone=DefaultColors.WHITE): color = tone.value.rgb() for row in map_data: for val in row: - image_data.append((int(color[0]*val), - int(color[1]*val), - int(color[2]*val))) + image_data.append((int(color[0] * val), + int(color[1] * val), + int(color[2] * val))) img = Image.new('RGB', (len(map_data), len(map_data[0]))) img.putdata(image_data) img.save(path.join(file_path, file_name)) +# TODO: Look into this ... def exactmatch(map_data, file_name='map_exactmatch', values=[]): """Store a BMP image of the map, using the given value-color pairs.""" image_data = []