29 lines
917 B
Python
29 lines
917 B
Python
import streamlit as st
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
def list_files() -> list:
|
|
#Zugriff auf project directory, listet alle gefunden Pythondateien auf
|
|
mypath = Path.cwd()
|
|
files = list(mypath.glob('*.py'))
|
|
return files
|
|
|
|
def read_file(file_path: Path) -> str:
|
|
# ErrorHandling einbauen, falls der Pfad falsch ist?
|
|
# Datei wird im Sidebar angeklickt, Inhalt wird ausgelesen
|
|
with file_path.open('r') as file:
|
|
return file.read()
|
|
|
|
def save_file(file_path: Path, content: str):
|
|
#wenn eine Datei im Code Editor abgeändert wird, soll die Funktion die Änderungen abspeichern
|
|
with file_path.open('w') as file:
|
|
file.write(content)
|
|
|
|
def open_file(file_path: Path):
|
|
#Inhalt und Dateipfad der geöffneten Datei wird im session_state gespeichert
|
|
content = read_file(file_path)
|
|
st.session_state["file_content"] = content
|
|
st.session_state["selected_file"] = file_path
|
|
|