Quality Improvements

- split a function into two for less complexity
- removed wildcard import
pull/7/head
Julius 6 years ago
parent 75d652461a
commit f65345ab0b

@ -21,20 +21,7 @@ class Joystick:
self.pressed = [] self.pressed = []
self.splaying = False self.splaying = False
def handle(self): def _handle_buttons(self, axis_dict, c):
c = self.configuration
nav = self.navigator
axis_dict = {}
# axes
for i in range(self.joystick.get_numaxes()):
axis = self.joystick.get_axis(i)
axis_dict['Axis {}'.format(i)] = axis
if i == c['GAS'] and axis > 0.1:
nav.forward()
elif i == c['GAS'] and axis < 0.1:
nav.stop()
# buttons
for i in range(self.joystick.get_numbuttons()): for i in range(self.joystick.get_numbuttons()):
button = self.joystick.get_button(i) button = self.joystick.get_button(i)
axis_dict['Button {}'.format(i)] = button axis_dict['Button {}'.format(i)] = button
@ -73,7 +60,22 @@ class Joystick:
self.pressed.append(i) self.pressed.append(i)
elif i == c['REC'] and button == 0 and i in self.pressed: elif i == c['REC'] and button == 0 and i in self.pressed:
self.pressed.remove(i) self.pressed.remove(i)
return axis_dict
def handle(self):
c = self.configuration
nav = self.navigator
axis_dict = {}
# axes
for i in range(self.joystick.get_numaxes()):
axis = self.joystick.get_axis(i)
axis_dict['Axis {}'.format(i)] = axis
if i == c['GAS'] and axis > 0.1:
nav.forward()
elif i == c['GAS'] and axis < 0.1:
nav.stop()
axis_dict = self._handle_buttons(axis_dict, c)
# hats # hats
for i in range(self.joystick.get_numhats()): for i in range(self.joystick.get_numhats()):
hat = self.joystick.get_hat(i) hat = self.joystick.get_hat(i)

@ -2,7 +2,6 @@ import picamera
import picamera.array import picamera.array
import pygame import pygame
import pygame.camera import pygame.camera
from pygame import *
def render_text_line(rimage, rcolor, rfont, text, pos=(0, 0)): def render_text_line(rimage, rcolor, rfont, text, pos=(0, 0)):
@ -31,7 +30,7 @@ class Screen:
else: else:
displayinfo = pygame.display.Info() displayinfo = pygame.display.Info()
fullsize = (displayinfo.current_w, displayinfo.current_h) fullsize = (displayinfo.current_w, displayinfo.current_h)
pygame.display.set_mode(fullsize, FULLSCREEN | DOUBLEBUF) pygame.display.set_mode(fullsize, pygame.FULLSCREEN | pygame.DOUBLEBUF)
class List(pygame.sprite.Sprite): class List(pygame.sprite.Sprite):

Loading…
Cancel
Save