refactors a little
This commit is contained in:
@@ -1,80 +1,7 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from .gui import App
|
||||
|
||||
def new_frame_horiz(parent):
|
||||
frame = tk.Frame(parent)
|
||||
frame.pack(fill=tk.X, expand=True)
|
||||
return frame
|
||||
app = App()
|
||||
app.run()
|
||||
|
||||
window = tk.Tk()
|
||||
window.title("Xerus")
|
||||
|
||||
header = tk.Frame(window)
|
||||
header.pack(side=tk.TOP, fill=tk.X, expand=True)
|
||||
|
||||
# Subjects choice list
|
||||
subjectFrame = new_frame_horiz(header)
|
||||
subjects = ["Henri", "Étienne", "Julia"]
|
||||
subjectLabel = tk.Label(subjectFrame, text="Résident")
|
||||
subjectLabel.pack(side=tk.LEFT)
|
||||
subjectChoice = ttk.Combobox(subjectFrame, values=subjects)
|
||||
subjectChoice.pack(side=tk.RIGHT, expand=True, fill=tk.X)
|
||||
|
||||
# Category choice list
|
||||
categoryFrame = new_frame_horiz(header)
|
||||
categories = ["Santé", "Comportement", "Quotidien", "Infos", "Activité"]
|
||||
categoryLabel = tk.Label(categoryFrame, text="Catégorie")
|
||||
categoryLabel.pack(side=tk.LEFT)
|
||||
categoryChoice = ttk.Combobox(categoryFrame, values=categories)
|
||||
categoryChoice.current(0)
|
||||
toLeft = tk.Button(categoryFrame, text="<")
|
||||
toRight = tk.Button(categoryFrame, text=">")
|
||||
|
||||
toRight.pack(side=tk.RIGHT)
|
||||
categoryChoice.pack(side=tk.RIGHT, fill=tk.X, expand=True)
|
||||
toLeft.pack(side=tk.RIGHT)
|
||||
|
||||
|
||||
# Text view
|
||||
textView = tk.Frame(window)
|
||||
textView.pack()
|
||||
|
||||
textStore = {
|
||||
"23 mars 2020": [
|
||||
{ 'time': "Matin", 'text': "Bien mangé ce matin. Sorti faire un tour pour voir les poules", },
|
||||
{ 'time': "Après-midi", 'text': "Rien de particulier" },
|
||||
],
|
||||
"24 mars 2020": [
|
||||
{ 'time': "Matin", 'text': "Bien mangé ce matin. Sorti faire un tour pour voir les poules", },
|
||||
{ 'time': "Après-midi", 'text': "Rien de particulier" },
|
||||
],
|
||||
"25 mars 2020": [
|
||||
{ 'time': "Matin", 'text': "Bien mangé ce matin. Sorti faire un tour pour voir les poules", },
|
||||
{ 'time': "Après-midi", 'text': "Rien de particulier" },
|
||||
],
|
||||
}
|
||||
|
||||
scrollbar = tk.Scrollbar(textView)
|
||||
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
|
||||
text = tk.Text(textView, yscrollcommand=scrollbar.set)
|
||||
scrollbar.config(command=text.yview)
|
||||
text.tag_config("d", underline=1) # Dates
|
||||
text.tag_config("t", foreground="grey") # Times
|
||||
text.pack()
|
||||
|
||||
for date, items in textStore.items():
|
||||
# Date header
|
||||
text.insert(tk.INSERT, f"{date}\n\n", "d")
|
||||
# Text
|
||||
for i in items:
|
||||
text.insert(tk.INSERT, f"{i['time']}. ", "t")
|
||||
text.insert(tk.INSERT, f"{i['text']}\n")
|
||||
text.insert(tk.INSERT, "\n")
|
||||
|
||||
text.config(state=tk.DISABLED)
|
||||
|
||||
|
||||
|
||||
window.mainloop()
|
||||
|
||||
126
xerus/gui.py
Normal file
126
xerus/gui.py
Normal file
@@ -0,0 +1,126 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
|
||||
def new_frame_horiz(parent):
|
||||
frame = tk.Frame(parent)
|
||||
frame.pack(fill=tk.X, expand=True)
|
||||
return frame
|
||||
|
||||
|
||||
def render_notes(notes, text_area):
|
||||
# Text
|
||||
for note in notes:
|
||||
text_area.insert(tk.INSERT, f"{note[0]}. ", "t")
|
||||
text_area.insert(tk.INSERT, f"{note[1]}\n")
|
||||
text_area.insert(tk.INSERT, "\n")
|
||||
|
||||
|
||||
DATA = { "Henri" :
|
||||
{ "Santé": { "23 mars 2020": [] },
|
||||
"Comportement": { "23 mars 2020": [] },
|
||||
"Quotidien": {
|
||||
"23 mars 2020": [
|
||||
( "Matin", "Bien mangé ce matin. Sorti faire un tour pour voir les poules" ),
|
||||
( "Après-midi", "Rien de particulier" ),
|
||||
],
|
||||
"24 mars 2020": [
|
||||
( "Matin", "Bien mangé ce matin. Sorti faire un tour pour voir les poules", ),
|
||||
( "Après-midi", "Rien de particulier" ),
|
||||
],
|
||||
"25 mars 2020": [
|
||||
( "Matin", "Bien mangé ce matin. Sorti faire un tour pour voir les poules" ),
|
||||
( "Après-midi", "Rien de particulier" ),
|
||||
],
|
||||
},
|
||||
"Infos": { "23 mars 2020": [] },
|
||||
"Activité": { "23 mars 2020": [] },
|
||||
},
|
||||
"Étienne":
|
||||
{ "Santé": { "23 mars 2020": [] },
|
||||
"Comportement": { "23 mars 2020": [] },
|
||||
"Quotidien": { "23 mars 2020": [] },
|
||||
"Infos": { "23 mars 2020": [] },
|
||||
"Activité": { "23 mars 2020": [] },
|
||||
},
|
||||
"Julia" :
|
||||
{ "Santé": { "23 mars 2020": [] },
|
||||
"Comportement": { "23 mars 2020": [] },
|
||||
"Quotidien": { "23 mars 2020": [] },
|
||||
"Infos": { "23 mars 2020": [] },
|
||||
"Activité": { "23 mars 2020": [] },
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class App(tk.Frame):
|
||||
|
||||
def __init__(self, master=None):
|
||||
super().__init__(master)
|
||||
self.current_category = 0
|
||||
self.current_subject = None
|
||||
self.pack()
|
||||
|
||||
def run(self):
|
||||
self.subjects = ["Henri", "Étienne", "Julia"]
|
||||
self.categories = ["Santé", "Comportement", "Quotidien", "Infos", "Activité"]
|
||||
self._create_widgets()
|
||||
self.mainloop()
|
||||
|
||||
def _set_subject(self):
|
||||
pass
|
||||
|
||||
def _set_category(self):
|
||||
pass
|
||||
|
||||
def _set_date_range(self):
|
||||
pass
|
||||
|
||||
def _create_widgets(self):
|
||||
self.header = tk.Frame(self)
|
||||
self.header.pack(side=tk.TOP, fill=tk.X, expand=True)
|
||||
|
||||
# Subjects choice list
|
||||
subjectFrame = new_frame_horiz(self.header)
|
||||
subjectLabel = tk.Label(subjectFrame, text="Résident")
|
||||
subjectLabel.pack(side=tk.LEFT)
|
||||
subjectChoice = ttk.Combobox(subjectFrame, values=self.subjects)
|
||||
subjectChoice.pack(side=tk.RIGHT, expand=True, fill=tk.X)
|
||||
|
||||
# Category choice list
|
||||
categoryFrame = new_frame_horiz(self.header)
|
||||
categoryLabel = tk.Label(categoryFrame, text="Catégorie")
|
||||
categoryLabel.pack(side=tk.LEFT)
|
||||
categoryChoice = ttk.Combobox(categoryFrame, values=self.categories)
|
||||
categoryChoice.current(0)
|
||||
toLeft = tk.Button(categoryFrame, text="<")
|
||||
toRight = tk.Button(categoryFrame, text=">")
|
||||
toRight.pack(side=tk.RIGHT)
|
||||
categoryChoice.pack(side=tk.RIGHT, fill=tk.X, expand=True)
|
||||
toLeft.pack(side=tk.RIGHT)
|
||||
|
||||
|
||||
# Text view
|
||||
textView = tk.Frame(self)
|
||||
textView.pack()
|
||||
scrollbar = tk.Scrollbar(textView)
|
||||
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
|
||||
text = tk.Text(textView, yscrollcommand=scrollbar.set)
|
||||
scrollbar.config(command=text.yview)
|
||||
text.tag_config("d", underline=1) # Dates
|
||||
text.tag_config("t", foreground="grey") # Times
|
||||
text.pack()
|
||||
|
||||
|
||||
current_subject = 0
|
||||
current_category = 0
|
||||
for date, notes in DATA[self.subjects[current_subject]][self.categories[current_category]].items():
|
||||
# Date header
|
||||
text.insert(tk.INSERT, f"{date}\n\n", "d")
|
||||
render_notes(notes, text)
|
||||
|
||||
text.config(state=tk.DISABLED)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user