improved error handling and logging

This commit is contained in:
langolierz
2018-05-03 01:47:50 +00:00
parent cc2fca3983
commit c15ec1247c
8 changed files with 30 additions and 27 deletions

View File

@@ -149,7 +149,6 @@ class Data(object):
if use_fixed_length and use_rand_start: if use_fixed_length and use_rand_start:
max_increase = int(max(end - start - max(fixed_length_value, 4),0)) max_increase = int(max(end - start - max(fixed_length_value, 4),0))
print('max increase is {} '.format(max_increase))
random_increase = randint(0,max_increase) random_increase = randint(0,max_increase)
new_start = start + random_increase new_start = start + random_increase
new_end = min(new_start + fixed_length_value, end) new_end = min(new_start + fixed_length_value, end)
@@ -157,11 +156,9 @@ class Data(object):
new_end = min(new_start + fixed_length_value, end) new_end = min(new_start + fixed_length_value, end)
elif not use_fixed_length and use_rand_start: elif not use_fixed_length and use_rand_start:
max_increase = int(max(end - start - 4,0)) max_increase = int(max(end - start - 4,0))
print('max increase is {} '.format(max_increase))
random_increase = randint(0,max_increase) random_increase = randint(0,max_increase)
new_start = start + random_increase new_start = start + random_increase
print('new start: {}, new end: {} '.format(new_start, new_end))
return new_start, new_end return new_start, new_end
def _update_next_bankslot_value(self, slot_num): def _update_next_bankslot_value(self, slot_num):

View File

@@ -50,25 +50,25 @@
}, },
{ {
"end": -1, "end": -1,
"length": -1, "length": 7.4,
"location": "", "location": "/home/pi/Videos/recordings/rec-2018-05-03-0.mp4",
"name": "", "name": "rec-2018-05-03-0.mp4",
"rate": 1, "rate": 1,
"start": -1 "start": -1
}, },
{ {
"end": -1, "end": -1,
"length": -1, "length": 2.32,
"location": "", "location": "/home/pi/Videos/recordings/rec-2018-05-03-1.mp4",
"name": "", "name": "rec-2018-05-03-1.mp4",
"rate": 1, "rate": 1,
"start": -1 "start": -1
}, },
{ {
"end": -1, "end": -1,
"length": -1, "length": 3.36,
"location": "", "location": "/home/pi/Videos/recordings/rec-2018-05-03-2.mp4",
"name": "", "name": "rec-2018-05-03-2.mp4",
"rate": 1, "rate": 1,
"start": -1 "start": -1
}, },

View File

@@ -225,6 +225,7 @@ class Display(object):
def _set_colour_from_alpha(self, now_alpha, preview_alpha, next_alpha): def _set_colour_from_alpha(self, now_alpha, preview_alpha, next_alpha):
upper_bound = 150 upper_bound = 150
is_recording = self.capture.is_recording == True
### scale values ### scale values
scaled_now = int(( now_alpha / 255 ) * (255 - upper_bound) + upper_bound) scaled_now = int(( now_alpha / 255 ) * (255 - upper_bound) + upper_bound)
scaled_preview = int(( preview_alpha / 255 ) * (255 - upper_bound) + upper_bound) scaled_preview = int(( preview_alpha / 255 ) * (255 - upper_bound) + upper_bound)
@@ -232,7 +233,7 @@ class Display(object):
### convert to hex ### convert to hex
now_colour = self.hex_from_rgb(scaled_now, scaled_now, 0) now_colour = self.hex_from_rgb(scaled_now, scaled_now, 0)
capture_colour = self.hex_from_rgb(255 * self.capture.is_recording, 0, scaled_preview) capture_colour = self.hex_from_rgb(255 * is_recording, 100, scaled_preview )
next_colour = self.hex_from_rgb(0, scaled_next, scaled_next) next_colour = self.hex_from_rgb(0, scaled_next, scaled_next)
### update the colours ### update the colours
self.display_text.tag_configure("NOW_ALPHA", background="black", foreground=now_colour) self.display_text.tag_configure("NOW_ALPHA", background="black", foreground=now_colour)
@@ -243,7 +244,6 @@ class Display(object):
def hex_from_rgb(r, g, b): def hex_from_rgb(r, g, b):
return '#%02x%02x%02x' % (r, g, b) return '#%02x%02x%02x' % (r, g, b)
def _update_screen_every_second(self): def _update_screen_every_second(self):
self.refresh_display() self.refresh_display()
self.tk.after(500, self._update_screen_every_second) self.tk.after(500, self._update_screen_every_second)

