Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to python 3.11 #1

Merged
merged 14 commits into from
Mar 29, 2024
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ celerybeat.pid
# Environments
.env
.venv
python
env/
venv/
ENV/
Expand Down Expand Up @@ -169,4 +170,4 @@ cython_debug/


# Project specific
jeoparpy/dir.txt
jeoparpy/dir.txt
15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# The original project is very old and still uses Python 2.7.18
# This needs to be updated to Python 3.8.5 or later after the project is updated
FROM python:2.7.18-buster
FROM python:3.11.8-bullseye

# Set some basic image metadata
LABEL org.opencontainers.image.description = "A Jeopardy game for the Raspberry Pi"
Expand All @@ -10,6 +8,15 @@ LABEL org.opencontainers.image.licenses=GPL3
# Set the working directory for installations
WORKDIR /app

# Install OS packages
RUN apt update && apt install -y \
libsdl2-dev libsdl2-2.0-0 \
libjpeg-dev libpng-dev libwebp-dev libtiff-dev \
libsdl2-image-dev libsdl2-image-2.0-0 \
libmikmod-dev libfishsound1-dev libsmpeg-dev liboggz2-dev \
libflac-dev libfluidsynth-dev libsdl2-mixer-dev libsdl2-mixer-2.0-0 \
libfreetype6-dev libsdl2-ttf-dev libsdl2-ttf-2.0-0 pipewire

# Add our python requirements file to the working directory
ADD requirements.txt .

Expand All @@ -29,4 +36,4 @@ ADD ./ .
# ADD ?????

# Set default command to run the start.py file
CMD ["/usr/local/bin/python", "start.py"]
CMD ["/usr/local/bin/python", "start.py"]
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Play Jeopardy on your Raspberry Pi

How to get Jeopardy running on your Raspberry Pi

- install docker
- create a copy of the `docker-compose.yml` file
- run `docker compose up`

### Hardware

Follow these instructions:</br>
Expand All @@ -16,6 +20,12 @@ http://hackaday.io/project/3721/instructions
Follow these instructions:</br>
http://hackaday.io/project/3721-game-show-emulator/log/12365

## Building

To build the container image localy:

docker compose --profile build build

## Notes

This software is designed to be used with the Raspberry Pi. If you would like to run Jeopardy on a Windows or Ubuntu please use Adam Beagle's <a href='https://github.com/adambeagle/jeoparpy'>jeoparpy software</a>.
Expand Down
14 changes: 7 additions & 7 deletions button.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def __init__(self):

#Setup pins and board
gpio.setmode(gpio.BCM)
gpio.setup(22, gpio.IN, pull_up_down=gpio.PUD_UP)
gpio.setup(4, gpio.IN, pull_up_down=gpio.PUD_UP)
gpio.setup(17, gpio.IN, pull_up_down=gpio.PUD_UP)
gpio.setup(22, gpio.IN, pull_up_down=gpio.PUD_DOWN)
gpio.setup(4, gpio.IN, pull_up_down=gpio.PUD_DOWN)
gpio.setup(17, gpio.IN, pull_up_down=gpio.PUD_DOWN)

#Put pins in variables
self.center_button = 22
Expand Down Expand Up @@ -50,7 +50,7 @@ def check(self):
center_input = gpio.input(self.center_button)
left_input = gpio.input(self.left_button)
right_input = gpio.input(self.right_button)
if center_input == True:
if center_input == gpio.HIGH:
if self.center_press > 0:
if self.DEBUG:
print('ADMIN: Console button 2 has been pressed')
Expand All @@ -62,7 +62,7 @@ def check(self):
self.center_press += 1

#Right buttons stuff
if right_input == True:
if right_input == gpio.HIGH:
if self.right_press > 0:
if self.DEBUG:
print('ADMIN: Console button 3 has been pressed')
Expand All @@ -74,7 +74,7 @@ def check(self):
self.right_press += 1

#Left button stuff
if left_input == True:
if left_input == gpio.HIGH:
if self.left_press > 0:
if self.DEBUG:
print('ADMIN: Console button 1 has been pressed')
Expand All @@ -92,4 +92,4 @@ def check(self):
while True:
test.first = ''
winner = test.poll()
print winner
print(winner)
11 changes: 7 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.8'

services:

# Building and testing environment
Expand All @@ -11,11 +11,13 @@ services:
tty: true
command: ["/bin/bash"]
volumes:
- ${PWD}:/app
#- ${PWD}:/app
- /tmp/.X11-unix:/tmp/.X11-unix
environment:
- DISPLAY=$DISPLAY
- DISPLAY=${DISPLAY:-:0}
privileged: true
profiles:
- build

