Skip to content

Commit

Permalink
Merge pull request #307 from Bristol-Braille/system-menu
Browse files Browse the repository at this point in the history
Run upgrade from system menu and signal handling
  • Loading branch information
woodcoder authored May 20, 2024
2 parents 4f393b7 + 200b257 commit 3433310
Show file tree
Hide file tree
Showing 29 changed files with 244 additions and 403 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Create version file
run: echo "$GITHUB_REF_NAME" > VERSION
- name: Make tarball
run: tar czvf canute-ui.tar.gz --transform "s,^,canute-ui-$GITHUB_REF_NAME/," README.md LICENSE requirements-pi.txt canute_ui ui libbookindex.so config.rc.in run.sh media.py books VERSION
run: tar czvf canute-ui.tar.gz --transform "s,^,canute-ui-$GITHUB_REF_NAME/," README.md LICENSE requirements-pi.txt canute_ui ui libbookindex.so config.rc.in run.sh books VERSION
- name: Release (if tagged)
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
Expand Down
7 changes: 2 additions & 5 deletions config.rc.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ media_dir = '/media'
# and the swappable flag means USB media that is interchangeable.
library = [
{ name = 'SD', path = 'sd-card', mountpoint = true },
{ name = 'USB1', path = 'front-usb', mountpoint = true, swappable = true },
{ name = 'USB2', path = 'back-usb', mountpoint = true, swappable = true }
{ name = 'USB1', path = 'usb0', mountpoint = true, swappable = true },
{ name = 'USB2', path = 'usb1', mountpoint = true, swappable = true }
]

# if required, a program to look for changes to removable media
media_helper = './media.py'

[comms]
# serial timeout in seconds
timeout = 1000
Expand Down
199 changes: 0 additions & 199 deletions media.py

This file was deleted.

2 changes: 1 addition & 1 deletion ui/book/buttons.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ..state import state

book_buttons = {
buttons = {
'single': {
'2': state.app.user.enter_go_to_page,
'5': state.app.user.insert_bookmark,
Expand Down
2 changes: 1 addition & 1 deletion ui/bookmarks/buttons.py → ui/bookmarks_menu/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def close_menu():
return lambda: state.app.close_menu(True)


bookmarks_buttons = {
buttons = {
'single': {
'L': state.app.close_menu,
'2': go_to_bookmark(0),
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions ui/braille.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,33 @@ def unicodes_to_alphas(unis):
allowed.
"""
return ''.join(map(unicode_to_alpha, unis))


def brailleify(rel):
"""
Used to format version and serial numbers
turning 1.3.45 or AKPR54633-1PHI into UEB
"""
# FIXME: we probably shouldn't be trying to do liblouis-level translation
ret = u''
digits = False
for c in rel:
if ASCII.isdigit(c):
if not digits:
ret += u'⠼'
digits = True
c = ueb_number_mapping[int(c)]
ret += alpha_to_unicode(c)
elif c == '.':
ret += u'⠲'
elif ASCII.isalpha(c):
if digits:
# UEB 'guidelines for technical material' suggests capital
# letter marker, not letter sign
ret += u'⠠'
digits = False
ret += alpha_to_unicode(c)
else: # e.g. dash in serial
digits = False
ret += alpha_to_unicode(c)
return ret
80 changes: 29 additions & 51 deletions ui/buttons.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,35 @@
import logging
from datetime import datetime
import signal
from datetime import datetime, timedelta
from .state import state
from .system_menu.system_menu import system_menu
from .library.buttons import library_buttons
from .book.buttons import book_buttons
from .go_to_page.buttons import go_to_page_buttons
from .bookmarks.buttons import bookmarks_buttons
from .language.buttons import language_buttons

from .config_loader import import_pages

log = logging.getLogger(__name__)

page_buttons = import_pages('buttons')

bindings = {
'library': library_buttons,
'book': book_buttons,
'go_to_page': go_to_page_buttons,
'bookmarks_menu': bookmarks_buttons,
'language': language_buttons,
'help_menu': {
'single': {
'L': state.app.close_menu,
'>': state.app.next_page,
'<': state.app.previous_page,
'R': state.app.help_menu.toggle,
},
'long': {
'L': state.app.close_menu,
'>': state.app.next_page,
'<': state.app.previous_page,
'R': state.app.help_menu.toggle,
'X': state.hardware.reset_display,
},
bindings = { p:m.buttons for p, m in page_buttons.items() }
bindings['help_menu'] = {
'single': {
'L': state.app.close_menu,
'>': state.app.next_page,
'<': state.app.previous_page,
'R': state.app.help_menu.toggle,
},
'long': {
'L': state.app.close_menu,
'>': state.app.next_page,
'<': state.app.previous_page,
'R': state.app.help_menu.toggle,
'X': state.hardware.reset_display,
},
'system_menu': {
'single': {
'R': state.app.help_menu.toggle,
'>': state.app.next_page,
'<': state.app.previous_page,
'L': state.app.close_menu,
},
'long': {
'R': state.app.help_menu.toggle,
'>': state.app.next_page,
'<': state.app.previous_page,
'L': state.app.close_menu,
'X': state.hardware.reset_display,
},
}
}

sys_menu = system_menu()

for i, item in enumerate(sys_menu):
action = sys_menu[item]
bindings['system_menu']['single'][str(i + 2)] = action

# add a signal handler to manage going to the system menu when the rear
# button is pressed (generates a usr1 signal)
def sigusr1_helper(*args):
state.app.go_to_system_menu()
signal.signal(signal.SIGUSR1, sigusr1_helper)

async def dispatch_button(key, press_type, state):
location = state.app.location_or_help_menu
Expand Down Expand Up @@ -91,7 +65,11 @@ async def check(driver, state):

for key in prev_buttons:
diff = (datetime.now() - prev_buttons[key]).total_seconds()
if diff > 0.5:
prev_buttons[key] = datetime.now()
threshold = 0.5 if key in long_buttons else 1
if diff > threshold:
prev_buttons[key] = datetime.now()
# wait three seconds before repeating every half second
if key not in long_buttons:
prev_buttons[key] += timedelta(seconds=2)
long_buttons[key] = True
await dispatch_button(key, 'long', state)
17 changes: 17 additions & 0 deletions ui/config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,20 @@ def load(config_file=config_file):
files_section['media_dir'] = os.path.expanduser(media_dir)

return config

def import_pages(module):
"""
return a dictionary of location -> module (such as buttons or view)
from a list of subpackages
"""
config = load()
ui_section = config.get('ui', {})
pages = ui_section.get('pages', [
'library',
'book',
'go_to_page',
'bookmarks_menu',
'system_menu',
'language'
])
return { p:__import__(f'{p}.{module}', globals(), fromlist=[None], level=1) for p in pages }
Loading

0 comments on commit 3433310

Please sign in to comment.