Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Notes application written in Python 3.8 & KivyMD
## version history
| version | date | description |
| :---: | :---: | :---: |
| 0.1.1 | 12/7/2022 | removing item drawer menu highlight, improving diff feature, bugfixes |
| 0.1.0 | 19/6/2022 | initial release |

## FAQ
Expand Down
4 changes: 2 additions & 2 deletions notes_app/color.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import AnyStr, List
from typing import List


class Color:
Expand Down Expand Up @@ -33,7 +33,7 @@ def __init__(self, name, rgba_value):
]


def get_color_by_name(colors_list: List[Color], color_name: AnyStr) -> Color:
def get_color_by_name(colors_list: List[Color], color_name: str) -> Color:
for color in colors_list:
if color.name == color_name:
return color
Expand Down
4 changes: 1 addition & 3 deletions notes_app/controller/notes_controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import AnyStr

from notes_app.view.notes_view import NotesView


Expand Down Expand Up @@ -39,7 +37,7 @@ def set_file_path(self, file_path) -> None:
self.model.update()
self.model.dump()

def read_file_data(self, file_path=None) -> AnyStr:
def read_file_data(self, file_path=None) -> str:
f = open(file_path or self.model.file_path, "r")
s = f.read()
f.close()
Expand Down
98 changes: 83 additions & 15 deletions notes_app/diff.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import difflib
from typing import AnyStr
from typing import List

TEXT_FILE_LINE_BREAK_CHAR = "\n"
# TEXT_FILE_LINE_BREAK_CHAR_TEMP_REPLACEMENT is used because difflib SequenceMatcher consumes line endings
Expand Down Expand Up @@ -27,35 +27,103 @@ def _merge(left, right):


def _replace_line_endings(
input_text: AnyStr, line_ending: AnyStr, line_ending_replacement: AnyStr
) -> AnyStr:
input_text: str, line_ending: str, line_ending_replacement: str
) -> str:
"""
_replace_line_endings
"""
return input_text.replace(line_ending, line_ending_replacement)


def merge_strings(before: AnyStr, after: AnyStr) -> AnyStr:
SEPARATORS = {
" ", # (blank space)
"~", # (tilde)
"`", # (grave accent)
"!", # (exclamation mark)
"@", # (at)
"#", # (pound)
"$", # (dollar sign)
"%", # (percent)
"^", # (carat)
"&", # (ampersand)
"*", # (asterisk)
"(", # (open parenthesis)
")", # (close parenthesis)
"_", # (underscore)
"-", # (hyphen)
"+", # (plus sign)
"=", # (equals)
"{", # (open brace)
"}", # (close brace)
"[", # (open bracket)
"]", # (close bracket)
"|", # (pipe)
"\\", # (backslash)
":", # (colon)
";", # (semicolon)
"<", # (less than)
",", # (comma)
">", # (greater than)
".", # (period)
"?", # (question mark)
"/", # (forward slash)
}


def _split(input_text: str) -> List:
result = []
offset = 0
for idx, string in enumerate(input_text):
if string in SEPARATORS:
result.append(input_text[offset:idx])
result.append(string)
offset = idx + 1
# the last word in the enumerated input text
if idx + 1 == len(input_text):
result.append(input_text[offset : idx + 1])
return result


def _join(input_list: List, separator: str) -> str:
result = str()
for idx, el in enumerate(input_list):
if (
idx == 0
or (el in SEPARATORS)
or (idx > 1 and input_list[idx - 1] in SEPARATORS)
):
result += el
else:
result += f"{separator}{el}"
return result


def merge_strings(before: str, after: str) -> str:
"""
merge_strings
"""
default_separator = " "
merged = _merge(
_replace_line_endings(
input_text=before,
line_ending=TEXT_FILE_LINE_BREAK_CHAR,
line_ending_replacement=TEXT_FILE_LINE_BREAK_CHAR_TEMP_REPLACEMENT,
).split(),
_replace_line_endings(
input_text=after,
line_ending=TEXT_FILE_LINE_BREAK_CHAR,
line_ending_replacement=TEXT_FILE_LINE_BREAK_CHAR_TEMP_REPLACEMENT,
).split(),
_split(
_replace_line_endings(
input_text=before,
line_ending=TEXT_FILE_LINE_BREAK_CHAR,
line_ending_replacement=TEXT_FILE_LINE_BREAK_CHAR_TEMP_REPLACEMENT,
)
),
_split(
_replace_line_endings(
input_text=after,
line_ending=TEXT_FILE_LINE_BREAK_CHAR,
line_ending_replacement=TEXT_FILE_LINE_BREAK_CHAR_TEMP_REPLACEMENT,
)
),
)