app:
image: ghcr.io/btc-raspberrypiclub/jeopardy:latest
Expand All @@ -24,6 +26,7 @@ services:
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
environment:
- DISPLAY=$DISPLAY
- DISPLAY=${DISPLAY:-:0}
- PW_AUDIO_MODULE=pipewire
privileged: true

4 changes: 2 additions & 2 deletions jeoparpy/game/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
See the "Customization" section of the README for details on how to
alter the resource files from which the game data is built.
"""
from gamedata import GameData
from gamestate import JeopGameState
from .gamedata import GameData
from .gamestate import JeopGameState
10 changes: 5 additions & 5 deletions jeoparpy/game/gamedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"""
from sys import stderr

from constants import AMOUNTS_PATH, CATEGORIES_PATH, CLUES_PATH, PLAYERS_PATH
from jeopplayer import JeopPlayer
from .constants import AMOUNTS_PATH, CATEGORIES_PATH, CLUES_PATH, PLAYERS_PATH
from .jeopplayer import JeopPlayer
from ..config import SUBTRACT_ON_INCORRECT
from ..util import get_stripped_nonempty_file_lines, to_numeric

Expand Down Expand Up @@ -122,7 +122,7 @@ def _build_players_from_file(self, path):
elif len(playerNames) < 3:
missing = 3 - len(playerNames)
playerNames += tuple('Player ' + str(i + 2)
for i in xrange(missing))
for i in range(missing))

return tuple(JeopPlayer(name) for name in playerNames)

Expand All @@ -137,8 +137,8 @@ def _map_clues(self, clues, numCategories):
((Category 1 clues), (Category 2 clues), ...))
"""
mapped = []
numPerCat = len(clues) / numCategories
for c in xrange(numCategories):
numPerCat = int(len(clues) / numCategories)
for c in range(numCategories):
start = c*numPerCat
mapped.append(tuple(clues[start:start + numPerCat]))

Expand Down
8 changes: 4 additions & 4 deletions jeoparpy/game/gamestate.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def set(self, state, **kwargs):
self.kwargs.update(kwargs)

if DEBUG and self.kwargs:
print 'State args set: {0}'.format(self.kwargs)
print('State args set: {0}'.format(self.kwargs))

def _verify_transition(self, newState):
"""
Expand Down Expand Up @@ -134,7 +134,7 @@ def state(self, val):
type(val).__name__), val)

# Verify state within valid range of defined states
if val not in xrange(self._numStates):
if val not in range(self._numStates):
raise StateSetError("Set of 'State' attempted with value " +
"that has no assigned state.", val)

Expand All @@ -145,7 +145,7 @@ def state(self, val):
self.kwargs = {}

if DEBUG:
print "State change: {0}".format(self)
print("State change: {0}".format(self))

class JeopGameState(GameState):
"""
Expand Down Expand Up @@ -265,4 +265,4 @@ def __str__(self):
addendum = ' Previous state: {0}; Attempted state: {1}'.format(
self.previous, self.attempted)

return self.msg + addendum
return self.msg + addendum
8 changes: 4 additions & 4 deletions jeoparpy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import os
import sys

from config import FPS_LIMIT, FULLSCREEN, SUBTRACT_ON_INCORRECT, SCREEN_SIZE
from constants import ANIMATIONEND, ANSWER_TIMEOUT, AUDIOEND, SKIP_INTRO_FLAG
from game import GameData, JeopGameState
from ui import Controller, do_congrats, do_credits, do_intro, do_scroll
from .config import FPS_LIMIT, FULLSCREEN, SUBTRACT_ON_INCORRECT, SCREEN_SIZE
from .constants import ANIMATIONEND, ANSWER_TIMEOUT, AUDIOEND, SKIP_INTRO_FLAG
from .game import GameData, JeopGameState
from .ui import Controller, do_congrats, do_credits, do_intro, do_scroll
import button

EVENTS_ALLOWED = (ANIMATIONEND, ANSWER_TIMEOUT,
Expand Down
6 changes: 3 additions & 3 deletions jeoparpy/selectMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import pygame, sys, os
from pygame.locals import *
from constants import ROOT_PATH
from config import DRIVE
from .constants import ROOT_PATH
from .config import DRIVE

pygame.init()

Expand Down Expand Up @@ -62,7 +62,7 @@ def get_options(self):
if self.games > 4:
self.games = 4
if self.games < 1:
print 'You must have a game in the /games directory!'
print('You must have a game in the /games directory!')
pygame.quit()
sys.exit()

Expand Down
10 changes: 5 additions & 5 deletions jeoparpy/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
CUSTOMIZATION:
See instructions in config.py and resmaps.py.
"""
from categoryscroll import do_scroll
from congrats import do_congrats
from controller import Controller
from credits import do_credits
from intro import do_intro
from .categoryscroll import do_scroll
from .congrats import do_congrats
from .controller import Controller
from .credits import do_credits
from .intro import do_intro
2 changes: 1 addition & 1 deletion jeoparpy/ui/audioplayer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pygame

