Barry Warsaw | 4638c5b | 1998-10-02 16:20:14 +0000 | [diff] [blame] | 1 | """Switchboard class. |
| 2 | |
| 3 | This class is used to coordinate updates among all Viewers. Every Viewer must |
| 4 | conform to the following interface: |
| 5 | |
| 6 | - it must include a method called update_yourself() which takes three |
| 7 | arguments; the red, green, and blue values of the selected color. |
| 8 | |
| 9 | - When a Viewer selects a color and wishes to update all other Views, it |
| 10 | should call update_views() on the Switchboard object. Not that the |
| 11 | Viewer typically does *not* update itself before calling update_views(), |
| 12 | since this would cause it to get updated twice. |
| 13 | """ |
| 14 | |
Barry Warsaw | 987fb92 | 1998-09-28 15:59:21 +0000 | [diff] [blame] | 15 | class Switchboard: |
Barry Warsaw | fda3ace | 1998-09-29 20:04:19 +0000 | [diff] [blame] | 16 | def __init__(self, colordb): |
Barry Warsaw | 987fb92 | 1998-09-28 15:59:21 +0000 | [diff] [blame] | 17 | self.__views = [] |
Barry Warsaw | fda3ace | 1998-09-29 20:04:19 +0000 | [diff] [blame] | 18 | self.__colordb = colordb |
Barry Warsaw | a7ba45b | 1998-10-01 16:46:43 +0000 | [diff] [blame] | 19 | self.__red = 0 |
| 20 | self.__green = 0 |
| 21 | self.__blue = 0 |
Barry Warsaw | 987fb92 | 1998-09-28 15:59:21 +0000 | [diff] [blame] | 22 | |
| 23 | def add_view(self, view): |
| 24 | self.__views.append(view) |
| 25 | |
Barry Warsaw | 1ac18cd | 1998-09-28 23:41:12 +0000 | [diff] [blame] | 26 | def update_views(self, red, green, blue): |
Barry Warsaw | a7ba45b | 1998-10-01 16:46:43 +0000 | [diff] [blame] | 27 | self.__red = red |
| 28 | self.__green = green |
| 29 | self.__blue = blue |
Barry Warsaw | 987fb92 | 1998-09-28 15:59:21 +0000 | [diff] [blame] | 30 | for v in self.__views: |
Barry Warsaw | 1ac18cd | 1998-09-28 23:41:12 +0000 | [diff] [blame] | 31 | v.update_yourself(red, green, blue) |
Barry Warsaw | fda3ace | 1998-09-29 20:04:19 +0000 | [diff] [blame] | 32 | |
Barry Warsaw | a7ba45b | 1998-10-01 16:46:43 +0000 | [diff] [blame] | 33 | def update_views_current(self): |
| 34 | self.update_views(self.__red, self.__green, self.__blue) |
| 35 | |
Barry Warsaw | cd09867 | 1998-10-05 21:14:12 +0000 | [diff] [blame^] | 36 | def current_rgb(self): |
| 37 | return self.__red, self.__green, self.__blue |
| 38 | |
Barry Warsaw | fda3ace | 1998-09-29 20:04:19 +0000 | [diff] [blame] | 39 | def colordb(self): |
| 40 | return self.__colordb |