Skip to content

Commit 9f6c455

Browse files
committed
cleaned up ui, upgraded to bootstrap5
1 parent c845ef9 commit 9f6c455

File tree

12 files changed

+232
-141
lines changed

12 files changed

+232
-141
lines changed

config/main.cfg.default

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ eyes_speed = 100
1010
eyes_duration = .4
1111
mouth_speed = 100
1212
mouth_duration = .4
13+
[character]
14+
name = teddy
15+
prefix = t

index.html

-93
This file was deleted.

lib/bear.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ def __init__(self, config):
3636
label='mouth'
3737
)
3838

39+
self.character = {
40+
'name': config.get('character', 'name'),
41+
'prefix': config.get('character', 'prefix')
42+
}
43+
logging.debug('character is:{}\nprefix is:{}'.format(self.character['name'], self.character['prefix']))
44+
3945
#set starting motor positions
4046
self.eyes.open()
4147
self.mouth.close()
4248
self.talkThread = Thread(target=self.__talkMonitor)
4349
self.blinkThread = Thread(target=self.__blinkMonitor)
44-
logging.debug("bear constructor finished")
50+
logging.debug("bear ccconstructor finished")
4551

4652
def __del__(self):
4753
logging.debug("bear deconstructor finished")

lib/servo.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from time import sleep
44
import logging
55
import RPi.GPIO as GPIO
6-
import time
76

87
class Servo:
98

lib/webServer.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env python
22

33
from aiohttp import web
4-
from time import sleep
5-
import logging, socket, socketio, time
4+
import jinja2
5+
import aiohttp_jinja2
6+
import os, socket, socketio
67

78
class WebServer:
89
def __init__(self,bear):
@@ -15,16 +16,18 @@ def __init__(self,bear):
1516
## Creates a new Aiohttp Web Application
1617
app = web.Application()
1718

18-
# Binds our Socket.IO server to our Web App
19-
## instance
19+
aiohttp_jinja2.setup(
20+
app, loader=jinja2.FileSystemLoader(os.path.join(os.getcwd(), "templates"))
21+
)
22+
23+
# bind socketio server to web app instance
2024
sio.attach(app)
2125

22-
## we can define aiohttp endpoints just as we normally
23-
## would with no change
26+
@aiohttp_jinja2.template("index.html")
2427
async def index(request):
25-
with open('index.html') as f:
26-
return web.Response(text=f.read(), content_type='text/html')
28+
return {'character':bear.character}
2729

30+
# respond to client events
2831
@sio.on('update_bear')
2932
async def update_bear(sid, data):
3033
bear.update(data)
@@ -38,17 +41,16 @@ async def speak(sid, phrase):
3841
@sio.on('play')
3942
async def play(sid, filename):
4043
if(filename != ""): bear.play(filename)
41-
await sio.emit('speaking_done')
44+
await sio.emit('playing_done')
4245

4346
@sio.on('fetch_phrases')
4447
async def fetch_phrases(sid):
4548
await sio.emit('phrases_fetched', bear.phrases)
4649

47-
## We bind our aiohttp endpoint to our app
48-
## router
50+
# bind aiohttp endpoint to app router
4951
app.router.add_get('/', index)
5052

51-
## add static file route
53+
# add route for static files
5254
app.router.add_static('/public', 'public')
5355

5456
self.app = app

main.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from lib.webServer import WebServer
1111

1212
logging.basicConfig(level=logging.DEBUG)
13+
logging.getLogger('asyncio').setLevel(logging.WARNING)
1314

1415
# read main config file
1516
config = configparser.RawConfigParser()

mock/bear.py

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def __init__(self, config):
3232
label='mouth'
3333
)
3434

35+
self.character = {
36+
'name': config.get('character', 'name'),
37+
'prefix': config.get('character', 'prefix')
38+
}
39+
logging.debug('character is:{}\nprefix is:{}'.format(self.character['name'], self.character['prefix']))
40+
3541
#set starting motor positions
3642
self.eyes.open()
3743
self.mouth.close()

public/css/main.css

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
body{
2+
background-image: url(/public/img/bg_naughty.png)
3+
}
4+
5+
area:focus{
6+
border: none;
7+
outline-style: none;
8+
-moz-outline-style:none;
9+
}
10+
11+
.form-switch.form-switch-md {
12+
padding-left: 4.5em;
13+
height: 2.5em;
14+
}
15+
16+
.form-switch.form-switch-md .form-check-input {
17+
margin-left: -4.5em;
18+
height: 2em;
19+
width: 4em;
20+
}
21+
22+
.form-switch.form-switch-md .form-check-label {
23+
padding-top: 0.5em;
24+
}

public/img/header_g.png

30.3 KB
Loading

public/img/header_t.png

29.7 KB
Loading

0 commit comments

Comments
 (0)