Barry Warsaw | fefbf79 | 1998-01-31 23:39:01 +0000 | [diff] [blame] | 1 | """Main Pynche (Pythonically Natural Color and Hue Editor) widget. |
| 2 | """ |
| 3 | |
Barry Warsaw | a69c1ba | 1998-09-28 23:38:44 +0000 | [diff] [blame] | 4 | import sys |
Barry Warsaw | fefbf79 | 1998-01-31 23:39:01 +0000 | [diff] [blame] | 5 | from Tkinter import * |
Barry Warsaw | a69c1ba | 1998-09-28 23:38:44 +0000 | [diff] [blame] | 6 | |
| 7 | # Milliseconds between interrupt checks |
| 8 | KEEPALIVE_TIMER = 500 |
Barry Warsaw | fefbf79 | 1998-01-31 23:39:01 +0000 | [diff] [blame] | 9 | |
Barry Warsaw | 552ac17 | 1998-02-17 22:25:23 +0000 | [diff] [blame] | 10 | |
| 11 | |
Barry Warsaw | a69c1ba | 1998-09-28 23:38:44 +0000 | [diff] [blame] | 12 | class 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 Warsaw | 552ac17 | 1998-02-17 22:25:23 +0000 | [diff] [blame] | 61 | |
Barry Warsaw | a69c1ba | 1998-09-28 23:38:44 +0000 | [diff] [blame] | 62 | 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 Warsaw | 552ac17 | 1998-02-17 22:25:23 +0000 | [diff] [blame] | 66 | |
| 67 | def __quit(self, event=None): |
Barry Warsaw | a69c1ba | 1998-09-28 23:38:44 +0000 | [diff] [blame] | 68 | sys.exit(0) |
Barry Warsaw | 552ac17 | 1998-02-17 22:25:23 +0000 | [diff] [blame] | 69 | |
Barry Warsaw | a69c1ba | 1998-09-28 23:38:44 +0000 | [diff] [blame] | 70 | def start(self): |
| 71 | self.__keepalive() |
| 72 | self.__root.mainloop() |
| 73 | |
| 74 | def parent(self): |
| 75 | return self.__root |
Barry Warsaw | f67575d | 1998-03-10 00:17:01 +0000 | [diff] [blame] | 76 | |
| 77 | def __popup_options(self, event=None): |
Barry Warsaw | a69c1ba | 1998-09-28 23:38:44 +0000 | [diff] [blame] | 78 | print 'Options...' |
Barry Warsaw | a114eb5 | 1998-03-16 23:08:35 +0000 | [diff] [blame] | 79 | |
Barry Warsaw | a69c1ba | 1998-09-28 23:38:44 +0000 | [diff] [blame] | 80 | 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 | |