blob: 503752e2dfee5535d152e365e118816b2072a074 [file] [log] [blame]
Barry Warsaw4638c5b1998-10-02 16:20:14 +00001"""Switchboard class.
2
3This class is used to coordinate updates among all Viewers. Every Viewer must
4conform 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 Warsaw987fb921998-09-28 15:59:21 +000015class Switchboard:
Barry Warsawfda3ace1998-09-29 20:04:19 +000016 def __init__(self, colordb):
Barry Warsaw987fb921998-09-28 15:59:21 +000017 self.__views = []
Barry Warsawfda3ace1998-09-29 20:04:19 +000018 self.__colordb = colordb
Barry Warsawa7ba45b1998-10-01 16:46:43 +000019 self.__red = 0
20 self.__green = 0
21 self.__blue = 0
Barry Warsaw987fb921998-09-28 15:59:21 +000022
23 def add_view(self, view):
24 self.__views.append(view)
25
Barry Warsaw1ac18cd1998-09-28 23:41:12 +000026 def update_views(self, red, green, blue):
Barry Warsawa7ba45b1998-10-01 16:46:43 +000027 self.__red = red
28 self.__green = green
29 self.__blue = blue
Barry Warsaw987fb921998-09-28 15:59:21 +000030 for v in self.__views:
Barry Warsaw1ac18cd1998-09-28 23:41:12 +000031 v.update_yourself(red, green, blue)
Barry Warsawfda3ace1998-09-29 20:04:19 +000032
Barry Warsawa7ba45b1998-10-01 16:46:43 +000033 def update_views_current(self):
34 self.update_views(self.__red, self.__green, self.__blue)
35
Barry Warsawfda3ace1998-09-29 20:04:19 +000036 def colordb(self):
37 return self.__colordb