merged_result_list = [el for sublist in merged for el in sublist]

return _replace_line_endings(
input_text=" ".join(merged_result_list),
input_text=_join(input_list=merged_result_list, separator=default_separator),
line_ending=TEXT_FILE_LINE_BREAK_CHAR_TEMP_REPLACEMENT,
line_ending_replacement=TEXT_FILE_LINE_BREAK_CHAR,
)
53 changes: 25 additions & 28 deletions notes_app/file.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import re
from typing import AnyStr, List, Dict
from typing import List, Dict

SECTION_FILE_NEW_SECTION_PLACEHOLDER = ""
SECTION_FILE_NAME_MINIMAL_CHAR_COUNT = 2


def get_validated_file_path(file_path):
try:
with open(file=file_path, mode="r"):
pass
except (PermissionError, FileNotFoundError, IsADirectoryError):
return
return file_path


class SectionIdentifier:
def __init__(
self,
defaults,
section_file_separator: AnyStr = None,
section_name: AnyStr = None,
self, defaults, section_file_separator: str = None, section_name: str = None,
):
self.defaults = defaults

Expand All @@ -25,13 +31,13 @@ def __init__(
)
self.section_name = section_name or self._transform_separator_to_name()

def _transform_separator_to_name(self) -> AnyStr:
def _transform_separator_to_name(self) -> str:
return re.search(
self.defaults.DEFAULT_SECTION_FILE_SEPARATOR_GROUP_SUBSTR_REGEX,
self.section_file_separator,
).group(1)

def _transform_name_to_separator(self, section_name) -> AnyStr:
def _transform_name_to_separator(self, section_name) -> str:
return self.defaults.DEFAULT_SECTION_FILE_SEPARATOR.format(name=section_name)


Expand All @@ -42,7 +48,7 @@ def __init__(self, file_path, controller, defaults):

self.defaults = defaults

self._raw_data_content: AnyStr = self._get_validated_raw_data(
self._raw_data_content: str = self._get_validated_raw_data(
raw_data=self.get_raw_data_content()
)

Expand All @@ -51,19 +57,10 @@ def __init__(self, file_path, controller, defaults):
] = self._get_section_identifiers_from_raw_data_content()

self._data_by_sections: Dict[
AnyStr, AnyStr
str, str
] = self._transform_raw_data_content_to_data_by_sections()

@staticmethod
def get_validated_file_path(file_path):
try:
with open(file=file_path, mode="r"):
pass
except (PermissionError, FileNotFoundError, IsADirectoryError):
return
return file_path

def _get_validated_raw_data(self, raw_data) -> AnyStr:
def _get_validated_raw_data(self, raw_data) -> str:
matches = re.findall(
self.defaults.DEFAULT_SECTION_FILE_SEPARATOR_REGEX, raw_data
)
Expand All @@ -84,7 +81,7 @@ def reload(self):
)
self._data_by_sections = self._transform_raw_data_content_to_data_by_sections()

def get_raw_data_content(self) -> AnyStr:
def get_raw_data_content(self) -> str:
return self._controller.read_file_data(file_path=self._file_path)

def _get_section_identifiers_from_raw_data_content(self) -> List[SectionIdentifier]:
Expand Down Expand Up @@ -123,7 +120,7 @@ def delete_section_identifier(self, section_file_separator) -> None:
def set_section_content(self, section_file_separator, section_content) -> None:
self._data_by_sections[section_file_separator] = section_content

def get_section_content(self, section_file_separator) -> AnyStr:
def get_section_content(self, section_file_separator) -> str:
return self._data_by_sections[section_file_separator]

