blob: e3a3b2cb60371c78f2e0eb296278e8850bd67c32 [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
7from Tkinter import *
Barry Warsawa9b45581998-09-29 20:03:53 +00008import tkMessageBox
Barry Warsawa69c1ba1998-09-28 23:38:44 +00009
10# Milliseconds between interrupt checks
11KEEPALIVE_TIMER = 500
Barry Warsawfefbf791998-01-31 23:39:01 +000012
Barry Warsaw552ac171998-02-17 22:25:23 +000013
14
Barry Warsawa69c1ba1998-09-28 23:38:44 +000015class PyncheWidget:
Barry Warsaw86daeb71998-10-01 16:46:16 +000016 def __init__(self, version, switchboard):
17 self.__sb = switchboard
18 self.__version = version
19 self.__textwin = None
Barry Warsawbd36d6e1998-10-02 16:05:48 +000020 self.__listwin = None
Barry Warsaw9044b8e1998-10-05 21:14:46 +000021 self.__detailswin = None
Barry Warsawa69c1ba1998-09-28 23:38:44 +000022 #
Barry Warsaw38365031998-10-06 19:39:34 +000023 # Is there already a default root for Tk, say because we're running
24 # under Guido's IDE? :-) Two conditions say no, either the import
25 # fails or _default_root is None.
26 tkroot = None
27 try:
28 from Tkinter import _default_root
29 tkroot = self.__tkroot = _default_root
30 except ImportError:
31 pass
32 if not tkroot:
33 tkroot = self.__tkroot = Tk(className='Pynche')
34 # but this isn't our top level widget, so make it invisible
35 tkroot.withdraw()
Barry Warsawa69c1ba1998-09-28 23:38:44 +000036 # create the menubar
Barry Warsaw38365031998-10-06 19:39:34 +000037 menubar = self.__menubar = Menu(tkroot)
Barry Warsawa69c1ba1998-09-28 23:38:44 +000038 #
39 # File menu
40 #
Barry Warsaw38365031998-10-06 19:39:34 +000041 filemenu = self.__filemenu = Menu(menubar, tearoff=0)
Barry Warsawa69c1ba1998-09-28 23:38:44 +000042 filemenu.add_command(label='Quit',
Barry Warsawe7f4a471998-10-06 19:50:33 +000043 command=self.__quit,
Barry Warsawa69c1ba1998-09-28 23:38:44 +000044 accelerator='Alt-Q',
45 underline=0)
Barry Warsawa69c1ba1998-09-28 23:38:44 +000046 #
Barry Warsaw86daeb71998-10-01 16:46:16 +000047 # View menu
48 #
Barry Warsaw38365031998-10-06 19:39:34 +000049 viewmenu = Menu(menubar, tearoff=0)
Barry Warsaw86daeb71998-10-01 16:46:16 +000050 viewmenu.add_command(label='Text Window...',
51 command=self.__popup_text,
52 underline=0)
Barry Warsawbd36d6e1998-10-02 16:05:48 +000053 viewmenu.add_command(label='Color List Window...',
54 command=self.__popup_listwin,
55 underline=0)
Barry Warsaw9044b8e1998-10-05 21:14:46 +000056 viewmenu.add_command(label='Details Window...',
57 command=self.__popup_details,
Barry Warsaw38365031998-10-06 19:39:34 +000058 underline=0)
59 #
Barry Warsawa69c1ba1998-09-28 23:38:44 +000060 # Help menu
61 #
Barry Warsaw38365031998-10-06 19:39:34 +000062 helpmenu = Menu(menubar, name='help', tearoff=0)
Barry Warsawa69c1ba1998-09-28 23:38:44 +000063 helpmenu.add_command(label='About...',
64 command=self.__popup_about,
65 underline=0)
Barry Warsaw38365031998-10-06 19:39:34 +000066 #
67 # Tie them all together
68 #
69 menubar.add_cascade(label='File',
70 menu=filemenu,
71 underline=0)
72 menubar.add_cascade(label='View',
73 menu=viewmenu,
74 underline=0)
75 menubar.add_cascade(label='Help',
76 menu=helpmenu,
77 underline=0)
78
79 # now create the top level window
80 root = self.__root = Toplevel(tkroot, class_='Pynche', menu=menubar)
Barry Warsawe7f4a471998-10-06 19:50:33 +000081 root.protocol('WM_DELETE_WINDOW', self.__quit)
Barry Warsaw38365031998-10-06 19:39:34 +000082 root.title('Pynche %s' % version)
83 root.iconname('Pynche')
84 root.tk.createtimerhandler(KEEPALIVE_TIMER, self.__keepalive)
Barry Warsawe7f4a471998-10-06 19:50:33 +000085 root.bind('<Alt-q>', self.__quit)
86 root.bind('<Alt-Q>', self.__quit)
87
88 def __quit(self, event=None):
89 self.__root.quit()
Barry Warsaw552ac171998-02-17 22:25:23 +000090
Barry Warsawa69c1ba1998-09-28 23:38:44 +000091 def __keepalive(self):
92 # Exercise the Python interpreter regularly so keyboard interrupts get
93 # through.
Barry Warsaw38365031998-10-06 19:39:34 +000094 self.__tkroot.tk.createtimerhandler(KEEPALIVE_TIMER, self.__keepalive)
Barry Warsaw552ac171998-02-17 22:25:23 +000095
Barry Warsawa69c1ba1998-09-28 23:38:44 +000096 def start(self):
97 self.__keepalive()
Barry Warsaw38365031998-10-06 19:39:34 +000098 self.__tkroot.mainloop()
Barry Warsawa69c1ba1998-09-28 23:38:44 +000099
100 def parent(self):
101 return self.__root
Barry Warsawf67575d1998-03-10 00:17:01 +0000102
Barry Warsawa69c1ba1998-09-28 23:38:44 +0000103 def __popup_about(self, event=None):
Barry Warsaw0926dea1998-10-07 03:36:58 +0000104 from Main import __version__
Barry Warsawad3a67c1998-10-06 18:52:59 +0000105 tkMessageBox.showinfo('About Pynche ' + __version__,
Barry Warsawa9b45581998-09-29 20:03:53 +0000106 '''\
Barry Warsawad3a67c1998-10-06 18:52:59 +0000107Pynche %s
108The PYthonically Natural
109Color and Hue Editor
Barry Warsawa69c1ba1998-09-28 23:38:44 +0000110
Barry Warsaw3886e3a1998-10-06 20:49:20 +0000111Copyright (C) 1998 CNRI
Barry Warsawa9b45581998-09-29 20:03:53 +0000112All rights reserved
Barry Warsawa69c1ba1998-09-28 23:38:44 +0000113
Barry Warsawa9b45581998-09-29 20:03:53 +0000114For information about Pynche
115contact: Barry A. Warsaw
Barry Warsawad3a67c1998-10-06 18:52:59 +0000116email: bwarsaw@python.org''' % __version__)
Barry Warsaw86daeb71998-10-01 16:46:16 +0000117
118 def __popup_text(self, event=None):
119 if not self.__textwin:
120 from TextViewer import TextViewer
121 self.__textwin = TextViewer(self.__sb, self.__root)
122 self.__sb.add_view(self.__textwin)
123 self.__textwin.deiconify()
Barry Warsawbd36d6e1998-10-02 16:05:48 +0000124
125 def __popup_listwin(self, event=None):
126 if not self.__listwin:
127 from ListViewer import ListViewer
128 self.__listwin = ListViewer(self.__sb, self.__root)
129 self.__sb.add_view(self.__listwin)
130 self.__listwin.deiconify()
Barry Warsaw9044b8e1998-10-05 21:14:46 +0000131
132 def __popup_details(self, event=None):
133 if not self.__detailswin:
134 from DetailsViewer import DetailsViewer
135 self.__detailswin = DetailsViewer(self.__sb, self.__root)
136 self.__sb.add_view(self.__detailswin)
137 self.__detailswin.deiconify()