From cde72c254d74cdca2c0d41345697bc9f53354764 Mon Sep 17 00:00:00 2001 From: Attomsk <1596464+Attomsk@users.noreply.github.com> Date: Fri, 3 May 2024 12:22:05 -0700 Subject: [PATCH] Fixed issues #5 #6 #7 --- .../python/examples/zerowriter.py | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/e-Paper/RaspberryPi_JetsonNano/python/examples/zerowriter.py b/e-Paper/RaspberryPi_JetsonNano/python/examples/zerowriter.py index f54a9d0..e876bf9 100644 --- a/e-Paper/RaspberryPi_JetsonNano/python/examples/zerowriter.py +++ b/e-Paper/RaspberryPi_JetsonNano/python/examples/zerowriter.py @@ -164,8 +164,8 @@ def initialize(self): self.start_server() - self.keyboard.on_press(self.handle_key_down, suppress=True) #handles modifiers and shortcuts - self.keyboard.on_release(self.handle_key_press, suppress=True) + self.keyboard.on_press(self.handle_key_press, suppress=True) #handles modifiers and shortcuts + self.keyboard.on_release(self.handle_key_up, suppress=True) self.menu = Menu(self.display_draw, self.epd, self.display_image) self.populate_main_menu() @@ -556,18 +556,20 @@ def delete_character(self): self.cursor_position = len(self.input_content) self.needs_display_update = True - def handle_key_down(self, e): + def handle_key_up(self, e): + if e.name == 'ctrl': #if control is released + self.control_active = False if e.name == 'shift': #if shift is released - self.shift_active = True - if e.name == 'ctrl': #if ctrl is released - self.control_active = True + self.shift_active = False def save_file(self): timestamp = time.strftime("%m%d") # Format: MMDD prefix = ''.join(self.previous_lines)[:20] alphanum_prefix = ''.join(ch for ch in prefix if ch.isalnum()) filename = os.path.join(os.path.dirname(__file__), 'data', f'{timestamp}_{alphanum_prefix}.txt') + self.previous_lines.append(self.input_content) self.save_previous_lines(filename, self.previous_lines) + self.input_content = self.previous_lines.pop(len(self.previous_lines)-1) self.consolemsg("[Saved]") def save_as_file(self, userinput): @@ -598,11 +600,10 @@ def set_gmail_pass(self, userinput): def handle_key_press(self, e): - - if e.name == 'ctrl': #if control is released - self.control_active = False - if e.name == 'shift': #if shift is released - self.shift_active = False + if e.name == 'ctrl': #if control is pressed + self.control_active = True + if e.name == 'shift': #if shift is pressed + self.shift_active = True if self.menu.inputMode: if len(e.name)==1: @@ -736,14 +737,21 @@ def handle_key_press(self, e): if self.cursor_position > self.chars_per_line: # Find the last space character before the line length limit last_space = self.input_content.rfind(' ', 0, self.chars_per_line) - sentence = self.input_content[:last_space] - # Append the sentence to the previous lines - self.previous_lines.append(sentence) + if last_space >= 0: + sentence = self.input_content[:last_space] + # Append the sentence to the previous lines + self.previous_lines.append(sentence) + + # Update input_content to contain the remaining characters + self.input_content = self.input_content[last_space + 1:] + self.needs_display_update=True + else: + #There are no spaces in this line so input should move to next line + self.previous_lines.append(self.input_content[0:self.chars_per_line]) + temp = self.input_content[-1] + self.input_content = temp + self.needs_display_update=True - # Update input_content to contain the remaining characters - self.input_content = self.input_content[last_space + 1:] - self.needs_display_update=True - # Update cursor_position to the length of the remaining input_content self.cursor_position = len(self.input_content)