blob: 7c709352c502274af171c6cd4e8a7efe49f1aef7 [file] [log] [blame]
Barry Warsawfefbf791998-01-31 23:39:01 +00001"""Main Pynche (Pythonically Natural Color and Hue Editor) widget.
Barry Warsaweb61fbd1998-10-02 16:06:27 +00002
3This window provides the basic decorations, primarily including the menubar.
4It is used to bring up other windows.
Barry Warsawfefbf791998-01-31 23:39:01 +00005"""
6
Barry Warsawa69c1ba1998-09-28 23:38:44 +00007import sys
Barry Warsawfefbf791998-01-31 23:39:01 +00008from Tkinter import *
Barry Warsawa9b45581998-09-29 20:03:53 +00009import tkMessageBox
Barry Warsawa69c1ba1998-09-28 23:38:44 +000010
11# Milliseconds between interrupt checks
12KEEPALIVE_TIMER = 500
Barry Warsawfefbf791998-01-31 23:39:01 +000013
Barry Warsaw552ac171998-02-17 22:25:23 +000014
15
Barry Warsawa69c1ba1998-09-28 23:38:44 +000016class PyncheWidget:
Barry Warsaw86daeb71998-10-01 16:46:16 +000017 def __init__(self, version, switchboard):
18 self.__sb = switchboard
19 self.__version = version
20 self.__textwin = None
Barry Warsawbd36d6e1998-10-02 16:05:48 +000021 self.__listwin = None
Barry Warsaw9044b8e1998-10-05 21:14:46 +000022 self.__detailswin = None
Barry Warsawa69c1ba1998-09-28 23:38:44 +000023 # create the first and top window
24 root = self.__root = Tk(className='Pynche')
25 root.protocol('WM_DELETE_WINDOW', self.__quit)
26 root.title('Pynche %s' % version)
27 root.iconname('Pynche')
28 root.tk.createtimerhandler(KEEPALIVE_TIMER, self.__keepalive)
29 #
30 # create the menubar
31 #
32 menubar = self.__menubar = Frame(root, relief=RAISED, borderwidth=2)
Barry Warsawb26743a1998-10-01 14:26:26 +000033 menubar.grid(row=0, column=0, columnspan=2, sticky='EW')
Barry Warsawa69c1ba1998-09-28 23:38:44 +000034 #
35 # File menu
36 #
37 filebtn = Menubutton(menubar, text='File',
38 underline=0)
39 filebtn.pack(side=LEFT)
40 filemenu = Menu(filebtn, tearoff=0)
41 filebtn['menu'] = filemenu
42 filemenu.add_command(label='Quit',
43 command=self.__quit,
44 accelerator='Alt-Q',
45 underline=0)
46 root.bind('<Alt-q>', self.__quit)
47 root.bind('<Alt-Q>', self.__quit)
48 #
Barry Warsaw86daeb71998-10-01 16:46:16 +000049 # View menu
50 #
51 viewbtn = Menubutton(menubar, text='View',
52 underline=0)
53 viewbtn.pack(side=LEFT)
54 viewmenu = Menu(viewbtn, tearoff=0)
55 viewbtn['menu'] = viewmenu
56 viewmenu.add_command(label='Text Window...',
57 command=self.__popup_text,
58 underline=0)
Barry Warsawbd36d6e1998-10-02 16:05:48 +000059 viewmenu.add_command(label='Color List Window...',
60 command=self.__popup_listwin,
61 underline=0)
Barry Warsaw9044b8e1998-10-05 21:14:46 +000062 viewmenu.add_command(label='Details Window...',
63 command=self.__popup_details,
64 underline=0) #
Barry Warsawa69c1ba1998-09-28 23:38:44 +000065 # Help menu
66 #
67 helpbtn = Menubutton(menubar, text='Help',
68 underline=0)
69 helpbtn.pack(side=RIGHT)
70 helpmenu = Menu(helpbtn, tearoff=0)
71 helpbtn['menu'] = helpmenu
72 helpmenu.add_command(label='About...',
73 command=self.__popup_about,
74 underline=0)
Barry Warsaw552ac171998-02-17 22:25:23 +000075
Barry Warsawa69c1ba1998-09-28 23:38:44 +000076 def __keepalive(self):
77 # Exercise the Python interpreter regularly so keyboard interrupts get
78 # through.
79 self.__root.tk.createtimerhandler(KEEPALIVE_TIMER, self.__keepalive)
Barry Warsaw552ac171998-02-17 22:25:23 +000080
81 def __quit(self, event=None):
Barry Warsawa69c1ba1998-09-28 23:38:44 +000082 sys.exit(0)
Barry Warsaw552ac171998-02-17 22:25:23 +000083
Barry Warsawa69c1ba1998-09-28 23:38:44 +000084 def start(self):
85 self.__keepalive()
86 self.__root.mainloop()
87
88 def parent(self):
89 return self.__root
Barry Warsawf67575d1998-03-10 00:17:01 +000090
Barry Warsawa69c1ba1998-09-28 23:38:44 +000091 def __popup_about(self, event=None):
Barry Warsawa9b45581998-09-29 20:03:53 +000092 tkMessageBox.showinfo('About Pynche 1.0',
93 '''\
94Pynche -- the PYthonically
95Natural Color and Hue Editor
Barry Warsawa69c1ba1998-09-28 23:38:44 +000096
Barry Warsawa9b45581998-09-29 20:03:53 +000097Copyright (C) 1998
98Barry A. Warsaw
99All rights reserved
Barry Warsawa69c1ba1998-09-28 23:38:44 +0000100
Barry Warsawa9b45581998-09-29 20:03:53 +0000101For information about Pynche
102contact: Barry A. Warsaw
103email: bwarsaw@python.org''')
Barry Warsaw86daeb71998-10-01 16:46:16 +0000104
105 def __popup_text(self, event=None):
106 if not self.__textwin:
107 from TextViewer import TextViewer
108 self.__textwin = TextViewer(self.__sb, self.__root)
109 self.__sb.add_view(self.__textwin)
110 self.__textwin.deiconify()
Barry Warsawbd36d6e1998-10-02 16:05:48 +0000111
112 def __popup_listwin(self, event=None):
113 if not self.__listwin:
114 from ListViewer import ListViewer
115 self.__listwin = ListViewer(self.__sb, self.__root)
116 self.__sb.add_view(self.__listwin)
117 self.__listwin.deiconify()
Barry Warsaw9044b8e1998-10-05 21:14:46 +0000118
119 def __popup_details(self, event=None):
120 if not self.__detailswin:
121 from DetailsViewer import DetailsViewer
122 self.__detailswin = DetailsViewer(self.__sb, self.__root)
123 self.__sb.add_view(self.__detailswin)
124 self.__detailswin.deiconify()