Skip to content

Commit

Permalink
Fixed issues #5 #6 #7
Browse files Browse the repository at this point in the history
  • Loading branch information
Attomsk committed May 3, 2024
1 parent 4eb7baf commit cde72c2
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions e-Paper/RaspberryPi_JetsonNano/python/examples/zerowriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit cde72c2

Please sign in to comment.