Skip to content
Snippets Groups Projects
Commit 63c490d9 authored by shinedday's avatar shinedday
Browse files

Fix conflict

parents 92f55901 53a4235d
No related branches found
No related tags found
No related merge requests found
...@@ -18,13 +18,16 @@ class Controleur: ...@@ -18,13 +18,16 @@ class Controleur:
def __init__( def __init__(
self, self,
fenetre : 'Fenetre', fenetre : 'Fenetre',
amas : 'Amas' scheduler : 'SchedulerIHM'
) -> None : ) -> None :
self.__th = None self.__th = None
self.__fenetre = fenetre self.__fenetre = fenetre
self.__fenetre.attach(self) self.__fenetre.attach(self)
self.__amas = amas
self.__amas.attach(self) self.__scheduler = scheduler
self.__scheduler.attach(self)
self.__amas = scheduler.get_amas()
self.__is_run = False self.__is_run = False
def get_fenetre(self) -> 'Fenetre': def get_fenetre(self) -> 'Fenetre':
...@@ -33,6 +36,9 @@ class Controleur: ...@@ -33,6 +36,9 @@ class Controleur:
def get_amas(self) -> 'Amas': def get_amas(self) -> 'Amas':
return self.__amas return self.__amas
def get_scheduler(self) -> 'SchedulerIHM':
return self.__scheduler
""" """
Draw a rectangle with x,y coords, height, width and color Draw a rectangle with x,y coords, height, width and color
""" """
...@@ -124,6 +130,9 @@ class Controleur: ...@@ -124,6 +130,9 @@ class Controleur:
def addPlotChart(self, name : str) -> int: def addPlotChart(self, name : str) -> int:
return self.__fenetre.addPlotChart(name) return self.__fenetre.addPlotChart(name)
def addLimitedPlotChart(self, name : str, limit) -> int:
return self.__fenetre.addLimitedPlotChart(name, limit)
""" """
Set the drawing policy to the curve of the plot chart identified by idCurve and id Set the drawing policy to the curve of the plot chart identified by idCurve and id
""" """
...@@ -195,46 +204,49 @@ class Controleur: ...@@ -195,46 +204,49 @@ class Controleur:
""" """
def updateAdd(self) -> None: def updateAdd(self) -> None:
print("Ajout d'un agent") print("Ajout d'un agent")
self.__amas.add_agent('red')
""" """
Remove an agent from amas Remove an agent from amas
""" """
def updateRemove(self) -> None: def updateRemove(self) -> None:
print("Suppresion d'un agent") print("Suppresion d'un agent")
self.__amas.remove_agent()
""" """
Reset amas Reset amas
""" """
def updateReset(self) -> None: def updateReset(self) -> None:
self.__amas.reset()
print("Reset de la simulation") print("Reset de la simulation")
""" """
Set the execution speed of amas Set the execution speed of amas
""" """
def updateScale(self, value : int) -> None: def updateScale(self, value : int) -> None:
self.__amas.set_sleep(int(value)) self.__scheduler.set_sleep(int(value))
""" """
Start or Stop the execution depending on the current state Start or Stop the execution depending on the current state
""" """
def updateStartStop(self) -> None: def updateStartStop(self) -> None:
if(self.__is_run): if self.__is_run:
self.__is_run = False self.__is_run = False
self.__amas.take_token() self.__scheduler.stop()
else: else:
self.__is_run = True self.__is_run = True
self.__amas.put_token() self.__scheduler.start()
def updateCycle(self,env,amas) -> None: """
Save the current state
"""
def updateSave(self) -> None:
self.__scheduler.save()
def updateCycle(self) -> None:
try: try:
self.updateWindow(env,amas) self.updateWindow()
except: except:
return return
def updateWindow(env,amas): def updateWindow(self):
pass pass
def initialisation(self) -> None: def initialisation(self) -> None:
...@@ -245,12 +257,12 @@ class Controleur: ...@@ -245,12 +257,12 @@ class Controleur:
""" """
def start(self) -> None: def start(self) -> None:
self.initialisation() self.initialisation()
self.__th = Thread(target=self.__amas.start) self.__th = Thread(target=self.__scheduler.run)
self.__th.start() self.__th.start()
self.__fenetre.display() self.__fenetre.display()
def updateClosing(self): def updateClosing(self):
self.__amas.exit_program() self.__scheduler.exit_program()
""" """
...@@ -262,8 +274,3 @@ class Controleur: ...@@ -262,8 +274,3 @@ class Controleur:
def logsDisplay(self, message : str) -> None: def logsDisplay(self, message : str) -> None:
self.__fenetre.logsDisplay() self.__fenetre.logsDisplay()
...@@ -11,6 +11,7 @@ from pyAmakIHM.classes.panelCommandes import PanelCommandes ...@@ -11,6 +11,7 @@ from pyAmakIHM.classes.panelCommandes import PanelCommandes
from pyAmakIHM.classes.panelVue import PanelVue from pyAmakIHM.classes.panelVue import PanelVue
from pyAmakIHM.classes.panelBarChart import PanelBarChart from pyAmakIHM.classes.panelBarChart import PanelBarChart
from pyAmakIHM.classes.panelPlotChart import PanelPlotChart from pyAmakIHM.classes.panelPlotChart import PanelPlotChart
from pyAmakIHM.classes.panelLimitedPlotChart import PanelLimitedPlotChart
from tkinter import ttk, Tk from tkinter import ttk, Tk
...@@ -163,6 +164,15 @@ class Fenetre : ...@@ -163,6 +164,15 @@ class Fenetre :
self.__onglet.add(self.__panelGraphiques[length],text = name) self.__onglet.add(self.__panelGraphiques[length],text = name)
return (length) return (length)
def addLimitedPlotChart(self, name : str, limit) -> int:
length = len(self.__panelGraphiques)
self.__panelGraphiques.append(PanelLimitedPlotChart(self.__onglet,length, limit))
self.__panelGraphiques[length].attach(self)
self.__onglet.add(self.__panelGraphiques[length],text = name)
return (length)
""" """
Set the drawing policy to the curve of the plot chart identified by idCurve and id Set the drawing policy to the curve of the plot chart identified by idCurve and id
""" """
......
...@@ -24,6 +24,9 @@ class PanelCommandes(LabelFrame): ...@@ -24,6 +24,9 @@ class PanelCommandes(LabelFrame):
bouttonStartStop = Button(self, text='start/stop',height=2,command=self.notifyObserverAboutStartStop) bouttonStartStop = Button(self, text='start/stop',height=2,command=self.notifyObserverAboutStartStop)
bouttonStartStop.pack(side='top',fill='x') bouttonStartStop.pack(side='top',fill='x')
bouttonSaveState = Button(self, text='save state',height=2,command=self.notifyObserverAboutSave)
bouttonSaveState.pack(side='top',fill='x')
frameBoutons = Frame(self) frameBoutons = Frame(self)
frameBoutons.pack(side='bottom',fill='x') frameBoutons.pack(side='bottom',fill='x')
...@@ -55,6 +58,9 @@ class PanelCommandes(LabelFrame): ...@@ -55,6 +58,9 @@ class PanelCommandes(LabelFrame):
def notifyObserverAboutStartStop(self) -> None: def notifyObserverAboutStartStop(self) -> None:
self.__observer.updateStartStop() self.__observer.updateStartStop()
def notifyObserverAboutSave(self) -> None:
self.__observer.updateSave()
""" """
Notify the observer that the scale has change its value and give the current value Notify the observer that the scale has change its value and give the current value
""" """
......
"""
Class PanelLimitedPlotChart
"""
from pyAmakIHM.classes.panelPlotChart import PanelPlotChart
from tkinter import Toplevel
class PanelLimitedPlotChart(PanelPlotChart):
"""
Class PanelLimitedPlotChart
"""
def __init__(
self,
root : 'Tk',
id : int,
limit : int
) -> None :
super().__init__(root, id)
self.__limit = limit
self.__limited = False
"""
Add a point to the id curve with x,y coords
"""
def addPoint(self, id : int, x : int, y : int) -> None:
self._axis.clear()
self._xAxis[id].append(x)
self._yAxis[id].append(y)
if(self.__limited):
del self._xAxis[id][0]
del self._yAxis[id][0]
else:
self.__limited = self.isLimited(id)
self._rebuild()
"""
Return true if number of points is over the limit
"""
def isLimited(self,id : int) -> bool:
return len(self._xAxis[id]) > self.__limit
"""
Return a copy of the object
"""
def createCopy(self, name : str, id : int) -> 'PanelLimitedPlotChart':
window = Toplevel()
window.title(name)
self._copy = PanelLimitedPlotChart(window, id, self.__limit)
self._copy.pack(fill='both',expand='yes')
self._copyWidget()
self._copy._rebuild()
self._copy._copy = self
self._copy._observer = self._observer
window.protocol("WM_DELETE_WINDOW", self._copy.on_closing)
window.geometry("+900+0")
return self._copy
"""
Copy the object
"""
def _copyWidget(self) -> None:
super()._copyWidget()
self._copy.__limit = self.__limit
self._copy.__limited = self.__limited
...@@ -22,11 +22,11 @@ class PanelPlotChart(Frame): ...@@ -22,11 +22,11 @@ class PanelPlotChart(Frame):
self.__root = root self.__root = root
self.__fig = Figure() self.__fig = Figure()
self.__axis = self.__fig.add_subplot() self._axis = self.__fig.add_subplot()
self.__xAxis = [[]] self._xAxis = [[]]
self.__yAxis = [[]] self._yAxis = [[]]
self.__axis.plot(self.__xAxis,self.__yAxis) self._axis.plot(self._xAxis,self._yAxis)
self.__graphique = FigureCanvasTkAgg(self.__fig,master = self) self.__graphique = FigureCanvasTkAgg(self.__fig,master = self)
self.__graphique.get_tk_widget().pack(fill='both',expand='yes') self.__graphique.get_tk_widget().pack(fill='both',expand='yes')
...@@ -38,59 +38,59 @@ class PanelPlotChart(Frame): ...@@ -38,59 +38,59 @@ class PanelPlotChart(Frame):
self.__id = id self.__id = id
self.__copy = None self._copy = None
self.__observer = None self._observer = None
""" """
Attach a observer to the object Attach a observer to the object
""" """
def attach(self, obs : 'Fenetre') -> None: def attach(self, obs : 'Fenetre') -> None:
self.__observer = obs self._observer = obs
""" """
Notify the observer about an event Notify the observer about an event
""" """
def notify(self, panel : 'PanelBarChart', id : int) -> None: def notify(self, panel : 'PanelBarChart', id : int) -> None:
self.__observer.updateGraphique(panel,id) self._observer.updateGraphique(panel,id)
""" """
Set the drawing policy for the curve identified by idCurve Set the drawing policy for the curve identified by idCurve
""" """
def setPolicy(self, idCurve : int, policy : str) -> None: def setPolicy(self, idCurve : int, policy : str) -> None:
self.__axis.clear() self._axis.clear()
self.__policy[idCurve] = policy self.__policy[idCurve] = policy
self.__rebuild() self._rebuild()
""" """
Set the title to the chart Set the title to the chart
""" """
def setTitle(self, name : str) -> None: def setTitle(self, name : str) -> None:
self.__axis.clear() self._axis.clear()
self.__title = name self.__title = name
self.__rebuild() self._rebuild()
""" """
Set the label on the x axis to the chart Set the label on the x axis to the chart
""" """
def setXLabel(self, name : str) -> None: def setXLabel(self, name : str) -> None:
self.__axis.clear() self._axis.clear()
self.__XLabel = name self.__XLabel = name
self.__rebuild() self._rebuild()
""" """
Set the label on the y axis to the chart Set the label on the y axis to the chart
""" """
def setYLabel(self, name : str) -> None: def setYLabel(self, name : str) -> None:
self.__axis.clear() self._axis.clear()
self.__YLabel = name self.__YLabel = name
self.__rebuild() self._rebuild()
""" """
Add a curve to the plot with the given policy Add a curve to the plot with the given policy
""" """
def addCurve(self, policy : str) -> None: def addCurve(self, policy : str) -> None:
self.__xAxis.append([]) self._xAxis.append([])
self.__yAxis.append([]) self._yAxis.append([])
self.__policy.append(policy) self.__policy.append(policy)
...@@ -98,22 +98,22 @@ class PanelPlotChart(Frame): ...@@ -98,22 +98,22 @@ class PanelPlotChart(Frame):
Add a point to the id curve with x,y coords Add a point to the id curve with x,y coords
""" """
def addPoint(self, id : int, x : int, y : int): def addPoint(self, id : int, x : int, y : int):
self.__axis.clear() self._axis.clear()
self.__xAxis[id].append(x) self._xAxis[id].append(x)
self.__yAxis[id].append(y) self._yAxis[id].append(y)
self.__rebuild() self._rebuild()
""" """
Rebuild the figure after any modification Rebuild the figure after any modification
""" """
def __rebuild(self) -> None: def _rebuild(self) -> None:
for i in range (len(self.__xAxis)): for i in range (len(self._xAxis)):
self.__axis.plot(self.__xAxis[i],self.__yAxis[i],self.__policy[i]) self._axis.plot(self._xAxis[i],self._yAxis[i],self.__policy[i])
self.__axis.title.set_text(self.__title) self._axis.title.set_text(self.__title)
self.__axis.set_xlabel(self.__XLabel) self._axis.set_xlabel(self.__XLabel)
self.__axis.set_ylabel(self.__YLabel) self._axis.set_ylabel(self.__YLabel)
self.__graphique.draw() self.__graphique.draw()
""" """
...@@ -123,38 +123,38 @@ class PanelPlotChart(Frame): ...@@ -123,38 +123,38 @@ class PanelPlotChart(Frame):
window = Toplevel() window = Toplevel()
window.title(name) window.title(name)
self.__copy = PanelPlotChart(window, id) self._copy = PanelPlotChart(window, id)
self.__copy.pack(fill='both',expand='yes') self._copy.pack(fill='both',expand='yes')
self.__copyWidget() self._copyWidget()
self.__copy.__rebuild() self._copy._rebuild()
self.__copy.__copy = self self._copy._copy = self
self.__copy.__observer = self.__observer self._copy._observer = self._observer
window.protocol("WM_DELETE_WINDOW", self.__copy.on_closing) window.protocol("WM_DELETE_WINDOW", self._copy.on_closing)
window.geometry("+900+0") window.geometry("+900+0")
return self.__copy return self._copy
""" """
Copy the object Copy the object
""" """
def __copyWidget(self) -> None: def _copyWidget(self) -> None:
self.__copy.__id = self.__id self._copy.__id = self.__id
self.__copy.__policy = self.__policy self._copy.__policy = self.__policy
self.__copy.__xAxis = self.__xAxis self._copy._xAxis = self._xAxis
self.__copy.__yAxis = self.__yAxis self._copy._yAxis = self._yAxis
self.__copy.__title = self.__title self._copy.__title = self.__title
self.__copy.__XLabel = self.__XLabel self._copy.__XLabel = self.__XLabel
self.__copy.__YLabel = self.__YLabel self._copy.__YLabel = self.__YLabel
""" """
Send the original object to the main window when the window is closing Send the original object to the main window when the window is closing
""" """
def on_closing(self) -> None: def on_closing(self) -> None:
self.__copyWidget() self._copyWidget()
self.__copy.__rebuild() self._copy._rebuild()
self.__root.destroy() self.__root.destroy()
self.notify(self.__copy, self.__copy.__id) self.notify(self._copy, self._copy.__id)
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment