Skip to content

Commit

Permalink
sideway scrolling in transaction texts
Browse files Browse the repository at this point in the history
  • Loading branch information
gerritnowald committed Dec 18, 2024
1 parent ebb5385 commit 67f6e7f
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion budget_book/transaction_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import argparse
import yaml
from joblib import load
import re

import functions # local functions in this repository

Expand Down Expand Up @@ -83,15 +84,24 @@ def main(stdscr):
current_row = args.row
top_row = max([current_row - y_entries + 1 , 0])
change = False # only save if data changed
offset = 0

while True:
# Print DataFrame rows
for i, (_, row) in enumerate(df.iloc[top_row : top_row + y_entries].iterrows()):
# description text
text = row[clm['text']]
text = re.sub(r'\s+', ' ', text) # Replace multiple spaces with a single space
text = re.sub(r'\d+', '', text) # Remove all numbers
if top_row + i == current_row:
attr = curses.color_pair(1)
offset = min([offset, max([len(text) - x_text , 0])])
text = text.ljust(x_text)[offset:x_text + offset]
else:
attr = curses.A_NORMAL
text = row[clm['text'] ].ljust(x_text )[:x_text ]
text = text.ljust(x_text)[:x_text]

# category
try:
category = row[clm['category']].ljust(x_category)[:x_category]
except:
Expand All @@ -108,18 +118,30 @@ def main(stdscr):
# navigate main loop

if key == curses.KEY_UP:
offset = 0
current_row = max(0, current_row - 1)
if current_row - top_row < 0:
top_row -= 1
elif key == curses.KEY_DOWN:
offset = 0
current_row = min(len(df) - 1, current_row + 1)
if current_row - top_row > y_entries - 1:
top_row += 1

# -----------------------------------------------------------------------------------
# scroll left & right

elif key == curses.KEY_RIGHT:
offset += 1
elif key == curses.KEY_LEFT:
offset -= 1
offset = max([offset,0])

# -----------------------------------------------------------------------------------
# split transaction

elif key == 115: # ASCII value of s key
offset = 0
curses.echo()
stdscr.addstr(y_entries + y_header + 1, 1, "Enter new amount: ")
stdscr.refresh()
Expand All @@ -142,6 +164,7 @@ def main(stdscr):
# categorize transaction

elif key == 10: # ASCII value of Enter key
offset = 0
if suggestions:
# text pre-processing
keywords_new = functions.PreProcText(df.loc[current_row:current_row, clm['text']] , minwordlength=4)
Expand Down

0 comments on commit 67f6e7f

Please sign in to comment.