Skip to content

Commit

Permalink
flake8 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JuiP committed Jul 21, 2020
1 parent ab0acd0 commit 8a9b6e1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
6 changes: 6 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[flake8]

# E402 module level import not at top of file
# gi.require_version() is required before later imports

ignore = E402
2 changes: 1 addition & 1 deletion LocoSugarActivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# along with this library; if not, write to the Free Software
# Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
import gi
gi.require_version('Gtk','3.0')
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk, GLib, Gdk

Expand Down
50 changes: 28 additions & 22 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# along with this library; if not, write to the Free Software
# Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
import gi
gi.require_version('Gtk','3.0')
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GdkPixbuf, GLib
import os
import glob
Expand Down Expand Up @@ -59,12 +59,12 @@
{'A': 'Á', 'E': 'É', 'I': 'Í', 'O': 'Ó', 'U': 'Ú',
'a': 'á', 'e': 'é', 'i': 'í', 'o': 'ó', 'u': 'ú'},
{'A': 'Â', 'E': 'Ê', 'I': 'Î', 'O': 'Ô', 'U': 'Û',
'a': 'Â', 'e': 'ê', 'i': 'î', 'o': 'ô', 'u': 'û'},
'a': 'Â', 'e': 'ê', 'i': 'î', 'o': 'ô', 'u': 'û'},
{'A': 'Ä', 'O': 'Õ', 'N': 'Ñ', 'U': 'Ũ',
'a': 'ä', 'o': 'õ', 'n': 'ñ', 'u': 'ũ'},
{'A': 'Ã', 'E': 'Ë', 'I': 'Ï', 'O': 'Ö', 'U': 'Ü',
'a': 'ã', 'e': 'ë', 'i': 'ï', 'o': 'ö', 'u': 'ü'},
{'A': 'Å', 'a': 'å'}]
{'A': 'Å', 'a': 'å'}]


class Game():
Expand Down Expand Up @@ -119,8 +119,11 @@ def __init__(self, canvas, parent=None, path=None):
'background2.jpg']
self._backgrounds = []
for bg in self._BG:
pixbuf = GdkPixbuf.Pixbuf.new_from_file(os.path.join(self._path, 'images', bg))
pixbuf = pixbuf.scale_simple(self._width, self._height, GdkPixbuf.InterpType.BILINEAR)
pixbuf = \
GdkPixbuf.Pixbuf.new_from_file(os.path.join(self._path,
'images', bg))
pixbuf = pixbuf.scale_simple(self._width, self._height,
GdkPixbuf.InterpType.BILINEAR)
self._backgrounds.append(Sprite(
self._sprites, 0, 0, pixbuf))
self._backgrounds[-1].type = 'background'
Expand All @@ -137,7 +140,7 @@ def __init__(self, canvas, parent=None, path=None):
self._panel.hide()

self._LOCOS = glob.glob(
os.path.join(self._path, 'images', 'loco*.png'))
os.path.join(self._path, 'images', 'loco*.png'))
self._loco_cards = []
for loco in self._LOCOS:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
Expand All @@ -147,7 +150,7 @@ def __init__(self, canvas, parent=None, path=None):
self._loco_dim = (int(150 * self._scale_x), int(208 * self._scale_y))

self._MEN = glob.glob(
os.path.join(self._path, 'images', 'man*.png'))
os.path.join(self._path, 'images', 'man*.png'))
self._man_cards = []
for loco in self._MEN:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
Expand All @@ -156,7 +159,7 @@ def __init__(self, canvas, parent=None, path=None):
self._man_cards[-1].type = 'loco'

self._TAUNTS = glob.glob(
os.path.join(self._path, 'images', 'taunt*.png'))
os.path.join(self._path, 'images', 'taunt*.png'))
self._taunt_cards = []
for loco in self._TAUNTS:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
Expand All @@ -165,7 +168,7 @@ def __init__(self, canvas, parent=None, path=None):
self._taunt_cards[-1].type = 'loco'

