Last change
on this file since 6b43c58 was
83eb5208,
checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago
|
Putting files in more ordered fashion
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[8cb6cd6] | 1 | """ |
---|
| 2 | `Singleton` plot helper module |
---|
| 3 | All its variables are bound to the module, |
---|
| 4 | which can not be instantiated repeatedly so IDs are session-specific. |
---|
| 5 | """ |
---|
| 6 | import sys |
---|
| 7 | |
---|
| 8 | this = sys.modules[__name__] |
---|
| 9 | |
---|
| 10 | this._plots = {} |
---|
| 11 | this._plot_id = 0 |
---|
| 12 | |
---|
| 13 | def clear(): |
---|
| 14 | """ |
---|
| 15 | Reset the plot dictionary |
---|
| 16 | """ |
---|
| 17 | this._plots = {} |
---|
| 18 | |
---|
| 19 | def addPlot(plot): |
---|
| 20 | """ |
---|
| 21 | Adds a new plot to the current dictionary of plots |
---|
| 22 | """ |
---|
| 23 | this._plot_id += 1 |
---|
[0268aed] | 24 | this._plots["Graph%s"%str(this._plot_id)] = plot |
---|
[8cb6cd6] | 25 | |
---|
| 26 | def deletePlot(plot_id): |
---|
| 27 | """ |
---|
| 28 | Deletes an existing plot from the dictionary |
---|
| 29 | """ |
---|
[ef01be4] | 30 | if plot_id in this._plots: |
---|
| 31 | del this._plots[plot_id] |
---|
[8cb6cd6] | 32 | |
---|
| 33 | def currentPlots(): |
---|
| 34 | """ |
---|
| 35 | Returns a list of IDs for all currently active plots |
---|
| 36 | """ |
---|
| 37 | return this._plots.keys() |
---|
| 38 | |
---|
| 39 | def plotById(plot_id): |
---|
| 40 | """ |
---|
| 41 | Returns the plot referenced by the ID |
---|
| 42 | """ |
---|
[ef01be4] | 43 | return this._plots[plot_id] if plot_id in this._plots else None |
---|
[8cb6cd6] | 44 | |
---|
| 45 | def idOfPlot(plot): |
---|
| 46 | """ |
---|
| 47 | Returns the ID of the plot |
---|
| 48 | """ |
---|
| 49 | plot_id = None |
---|
| 50 | for key in this._plots.keys(): |
---|
| 51 | if this._plots[key] == plot: |
---|
| 52 | plot_id = key |
---|
| 53 | break |
---|
| 54 | |
---|
| 55 | return plot_id |
---|
Note: See
TracBrowser
for help on using the repository browser.