0% found this document useful (0 votes)
2 views4 pages

Cod

The document describes a university schedule application built using Tkinter in Python. It allows users to add courses with details such as course name, professor, type, day, start time, and end time, and provides functionalities to save the schedule as a JSON file or print it as a PDF. The application includes a graphical interface with color-coded representations for different professors and course types.

Uploaded by

liviucalistru95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Cod

The document describes a university schedule application built using Tkinter in Python. It allows users to add courses with details such as course name, professor, type, day, start time, and end time, and provides functionalities to save the schedule as a JSON file or print it as a PDF. The application includes a graphical interface with color-coded representations for different professors and course types.

Uploaded by

liviucalistru95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

import tkinter as tk

from tkinter import messagebox, filedialog


from tkinter import ttk
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
import json

class Curs:
def __init__(self, nume, profesor, tip, zi, ora_inceput, ora_sfarsit):
self.nume = nume
self.profesor = profesor
self.tip = tip
self.zi = zi
self.ora_inceput = ora_inceput
self.ora_sfarsit = ora_sfarsit

class AplicatieOrar:
def __init__(self, root):
self.root = root
self.root.title("Orar Universitar")
self.root.resizable(False, False)

self.orar = []
self.profesor_culori = {
"Prof. A": "lightblue",
"Prof. B": "lightgreen",
"Prof. C": "lightyellow",
"Prof. D": "lightcoral",
"Prof. E": "lightpink"
}
self.tip_culori = {
"Curs": "lightgray",
"Seminar": "lightcyan",
"Laborator": "lightgoldenrod"
}

# Mapping course names to professors


self.course_professor_mapping = {
"Curs 1": "Prof. A",
"Curs 2": "Prof. B",
"Seminar 1": "Prof. C",
"Laborator 1": "Prof. D",
"Laborator 2": "Prof. E"
}

# Label cu denumirea universității