View File

@@ -17,7 +17,7 @@ class MessageHandler(object):
return logger return logger
def set_message(self, message_type, message, stacktrace=''): def set_message(self, message_type, message, stacktrace=''):
self.current_message = [message_type, message, True] self.current_message = [message_type, str(message), True]
self.number_of_messages = self.number_of_messages + 1 self.number_of_messages = self.number_of_messages + 1
if message_type is 'ERROR': if message_type is 'ERROR':
self.logger.error('ERROR MESSAGE IS: {} \n STACKTRACE IS: {}'.format(message, stacktrace)) self.logger.error('ERROR MESSAGE IS: {} \n STACKTRACE IS: {}'.format(message, stacktrace))

View File

@@ -43,7 +43,12 @@ actions.toggle_x_autorepeat()
frame.pack() frame.pack()
tk.attributes("-fullscreen", True) tk.attributes("-fullscreen", True)
try: def handle_error(exc, val, tb):
tk.mainloop() print('traceback for error : {}'.format(traceback.format_exc()))
except: message_handler.set_message('ERROR', val, traceback.format_exc())
message_handler.set_message(traceback.print_tb(sys.exc_traceback, limit=1, file=sys.stdout))
tk.report_callback_exception = handle_error
tk.mainloop()

View File

@@ -98,11 +98,7 @@ class MidiInput(object):
def call_method_name(self, method_name, argument=None): def call_method_name(self, method_name, argument=None):
if argument is not None: if argument is not None:
# try:
getattr(self.actions, method_name)(argument) getattr(self.actions, method_name)(argument)
#except TypeError as e:
# print(e)
# self.message_handler.set_message('INFO', 'bad midi cc mapping')
else: else:
getattr(self.actions, method_name)() getattr(self.actions, method_name)()

View File

@@ -1,5 +1,7 @@
import string import string
import datetime import datetime
import traceback
import sys
class NumpadInput(object): class NumpadInput(object):
def __init__(self, root, message_handler, display, actions, data): def __init__(self, root, message_handler, display, actions, data):
@@ -29,6 +31,11 @@ class NumpadInput(object):
else: else:
print('{} is not in keypad map'.format(event.char)) print('{} is not in keypad map'.format(event.char))
def on_key_release(self, event):
numpad = list(string.ascii_lowercase[0:19])
if event.char in numpad:
self.check_key_release_settings(event.char)
def run_action_for_mapped_key(self, key): def run_action_for_mapped_key(self, key):
this_mapping = self.key_mappings[key] this_mapping = self.key_mappings[key]
if self.data.control_mode in this_mapping: if self.data.control_mode in this_mapping:
@@ -47,10 +54,7 @@ class NumpadInput(object):
self.display.refresh_display() self.display.refresh_display()
def on_key_release(self, event):
numpad = list(string.ascii_lowercase[0:19])
if event.char in numpad:
self.check_key_release_settings(event.char)
def check_key_release_settings(self, key): def check_key_release_settings(self, key):

View File

@@ -93,6 +93,7 @@ class VideoPlayer:
if(position > end_threshold): if(position > end_threshold):
self.status = 'FINISHED' self.status = 'FINISHED'
self.omx_player.pause() self.omx_player.pause()
print('its paused at end!') print('its paused at end!')
elif(self.omx_running): elif(self.omx_running):
self.root.after(5, self.pause_at_end) self.root.after(5, self.pause_at_end)