1998-01-31 23:39:01 +00:00
|
|
|
|
"""Main Pynche (Pythonically Natural Color and Hue Editor) widget.
|
1998-10-02 16:06:27 +00:00
|
|
|
|
|
|
|
|
|
This window provides the basic decorations, primarily including the menubar.
|
|
|
|
|
It is used to bring up other windows.
|
1998-01-31 23:39:01 +00:00
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from Tkinter import *
|
1998-09-29 20:03:53 +00:00
|
|
|
|
import tkMessageBox
|
1998-01-31 23:39:01 +00:00
|
|
|
|
|
1998-09-28 23:38:44 +00:00
|
|
|
|
# Milliseconds between interrupt checks
|
|
|
|
|
KEEPALIVE_TIMER = 500
|
1998-02-17 22:25:23 +00:00
|
|
|
|
|
|
|
|
|
|
1998-02-12 19:52:31 +00:00
|
|
|
|
|
1998-09-28 23:38:44 +00:00
|
|
|
|
class PyncheWidget:
|
1998-10-01 16:46:16 +00:00
|
|
|
|
def __init__(self, version, switchboard):
|
|
|
|
|
self.__sb = switchboard
|
|
|
|
|
self.__version = version
|
|
|
|
|
self.__textwin = None
|
1998-10-02 16:05:48 +00:00
|
|
|
|
self.__listwin = None
|
1998-10-05 21:14:46 +00:00
|
|
|
|
self.__detailswin = None
|
1998-09-28 23:38:44 +00:00
|
|
|
|
#
|
1998-10-06 19:39:34 +00:00
|
|
|
|
# Is there already a default root for Tk, say because we're running
|
|
|
|
|
# under Guido's IDE? :-) Two conditions say no, either the import
|
|
|
|
|
# fails or _default_root is None.
|
|
|
|
|
tkroot = None
|
|
|
|
|
try:
|
|
|
|
|
from Tkinter import _default_root
|
|
|
|
|
tkroot = self.__tkroot = _default_root
|
|
|
|
|
except ImportError:
|
|
|
|
|
pass
|
|
|
|
|
if not tkroot:
|
|
|
|
|
tkroot = self.__tkroot = Tk(className='Pynche')
|
|
|
|
|
# but this isn't our top level widget, so make it invisible
|
|
|
|
|
tkroot.withdraw()
|
1998-09-28 23:38:44 +00:00
|
|
|
|
# create the menubar
|
1998-10-06 19:39:34 +00:00
|
|
|
|
menubar = self.__menubar = Menu(tkroot)
|
1998-09-28 23:38:44 +00:00
|
|
|
|
#
|
|
|
|
|
# File menu
|
|
|
|
|
#
|
1998-10-06 19:39:34 +00:00
|
|
|
|
filemenu = self.__filemenu = Menu(menubar, tearoff=0)
|
1998-09-28 23:38:44 +00:00
|
|
|
|
filemenu.add_command(label='Quit',
|
1998-10-06 19:50:33 +00:00
|
|
|
|
command=self.__quit,
|
1998-09-28 23:38:44 +00:00
|
|
|
|
accelerator='Alt-Q',
|
|
|
|
|
underline=0)
|
|
|
|
|
#
|
1998-10-01 16:46:16 +00:00
|
|
|
|
# View menu
|
|
|
|
|
#
|
1998-10-06 19:39:34 +00:00
|
|
|
|
viewmenu = Menu(menubar, tearoff=0)
|
1998-10-01 16:46:16 +00:00
|
|
|
|
viewmenu.add_command(label='Text Window...',
|
|
|
|
|
command=self.__popup_text,
|
|
|
|
|
underline=0)
|
1998-10-02 16:05:48 +00:00
|
|
|
|
viewmenu.add_command(label='Color List Window...',
|
|
|
|
|
command=self.__popup_listwin,
|
|
|
|
|
underline=0)
|
1998-10-05 21:14:46 +00:00
|
|
|
|
viewmenu.add_command(label='Details Window...',
|
|
|
|
|
command=self.__popup_details,
|
1998-10-06 19:39:34 +00:00
|
|
|
|
underline=0)
|
|
|
|
|
#
|
1998-09-28 23:38:44 +00:00
|
|
|
|
# Help menu
|
|
|
|
|
#
|
1998-10-06 19:39:34 +00:00
|
|
|
|
helpmenu = Menu(menubar, name='help', tearoff=0)
|
1998-09-28 23:38:44 +00:00
|
|
|
|
helpmenu.add_command(label='About...',
|
|
|
|
|
command=self.__popup_about,
|
|
|
|
|
underline=0)
|
1998-10-06 19:39:34 +00:00
|
|
|
|
#
|
|
|
|
|
# Tie them all together
|
|
|
|
|
#
|
|
|
|
|
menubar.add_cascade(label='File',
|
|
|
|
|
menu=filemenu,
|
|
|
|
|
underline=0)
|
|
|
|
|
menubar.add_cascade(label='View',
|
|
|
|
|
menu=viewmenu,
|
|
|
|
|
underline=0)
|
|
|
|
|
menubar.add_cascade(label='Help',
|
|
|
|
|
menu=helpmenu,
|
|
|
|
|
underline=0)
|
|
|
|
|
|
|
|
|
|
# now create the top level window
|
|
|
|
|
root = self.__root = Toplevel(tkroot, class_='Pynche', menu=menubar)
|
1998-10-06 19:50:33 +00:00
|
|
|
|
root.protocol('WM_DELETE_WINDOW', self.__quit)
|
1998-10-06 19:39:34 +00:00
|
|
|
|
root.title('Pynche %s' % version)
|
|
|
|
|
root.iconname('Pynche')
|
|
|
|
|
root.tk.createtimerhandler(KEEPALIVE_TIMER, self.__keepalive)
|
1998-10-06 19:50:33 +00:00
|
|
|
|
root.bind('<Alt-q>', self.__quit)
|
|
|
|
|
root.bind('<Alt-Q>', self.__quit)
|
|
|
|
|
|
|
|
|
|
def __quit(self, event=None):
|
|
|
|
|
self.__root.quit()
|
1998-09-28 23:38:44 +00:00
|
|
|
|
|
|
|
|
|
def __keepalive(self):
|
|
|
|
|
# Exercise the Python interpreter regularly so keyboard interrupts get
|
|
|
|
|
# through.
|
1998-10-06 19:39:34 +00:00
|
|
|
|
self.__tkroot.tk.createtimerhandler(KEEPALIVE_TIMER, self.__keepalive)
|
1998-02-12 19:52:31 +00:00
|
|
|
|
|
1998-09-28 23:38:44 +00:00
|
|
|
|
def start(self):
|
|
|
|
|
self.__keepalive()
|
1998-10-06 19:39:34 +00:00
|
|
|
|
self.__tkroot.mainloop()
|
1998-02-17 22:25:23 +00:00
|
|
|
|
|
1998-09-28 23:38:44 +00:00
|
|
|
|
def parent(self):
|
|
|
|
|
return self.__root
|
|
|
|
|
|
1998-02-17 22:25:23 +00:00
|
|
|
|
def __popup_about(self, event=None):
|
1998-10-07 03:36:58 +00:00
|
|
|
|
from Main import __version__
|
1998-10-06 18:52:59 +00:00
|
|
|
|
tkMessageBox.showinfo('About Pynche ' + __version__,
|
1998-09-29 20:03:53 +00:00
|
|
|
|
'''\
|
1998-10-06 18:52:59 +00:00
|
|
|
|
Pynche %s
|
|
|
|
|
The PYthonically Natural
|
|
|
|
|
Color and Hue Editor
|
1998-09-29 20:03:53 +00:00
|
|
|
|
|
1998-10-06 20:49:20 +00:00
|
|
|
|
Copyright (C) 1998 CNRI
|
1998-09-29 20:03:53 +00:00
|
|
|
|
All rights reserved
|
|
|
|
|
|
1998-10-07 03:40:29 +00:00
|
|
|
|
For information about Pynche contact
|
|
|
|
|
author: Barry A. Warsaw
|
|
|
|
|
email : bwarsaw@python.org''' % __version__)
|
1998-10-01 16:46:16 +00:00
|
|
|
|
|
|
|
|
|
def __popup_text(self, event=None):
|
|
|
|
|
if not self.__textwin:
|
|
|
|
|
from TextViewer import TextViewer
|
|
|
|
|
self.__textwin = TextViewer(self.__sb, self.__root)
|
|
|
|
|
self.__sb.add_view(self.__textwin)
|
|
|
|
|
self.__textwin.deiconify()
|
1998-10-02 16:05:48 +00:00
|
|
|
|
|
|
|
|
|
def __popup_listwin(self, event=None):
|
|
|
|
|
if not self.__listwin:
|
|
|
|
|
from ListViewer import ListViewer
|
|
|
|
|
self.__listwin = ListViewer(self.__sb, self.__root)
|
|
|
|
|
self.__sb.add_view(self.__listwin)
|
|
|
|
|
self.__listwin.deiconify()
|
1998-10-05 21:14:46 +00:00
|
|
|
|
|
|
|
|
|
def __popup_details(self, event=None):
|
|
|
|
|
if not self.__detailswin:
|
|
|
|
|
from DetailsViewer import DetailsViewer
|
|
|
|
|
self.__detailswin = DetailsViewer(self.__sb, self.__root)
|
|
|
|
|
self.__sb.add_view(self.__detailswin)
|
|
|
|
|
self.__detailswin.deiconify()
|