def delete_all_sections_content(self) -> None:
Expand All @@ -140,14 +137,14 @@ def rename_section(
by replacing the section identifier in the _section_identifiers list
and by replacing the key in the _data_by_sections dict
"""
idx = 0
for idx, section_identifier in enumerate(self._section_identifiers):
if section_identifier.section_file_separator == old_section_file_separator:
break

# need to preserve the order of the _section_identifiers list item
# and the _data_by_sections dict items so that new items are placed at the end
self._section_identifiers.pop(idx)

for idx, section_identifier in enumerate(self._section_identifiers):
if section_identifier.section_file_separator == old_section_file_separator:
self._section_identifiers.pop(idx)

self._section_identifiers.append(
SectionIdentifier(
defaults=self.defaults,
Expand All @@ -160,7 +157,7 @@ def rename_section(
]
del self._data_by_sections[old_section_file_separator]

def _transform_raw_data_content_to_data_by_sections(self) -> Dict[AnyStr, AnyStr]:
def _transform_raw_data_content_to_data_by_sections(self) -> Dict[str, str]:
dict_data = dict()
for item in zip(
self._section_identifiers,
Expand All @@ -172,7 +169,7 @@ def _transform_raw_data_content_to_data_by_sections(self) -> Dict[AnyStr, AnyStr
dict_data[item[0].section_file_separator] = item[1]
return dict_data

def transform_data_by_sections_to_raw_data_content(self) -> AnyStr:
def transform_data_by_sections_to_raw_data_content(self) -> str:
text_data = str()
for k, v in self._data_by_sections.items():
text_data += k
Expand Down
4 changes: 2 additions & 2 deletions notes_app/font.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import AnyStr, List
from typing import List

AVAILABLE_FONTS = [
"DejaVuSans",
Expand All @@ -10,7 +10,7 @@
]


def get_next_font(fonts_list: List[AnyStr], font_name: AnyStr) -> AnyStr:
def get_next_font(fonts_list: List[str], font_name: str) -> str:
iterable_available_fonts = iter(fonts_list)

for font in iterable_available_fonts:
Expand Down
7 changes: 1 addition & 6 deletions notes_app/mark.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
from typing import AnyStr


def get_marked_text(
text: AnyStr, highlight_style: AnyStr, highlight_color: AnyStr
) -> AnyStr:
def get_marked_text(text: str, highlight_style: str, highlight_color: str) -> str:
return (
f"[{highlight_style}]"
f"[color={highlight_color}]"
Expand Down
3 changes: 1 addition & 2 deletions notes_app/model/notes_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import json
import time
from os import linesep, path
from typing import AnyStr

GENERAL_DATE_TIME_FORMAT = "%Y-%m-%d %H:%M:%S"


def format_local_epoch(format: AnyStr, epoch_time: int) -> AnyStr:
def format_local_epoch(format: str, epoch_time: int) -> str:
"""
format epoch in local time based on provided format
"""
Expand Down
13 changes: 5 additions & 8 deletions notes_app/search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re
from typing import AnyStr

SEARCH_MINIMAL_CHAR_COUNT = 2

Expand Down Expand Up @@ -105,7 +104,7 @@ def search_for_occurrences(self, pattern, file, current_section_identifier):


def transform_position_text_placeholder_to_position(
position_text_placeholder: AnyStr = None,
position_text_placeholder: str = None,
) -> int:
if position_text_placeholder:
return int(
Expand All @@ -116,25 +115,23 @@ def transform_position_text_placeholder_to_position(
return 0


def transform_position_to_position_text_placeholder(position_start: int = 0) -> AnyStr:
def transform_position_to_position_text_placeholder(position_start: int = 0) -> str:
if position_start:
return f"{SEARCH_LIST_ITEM_POSITION_DISPLAY_VALUE}{position_start}"
return f"{SEARCH_LIST_ITEM_POSITION_DISPLAY_VALUE}0"


def transform_section_text_placeholder_to_section_name(
section_text_placeholder: AnyStr = None,
) -> AnyStr:
section_text_placeholder: str = None,
) -> str:
if section_text_placeholder:
return section_text_placeholder.replace(
SEARCH_LIST_ITEM_SECTION_DISPLAY_VALUE, ""
)
return ""


def transform_section_name_to_section_text_placeholder(
section_name: AnyStr = "",
) -> AnyStr:
def transform_section_name_to_section_text_placeholder(section_name: str = "",) -> str:
if section_name:
return f"{SEARCH_LIST_ITEM_SECTION_DISPLAY_VALUE}{section_name}"
return f"{SEARCH_LIST_ITEM_SECTION_DISPLAY_VALUE}"
2 changes: 1 addition & 1 deletion notes_app/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.0"
__version__ = "0.1.1"
4 changes: 2 additions & 2 deletions notes_app/view/notes_view.kv
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
id: section_item
text: root.text
theme_text_color: "Custom"
on_release: self.parent.set_color_item(self)
# on_release: self.parent.set_color_item(self)
on_size:
self.ids._right_container.width = icons_container.width
self.ids._right_container.x = icons_container.width
Expand Down Expand Up @@ -51,7 +51,7 @@
MDScreen:
FloatLayout:
id: float_text_layout
TextInput:
CustomTextInput:
id: text_input
multiline: True
do_wrap: True
Expand Down
Loading