from resmaps import SOUNDS, CLUE_READS
from .resmaps import SOUNDS, CLUE_READS

###############################################################################
class AudioPlayer(object):
Expand Down
8 changes: 4 additions & 4 deletions jeoparpy/ui/categoryscroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

import pygame

from config import CATEGORY_HOLD_TIME
from constants import JEOP_BLUE
from resmaps import FONTS
from util import (autofit_text, BorderedBox, draw_centered_textblock,
from .config import CATEGORY_HOLD_TIME
from .constants import JEOP_BLUE
from .resmaps import FONTS
from .util import (autofit_text, BorderedBox, draw_centered_textblock,
get_anim_data, shadow_text)
from ..config import FPS_LIMIT
from ..util import chunker
Expand Down
8 changes: 4 additions & 4 deletions jeoparpy/ui/congrats.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"""
import pygame

from constants import JEOP_BLUE
from resmaps import FONTS
from util import scale
from .constants import JEOP_BLUE
from .resmaps import FONTS
from .util import scale

def do_congrats(screen, clock, winners, audioPlayer):
"""
Expand Down Expand Up @@ -103,7 +103,7 @@ def _fade_in_sfc(screen, sfc, clock, time):
fpsGoal = int(255.0 / time) # frames to draw / time to spend in secs
sfc.fill(JEOP_BLUE)

for alpha in xrange(256):
for alpha in range(256):
sfc.set_alpha(alpha)
screen.blit(lastScreen, (0, 0))
screen.blit(sfc, (0, 0))
Expand Down
6 changes: 3 additions & 3 deletions jeoparpy/ui/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"""
import pygame

from audioplayer import JeopAudioPlayer
from maingame import Clue, GameBoard, OpenClueAnimation, PodiaPanel
from .audioplayer import JeopAudioPlayer
from .maingame import Clue, GameBoard, OpenClueAnimation, PodiaPanel
from ..config import DEBUG
from ..constants import AUDIOEND

Expand Down Expand Up @@ -68,7 +68,7 @@ def draw(self, screen):
for sfc in self._sfcs:
if sfc.dirty:
if DEBUG:
print 'draw %s' % type(sfc).__name__
print('draw %s' % type(sfc).__name__)

if isinstance(sfc, pygame.sprite.Sprite):
screen.blit(sfc.image, sfc.rect)
Expand Down
8 changes: 4 additions & 4 deletions jeoparpy/ui/credits.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import pygame
from pygame.locals import QUIT, KEYDOWN, K_q

from constants import JEOP_BLUE
from resmaps import FONTS, IMAGES
from util import get_anim_data, scale, shadow_text
from .constants import JEOP_BLUE
from .resmaps import FONTS, IMAGES
from .util import get_anim_data, scale, shadow_text

###############################################################################
class CreditLine(pygame.sprite.DirtySprite):
Expand Down Expand Up @@ -281,7 +281,7 @@ def _scroll_credits(screen, scrRect, clock, lines, numFrames, step, fpsLimit):
screen.fill(JEOP_BLUE)
bg = screen.copy()

for frame in xrange(numFrames):
for frame in range(numFrames):
lines.update(step, scrRect.h)
lines.clear(screen, bg)
lines.draw(screen)
Expand Down
8 changes: 4 additions & 4 deletions jeoparpy/ui/intro.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import pygame
from pygame.locals import KEYDOWN, QUIT

from constants import JEOP_BLUE, RULES, SUBTITLE
from resmaps import FONTS, IMAGES
from util import (draw_centered_textblock, draw_textline, restrict_fontsize,
from .constants import JEOP_BLUE, RULES, SUBTITLE
from .resmaps import FONTS, IMAGES
from .util import (draw_centered_textblock, draw_textline, restrict_fontsize,
scale, shadow_text, wait_for_keypress)

###############################################################################
Expand Down Expand Up @@ -168,7 +168,7 @@ def _fade_in_title(screen, background, text, textRect, bannerColor, clock):
fpsGoal = int(255 / 7.8) #frames to draw / time to spend in secs

pygame.time.delay(2000)
for alpha in xrange(256):
for alpha in range(256):
background.fill(bannerColor, textRect)
text.set_alpha(alpha)
background.blit(text, textRect)
Expand Down
8 changes: 4 additions & 4 deletions jeoparpy/ui/maingame/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
JeoparPy, i.e. everything from when the main game board and podia appear
until the game is over and the congratulations screen appears.
"""
from clue import Clue
from clueanimation import OpenClueAnimation
from gameboard import GameBoard
from podiapanel import PodiaPanel
from .clue import Clue
from .clueanimation import OpenClueAnimation
from .gameboard import GameBoard
from .podiapanel import PodiaPanel
Loading
Loading