-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
76 lines (67 loc) · 2.66 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# coding: utf8
import os
import json
from kivy.app import App
from kivy.properties import ObjectProperty
from kivy.storage.jsonstore import JsonStore
from kivy.uix.label import Label
from data_obj import Skill, Student
from root import Root
class ProjectZApp(App):
students_data = ObjectProperty(JsonStore('data/students.json'))
skills_data = ObjectProperty(JsonStore('data/skills.json'))
data_output = ObjectProperty(JsonStore('data/outputs.json'))
confirm_popup = ObjectProperty()
def build(self):
students, classes = self.get_students()
skills, skill_sets = self.get_skills()
self.root = Root(students, classes, skills, skill_sets)
return self.root
def get_students(self):
data = self.students_data
students = [Student(id_, **data[id_]) for id_ in data]
temp_list, classes = [], []
for s in students:
if s.class_obj.class_ in temp_list:
pass
else:
temp_list.append(s.class_obj.class_)
classes.append(s.class_obj)
students.sort(key=lambda x: x.surname)
return students, classes
def get_skills(self):
data = self.skills_data
skills = [Skill(id_, **data[id_]) for id_ in data]
temp_list, skill_sets = [], []
for s in skills:
if s.skill_set_obj.set_name in temp_list:
pass
else:
temp_list.append(s.skill_set_obj.set_name)
skill_sets.append(s.skill_set_obj)
return skills, skill_sets
def export_data(self, i=0):
self.root.start_screen.display_header.clear_widgets()
self.root.start_screen.display_label.clear_widgets()
file = 'export_{}'.format(i)
data = {key: self.data_output[key] for key in self.data_output}
path = '/'.join([self.user_data_dir, file])
if os.path.isfile(path):
i += 1
self.export_data(i)
else:
with open(path, 'w') as file:
json.dump(data, file)
file.close()
label = Label(text="Votre fichier a été exporté avec\n"
"Succès, il est situé en :\n{}\nLes données du"
"téléphone ont été effacées".format(path))
self.root.start_screen.display_label.add_widget(label)
list_keys = {i: key for key in self.data_output}
[self.data_output.store_delete(key) for i, key in list_keys.items()]
self.data_output._is_changed = True
self.data_output.store_sync()
def on_pause(self):
return True
if __name__ == '__main__':
ProjectZApp().run()