Skip to content

Commit

Permalink
Try separate manual as data
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightbridge-KS committed Mar 23, 2024
1 parent 344df2b commit 348838a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
5 changes: 3 additions & 2 deletions modules/app_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
)
import nm
from utils import attempt_float, read_markdown_file
from modules.manual import man_app
from modules.manual import read_man # man_app

# Change App
class AppChange(ft.UserControl):
Expand Down Expand Up @@ -35,7 +35,8 @@ def build(self):
self.btn,
self.output_text_field,
ft.Text("How to use", theme_style=ft.TextThemeStyle.TITLE_MEDIUM),
ft.Markdown(man_app["change"], selectable=True)
# ft.Markdown(man_app["change"], selectable=True),
ft.Markdown(read_man("change_app_man.md"), selectable=True)
]
)
)
Expand Down
5 changes: 3 additions & 2 deletions modules/app_spine_ht_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
)
import nm
from utils import parse_str_to_num_or_list, read_markdown_file
from modules.manual import man_app
from modules.manual import read_man # man_app

# Spine Ht Loss App
class AppSpineHtLoss(ft.UserControl):
Expand Down Expand Up @@ -36,7 +36,8 @@ def build(self):
self.btn,
self.output_text_field,
ft.Text("How to use", theme_style=ft.TextThemeStyle.TITLE_MEDIUM),
ft.Markdown(man_app["spine_ht_loss"], selectable=True)
# ft.Markdown(man_app["spine_ht_loss"], selectable=True)
ft.Markdown(read_man("spine_ht_loss_man.md"), selectable=True)
]
)
)
Expand Down
File renamed without changes.
File renamed without changes.
36 changes: 29 additions & 7 deletions modules/manual.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
man_app={
"change": f"""- Input current value as number (e.g. 2)
- Input previous value as number (e.g. 1)
- % change = (current - previous) * 100 / previous""",
"spine_ht_loss": f"""- Input height in centimeter (e.g. 10)
- Comma-separated value to calculate mean (e.g. 10, 12)"""
}
# man_app={
# "change": f"""- Input current value as number (e.g. 2)
# - Input previous value as number (e.g. 1)
# - % change = (current - previous) * 100 / previous""",
# "spine_ht_loss": f"""- Input height in centimeter (e.g. 10)
# - Comma-separated value to calculate mean (e.g. 10, 12)"""
# }

def read_man(man_name):
"""Read Markdown from `man/`"""
# Technique from this https://py-pkgs.org/04-package-structure#including-non-code-files-in-a-package
from importlib import resources
with resources.path("modules.man", man_name) as file_path:
markdown_content = read_markdown_file(file_path)
return markdown_content


def read_markdown_file(file_path):
from pathlib import Path
file_path = Path(file_path)
try:
# Open the markdown file in read mode
with open(file_path, 'r', encoding='utf-8') as file:
# Read the entire file content into a string
markdown_content = file.read()
return markdown_content
except FileNotFoundError:
print(f"The file {file_path} was not found.")
except Exception as e:
print(f"An error occurred: {e}")


0 comments on commit 348838a

Please sign in to comment.