diff --git a/pyAmakIHM/classes/controleur.py b/pyAmakIHM/classes/controleur.py index 942d483423d2790d1b2ffeb0d245a9850bf32285..c940eddc8c2b5bca476da71672342a5e169ee0f8 100644 --- a/pyAmakIHM/classes/controleur.py +++ b/pyAmakIHM/classes/controleur.py @@ -18,13 +18,16 @@ class Controleur: def __init__( self, fenetre : 'Fenetre', - amas : 'Amas' + scheduler : 'SchedulerIHM' ) -> None : self.__th = None self.__fenetre = fenetre 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 def get_fenetre(self) -> 'Fenetre': @@ -33,6 +36,9 @@ class Controleur: def get_amas(self) -> 'Amas': return self.__amas + def get_scheduler(self) -> 'SchedulerIHM': + return self.__scheduler + """ Draw a rectangle with x,y coords, height, width and color """ @@ -124,6 +130,9 @@ class Controleur: def addPlotChart(self, name : str) -> int: 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 """ @@ -195,46 +204,49 @@ class Controleur: """ def updateAdd(self) -> None: print("Ajout d'un agent") - self.__amas.add_agent('red') """ Remove an agent from amas """ def updateRemove(self) -> None: print("Suppresion d'un agent") - self.__amas.remove_agent() """ Reset amas """ def updateReset(self) -> None: - self.__amas.reset() print("Reset de la simulation") """ Set the execution speed of amas """ 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 """ def updateStartStop(self) -> None: - if(self.__is_run): + if self.__is_run: self.__is_run = False - self.__amas.take_token() + self.__scheduler.stop() else: 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: - self.updateWindow(env,amas) + self.updateWindow() except: return - def updateWindow(env,amas): + def updateWindow(self): pass def initialisation(self) -> None: @@ -245,12 +257,12 @@ class Controleur: """ def start(self) -> None: self.initialisation() - self.__th = Thread(target=self.__amas.start) + self.__th = Thread(target=self.__scheduler.run) self.__th.start() self.__fenetre.display() def updateClosing(self): - self.__amas.exit_program() + self.__scheduler.exit_program() """ @@ -262,8 +274,3 @@ class Controleur: def logsDisplay(self, message : str) -> None: self.__fenetre.logsDisplay() - - - - - diff --git a/pyAmakIHM/classes/fenetre.py b/pyAmakIHM/classes/fenetre.py index b47dc3ba6519e1bb1eef6259957898a007b35963..504a4eefc15899e8b638784a5dedb83d57de774e 100644 --- a/pyAmakIHM/classes/fenetre.py +++ b/pyAmakIHM/classes/fenetre.py @@ -11,6 +11,7 @@ from pyAmakIHM.classes.panelCommandes import PanelCommandes from pyAmakIHM.classes.panelVue import PanelVue from pyAmakIHM.classes.panelBarChart import PanelBarChart from pyAmakIHM.classes.panelPlotChart import PanelPlotChart +from pyAmakIHM.classes.panelLimitedPlotChart import PanelLimitedPlotChart from tkinter import ttk, Tk @@ -163,6 +164,15 @@ class Fenetre : self.__onglet.add(self.__panelGraphiques[length],text = name) 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 """ diff --git a/pyAmakIHM/classes/panelCommandes.py b/pyAmakIHM/classes/panelCommandes.py index b0c775f6521b75c337b549012a72fd8b367fa5d9..81a1a72cca24b79613f0acb839aeb7cc38993f3f 100644 --- a/pyAmakIHM/classes/panelCommandes.py +++ b/pyAmakIHM/classes/panelCommandes.py @@ -24,6 +24,9 @@ class PanelCommandes(LabelFrame): bouttonStartStop = Button(self, text='start/stop',height=2,command=self.notifyObserverAboutStartStop) 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.pack(side='bottom',fill='x') @@ -55,6 +58,9 @@ class PanelCommandes(LabelFrame): def notifyObserverAboutStartStop(self) -> None: 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 """ diff --git a/pyAmakIHM/classes/panelLimitedPlotChart.py b/pyAmakIHM/classes/panelLimitedPlotChart.py new file mode 100644 index 0000000000000000000000000000000000000000..99e28ab5c18a27c667456ea873a5d965fdc75095 --- /dev/null +++ b/pyAmakIHM/classes/panelLimitedPlotChart.py @@ -0,0 +1,75 @@ +""" +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 diff --git a/pyAmakIHM/classes/panelPlotChart.py b/pyAmakIHM/classes/panelPlotChart.py index 3a5e72b36b1e42e2ebba9d4b6135ce881a6469d0..c97fc3ce491b156254a16c1c06e527c8e6a6d0c8 100644 --- a/pyAmakIHM/classes/panelPlotChart.py +++ b/pyAmakIHM/classes/panelPlotChart.py @@ -22,11 +22,11 @@ class PanelPlotChart(Frame): self.__root = root self.__fig = Figure() - self.__axis = self.__fig.add_subplot() - self.__xAxis = [[]] - self.__yAxis = [[]] + self._axis = self.__fig.add_subplot() + self._xAxis = [[]] + 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.get_tk_widget().pack(fill='both',expand='yes') @@ -38,59 +38,59 @@ class PanelPlotChart(Frame): self.__id = id - self.__copy = None - self.__observer = None + self._copy = None + self._observer = None """ Attach a observer to the object """ def attach(self, obs : 'Fenetre') -> None: - self.__observer = obs + self._observer = obs """ Notify the observer about an event """ 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 """ def setPolicy(self, idCurve : int, policy : str) -> None: - self.__axis.clear() + self._axis.clear() self.__policy[idCurve] = policy - self.__rebuild() + self._rebuild() """ Set the title to the chart """ def setTitle(self, name : str) -> None: - self.__axis.clear() + self._axis.clear() self.__title = name - self.__rebuild() + self._rebuild() """ Set the label on the x axis to the chart """ def setXLabel(self, name : str) -> None: - self.__axis.clear() + self._axis.clear() self.__XLabel = name - self.__rebuild() + self._rebuild() """ Set the label on the y axis to the chart """ def setYLabel(self, name : str) -> None: - self.__axis.clear() + self._axis.clear() self.__YLabel = name - self.__rebuild() + self._rebuild() """ Add a curve to the plot with the given policy """ def addCurve(self, policy : str) -> None: - self.__xAxis.append([]) - self.__yAxis.append([]) + self._xAxis.append([]) + self._yAxis.append([]) self.__policy.append(policy) @@ -98,22 +98,22 @@ class PanelPlotChart(Frame): Add a point to the id curve with x,y coords """ def addPoint(self, id : int, x : int, y : int): - self.__axis.clear() - self.__xAxis[id].append(x) - self.__yAxis[id].append(y) + self._axis.clear() + self._xAxis[id].append(x) + self._yAxis[id].append(y) - self.__rebuild() + self._rebuild() """ Rebuild the figure after any modification """ - def __rebuild(self) -> None: - for i in range (len(self.__xAxis)): - self.__axis.plot(self.__xAxis[i],self.__yAxis[i],self.__policy[i]) + def _rebuild(self) -> None: + for i in range (len(self._xAxis)): + self._axis.plot(self._xAxis[i],self._yAxis[i],self.__policy[i]) - self.__axis.title.set_text(self.__title) - self.__axis.set_xlabel(self.__XLabel) - self.__axis.set_ylabel(self.__YLabel) + self._axis.title.set_text(self.__title) + self._axis.set_xlabel(self.__XLabel) + self._axis.set_ylabel(self.__YLabel) self.__graphique.draw() """ @@ -123,38 +123,38 @@ class PanelPlotChart(Frame): window = Toplevel() window.title(name) - self.__copy = PanelPlotChart(window, id) - self.__copy.pack(fill='both',expand='yes') + self._copy = PanelPlotChart(window, id) + self._copy.pack(fill='both',expand='yes') - self.__copyWidget() + self._copyWidget() - self.__copy.__rebuild() + self._copy._rebuild() - self.__copy.__copy = self - self.__copy.__observer = self.__observer + self._copy._copy = self + 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") - return self.__copy + return self._copy """ Copy the object """ - def __copyWidget(self) -> None: - self.__copy.__id = self.__id - self.__copy.__policy = self.__policy - self.__copy.__xAxis = self.__xAxis - self.__copy.__yAxis = self.__yAxis - self.__copy.__title = self.__title - self.__copy.__XLabel = self.__XLabel - self.__copy.__YLabel = self.__YLabel + def _copyWidget(self) -> None: + self._copy.__id = self.__id + self._copy.__policy = self.__policy + self._copy._xAxis = self._xAxis + self._copy._yAxis = self._yAxis + self._copy.__title = self.__title + self._copy.__XLabel = self.__XLabel + self._copy.__YLabel = self.__YLabel """ Send the original object to the main window when the window is closing """ def on_closing(self) -> None: - self.__copyWidget() - self.__copy.__rebuild() + self._copyWidget() + self._copy._rebuild() self.__root.destroy() - self.notify(self.__copy, self.__copy.__id) + self.notify(self._copy, self._copy.__id) diff --git a/release/pyAmakIHM-0.0.1-py3-none-any.whl b/release/pyAmakIHM-0.0.1-py3-none-any.whl new file mode 100644 index 0000000000000000000000000000000000000000..1d052d2e270322ed8ab972cd0a7155f7c7ed0578 Binary files /dev/null and b/release/pyAmakIHM-0.0.1-py3-none-any.whl differ