1998-01-31 19:39:01 -04:00
|
|
|
|
"""Main Pynche (Pythonically Natural Color and Hue Editor) widget.
|
1998-10-02 13:06:27 -03:00
|
|
|
|
|
|
|
|
|
This window provides the basic decorations, primarily including the menubar.
|
|
|
|
|
It is used to bring up other windows.
|
1998-01-31 19:39:01 -04:00
|
|
|
|
"""
|
|
|
|
|
|
1998-09-28 20:38:44 -03:00
|
|
|
|
import sys
|
1998-01-31 19:39:01 -04:00
|
|
|
|
from Tkinter import *
|
1998-09-29 17:03:53 -03:00
|
|
|
|
import tkMessageBox
|
1998-01-31 19:39:01 -04:00
|
|
|
|
|
1998-09-28 20:38:44 -03:00
|
|
|
|
# Milliseconds between interrupt checks
|
|
|
|
|
KEEPALIVE_TIMER = 500
|
1998-02-17 18:25:23 -04:00
|
|
|
|
|
|
|
|
|
|
1998-02-12 15:52:31 -04:00
|
|
|
|
|
1998-09-28 20:38:44 -03:00
|
|
|
|
class PyncheWidget:
|
1998-10-01 13:46:16 -03:00
|
|
|
|
def __init__(self, version, switchboard):
|
|
|
|
|
self.__sb = switchboard
|
|
|
|
|
self.__version = version
|
|
|
|
|
self.__textwin = None
|
1998-10-02 13:05:48 -03:00
|
|
|
|
self.__listwin = None
|
1998-09-28 20:38:44 -03:00
|
|
|
|
# create the first and top window
|
|
|
|
|
root = self.__root = Tk(className='Pynche')
|
|
|
|
|
root.protocol('WM_DELETE_WINDOW', self.__quit)
|
|
|
|
|
root.title('Pynche %s' % version)
|
|
|
|
|
root.iconname('Pynche')
|
|
|
|
|
root.tk.createtimerhandler(KEEPALIVE_TIMER, self.__keepalive)
|
|
|
|
|
#
|
|
|
|
|
# create the menubar
|
|
|
|
|
#
|
|
|
|
|
menubar = self.__menubar = Frame(root, relief=RAISED, borderwidth=2)
|
1998-10-01 11:26:26 -03:00
|
|
|
|
menubar.grid(row=0, column=0, columnspan=2, sticky='EW')
|
1998-09-28 20:38:44 -03:00
|
|
|
|
#
|
|
|
|
|
# File menu
|
|
|
|
|
#
|
|
|
|
|
filebtn = Menubutton(menubar, text='File',
|
|
|
|
|
underline=0)
|
|
|
|
|
filebtn.pack(side=LEFT)
|
|
|
|
|
filemenu = Menu(filebtn, tearoff=0)
|
|
|
|
|
filebtn['menu'] = filemenu
|
|
|
|
|
filemenu.add_command(label='Quit',
|
|
|
|
|
command=self.__quit,
|
|
|
|
|
accelerator='Alt-Q',
|
|
|
|
|
underline=0)
|
|
|
|
|
root.bind('<Alt-q>', self.__quit)
|
|
|
|
|
root.bind('<Alt-Q>', self.__quit)
|
|
|
|
|
#
|
1998-10-01 13:46:16 -03:00
|
|
|
|
# View menu
|
|
|
|
|
#
|
|
|
|
|
viewbtn = Menubutton(menubar, text='View',
|
|
|
|
|
underline=0)
|
|
|
|
|
viewbtn.pack(side=LEFT)
|
|
|
|
|
viewmenu = Menu(viewbtn, tearoff=0)
|
|
|
|
|
viewbtn['menu'] = viewmenu
|
|
|
|
|
viewmenu.add_command(label='Text Window...',
|
|
|
|
|
command=self.__popup_text,
|
|
|
|
|
underline=0)
|
1998-10-02 13:05:48 -03:00
|
|
|
|
viewmenu.add_command(label='Color List Window...',
|
|
|
|
|
command=self.__popup_listwin,
|
|
|
|
|
underline=0)
|
1998-10-01 13:46:16 -03:00
|
|
|
|
#
|
1998-09-28 20:38:44 -03:00
|
|
|
|
# Help menu
|
|
|
|
|
#
|
|
|
|
|
helpbtn = Menubutton(menubar, text='Help',
|
|
|
|
|
underline=0)
|
|
|
|
|
helpbtn.pack(side=RIGHT)
|
|
|
|
|
helpmenu = Menu(helpbtn, tearoff=0)
|
|
|
|
|
helpbtn['menu'] = helpmenu
|
|
|
|
|
helpmenu.add_command(label='About...',
|
|
|
|
|
command=self.__popup_about,
|
|
|
|
|
underline=0)
|
|
|
|
|
|
|
|
|
|
def __keepalive(self):
|
|
|
|
|
# Exercise the Python interpreter regularly so keyboard interrupts get
|
|
|
|
|
# through.
|
|
|
|
|
self.__root.tk.createtimerhandler(KEEPALIVE_TIMER, self.__keepalive)
|
1998-02-12 15:52:31 -04:00
|
|
|
|
|
1998-09-28 20:38:44 -03:00
|
|
|
|
def __quit(self, event=None):
|
|
|
|
|
sys.exit(0)
|
1998-02-12 15:52:31 -04:00
|
|
|
|
|
1998-09-28 20:38:44 -03:00
|
|
|
|
def start(self):
|
|
|
|
|
self.__keepalive()
|
|
|
|
|
self.__root.mainloop()
|
1998-02-17 18:25:23 -04:00
|
|
|
|
|
1998-09-28 20:38:44 -03:00
|
|
|
|
def parent(self):
|
|
|
|
|
return self.__root
|
|
|
|
|
|
1998-02-17 18:25:23 -04:00
|
|
|
|
def __popup_about(self, event=None):
|
1998-09-29 17:03:53 -03:00
|
|
|
|
tkMessageBox.showinfo('About Pynche 1.0',
|
|
|
|
|
'''\
|
|
|
|
|
Pynche -- the PYthonically
|
|
|
|
|
Natural Color and Hue Editor
|
|
|
|
|
|
|
|
|
|
Copyright (C) 1998
|
|
|
|
|
Barry A. Warsaw
|
|
|
|
|
All rights reserved
|
|
|
|
|
|
|
|
|
|
For information about Pynche
|
|
|
|
|
contact: Barry A. Warsaw
|
|
|
|
|
email: bwarsaw@python.org''')
|
1998-10-01 13:46:16 -03: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 13:05:48 -03: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()
|