diff --git a/pyAmakIHM/classes/amas.py b/pyAmakIHM/classes/amas.py deleted file mode 100644 index 619cba025422f45455f3a9192306fa43aeb11f4d..0000000000000000000000000000000000000000 --- a/pyAmakIHM/classes/amas.py +++ /dev/null @@ -1,31 +0,0 @@ -from time import sleep -class Amas: - def __init__(self): - self.agents = [] - self.sleep = 1 - self.__observer = None - - def attach(self,observer): - self.__observer = observer - - def notifyObserver(self,value): - self.__observer.updateCycle(value) - - def add_agent(self,name): - self.agents.append(name) - - def remove_agent(self): - del self.agents[len(self.agents)-1] - - def reset(self): - self.agents = [] - - def set_speed(self,value): - self.sleep = value - - def cycle(self): - while (True): - for i in range (len(self.agents)): - print('Je suis le numéro %d' % i) - sleep(10 / self.sleep) - self.notifyObserver(self.sleep) diff --git a/pyAmakIHM/classes/controleur.py b/pyAmakIHM/classes/controleur.py index d91537b93a1b761401fdf0068a524cc7fc3f63be..eef2dcf07db5c20a0950721331607b406716834f 100644 --- a/pyAmakIHM/classes/controleur.py +++ b/pyAmakIHM/classes/controleur.py @@ -57,6 +57,12 @@ class Controleur: def draw_image(self, x : float, y : float, name : str) -> int: return self.__fenetre.draw_image(x, y, name) + """ + Draw a text with x,y coords + """ + def draw_text(self, x : float, y : float, text : str) -> int: + return self.__fenetre.draw_text(x,y,text) + """ Move an image to x,y coords """ @@ -106,18 +112,54 @@ class Controleur: def addBarChart(self, name : str) -> int: return self.__fenetre.addBarChart(name) + """ + Set the color to the bar chart identified by id + """ def setColor(self, id : int, color : str) -> None: self.__fenetre.setColor(id, color) + """ + Add a plot chart to the window + """ + def addPlotChart(self, name : str) -> int: + return self.__fenetre.addPlotChart(name) + + """ + Set the drawing policy to the curve of the plot chart identified by idCurve and id + """ + def setPolicy(self, id : int, idCurve : int, policy : str) -> None: + self.__fenetre.setPolicy(id, idCurve, policy) + + """ + Set the title to the chart identified by id + """ def setTitle(self, id : int, name : str) -> None: self.__fenetre.setTitle(id, name) + """ + Set the label on the x axis to the chart identified by id + """ def setXLabel(self, id : int, name : str) -> None: self.__fenetre.setXLabel(id, name) + """ + Set the label on the y axis to the chart identified by id + """ def setYLabel(self, id : int, name : str) -> None: self.__fenetre.setYLabel(id, name) + """ + Add a curve to the plot with the given policy + """ + def addCurve(self, id : int, policy : str) -> None: + self.__fenetre.addCurve(id,policy) + + """ + Add a point to the plot with x,y coords + """ + def addPoint(self, id : int, id_curve : int, x : float, y : float) -> None: + self.__fenetre.addPoint(id,id_curve,x,y) + """ Add a column at the end of the figure """ @@ -166,7 +208,6 @@ class Controleur: Reset amas """ def updateReset(self) -> None: - #self.remove_all() self.__amas.reset() print("Reset de la simulation") @@ -196,11 +237,14 @@ class Controleur: def updateWindow(env,amas): pass - def initialisation(self): + def __initialisation(self) -> None: pass - def start(self): - self.initialisation() + """ + Launch the amas in a thread and display the window + """ + def start(self) -> None: + self.__initialisation() self.__th = Thread(target=self.__amas.start) self.__th.start() self.__fenetre.display() diff --git a/pyAmakIHM/classes/fenetre.py b/pyAmakIHM/classes/fenetre.py index 644906860aff2ac6f8a451dec65e22a8a172cc4a..076b177a2314d0aa996944c92aefcda1a280ae2d 100644 --- a/pyAmakIHM/classes/fenetre.py +++ b/pyAmakIHM/classes/fenetre.py @@ -9,7 +9,8 @@ sys.path.insert(0, str(pathlib.Path(__file__).parent)) from pyAmakIHM.classes.panelCommandes import PanelCommandes from pyAmakIHM.classes.panelVue import PanelVue -from pyAmakIHM.classes.panelGraphique import PanelGraphique +from pyAmakIHM.classes.panelBarChart import PanelBarChart +from pyAmakIHM.classes.panelPlotChart import PanelPlotChart from tkinter import ttk, Tk @@ -86,6 +87,12 @@ class Fenetre : def draw_image(self, x : float, y : float, name : str) -> int: return self.__panelVue.draw_image(x,y,name) + """ + Draw a text with x,y coords + """ + def draw_text(self, x : float, y : float, text : str) -> int: + return self.__panelVue.draw_text(x,y,text) + """ Move an image to x,y coords """ @@ -133,24 +140,65 @@ class Fenetre : """ def addBarChart(self, name : str) -> int: length = len(self.__panelGraphiques) - self.__panelGraphiques.append(PanelGraphique(self.__onglet,length)) + self.__panelGraphiques.append(PanelBarChart(self.__onglet,length)) self.__panelGraphiques[length].attach(self) self.__onglet.add(self.__panelGraphiques[length],text = name) return (length) + """ + Set the color to the bar chart identified by id + """ def setColor(self, id : int, color : str) -> None: self.__panelGraphiques[id].setColor(color) + """ + Add a plot chart to the window + """ + def addPlotChart(self, name : str) -> int: + length = len(self.__panelGraphiques) + self.__panelGraphiques.append(PanelPlotChart(self.__onglet,length)) + + 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 + """ + def setPolicy(self, id : int, idCurve, policy : str) -> None: + self.__panelGraphiques[id].setPolicy(idCurve,policy) + + """ + Set the title to the chart identified by id + """ def setTitle(self, id : int, name : str) -> None: self.__panelGraphiques[id].setTitle(name) + """ + Set the label on the x axis to the chart identified by id + """ def setXLabel(self, id : int, name : str) -> None: self.__panelGraphiques[id].setXLabel(name) + """ + Set the label on the y axis to the chart identified by id + """ def setYLabel(self, id : int, name : str) -> None: self.__panelGraphiques[id].setYLabel(name) + """ + Add a curve to the plot + """ + def addCurve(self, id : int, policy : str) -> None: + self.__panelGraphiques[id].addCurve(policy) + + """ + Add a point to the plot with x,y coords + """ + def addPoint(self, id : int, id_curve : int, x : float, y : float) -> None: + self.__panelGraphiques[id].addPoint(id_curve,x,y) + """ Add a column at the end of the figure """ @@ -190,7 +238,7 @@ class Fenetre : """ Bind the mouse's button release when a tab is dragged """ - def is_drag(self, event : 'event'): + def is_drag(self, event : 'event') -> None: self.__root.config(cursor="fleur") self.__onglet.bind('<ButtonRelease>',self.tab_drop) @@ -216,7 +264,10 @@ class Fenetre : self.__panelGraphiques[id] = panel self.__onglet.add(self.__panelGraphiques[id]) - def on_closing(self): + """ + Notify the controleur to stop the app and close the window + """ + def on_closing(self) -> None: self.__observer.updateClosing() for pan in self.__panelGraphiques: pan.quit() diff --git a/pyAmakIHM/classes/panelGraphique.py b/pyAmakIHM/classes/panelBarChart.py similarity index 86% rename from pyAmakIHM/classes/panelGraphique.py rename to pyAmakIHM/classes/panelBarChart.py index 05249a63b864c1c1f1d19134274b06c0b93b3d05..fbe6e8bb1247df07d71aa7b22a7f58f440718af8 100644 --- a/pyAmakIHM/classes/panelGraphique.py +++ b/pyAmakIHM/classes/panelBarChart.py @@ -1,14 +1,14 @@ """ -Class PanelGraphique +Class PanelBarChart """ from tkinter import Frame, Toplevel from matplotlib.figure import Figure from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg -class PanelGraphique(Frame): +class PanelBarChart(Frame): """ - Class PanelGraphique + Class PanelBarChart """ def __init__( @@ -25,6 +25,7 @@ class PanelGraphique(Frame): self.__axis = self.__fig.add_subplot() self.__xAxis = [] self.__yAxis = [] + self.__axis.bar(self.__xAxis,self.__yAxis) self.__graphique = FigureCanvasTkAgg(self.__fig,master = self) @@ -49,24 +50,36 @@ class PanelGraphique(Frame): """ Notify the observer about an event """ - def notify(self, panel : 'PanelGraphique', id : int) -> None: + def notify(self, panel : 'PanelBarChart', id : int) -> None: self.__observer.updateGraphique(panel,id) + """ + Set the color to the bar chart + """ def setColor(self, color : str) -> None: self.__axis.clear() self.__color = color self.__rebuild() + """ + Set the title to the chart + """ def setTitle(self, name : str) -> None: self.__axis.clear() self.__title = name self.__rebuild() + """ + Set the label on the x axis to the chart + """ def setXLabel(self, name : str) -> None: self.__axis.clear() self.__XLabel = name self.__rebuild() + """ + Set the label on the y axis to the chart + """ def setYLabel(self, name : str) -> None: self.__axis.clear() self.__YLabel = name @@ -127,11 +140,11 @@ class PanelGraphique(Frame): """ Return a copy of the object """ - def createCopy(self, name : str, id : int): + def createCopy(self, name : str, id : int) -> 'PanelBarChart': window = Toplevel() window.title(name) - self.__copy = PanelGraphique(window, id) + self.__copy = PanelBarChart(window, id) self.__copy.pack(fill='both',expand='yes') self.__copyWidget() @@ -149,7 +162,7 @@ class PanelGraphique(Frame): """ Copy the object """ - def __copyWidget(self): + def __copyWidget(self) -> None: self.__copy.__id = self.__id self.__copy.__xAxis = self.__xAxis self.__copy.__yAxis = self.__yAxis @@ -158,9 +171,9 @@ class PanelGraphique(Frame): self.__copy.__YLabel = self.__YLabel """ - Send the original object when the window is closing + Send the original object to the main window when the window is closing """ - def on_closing(self): + def on_closing(self) -> None: self.__copyWidget() self.__copy.__rebuild() self.__root.destroy() diff --git a/pyAmakIHM/classes/panelCommandes.py b/pyAmakIHM/classes/panelCommandes.py index 595b315b1ff3ed7bfee49f12cc8c0a8ab87532fa..60c0ade2dea6b8ed0be7f47872247faf547c0ec1 100644 --- a/pyAmakIHM/classes/panelCommandes.py +++ b/pyAmakIHM/classes/panelCommandes.py @@ -28,6 +28,7 @@ class PanelCommandes(LabelFrame): frameBoutons.pack(side='bottom',fill='x') slider = Scale(frameBoutons,orient='horizontal',from_=1,to=10,command=self.notifyObserverAboutScale) + slider.set(10) slider.pack(side='bottom',fill='x') bouttonPlus = Button(frameBoutons,text='+',command=self.plus) diff --git a/pyAmakIHM/classes/panelPlotChart.py b/pyAmakIHM/classes/panelPlotChart.py new file mode 100644 index 0000000000000000000000000000000000000000..3a5e72b36b1e42e2ebba9d4b6135ce881a6469d0 --- /dev/null +++ b/pyAmakIHM/classes/panelPlotChart.py @@ -0,0 +1,160 @@ +""" +Class PanelPlotChart +""" + +from tkinter import Frame, Toplevel +from matplotlib.figure import Figure +from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg + +class PanelPlotChart(Frame): + """ + Class PanelPlotChart + """ + + def __init__( + self, + root : 'Tk', + id : int + ) -> None : + + super().__init__(root) + + self.__root = root + self.__fig = Figure() + + self.__axis = self.__fig.add_subplot() + 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') + + self.__title = '' + self.__XLabel = '' + self.__YLabel = '' + self.__policy = ['bo-'] + + self.__id = id + + self.__copy = None + self.__observer = None + + """ + Attach a observer to the object + """ + def attach(self, obs : 'Fenetre') -> None: + self.__observer = obs + + """ + Notify the observer about an event + """ + def notify(self, panel : 'PanelBarChart', id : int) -> None: + 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.__policy[idCurve] = policy + self.__rebuild() + + """ + Set the title to the chart + """ + def setTitle(self, name : str) -> None: + self.__axis.clear() + self.__title = name + self.__rebuild() + + """ + Set the label on the x axis to the chart + """ + def setXLabel(self, name : str) -> None: + self.__axis.clear() + self.__XLabel = name + self.__rebuild() + + """ + Set the label on the y axis to the chart + """ + def setYLabel(self, name : str) -> None: + self.__axis.clear() + self.__YLabel = name + 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.__policy.append(policy) + + + """ + 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.__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]) + + self.__axis.title.set_text(self.__title) + self.__axis.set_xlabel(self.__XLabel) + self.__axis.set_ylabel(self.__YLabel) + self.__graphique.draw() + + """ + Return a copy of the object + """ + def createCopy(self, name : str, id : int) -> 'PanelPlotChart': + window = Toplevel() + window.title(name) + + self.__copy = PanelPlotChart(window, id) + 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: + 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.__root.destroy() + self.notify(self.__copy, self.__copy.__id) diff --git a/pyAmakIHM/classes/panelVue.py b/pyAmakIHM/classes/panelVue.py index 5d8998fe105b4df69de428dc6bb490b859e28cde..334f87212c528e5211d0ff24be592e42f242cbd8 100644 --- a/pyAmakIHM/classes/panelVue.py +++ b/pyAmakIHM/classes/panelVue.py @@ -92,6 +92,12 @@ class PanelVue(Canvas): return self.create_image(x,y,image=new_image) + """ + Draw a text with x,y coords + """ + def draw_text(self, x : float, y : float, text : str) -> int: + return self.create_text(x,y,anchor="w",fill='black',text=text) + """ Move an element to x,y coords """