Skip to content

Commit

Permalink
Fixed issues #9 #11 #12 #13
Browse files Browse the repository at this point in the history
  • Loading branch information
Attomsk committed May 4, 2024
1 parent cde72c2 commit 33f98b3
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions e-Paper/RaspberryPi_JetsonNano/python/examples/zerowriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ def __init__(self):
self.parent_menu = None # used to store the menu that was open before the load menu was opened
self.server_address = "not active"
self.cache_file_path = os.path.join(os.path.dirname(__file__), 'data', 'cache.txt')

self.doReset = False

def initialize(self):
self.epd.init()
self.epd.Clear()
Expand Down Expand Up @@ -556,6 +557,17 @@ def delete_character(self):
self.cursor_position = len(self.input_content)
self.needs_display_update = True

def delete_previous_word(self):
#find the location of the last word in the line
last_space = self.input_content.rstrip().rfind(' ', 0, self.chars_per_line)
sentence = ""
#Remove previous word
if last_space >= 0:
sentence = self.input_content[:last_space+1]
self.input_content = sentence
self.cursor_position = len(self.input_content)
#self.needs_display_update = True

def handle_key_up(self, e):
if e.name == 'ctrl': #if control is released
self.control_active = False
Expand All @@ -569,6 +581,7 @@ def save_file(self):
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.save_previous_lines(self.cache_file_path, self.previous_lines)
self.input_content = self.previous_lines.pop(len(self.previous_lines)-1)
self.consolemsg("[Saved]")

Expand Down Expand Up @@ -673,10 +686,10 @@ def handle_key_press(self, e):
if e.name == "g" and self.control_active: #ctrl+g gmail
self.gmail_send()
if e.name == "r" and self.control_active: #ctrl+r slow refresh
self.epd.init()
self.epd.Clear()
self.update_display()
self.doReset = True
if e.name == "backspace" and self.control_active: #ctrl+backspace delete prev word
self.delete_previous_word()

if e.name == "tab":
self.insert_character(" ")
self.insert_character(" ")
Expand Down Expand Up @@ -771,6 +784,12 @@ def exit(self):
exit(0)

def loop(self):
if self.doReset:
self.epd.init()
self.epd.Clear()
self.update_display()
self.doReset = False

if self.menu.inputMode and not self.menu.screenupdating:
self.menu.partial_update()

Expand All @@ -788,3 +807,6 @@ def run(self):
self.load_file_into_previous_lines("cache.txt")
while True:
self.loop()
# This small sleep prevents zerowriter from consuming 100% cpu
# This does not negatively affect input delay
time.sleep(0.01)

0 comments on commit 33f98b3

Please sign in to comment.