Mercurial > cpython-lru_cache-weakref
annotate Lib/idlelib/keybindingDialog.py @ 27998:e27f58a50737 legacy-trunk
SF bug #690377: Dud footnote reference in distutils docs
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 21 Feb 2003 02:47:09 +0000 |
| parents | b8c72e86a12d |
| children | 94e5d1b8f696 |
| rev | line source |
|---|---|
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
1 """ |
| 26959 | 2 dialog for building tkinter accelerator key bindings |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
3 """ |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
4 from Tkinter import * |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
5 import tkMessageBox |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
6 import string, os |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
7 |
|
21762
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
8 class GetKeysDialog(Toplevel): |
|
21763
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
9 def __init__(self,parent,title,action,currentKeySequences): |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
10 """ |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
11 action - string, the name of the virtual event these keys will be |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
12 mapped to |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
13 currentKeys - list, a list of all key sequence lists currently mapped |
| 26959 | 14 to virtual events, for overlap checking |
|
21763
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
15 """ |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
16 Toplevel.__init__(self, parent) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
17 self.configure(borderwidth=5) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
18 self.resizable(height=FALSE,width=FALSE) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
19 self.title(title) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
20 self.transient(parent) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
21 self.grab_set() |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
22 self.protocol("WM_DELETE_WINDOW", self.Cancel) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
23 self.parent = parent |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
24 self.action=action |
|
21763
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
25 self.currentKeySequences=currentKeySequences |
|
21762
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
26 self.result='' |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
27 self.keyString=StringVar(self) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
28 self.keyString.set('') |
|
25478
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
29 self.SetModifiersForPlatform() |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
30 self.modifier_vars = [] |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
31 for modifier in self.modifiers: |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
32 variable = StringVar(self) |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
33 variable.set('') |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
34 self.modifier_vars.append(variable) |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
35 self.CreateWidgets() |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
36 self.LoadFinalKeyList() |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
37 self.withdraw() #hide while setting geometry |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
38 self.update_idletasks() |
| 26959 | 39 self.geometry("+%d+%d" % |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
40 ((parent.winfo_rootx()+((parent.winfo_width()/2) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
41 -(self.winfo_reqwidth()/2)), |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
42 parent.winfo_rooty()+((parent.winfo_height()/2) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
43 -(self.winfo_reqheight()/2)) )) ) #centre dialog over parent |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
44 self.deiconify() #geometry set, unhide |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
45 self.wait_window() |
| 26959 | 46 |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
47 def CreateWidgets(self): |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
48 frameMain = Frame(self,borderwidth=2,relief=SUNKEN) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
49 frameMain.pack(side=TOP,expand=TRUE,fill=BOTH) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
50 frameButtons=Frame(self) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
51 frameButtons.pack(side=BOTTOM,fill=X) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
52 self.buttonOk = Button(frameButtons,text='Ok', |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
53 width=8,command=self.Ok) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
54 self.buttonOk.grid(row=0,column=0,padx=5,pady=5) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
55 self.buttonCancel = Button(frameButtons,text='Cancel', |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
56 width=8,command=self.Cancel) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
57 self.buttonCancel.grid(row=0,column=1,padx=5,pady=5) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
58 self.frameKeySeqBasic = Frame(frameMain) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
59 self.frameKeySeqAdvanced = Frame(frameMain) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
60 self.frameControlsBasic = Frame(frameMain) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
61 self.frameHelpAdvanced = Frame(frameMain) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
62 self.frameKeySeqAdvanced.grid(row=0,column=0,sticky=NSEW,padx=5,pady=5) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
63 self.frameKeySeqBasic.grid(row=0,column=0,sticky=NSEW,padx=5,pady=5) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
64 self.frameKeySeqBasic.lift() |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
65 self.frameHelpAdvanced.grid(row=1,column=0,sticky=NSEW,padx=5) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
66 self.frameControlsBasic.grid(row=1,column=0,sticky=NSEW,padx=5) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
67 self.frameControlsBasic.lift() |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
68 self.buttonLevel = Button(frameMain,command=self.ToggleLevel, |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
69 text='Advanced Key Binding Entry >>') |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
70 self.buttonLevel.grid(row=2,column=0,stick=EW,padx=5,pady=5) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
71 labelTitleBasic = Label(self.frameKeySeqBasic, |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
72 text="New keys for '"+self.action+"' :") |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
73 labelTitleBasic.pack(anchor=W) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
74 labelKeysBasic = Label(self.frameKeySeqBasic,justify=LEFT, |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
75 textvariable=self.keyString,relief=GROOVE,borderwidth=2) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
76 labelKeysBasic.pack(ipadx=5,ipady=5,fill=X) |
|
25478
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
77 self.modifier_checkbuttons = {} |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
78 column = 0 |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
79 for modifier, variable in zip(self.modifiers, self.modifier_vars): |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
80 label = self.modifier_label.get(modifier, modifier) |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
81 check=Checkbutton(self.frameControlsBasic, |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
82 command=self.BuildKeyString, |
|
25478
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
83 text=label,variable=variable,onvalue=modifier,offvalue='') |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
84 check.grid(row=0,column=column,padx=2,sticky=W) |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
85 self.modifier_checkbuttons[modifier] = check |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
86 column += 1 |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
87 labelFnAdvice=Label(self.frameControlsBasic,justify=LEFT, |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
88 text="Select the desired modifier\n"+ |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
89 "keys above, and final key\n"+ |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
90 "from the list on the right.") |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
91 labelFnAdvice.grid(row=1,column=0,columnspan=4,padx=2,sticky=W) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
92 self.listKeysFinal=Listbox(self.frameControlsBasic,width=15,height=10, |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
93 selectmode=SINGLE) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
94 self.listKeysFinal.bind('<ButtonRelease-1>',self.FinalKeySelected) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
95 self.listKeysFinal.grid(row=0,column=4,rowspan=4,sticky=NS) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
96 scrollKeysFinal=Scrollbar(self.frameControlsBasic,orient=VERTICAL, |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
97 command=self.listKeysFinal.yview) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
98 self.listKeysFinal.config(yscrollcommand=scrollKeysFinal.set) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
99 scrollKeysFinal.grid(row=0,column=5,rowspan=4,sticky=NS) |
|
21762
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
100 self.buttonClear=Button(self.frameControlsBasic, |
|
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
101 text='Clear Keys',command=self.ClearKeySeq) |
|
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
102 self.buttonClear.grid(row=2,column=0,columnspan=4) |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
103 labelTitleAdvanced = Label(self.frameKeySeqAdvanced,justify=LEFT, |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
104 text="Enter new binding(s) for '"+self.action+"' :\n"+ |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
105 "(will not be checked for validity)") |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
106 labelTitleAdvanced.pack(anchor=W) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
107 self.entryKeysAdvanced=Entry(self.frameKeySeqAdvanced, |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
108 textvariable=self.keyString) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
109 self.entryKeysAdvanced.pack(fill=X) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
110 labelHelpAdvanced=Label(self.frameHelpAdvanced,justify=LEFT, |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
111 text="Key bindings are specified using tkinter key id's as\n"+ |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
112 "in these samples: <Control-f>, <Shift-F2>, <F12>,\n" |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
113 "<Control-space>, <Meta-less>, <Control-Alt-Shift-x>.\n\n"+ |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
114 "'Emacs style' multi-keystroke bindings are specified as\n"+ |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
115 "follows: <Control-x><Control-y> or <Meta-f><Meta-g>.\n\n"+ |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
116 "Multiple separate bindings for one action should be\n"+ |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
117 "separated by a space, eg., <Alt-v> <Meta-v>." ) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
118 labelHelpAdvanced.grid(row=0,column=0,sticky=NSEW) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
119 |
|
25478
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
120 def SetModifiersForPlatform(self): |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
121 """Determine list of names of key modifiers for this platform. |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
122 |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
123 The names are used to build Tk bindings -- it doesn't matter if the |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
124 keyboard has these keys, it matters if Tk understands them. The |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
125 order is also important: key binding equality depends on it, so |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
126 config-keys.def must use the same ordering. |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
127 """ |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
128 import sys |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
129 if sys.platform == 'darwin' and sys.executable.count('.app'): |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
130 self.modifiers = ['Shift', 'Control', 'Option', 'Command'] |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
131 else: |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
132 self.modifiers = ['Control', 'Alt', 'Shift'] |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
133 self.modifier_label = {'Control': 'Ctrl'} |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
134 |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
135 def ToggleLevel(self): |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
136 if self.buttonLevel.cget('text')[:8]=='Advanced': |
|
21762
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
137 self.ClearKeySeq() |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
138 self.buttonLevel.config(text='<< Basic Key Binding Entry') |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
139 self.frameKeySeqAdvanced.lift() |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
140 self.frameHelpAdvanced.lift() |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
141 self.entryKeysAdvanced.focus_set() |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
142 else: |
|
21762
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
143 self.ClearKeySeq() |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
144 self.buttonLevel.config(text='Advanced Key Binding Entry >>') |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
145 self.frameKeySeqBasic.lift() |
| 26959 | 146 self.frameControlsBasic.lift() |
| 147 | |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
148 def FinalKeySelected(self,event): |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
149 self.BuildKeyString() |
| 26959 | 150 |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
151 def BuildKeyString(self): |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
152 keyList=[] |
|
21762
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
153 modifiers=self.GetModifiers() |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
154 finalKey=self.listKeysFinal.get(ANCHOR) |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
155 if modifiers: modifiers[0]='<'+modifiers[0] |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
156 keyList=keyList+modifiers |
| 26959 | 157 if finalKey: |
| 158 if (not modifiers) and (finalKey not | |
|
22127
5994440e5dd5
further work on new config system
Steven M. Gava <elguavas@python.net>
parents:
21909
diff
changeset
|
159 in self.alphanumKeys+self.punctuationKeys): |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
160 finalKey='<'+self.TranslateKey(finalKey) |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
161 else: |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
162 finalKey=self.TranslateKey(finalKey) |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
163 keyList.append(finalKey+'>') |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
164 keyStr=string.join(keyList,'-') |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
165 self.keyString.set(keyStr) |
| 26959 | 166 |
|
21762
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
167 def GetModifiers(self): |
|
25478
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
168 modList = [variable.get() for variable in self.modifier_vars] |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
169 return filter(None, modList) |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
170 |
|
21762
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
171 def ClearKeySeq(self): |
|
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
172 self.listKeysFinal.select_clear(0,END) |
|
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
173 self.listKeysFinal.yview(MOVETO, '0.0') |
|
25478
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
174 for variable in self.modifier_vars: |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
175 variable.set('') |
|
8c95486301b3
Mac users now see correct modifiers in the Key Binding Entry window.
Tony Lownds <tony@lownds.com>
parents:
22127
diff
changeset
|
176 self.keyString.set('') |
| 26959 | 177 |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
178 def LoadFinalKeyList(self): |
|
21762
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
179 #these tuples are also available for use in validity checks |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
180 self.functionKeys=('F1','F2','F2','F4','F5','F6','F7','F8','F9', |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
181 'F10','F11','F12') |
|
21762
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
182 self.alphanumKeys=tuple(string.ascii_lowercase+string.digits) |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
183 self.punctuationKeys=tuple('~!@#%^&*()_-+={}[]|;:,.<>/?') |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
184 self.whitespaceKeys=('Tab','Space','Return') |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
185 self.editKeys=('BackSpace','Delete','Insert') |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
186 self.moveKeys=('Home','End','Page Up','Page Down','Left Arrow', |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
187 'Right Arrow','Up Arrow','Down Arrow') |
|
21762
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
188 #make a tuple of most of the useful common 'final' keys |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
189 keys=(self.alphanumKeys+self.punctuationKeys+self.functionKeys+ |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
190 self.whitespaceKeys+self.editKeys+self.moveKeys) |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
191 apply(self.listKeysFinal.insert, |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
192 (END,)+keys) |
| 26959 | 193 |
|
21764
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
194 def TranslateKey(self,key): |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
195 #translate from key list value to tkinter key-id |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
196 translateDict={'~':'asciitilde','!':'exclam','@':'at','#':'numbersign', |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
197 '%':'percent','^':'asciicircum','&':'ampersand','*':'asterisk', |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
198 '(':'parenleft',')':'parenright','_':'underscore','-':'minus', |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
199 '+':'plus','=':'equal','{':'braceleft','}':'braceright', |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
200 '[':'bracketleft',']':'bracketright','|':'bar',';':'semicolon', |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
201 ':':'colon',',':'comma','.':'period','<':'less','>':'greater', |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
202 '/':'slash','?':'question','Page Up':'Prior','Page Down':'Next', |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
203 'Left Arrow':'Left','Right Arrow':'Right','Up Arrow':'Up', |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
204 'Down Arrow': 'Down'} |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
205 if key in translateDict.keys(): |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
206 key=translateDict[key] |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
207 key='Key-'+key |
|
0110a0983e61
further work on keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21763
diff
changeset
|
208 return key |
| 26959 | 209 |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
210 def Ok(self, event=None): |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
211 if self.KeysOk(): |
|
21762
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
212 self.result=self.keyString.get() |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
213 self.destroy() |
| 26959 | 214 |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
215 def Cancel(self, event=None): |
|
21762
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
216 self.result='' |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
217 self.destroy() |
| 26959 | 218 |
|
21763
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
219 def KeysOk(self): |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
220 #simple validity check |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
221 keysOk=1 |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
222 keys=self.keyString.get() |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
223 keys.strip() |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
224 finalKey=self.listKeysFinal.get(ANCHOR) |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
225 modifiers=self.GetModifiers() |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
226 keySequence=keys.split()#make into a key sequence list for overlap check |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
227 if not keys: #no keys specified |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
228 tkMessageBox.showerror(title='Key Sequence Error', |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
229 message='No keys specified.') |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
230 keysOk=0 |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
231 elif not keys.endswith('>'): #no final key specified |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
232 tkMessageBox.showerror(title='Key Sequence Error', |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
233 message='No final key specified.') |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
234 keysOk=0 |
| 26959 | 235 elif (not modifiers) and (finalKey in |
|
22127
5994440e5dd5
further work on new config system
Steven M. Gava <elguavas@python.net>
parents:
21909
diff
changeset
|
236 self.alphanumKeys+self.punctuationKeys): |
|
5994440e5dd5
further work on new config system
Steven M. Gava <elguavas@python.net>
parents:
21909
diff
changeset
|
237 #modifier required |
|
21763
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
238 tkMessageBox.showerror(title='Key Sequence Error', |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
239 message='No modifier key(s) specified.') |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
240 keysOk=0 |
| 26959 | 241 elif (modifiers==['Shift']) and (finalKey not |
|
22127
5994440e5dd5
further work on new config system
Steven M. Gava <elguavas@python.net>
parents:
21909
diff
changeset
|
242 in self.functionKeys+('Tab',)): |
|
21763
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
243 #shift alone is only a useful modifier with a function key |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
244 tkMessageBox.showerror(title='Key Sequence Error', |
|
22127
5994440e5dd5
further work on new config system
Steven M. Gava <elguavas@python.net>
parents:
21909
diff
changeset
|
245 message='Shift alone is not a useful modifier '+ |
|
5994440e5dd5
further work on new config system
Steven M. Gava <elguavas@python.net>
parents:
21909
diff
changeset
|
246 'when used with this final key key.') |
|
21763
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
247 keysOk=0 |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
248 elif keySequence in self.currentKeySequences: #keys combo already in use |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
249 tkMessageBox.showerror(title='Key Sequence Error', |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
250 message='This key combination is already in use.') |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
251 keysOk=0 |
|
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
252 return keysOk |
| 26959 | 253 |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
254 if __name__ == '__main__': |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
255 #test the dialog |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
256 root=Tk() |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
257 def run(): |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
258 keySeq='' |
|
21763
652dc51b5f83
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21762
diff
changeset
|
259 dlg=GetKeysDialog(root,'Get Keys','find-again',[]) |
|
21762
a1b0658293a7
keybinding configuration
Steven M. Gava <elguavas@python.net>
parents:
21711
diff
changeset
|
260 print dlg.result |
|
21711
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
261 Button(root,text='Dialog',command=run).pack() |
|
437393e780cb
key binding handling dialog
Steven M. Gava <elguavas@python.net>
parents:
diff
changeset
|
262 root.mainloop() |
