-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCours.py
More file actions
89 lines (72 loc) · 2.21 KB
/
Cours.py
File metadata and controls
89 lines (72 loc) · 2.21 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/python
# -*- coding: utf-8 -*-
from os import getcwd, listdir, path
from PyQt4.QtCore import SIGNAL
from Recognizer import *
from State import State
class Cours():
# Constructeur
def __init__(self):
self.cours={}
self.charger()
def charger(self):
curr=getcwd()
for x in listdir(curr+"/cours"):
if path.isfile(path.join(curr+"/cours", x)):
pass
else :
self.create(x)
for y in listdir(curr+"/cours/"+x):
if path.isfile(path.join(curr+"/cours/"+x, y)):
y=y[:y.find(".")]
self.load(x,y)
def create(self,x):
self.cours[x]={}
def load(self,x,y):
try:
a=open("cours/"+x+"/"+y+".txt")
z=a.readlines()
a.close()
#verification fichier
nb=0
for xi in z:
for yi in xi:
if yi==":":nb+=1
if nb<4:
print nb,y
raise "Pas assez de questions : mauvais fichier"
#end
self.cours[x][y]={}
for codec in ["utf-8","ISO-8859-15","utf-16",""]:
try:
for j in z:
j=j.strip().decode(codec)
u=j.split(":")[1]
v=j.split(":")[0]
self.cours[x][y][u]=v
break
except:
pass
return True
except:
print "invalid file : "+x+"/"+y+"\n"
return False
###############
## GETTERS
###############
def getKeyfromInt(self,nb):
i=self.cours.keys();
i.sort()
return i[nb]
def getListfromKey(self,key):
return self.cours[key].keys()
def getChapter(self,x,y):
return self.cours[x][y]
def QCours(mw):
mw.connect(mw.pushButtonBack4, SIGNAL("released()"), mw.retourCours)
mw.connect(mw.lineEditCours, SIGNAL("returnPressed()"), mw.checkCours)
mw.connect(mw.lineEditCours, SIGNAL("textEdited (const QString&)"), mw.clearValidite)
mw.connect(mw.pushButtonCpa3, SIGNAL("released()"), mw.saisPas)
mw.connect(mw.pushButtonValideCours, SIGNAL("released()"), mw.checkCours)
def inTrue(mot,corr):
return Recognizer().isInList(mot,corr)