self._GHOSTS = glob.glob(
os.path.join(self._path, 'images', 'ghost*.png'))
os.path.join(self._path, 'images', 'ghost*.png'))
self._ghost_cards = []
for loco in self._GHOSTS:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
Expand All @@ -178,8 +181,10 @@ def __init__(self, canvas, parent=None, path=None):
self._LOCOS[0], int(150 * self._scale_x), int(208 * self._scale_y))
self._man_pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
self._MEN[0], int(150 * self._scale_x), int(208 * self._scale_y))
self._ghost_pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
self._GHOSTS[0], int(150 * self._scale_x), int(208 * self._scale_y))
self._ghost_pixbuf = \
GdkPixbuf.Pixbuf.new_from_file_at_size(self._GHOSTS[0],
int(150 * self._scale_x),
int(208 * self._scale_y))
for i in range(len(MSGS[1])): # Check re i18n
self._sticky_cards.append(Sprite(self._sprites, 0, 0,
self._loco_pixbuf))
Expand Down Expand Up @@ -233,7 +238,7 @@ def _show_time(self):
self.score = 0
self._parent.fullscreen()
aplay.play(os.path.join(
self._path, 'sounds', 'sonar.ogg'))
self._path, 'sounds', 'sonar.ogg'))
GLib.timeout_add(5000, self.new_game, True)

def new_game(self, first_time):
Expand Down Expand Up @@ -261,7 +266,7 @@ def new_game(self, first_time):
self._panel.set_label(LABELS[self.level])
self._panel.set_layer(PANEL_LAYER)
aplay.play(os.path.join(
self._path, 'sounds', 'drip.ogg'))
self._path, 'sounds', 'drip.ogg'))
self._timer_reset()

if self.level == 0:
Expand All @@ -270,15 +275,15 @@ def new_game(self, first_time):
self._loco_quadrant %= 4
x, y = self._quad_to_xy(self._loco_quadrant)
aplay.play(os.path.join(
self._path, 'sounds', 'bark.ogg'))
self._path, 'sounds', 'bark.ogg'))
self._loco_cards[0].move((x, y))
self._loco_pos = (x, y)
elif self.level == 1:
aplay.play(os.path.join(
self._path, 'sounds', 'glass.ogg'))
self._path, 'sounds', 'glass.ogg'))
elif self.level == 2:
aplay.play(os.path.join(
self._path, 'sounds', 'glass.ogg'))
self._path, 'sounds', 'glass.ogg'))
# Place some Locos on the canvas
for i in range(self._counter + 1):
self._loco_quadrant += int(uniform(1, 4))
Expand All @@ -289,7 +294,7 @@ def new_game(self, first_time):
self._sticky_cards[i].set_layer(LOCO_LAYER)
elif self.level == 3:
aplay.play(os.path.join(
self._path, 'sounds', 'bark.ogg'))
self._path, 'sounds', 'bark.ogg'))
# Place some Locos on the left-side of the canvas
for i in range(self._counter + 1):
self._loco_quadrant = int(uniform(2, 4))
Expand Down Expand Up @@ -348,7 +353,8 @@ def _quad_to_xy(self, q):
x = int(max(0, (self._width / 2.) * uniform(0, 1) - self._loco_dim[0]))
if q in [0, 1]:
x += int(self._width / 2.)
y = int(max(0, (self._height / 2.) * uniform(0, 1) - self._loco_dim[1]))
y = int(max(0,
(self._height / 2.) * uniform(0, 1) - self._loco_dim[1]))
if q in [1, 2]:
y += int(self._height / 2.)
return x, y
Expand Down Expand Up @@ -459,7 +465,7 @@ def _keypress_cb(self, area, event):
self._panel.set_layer(PANEL_LAYER)
self._waiting_for_delete = True
aplay.play(os.path.join(
self._path, 'sounds', 'glass.ogg'))
self._path, 'sounds', 'glass.ogg'))
else:
for i in range(n):
if self._sticky_cards[i].labels[0] == k:
Expand All @@ -470,7 +476,7 @@ def _keypress_cb(self, area, event):
# Test for end condition
if self.level == 6 and \
self._correct == len(MSGS[self._counter]) - \
MSGS[self._counter].count(' '):
MSGS[self._counter].count(' '):
c = 0
for i in range(len(MSGS[self._counter])):
if MSGS[self._counter][i] == ' ':
Expand All @@ -482,7 +488,7 @@ def _keypress_cb(self, area, event):
self._panel.set_layer(PANEL_LAYER)
self._waiting_for_enter = True
aplay.play(os.path.join(
self._path, 'sounds', 'drip.ogg'))
self._path, 'sounds', 'drip.ogg'))
return
else:
for i in range(n):
Expand Down Expand Up @@ -601,7 +607,7 @@ def do_expose_event(self, event):
# Restrict Cairo to the exposed area
cr = self._canvas.window.cairo_create()
cr.rectangle(event.area.x, event.area.y,
event.area.width, event.area.height)
event.area.width, event.area.height)
cr.clip()
# Refresh sprite list
self._sprites.redraw_sprites(cr=cr)
Expand Down

0 comments on commit 8a9b6e1

Please sign in to comment.