blob: 3f15702b62f159f6c0bcd209aa173c2523538138 [file] [log] [blame]
Barry Warsawfefbf791998-01-31 23:39:01 +00001"""Main Pynche (Pythonically Natural Color and Hue Editor) widget.
2"""
3
Barry Warsawa69c1ba1998-09-28 23:38:44 +00004import sys
Barry Warsawfefbf791998-01-31 23:39:01 +00005from Tkinter import *
Barry Warsawa69c1ba1998-09-28 23:38:44 +00006
7# Milliseconds between interrupt checks
8KEEPALIVE_TIMER = 500
Barry Warsawfefbf791998-01-31 23:39:01 +00009
Barry Warsaw552ac171998-02-17 22:25:23 +000010
11
Barry Warsawa69c1ba1998-09-28 23:38:44 +000012class PyncheWidget:
13 def __init__(self, version):
14 # create the first and top window
15 root = self.__root = Tk(className='Pynche')
16 root.protocol('WM_DELETE_WINDOW', self.__quit)
17 root.title('Pynche %s' % version)
18 root.iconname('Pynche')
19 root.tk.createtimerhandler(KEEPALIVE_TIMER, self.__keepalive)
20 #
21 # create the menubar
22 #
23 menubar = self.__menubar = Frame(root, relief=RAISED, borderwidth=2)
24 menubar.pack(fill=X)
25 #
26 # File menu
27 #
28 filebtn = Menubutton(menubar, text='File',
29 underline=0)
30 filebtn.pack(side=LEFT)
31 filemenu = Menu(filebtn, tearoff=0)
32 filebtn['menu'] = filemenu
33 filemenu.add_command(label='Quit',
34 command=self.__quit,
35 accelerator='Alt-Q',
36 underline=0)
37 root.bind('<Alt-q>', self.__quit)
38 root.bind('<Alt-Q>', self.__quit)
39 #
40 # Edit Menu
41 #
42 editbtn = Menubutton(menubar, text='Edit',
43 underline=0)
44 editbtn.pack(side=LEFT)
45 editmenu = Menu(editbtn, tearoff=0)
46 editbtn['menu'] = editmenu
47 editmenu.add_command(label='Options...',
48 command=self.__popup_options,
49 underline=0)
50 #
51 # Help menu
52 #
53 helpbtn = Menubutton(menubar, text='Help',
54 underline=0)
55 helpbtn.pack(side=RIGHT)
56 helpmenu = Menu(helpbtn, tearoff=0)
57 helpbtn['menu'] = helpmenu
58 helpmenu.add_command(label='About...',
59 command=self.__popup_about,
60 underline=0)
Barry Warsaw552ac171998-02-17 22:25:23 +000061
Barry Warsawa69c1ba1998-09-28 23:38:44 +000062 def __keepalive(self):
63 # Exercise the Python interpreter regularly so keyboard interrupts get
64 # through.
65 self.__root.tk.createtimerhandler(KEEPALIVE_TIMER, self.__keepalive)
Barry Warsaw552ac171998-02-17 22:25:23 +000066
67 def __quit(self, event=None):
Barry Warsawa69c1ba1998-09-28 23:38:44 +000068 sys.exit(0)
Barry Warsaw552ac171998-02-17 22:25:23 +000069
Barry Warsawa69c1ba1998-09-28 23:38:44 +000070 def start(self):
71 self.__keepalive()
72 self.__root.mainloop()
73
74 def parent(self):
75 return self.__root
Barry Warsawf67575d1998-03-10 00:17:01 +000076
77 def __popup_options(self, event=None):
Barry Warsawa69c1ba1998-09-28 23:38:44 +000078 print 'Options...'
Barry Warsawa114eb51998-03-16 23:08:35 +000079
Barry Warsawa69c1ba1998-09-28 23:38:44 +000080 def __popup_about(self, event=None):
81 print 'About...'
82
83## # create chip window
84## group = Pmw.Group(parent, tag_text='Current Color')
85## interior = group.interior()
86## group.pack(side=LEFT, expand=YES, fill=BOTH)
87## self.__selected = ChipWidget(interior,
88## label_text='Selected')
89## self.__selected.grid()
90## self.__nearest = ChipWidget(interior,
91## label_text='Nearest')
92## self.__nearest.grid(row=0, column=1)
93
94## # TBD: this is somewhat bogus, as the code should be in a derived
95## # class of ChipWidget.
96## self.__chip = self.__nearest.component('chip')
97## self.__chip.bind('<ButtonPress-1>', self.__buttonpress)
98## self.__chip.bind('<ButtonRelease-1>', self.__buttonrelease)
99
100## # create the type-in window
101## self.__typein = TypeinWidget(interior)
102## self.__typein.grid(row=0, column=2)
103
104## # Check keywords and initialize options
105## self.initialiseoptions(PyncheWidget)
106
107## self.__typein.configure(delegate=self)
108## self.__reds.configure(delegate=self)
109## self.__greens.configure(delegate=self)
110## self.__blues.configure(delegate=self)
111
112## def __popup_about(self, event=None):
113## if not self.__about_dialog:
114## Pmw.aboutversion('1.0')
115## Pmw.aboutcopyright('Copyright (C) 1998 Barry A. Warsaw\n'
116## 'All rights reserved')
117## Pmw.aboutcontact('For information about Pynche contact:\n'
118## 'Barry A. Warsaw\n'
119## 'email: bwarsaw@python.org')
120## self.__about_dialog = Pmw.AboutDialog(
121## applicationname='Pynche -- the PYthonically Natural\n'
122## 'Color and Hue Editor')
123## self.__about_dialog.show()
124