Lots of changes to support loading alternative color name database.

You can switch database by just loading the new one; the list window
and nearest colors adapt to the new database.

Some reorganizing of code.  Also, the name of the database file is
stored in the ~/.pynche pickle.  If it can't be loaded, fallbacks are
used.
This commit is contained in:
Barry Warsaw 1999-04-26 23:17:16 +00:00
parent 0ec1493d0b
commit 0604d72318
6 changed files with 191 additions and 89 deletions

View file

@ -23,6 +23,7 @@ class PyncheWidget:
self.__listwin = None
self.__detailswin = None
self.__helpwin = None
self.__dialogstate = {}
modal = self.__modal = not not master
# If a master was given, we are running as a modal dialog servant to
# some other application. We rearrange our UI in this case (there's
@ -51,8 +52,11 @@ class PyncheWidget:
#
# File menu
#
filemenu = self.__filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label='Load palette...',
command=self.__load,
underline=0)
if not modal:
filemenu = self.__filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label='Quit',
command=self.__quit,
accelerator='Alt-Q',
@ -66,7 +70,7 @@ class PyncheWidget:
underline=0)
viewmenu.add_command(label='Color List Window...',
command=self.__popup_listwin,
underline=0)
underline=6)
viewmenu.add_command(label='Details Window...',
command=self.__popup_details,
underline=0)
@ -186,6 +190,33 @@ email: bwarsaw@python.org''' % __version__)
self.__sb.add_view(self.__detailswin)
self.__detailswin.deiconify()
def __load(self, event=None):
import FileDialog
import ColorDB
while 1:
d = FileDialog.FileDialog(self.__root)
file = d.go(pattern='*.txt', key=self.__dialogstate)
if file is None:
# cancel button
return
try:
colordb = ColorDB.get_colordb(file)
except IOError:
tkMessageBox.showerror('Read error', '''\
Could not open file for reading:
%s''' % file)
continue
if colordb is None:
tkMessageBox.showerror('Unrecognized color file type', '''\
Unrecognized color file type in file:
%s''' % file)
continue
break
self.__sb.set_colordb(colordb)
if self.__listwin:
self.__listwin.flush()
self.__sb.update_views_current()
def withdraw(self):
self.__root.withdraw()