summaryrefslogtreecommitdiffstats
path: root/Tools/pynche/Switchboard.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>1998-10-22 03:25:59 (GMT)
committerBarry Warsaw <barry@python.org>1998-10-22 03:25:59 (GMT)
commitca07ba00acdd020e0c179277ed829a8ce1664245 (patch)
tree03ddbed7626ca441d4c90d599b2028773f8e298c /Tools/pynche/Switchboard.py
parent04da10c7a2fa0bd060e8052a9fe3d47623324b94 (diff)
downloadcpython-ca07ba00acdd020e0c179277ed829a8ce1664245.zip
cpython-ca07ba00acdd020e0c179277ed829a8ce1664245.tar.gz
cpython-ca07ba00acdd020e0c179277ed829a8ce1664245.tar.bz2
Many changes to support a second mode of operation. Pynche can now be
run either as a standalone application (by running pynche or pynche.pyw), or as a modal dialog inside another application. This can be done by importing pyColorChooser and running askcolor(). The API for this is the same as the tkColorChooser.askcolor() API, namely: When `Okay' is hit, askcolor() returns ((r, g, b), "name"). When `Cancel' is hit, askcolor() returns (None, None). Note the following differences: 1. pyColorChooser.askcolor() takes an optional keyword `master' which if set tells Pynche to run as a modal dialog. `master' is a Tkinter parent window. Without the `master' keyword Pynche runs standalone. 2. in pyColorChooser.askcolor() will return a Tk/X11 color name as "name" if there is an exact match, otherwise it will return a color spec, e.g. "#rrggbb". tkColorChooser can't return a color name. There are also some UI differences when running standalone vs. modal. When modal, there is no "File" menu, but instead there are "Okay" and "Cancel" buttons. The implementation of all this is a bit of a hack, but it seems to work moderately well. I'm not guaranteeing the pyColorChooser.Chooser class has the same semantics as the tkColorChooser.Chooser class.
Diffstat (limited to 'Tools/pynche/Switchboard.py')
-rw-r--r--Tools/pynche/Switchboard.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/Tools/pynche/Switchboard.py b/Tools/pynche/Switchboard.py
index 7ac3df1..d8fd14c 100644
--- a/Tools/pynche/Switchboard.py
+++ b/Tools/pynche/Switchboard.py
@@ -17,12 +17,14 @@ import marshal
class Switchboard:
def __init__(self, colordb, initfile):
+ self.__initfile = initfile
self.__colordb = colordb
self.__optiondb = {}
self.__views = []
self.__red = 0
self.__green = 0
self.__blue = 0
+ self.__canceled = 0
# read the initialization file
fp = None
if initfile:
@@ -61,17 +63,18 @@ class Switchboard:
def optiondb(self):
return self.__optiondb
- def save_views(self, file):
+ def save_views(self):
# save the current color
self.__optiondb['RED'] = self.__red
self.__optiondb['GREEN'] = self.__green
self.__optiondb['BLUE'] = self.__blue
for v in self.__views:
- v.save_options(self.__optiondb)
+ if hasattr(v, 'save_options'):
+ v.save_options(self.__optiondb)
fp = None
try:
try:
- fp = open(file, 'w')
+ fp = open(self.__initfile, 'w')
except IOError:
print 'Cannot write options to file:', file
else:
@@ -79,3 +82,14 @@ class Switchboard:
finally:
if fp:
fp.close()
+
+ def withdraw_views(self):
+ for v in self.__views:
+ if hasattr(v, 'withdraw'):
+ v.withdraw()
+
+ def canceled(self):
+ self.__canceled = 1
+
+ def canceled_p(self):
+ return self.__canceled