mirror of
https://github.com/ApfelTeeSaft/SplitNotes.git
synced 2026-08-26 19:33:39 +00:00
Settings Menu
Finished the settings menu and systems for saving and loading settings from a config file.
This commit is contained in:
+23
-22
@@ -15,14 +15,15 @@ these can be used for titles.
|
||||
all other lines of text are added as notes
|
||||
"""
|
||||
|
||||
|
||||
def get_note_lines(file_path):
|
||||
"""
|
||||
Reads file at given path and returns
|
||||
a list containing all rows of text in given file.
|
||||
Returns false if file can not be read.
|
||||
"""
|
||||
|
||||
#check so file isn't too big
|
||||
|
||||
# check so file isn't too big
|
||||
if path.getsize(file_path) > config.MAX_FILE_SIZE:
|
||||
return False
|
||||
|
||||
@@ -30,37 +31,37 @@ def get_note_lines(file_path):
|
||||
notes_file = open(file_path, "r")
|
||||
except:
|
||||
return False
|
||||
|
||||
#read file line per line
|
||||
|
||||
# read file line per line
|
||||
f_lines = []
|
||||
keep_reading = True
|
||||
while keep_reading:
|
||||
cur_line = notes_file.readline()
|
||||
|
||||
|
||||
if cur_line:
|
||||
f_lines.append(cur_line)
|
||||
else:
|
||||
keep_reading = False
|
||||
|
||||
return f_lines
|
||||
|
||||
|
||||
|
||||
|
||||
def encode_notes(note_lines):
|
||||
"""
|
||||
Takes a list containing strings.
|
||||
Encodes given strings according to the note formatting.
|
||||
Returns the list containing the notes for every split.
|
||||
"""
|
||||
|
||||
|
||||
def is_title(line):
|
||||
if not line:
|
||||
return False
|
||||
|
||||
|
||||
return (line[0] == "[") and (line[-1] == "]")
|
||||
|
||||
|
||||
def is_newline(line):
|
||||
return (line == "\n") or (line == "\r")
|
||||
|
||||
|
||||
def remove_new_line(line):
|
||||
if (len(line) >= 1) and (is_newline(line[-1])):
|
||||
return line[:-1]
|
||||
@@ -69,9 +70,9 @@ def encode_notes(note_lines):
|
||||
|
||||
note_list = []
|
||||
cur_notes = ""
|
||||
|
||||
|
||||
for line in note_lines:
|
||||
#remove whitespace at beginning and end
|
||||
# remove whitespace at beginning and end
|
||||
line = line.strip(" ")
|
||||
|
||||
if is_newline(line):
|
||||
@@ -81,11 +82,11 @@ def encode_notes(note_lines):
|
||||
else:
|
||||
line = remove_new_line(line)
|
||||
if not is_title(line):
|
||||
cur_notes += line + "\n" #newline
|
||||
|
||||
cur_notes += line + "\n" # newline
|
||||
|
||||
if cur_notes:
|
||||
note_list.append(cur_notes)
|
||||
|
||||
|
||||
return note_list
|
||||
|
||||
|
||||
@@ -97,12 +98,12 @@ def get_notes(file_path):
|
||||
Returns False if file is empty.
|
||||
"""
|
||||
note_lines = get_note_lines(file_path)
|
||||
|
||||
|
||||
if not note_lines:
|
||||
return False
|
||||
|
||||
|
||||
note_list = encode_notes(note_lines)
|
||||
|
||||
|
||||
return note_list
|
||||
|
||||
|
||||
@@ -112,10 +113,10 @@ def select_file():
|
||||
Returns False upon no file selection.
|
||||
Otherwise returns absolute path to selected file.
|
||||
"""
|
||||
|
||||
|
||||
file = file_dia.askopenfilename(filetypes=config.TEXT_FILES)
|
||||
|
||||
|
||||
if file:
|
||||
return file
|
||||
else:
|
||||
return False
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user