self.label_universitate = tk.Label(root, text="Universitatea Vasile
Alecsandri", font=("Arial", 16))
self.label_universitate.grid(row=0, column=0, columnspan=4, pady=10,
sticky='nsew')

# Etichete și câmpuri
self.create_widgets()

# Canvas pentru a desena orarul


self.canvas = tk.Canvas(root, width=600, height=400, bg="white")
self.canvas.grid(row=8, column=0, columnspan=4, sticky='nsew')

# Configurarea grilei pentru a se adapta la dimensiuni


for i in range(5):
root.grid_columnconfigure(i, weight=1)
root.grid_rowconfigure(8, weight=1)

def create_widgets(self):
tk.Label(self.root, text="Nume Curs:").grid(row=1, column=0, sticky='e')
self.txt_nume = ttk.Combobox(self.root,
values=list(self.course_professor_mapping.keys()), state="readonly")
self.txt_nume.grid(row=1, column=1, sticky='ew')
self.txt_nume.bind("<<ComboboxSelected>>", self.on_course_selected)

tk.Label(self.root, text="Profesor:").grid(row=2, column=0, sticky='e')


self.profesor_combo = ttk.Combobox(self.root,
values=list(self.profesor_culori.keys()), state="readonly")
self.profesor_combo.grid(row=2, column=1, sticky='ew')

tk.Label(self.root, text="Tip Curs:").grid(row=3, column=0, sticky='e')


self.var_tip = tk.StringVar(value="Curs")
tk.Radiobutton(self.root, text="Curs", variable=self.var_tip,
value="Curs").grid(row=3, column=1, sticky='w')
tk.Radiobutton(self.root, text="Seminar", variable=self.var_tip,
value="Seminar").grid(row=3, column=1, sticky='e')
tk.Radiobutton(self.root, text="Laborator", variable=self.var_tip,
value="Laborator").grid(row=3, column=1, sticky='se')

tk.Label(self.root, text="Zi:").grid(row=4, column=0, sticky='e')


self.txt_zi = tk.Entry(self.root)
self.txt_zi.grid(row=4, column=1, sticky='ew')

tk.Label(self.root, text="Ora Început:").grid(row=5, column=0, sticky='e')


self.ora_inceput_combo = ttk.Combobox(self.root,
values=self.create_time_slots())
self.ora_inceput_combo.grid(row=5, column=1, sticky='ew')

tk.Label(self.root, text="Ora Sfârșit:").grid(row=6, column=0, sticky='e')


self.ora_sfarsit_combo = ttk.Combobox(self.root,
values=self.create_time_slots())
self.ora_sfarsit_combo.grid(row=6, column=1, sticky='ew')

# Butoane
button_frame = tk.Frame(self.root)
button_frame.grid(row=7, column=0, columnspan=4, pady=10, sticky='ew')

tk.Button(button_frame, text="Adaugă Curs",


command=self.adauga_curs).grid(row=0, column=0, padx=5)
tk.Button(button_frame, text="Salvează",
command=self.salveaza_orar).grid(row=0, column=1, padx=5)
tk.Button(button_frame, text="Printare", command=self.printare).grid(row=0,
column=2, padx=5)
tk.Button(button_frame, text="Editare",
command=self.editare_curs).grid(row=0, column=3, padx=5)
tk.Button(button_frame, text="Ieșire", command=self.root.quit).grid(row=0,
column=4, padx=5)

def on_course_selected(self, event):


course_name = self.txt_nume.get()
professor_name = self.course_professor_mapping.get(course_name)
self.profesor_combo.set(professor_name if professor_name else "")
def create_time_slots(self):
time_slots = []
for hour in range(8, 21): # Interval de la 8:00 la 20:00
time_slots.append(f"{hour}:00")
time_slots.append(f"{hour}:30")
return time_slots

def adauga_curs(self):
curs_nou = Curs(
self.txt_nume.get(),
self.profesor_combo.get(),
self.var_tip.get(),
self.txt_zi.get(),
self.ora_inceput_combo.get(),
self.ora_sfarsit_combo.get()
)
self.orar.append(curs_nou)
self.actualizeaza_orar()
self.clear_fields()

def actualizeaza_orar(self):
self.canvas.delete("all") # Șterge toate formele existente

for curs in self.orar:


start_hour = int(curs.ora_inceput.split(":")[0])
start_minute = int(curs.ora_inceput.split(":")[1])
end_hour = int(curs.ora_sfarsit.split(":")[0])
end_minute = int(curs.ora_sfarsit.split(":")[1])

# Calculăm poziția în funcție de oră


y_start = (start_hour - 8) * 40 + (start_minute // 30) * 20
y_end = (end_hour - 8) * 40 + (end_minute // 30) * 20

# Culorile pentru dreptunghiuri


profesor_color = self.profesor_culori.get(curs.profesor, "white")
tip_color = self.tip_culori.get(curs.tip, "lightgray")

# Desenăm dreptunghiul pentru intervalul orar


self.canvas.create_rectangle(50, y_start, 550, y_end, fill=tip_color,
outline="black")

# Adăugăm text pentru profesor, interval orar și tip curs


self.canvas.create_text(100, (y_start + y_end) // 2,
text=curs.profesor, anchor="w", fill=profesor_color)
self.canvas.create_text(300, (y_start + y_end) // 2, text=f"{curs.nume}
({curs.ora_inceput} - {curs.ora_sfarsit})", anchor="center")
self.canvas.create_text(500, (y_start + y_end) // 2, text=f"{curs.tip}
- {'Săptămână impară' if self.is_odd_week(curs.zi) else 'Săptămână pară'}",
anchor="e", fill="black")

def is_odd_week(self, week_number):


try:
week = int(week_number)
return week % 2 != 0
except ValueError:
return False

def clear_fields(self):
self.txt_nume.set('') # Reset the ComboBox
self.profesor_combo.set('') # Reset the ComboBox
self.var_tip.set("Curs") # Reset radiobutton
self.txt_zi.delete(0, tk.END)
self.ora_inceput_combo.set('') # Reset the ComboBox
self.ora_sfarsit_combo.set('') # Reset the ComboBox

def salveaza_orar(self):
filename = filedialog.asksaveasfilename(defaultextension=".json",
filetypes=[("JSON files", "*.json")])
if filename:
with open(filename, 'w') as f:
json.dump([curs.__dict__ for curs in self.orar], f)
messagebox.showinfo("Info", "Orarul a fost salvat.")

def printare(self):
filename = filedialog.asksaveasfilename(defaultextension=".pdf",
filetypes=[("PDF files", "*.pdf")])
if filename:
self.generare_pdf(filename)
messagebox.showinfo("Info", f"Orarul a fost salvat ca PDF: {filename}")

def generare_pdf(self, filename):


c = canvas.Canvas(filename, pagesize=letter)
width, height = letter

c.drawString(100, height - 50, "Orar Universitar")


c.drawString(100, height - 70, "Zi: " + self.txt_zi.get())

# Adăugăm cursurile în PDF


y = height - 100
for curs in self.orar:
c.drawString(100, y, f"{curs.nume} - {curs.profesor} - {curs.tip}
({curs.ora_inceput} - {curs.ora_sfarsit})")
y -= 20

c.save()

def editare_curs(self):
messagebox.showinfo("Info", "Funcționalitate de editare nu este
implementată încă.")

if __name__ == "__main__":
root = tk.Tk()
app = AplicatieOrar(root)
root.mainloop()

You might also like