Skip to content
Snippets Groups Projects
Commit 6023079f authored by Jdrezen's avatar Jdrezen
Browse files

Modification de la portée des attributs de plotChart pour les utiliser dans la classe fille

parent 8d9b44c8
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ Class PanelLimitedPlotChart
"""
from pyAmakIHM.classes.panelPlotChart import PanelPlotChart
from tkinter import Toplevel
class PanelLimitedPlotChart(PanelPlotChart):
"""
......@@ -21,18 +22,42 @@ class PanelLimitedPlotChart(PanelPlotChart):
self.__limited = False
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)
if(self.__limited):
del self.__xAxis[0]
del self.__yAxis[0]
del self._xAxis[id][0]
del self._yAxis[id][0]
else:
self.__limited = self.isLimited()
self.__limited = self.isLimited(id)
self.__rebuild()
self._rebuild()
def isLimited(self):
return len(self.__xAxis) > self.__limit
def isLimited(self,id):
return len(self._xAxis[id]) > self.__limit
def createCopy(self, name : str, id : int) -> 'PanelPlotChart':
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
def _copyWidget(self):
super()._copyWidget()
self._copy.__limit = self.__limit
self._copy.__limited = self.__limited
......@@ -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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment