Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
Add EDS\OD file at runtime close #45
Browse files Browse the repository at this point in the history
  • Loading branch information
Boneill3 committed Mar 25, 2021
1 parent 76d72f2 commit 58e41f7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 17 deletions.
2 changes: 1 addition & 1 deletion canopen_monitor/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def main():

# Start the can bus and the curses app
with MagicCANBus(args.interfaces, no_block=args.no_block) as bus, \
App(mt) as app:
App(mt, eds_configs) as app:
while True:
# Bus updates
for message in bus:
Expand Down
68 changes: 53 additions & 15 deletions canopen_monitor/app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from __future__ import annotations
import curses
import datetime as dt
from easygui import fileopenbox
from shutil import copy
from enum import Enum
from . import APP_NAME, APP_VERSION, APP_LICENSE, APP_AUTHOR, APP_DESCRIPTION, \
APP_URL
APP_URL, CACHE_DIR
from .can import MessageTable, MessageType
from .ui import MessagePane, PopupWindow
from .parse import eds

# Key Constants not defined in curses
# _UBUNTU key constants work in Ubuntu
Expand Down Expand Up @@ -45,17 +48,33 @@ class KeyMap(Enum):
value[2]: curses input value key
"""

F1 = {'name':'F1','description':'Toggle app info menu','key' : curses.KEY_F1}
F2 = {'name':'F2', 'description':'Toggle this menu', 'key': curses.KEY_F2}
UP_ARR = {'name':'Up Arrow', 'description':'Scroll pane up 1 row', 'key':curses.KEY_UP}
DOWN_ARR = {'name':'Down Arrow', 'description':'Scroll pane down 1 row', 'key':curses.KEY_DOWN}
LEFT_ARR = {'name':'Left Arrow', 'description':'Scroll pane left 4 cols', 'key':curses.KEY_LEFT}
RIGHT_ARR = {'name':'Right Arrow', 'description':'Scroll pane right 4 cols', 'key':curses.KEY_RIGHT}
S_UP_ARR = {'name':'Shift + Up Arrow', 'description':'Scroll pane up 16 rows', 'key':KEY_S_UP}
S_DOWN_ARR ={'name':'Shift + Down Arrow', 'description':'Scroll pane down 16 rows', 'key':KEY_S_DOWN}
C_UP_ARR ={'name':'Ctrl + Up Arrow', 'description':'Move pane selection up', 'key':[KEY_C_UP, KEY_C_UP_UBUNTU]}
C_DOWN_ARR ={'name':'Ctrl + Down Arrow', 'description':'Move pane selection down', 'key':[KEY_C_DOWN, KEY_C_DOWN_UBUNTU]}
RESIZE ={'name':'Resize Terminal', 'description':'Reset the dimensions of the app', 'key':curses.KEY_RESIZE}
F1 = {'name': 'F1', 'description': 'Toggle app info menu',
'key': curses.KEY_F1}
F2 = {'name': 'F2', 'description': 'Toggle this menu', 'key': curses.KEY_F2}
F3 = {'name': 'F3', 'description': 'Toggle eds file select',
'key': curses.KEY_F3}
UP_ARR = {'name': 'Up Arrow', 'description': 'Scroll pane up 1 row',
'key': curses.KEY_UP}
DOWN_ARR = {'name': 'Down Arrow', 'description': 'Scroll pane down 1 row',
'key': curses.KEY_DOWN}
LEFT_ARR = {'name': 'Left Arrow', 'description': 'Scroll pane left 4 cols',
'key': curses.KEY_LEFT}
RIGHT_ARR = {'name': 'Right Arrow',
'description': 'Scroll pane right 4 cols',
'key': curses.KEY_RIGHT}
S_UP_ARR = {'name': 'Shift + Up Arrow',
'description': 'Scroll pane up 16 rows', 'key': KEY_S_UP}
S_DOWN_ARR = {'name': 'Shift + Down Arrow',
'description': 'Scroll pane down 16 rows', 'key': KEY_S_DOWN}
C_UP_ARR = {'name': 'Ctrl + Up Arrow',
'description': 'Move pane selection up',
'key': [KEY_C_UP, KEY_C_UP_UBUNTU]}
C_DOWN_ARR = {'name': 'Ctrl + Down Arrow',
'description': 'Move pane selection down',
'key': [KEY_C_DOWN, KEY_C_DOWN_UBUNTU]}
RESIZE = {'name': 'Resize Terminal',
'description': 'Reset the dimensions of the app',
'key': curses.KEY_RESIZE}


class App:
Expand All @@ -71,13 +90,14 @@ class App:
:type selected_pane: MessagePane
"""

def __init__(self: App, message_table: MessageTable):
def __init__(self: App, message_table: MessageTable, eds_configs: dict):
"""
App Initialization function
:param message_table: Reference to shared message table object
:type MessageTable
"""
self.table = message_table
self.eds_configs = eds_configs
self.selected_pane_pos = 0
self.selected_pane = None
self.key_dict = {
Expand All @@ -93,7 +113,8 @@ def __init__(self: App, message_table: MessageTable):
KeyMap.RIGHT_ARR.value['key']: self.right,
KeyMap.RESIZE.value['key']: self.resize,
KeyMap.F1.value['key']: self.f1,
KeyMap.F2.value['key']: self.f2
KeyMap.F2.value['key']: self.f2,
KeyMap.F3.value['key']: self.f3
}

def __enter__(self: App) -> App:
Expand Down Expand Up @@ -269,6 +290,23 @@ def f2(self):
self.info_win.clear()
self.hotkeys_win.toggle()

def f3(self):
"""
Toggles Add File window
:return: None
"""
filepath = fileopenbox(title='Select Object Dictionary Files',
filetypes=[['*.dcf', '*.eds', '*.xdd',
'Object Dictionary Files']],
multiple=False,
default='~/.cache/canopen-monitor/')

if (filepath is not None):
file = eds.load_eds_file(filepath)
copy(filepath, CACHE_DIR)
self.eds_configs[file.node_id] = file


def _handle_keyboard_input(self: App) -> None:
"""
Retrieves keyboard input and calls the associated key function
Expand Down Expand Up @@ -334,7 +372,7 @@ def __draw__footer(self: App) -> None:
:return: None
"""
height, width = self.screen.getmaxyx()
footer = '<F1>: Info, <F2>: Hotkeys'
footer = '<F1>: Info, <F2>: Hotkeys, <F3>: Add OD File'
self.screen.addstr(height - 1, 1, footer)

def draw(self: App, ifaces: [tuple]) -> None:
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
install_requires=[
"pyvit >= 0.2.1",
"psutil >= 5.8.0",
"python-dateutil >= 2.8.1"
"python-dateutil >= 2.8.1",
"easygui >= 0.98.2",
],
extras_require={
"dev": [
Expand Down

0 comments on commit 58e41f7

Please sign in to comment.