3 This class is used to coordinate updates among all Viewers. Every Viewer must
4 conform to the following interface:
6 - it must include a method called update_yourself() which takes three
7 arguments; the red, green, and blue values of the selected color.
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.
16 from types
import DictType
20 def __init__(self
, colordb
, initfile
):
21 self
.__initfile
= initfile
22 self
.__colordb
= colordb
29 # read the initialization file
35 self
.__optiondb
= marshal
.load(fp
)
36 if type(self
.__optiondb
) <> DictType
:
38 'Problem reading options from file: %s\n' %
41 except (IOError, EOFError):
47 def add_view(self
, view
):
48 self
.__views
.append(view
)
50 def update_views(self
, red
, green
, blue
):
54 for v
in self
.__views
:
55 v
.update_yourself(red
, green
, blue
)
57 def update_views_current(self
):
58 self
.update_views(self
.__red
, self
.__green
, self
.__blue
)
60 def current_rgb(self
):
61 return self
.__red
, self
.__green
, self
.__blue
67 return self
.__optiondb
70 # save the current color
71 self
.__optiondb
['RED'] = self
.__red
72 self
.__optiondb
['GREEN'] = self
.__green
73 self
.__optiondb
['BLUE'] = self
.__blue
74 for v
in self
.__views
:
75 if hasattr(v
, 'save_options'):
76 v
.save_options(self
.__optiondb
)
80 fp
= open(self
.__initfile
, 'w')
82 sys
.stderr
.write('Cannot write options to file: %s\n' %
85 marshal
.dump(self
.__optiondb
, fp
)
90 def withdraw_views(self
):
91 for v
in self
.__views
:
92 if hasattr(v
, 'withdraw'):
95 def canceled(self
, flag
=1):
96 self
.__canceled
= flag
99 return self
.__canceled