This repository has been archived on 2021-09-15. You can view files and clone it, but cannot push or open issues or pull requests.
L3GestionParking/src/c/Main.py

175 lines
6.4 KiB
Python
Raw Normal View History

2014-12-22 18:02:08 +00:00
import sys
2014-12-23 18:05:26 +00:00
2015-01-12 15:06:44 +00:00
from PyQt4 import QtGui
2014-12-23 18:05:26 +00:00
2015-01-12 15:49:41 +00:00
from src.c.Borne import Borne
2015-01-12 15:06:44 +00:00
from src.c.DetailsPlaces import DetailsPlaces
2014-12-22 18:02:08 +00:00
from src.c.log.log import Log
2014-12-26 22:09:49 +00:00
from src.c.log.log import lvl
from src.c.CreaParking import CreaParking
2015-02-04 13:20:39 +00:00
from src.m.Service import Service
2015-01-13 23:39:12 +00:00
from src.m.Parking import Parking
2015-02-04 13:20:39 +00:00
from src.m.Service import TypeService
from src.m.connexionBDD import connexionBDD
2014-12-26 22:09:49 +00:00
from src.v.MyQMainWindow import MyQMainWindow
2014-12-26 16:38:51 +00:00
from src.v.Ui_MainWindow import Ui_MainWindow
2014-12-23 18:05:26 +00:00
2014-12-22 18:02:08 +00:00
__author__ = 'sidya'
class Main:
def __init__(self):
2014-12-23 18:05:26 +00:00
# Init des logs
2015-01-12 15:06:44 +00:00
self.lvl = lvl() # Public : Acces au constante
2014-12-26 22:09:49 +00:00
self.__log = Log()
2014-12-22 18:02:08 +00:00
app = QtGui.QApplication(sys.argv)
2014-12-26 22:09:49 +00:00
self.__view = MyQMainWindow()
self.__ui = Ui_MainWindow()
self.__ui.setupUi(self.__view)
2014-12-22 18:02:08 +00:00
2015-01-12 15:06:44 +00:00
2015-01-12 15:49:41 +00:00
# connect
2014-12-26 22:09:49 +00:00
self.__ui.comboBox.currentIndexChanged['QString'].connect(self.selectParking)
self.__ui.btn_creer.clicked.connect(self.creerParking)
2015-01-12 15:06:44 +00:00
self.__ui.btn_supprimer.clicked.connect(self.rmParking)
self.__ui.btn_details.clicked.connect(self.detailsPlacesParking)
2015-02-04 13:20:39 +00:00
self.__ui.btn_borne.clicked.connect(self.afficherBornes)
self.__ui.actionNouveau_2.triggered.connect(self.nouveau)
self.__ui.actionSauvegarder.triggered.connect(self.sauver)
self.__ui.actionCharger.triggered.connect(self.charger)
self.__ui.actionQuitter.triggered.connect(self.quitter)
2015-01-12 15:06:44 +00:00
2014-12-26 22:09:49 +00:00
2014-12-26 16:38:51 +00:00
2014-12-22 18:02:08 +00:00
#Chargement activité
self.loadLastActivity()
2014-12-26 22:09:49 +00:00
self.showWindow()
2014-12-22 18:02:08 +00:00
sys.exit(app.exec_())
2014-12-23 18:05:26 +00:00
def activity(self, msg, lvl):
2014-12-26 22:09:49 +00:00
self.__log.printL(msg, lvl)
self.addItemActivite(self.activite.readlines()[-1])
2014-12-22 18:02:08 +00:00
def loadLastActivity(self):
try:
self.activite = open("log/activity.log", "r")
2014-12-23 18:05:26 +00:00
except IOError:
2014-12-22 18:02:08 +00:00
self.activite = open("log/activity.log", "w")
self.activite.close()
self.activite = open("log/activity.log", "r")
liste = self.activite.readlines()
for l in [l[:-1] for l in liste[-11:-1]]:
2014-12-26 22:09:49 +00:00
self.addItemActivite(l)
2014-12-23 21:18:11 +00:00
2014-12-26 16:38:51 +00:00
def addItemActivite(self, line):
2014-12-26 22:09:49 +00:00
self.__ui.listWidget.addItem(line)
2014-12-26 16:38:51 +00:00
2014-12-23 21:18:11 +00:00
def majListeParking(self):
2014-12-26 22:09:49 +00:00
self.__ui.comboBox.clear()
self.__ui.comboBox.addItem("Selectionner un parking")
2015-02-04 13:20:39 +00:00
for p in Parking.getAllActif():
2014-12-26 22:09:49 +00:00
self.__ui.comboBox.addItem(p.nom)
2014-12-26 16:38:51 +00:00
def selectParking(self):
2015-02-04 13:20:39 +00:00
#onglet detail parking
2014-12-26 22:09:49 +00:00
self.__ui.nom.clear()
self.__ui.placesParNiveau.clear()
self.__ui.placesDispo.clear()
self.__ui.placesSuperAbo.clear()
2015-01-12 15:06:44 +00:00
if self.__ui.comboBox.count() > 1:
2015-02-04 13:20:39 +00:00
p = Parking.getAllActif()
2015-01-13 23:39:12 +00:00
self.__ui.nom.setText(p[self.__ui.comboBox.currentIndex() - 1].nom)
self.__ui.placesParNiveau.setText(str(p[self.__ui.comboBox.currentIndex() - 1].nbPlaces))
2015-01-12 15:06:44 +00:00
self.__ui.placesDispo.setText(
2015-01-13 23:39:12 +00:00
str(p[self.__ui.comboBox.currentIndex() - 1].nbPlacesLibresParking))
self.__ui.placesSuperAbo.setText(str(p[self.__ui.comboBox.currentIndex() - 1].nbSuperAbo))
2015-02-04 13:20:39 +00:00
self.__ui.btn_details.setDisabled(False)
self.__ui.btn_supprimer.setDisabled(False)
self.__ui.btn_borne.setDisabled(False)
else:
self.__ui.btn_details.setDisabled(True)
self.__ui.btn_supprimer.setDisabled(True)
self.__ui.btn_borne.setDisabled(True)
#onglet Service
for s in Service.serviceEnCours:
if s.typeService == TypeService.LIVRAISON :
self.__ui.comboBox_livraison.addItem(str(s.id))
if s.typeService == TypeService.ENTRETIEN :
self.__ui.comboBox_entretien.addItem(str(s.id))
if s.typeService == TypeService.MAINTENANCE :
self.__ui.comboBox_maintenance.addItem(str(s.id))
#Onglet Stats
2014-12-26 16:38:51 +00:00
def creerParking(self):
2014-12-26 22:09:49 +00:00
self.__view.hide()
self.__widgetCourant = CreaParking(self)
2015-01-12 15:06:44 +00:00
def rmParking(self):
if self.__ui.comboBox.currentIndex() != 0:
result = QtGui.QMessageBox.question(self.__view,
"Confirmer Supression...",
"Etes vous sur de vouloir supprimer ?\n"
"(La suppression sera définitive)",
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
if result == QtGui.QMessageBox.Yes:
2015-02-04 13:20:39 +00:00
Parking.remove(Parking.parkings[self.__ui.comboBox.currentIndex() - 1])
2015-01-12 15:06:44 +00:00
self.__view.hide()
self.showWindow()
def detailsPlacesParking(self):
2015-02-04 13:20:39 +00:00
if self.__ui.comboBox.currentIndex() != 0 :
2015-01-12 15:06:44 +00:00
self.__view.hide()
2015-02-04 13:20:39 +00:00
self.__widgetCourant = DetailsPlaces(self, Parking.getAllActif()[self.__ui.comboBox.currentIndex() - 1])
2015-01-12 15:06:44 +00:00
2015-02-04 13:20:39 +00:00
def afficherBornes(self):
2015-01-12 15:06:44 +00:00
if self.__ui.comboBox.currentIndex() != 0:
self.__view.hide()
2015-02-04 13:20:39 +00:00
Borne.bornes.append(Borne(self, Parking.getAllActif()[self.__ui.comboBox.currentIndex() - 1]))
Borne.bornes.append(Borne(self, Parking.getAllActif()[self.__ui.comboBox.currentIndex() - 1]))
def nouveau(self):
result = QtGui.QMessageBox.question(self.__view,
"Confirmer Nouveau...",
"Etes vous sur de vouloir supprimer ?\n"
"(Toutes données non sauvegardées seront perdues)",
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
if result == QtGui.QMessageBox.Yes:
c = connexionBDD()
c.initialisationBDD()
c.seDeconnecter()
Parking.removeAllRam()
self.majListeParking()
def charger(self):
path = QtGui.QFileDialog.getOpenFileName(self.__view,"Charger",".")
if path:
connexionBDD.charger(path)
self.majListeParking()
def sauver(self):
path = QtGui.QFileDialog.getSaveFileName(self.__view,"Sauvegarder",".")
if path:
connexionBDD.sauver(path)
self.majListeParking()
2015-01-12 15:06:44 +00:00
2015-02-04 13:20:39 +00:00
def quitter(self):
self.__view.close()
2015-01-12 15:06:44 +00:00
2014-12-26 22:09:49 +00:00
def showWindow(self):
self.majListeParking()
self.__view.show()
2015-01-12 15:06:44 +00:00
self.__widgetCourant = None # supprime eventuel widget
2015-02-04 13:20:39 +00:00
Borne.bornes = []
2015-01-12 15:06:44 +00:00
self.__view.focusWidget() # reprend le focus sur la fenetre principal