Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
55698cc3
Commit
55698cc3
authored
Dec 27, 2018
by
Cheryl Sabella
Committed by
Terry Jan Reedy
Dec 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-35598: IDLE: Update config_key.py with PEP8 names (GH-11330)
A few other changes make the code easier to follow.
parent
0133f9fc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
217 additions
and
187 deletions
+217
-187
Lib/idlelib/config_key.py
Lib/idlelib/config_key.py
+191
-161
Lib/idlelib/idle_test/htest.py
Lib/idlelib/idle_test/htest.py
+1
-2
Lib/idlelib/idle_test/test_config_key.py
Lib/idlelib/idle_test/test_config_key.py
+24
-24
Misc/NEWS.d/next/IDLE/2018-12-27-15-29-11.bpo-35598.FWOOm8.rst
...NEWS.d/next/IDLE/2018-12-27-15-29-11.bpo-35598.FWOOm8.rst
+1
-0
No files found.
Lib/idlelib/config_key.py
View file @
55698cc3
...
...
@@ -13,39 +13,42 @@ class GetKeysDialog(Toplevel):
# Dialog title for invalid key sequence
keyerror_title
=
'Key Sequence Error'
def
__init__
(
self
,
parent
,
title
,
action
,
current
KeyS
equences
,
def
__init__
(
self
,
parent
,
title
,
action
,
current
_key_s
equences
,
*
,
_htest
=
False
,
_utest
=
False
):
"""
parent - parent of this dialog
title - string which is the title of the popup dialog
action - string, the name of the virtual event these keys will be
mapped to
currentKeys - list, a list of all key sequence lists currently mapped
to virtual events, for overlap checking
_utest - bool, do not wait when running unittest
current_key_sequences - list, a list of all key sequence lists
currently mapped to virtual events, for overlap checking
_htest - bool, change box location when running htest
_utest - bool, do not wait when running unittest
"""
Toplevel
.
__init__
(
self
,
parent
)
self
.
withdraw
()
#hide while setting geometry
self
.
withdraw
()
# Hide while setting geometry.
self
.
configure
(
borderwidth
=
5
)
self
.
resizable
(
height
=
F
ALSE
,
width
=
FALSE
)
self
.
resizable
(
height
=
F
alse
,
width
=
False
)
self
.
title
(
title
)
self
.
transient
(
parent
)
self
.
grab_set
()
self
.
protocol
(
"WM_DELETE_WINDOW"
,
self
.
C
ancel
)
self
.
protocol
(
"WM_DELETE_WINDOW"
,
self
.
c
ancel
)
self
.
parent
=
parent
self
.
action
=
action
self
.
current
KeySequences
=
currentKeyS
equences
self
.
action
=
action
self
.
current
_key_sequences
=
current_key_s
equences
self
.
result
=
''
self
.
keyString
=
StringVar
(
self
)
self
.
keyString
.
set
(
''
)
self
.
SetModifiersForPlatform
()
# set self.modifiers, self.modifier_label
self
.
key_string
=
StringVar
(
self
)
self
.
key_string
.
set
(
''
)
# Set self.modifiers, self.modifier_label.
self
.
set_modifiers_for_platform
()
self
.
modifier_vars
=
[]
for
modifier
in
self
.
modifiers
:
variable
=
StringVar
(
self
)
variable
.
set
(
''
)
self
.
modifier_vars
.
append
(
variable
)
self
.
advanced
=
False
self
.
CreateW
idgets
()
self
.
LoadFinalKeyL
ist
()
self
.
create_w
idgets
()
self
.
load_final_key_l
ist
()
self
.
update_idletasks
()
self
.
geometry
(
"+%d+%d"
%
(
...
...
@@ -54,83 +57,99 @@ class GetKeysDialog(Toplevel):
parent
.
winfo_rooty
()
+
((
parent
.
winfo_height
()
/
2
-
self
.
winfo_reqheight
()
/
2
)
if
not
_htest
else
150
)
)
)
#
centre dialog over parent (or below htest box)
)
)
#
Center dialog over parent (or below htest box).
if
not
_utest
:
self
.
deiconify
()
#geometry set, unhide
self
.
deiconify
()
# Geometry set, unhide.
self
.
wait_window
()
def
showerror
(
self
,
*
args
,
**
kwargs
):
# Make testing easier. Replace in #30751.
messagebox
.
showerror
(
*
args
,
**
kwargs
)
def
CreateWidgets
(
self
):
frameMain
=
Frame
(
self
,
borderwidth
=
2
,
relief
=
SUNKEN
)
frameMain
.
pack
(
side
=
TOP
,
expand
=
TRUE
,
fill
=
BOTH
)
frameButtons
=
Frame
(
self
)
frameButtons
.
pack
(
side
=
BOTTOM
,
fill
=
X
)
self
.
buttonOK
=
Button
(
frameButtons
,
text
=
'OK'
,
width
=
8
,
command
=
self
.
OK
)
self
.
buttonOK
.
grid
(
row
=
0
,
column
=
0
,
padx
=
5
,
pady
=
5
)
self
.
buttonCancel
=
Button
(
frameButtons
,
text
=
'Cancel'
,
width
=
8
,
command
=
self
.
Cancel
)
self
.
buttonCancel
.
grid
(
row
=
0
,
column
=
1
,
padx
=
5
,
pady
=
5
)
self
.
frameKeySeqBasic
=
Frame
(
frameMain
)
self
.
frameKeySeqAdvanced
=
Frame
(
frameMain
)
self
.
frameControlsBasic
=
Frame
(
frameMain
)
self
.
frameHelpAdvanced
=
Frame
(
frameMain
)
self
.
frameKeySeqAdvanced
.
grid
(
row
=
0
,
column
=
0
,
sticky
=
NSEW
,
padx
=
5
,
pady
=
5
)
self
.
frameKeySeqBasic
.
grid
(
row
=
0
,
column
=
0
,
sticky
=
NSEW
,
padx
=
5
,
pady
=
5
)
self
.
frameKeySeqBasic
.
lift
()
self
.
frameHelpAdvanced
.
grid
(
row
=
1
,
column
=
0
,
sticky
=
NSEW
,
padx
=
5
)
self
.
frameControlsBasic
.
grid
(
row
=
1
,
column
=
0
,
sticky
=
NSEW
,
padx
=
5
)
self
.
frameControlsBasic
.
lift
()
self
.
buttonLevel
=
Button
(
frameMain
,
command
=
self
.
ToggleLevel
,
text
=
'Advanced Key Binding Entry >>'
)
self
.
buttonLevel
.
grid
(
row
=
2
,
column
=
0
,
stick
=
EW
,
padx
=
5
,
pady
=
5
)
labelTitleBasic
=
Label
(
self
.
frameKeySeqBasic
,
text
=
"New keys for '"
+
self
.
action
+
"' :"
)
labelTitleBasic
.
pack
(
anchor
=
W
)
labelKeysBasic
=
Label
(
self
.
frameKeySeqBasic
,
justify
=
LEFT
,
textvariable
=
self
.
keyString
,
relief
=
GROOVE
,
borderwidth
=
2
)
labelKeysBasic
.
pack
(
ipadx
=
5
,
ipady
=
5
,
fill
=
X
)
def
create_widgets
(
self
):
frame
=
Frame
(
self
,
borderwidth
=
2
,
relief
=
SUNKEN
)
frame
.
pack
(
side
=
TOP
,
expand
=
True
,
fill
=
BOTH
)
frame_buttons
=
Frame
(
self
)
frame_buttons
.
pack
(
side
=
BOTTOM
,
fill
=
X
)
self
.
button_ok
=
Button
(
frame_buttons
,
text
=
'OK'
,
width
=
8
,
command
=
self
.
ok
)
self
.
button_ok
.
grid
(
row
=
0
,
column
=
0
,
padx
=
5
,
pady
=
5
)
self
.
button_cancel
=
Button
(
frame_buttons
,
text
=
'Cancel'
,
width
=
8
,
command
=
self
.
cancel
)
self
.
button_cancel
.
grid
(
row
=
0
,
column
=
1
,
padx
=
5
,
pady
=
5
)
# Basic entry key sequence.
self
.
frame_keyseq_basic
=
Frame
(
frame
)
self
.
frame_keyseq_basic
.
grid
(
row
=
0
,
column
=
0
,
sticky
=
NSEW
,
padx
=
5
,
pady
=
5
)
basic_title
=
Label
(
self
.
frame_keyseq_basic
,
text
=
f"New keys for '
{
self
.
action
}
' :"
)
basic_title
.
pack
(
anchor
=
W
)
basic_keys
=
Label
(
self
.
frame_keyseq_basic
,
justify
=
LEFT
,
textvariable
=
self
.
key_string
,
relief
=
GROOVE
,
borderwidth
=
2
)
basic_keys
.
pack
(
ipadx
=
5
,
ipady
=
5
,
fill
=
X
)
# Basic entry controls.
self
.
frame_controls_basic
=
Frame
(
frame
)
self
.
frame_controls_basic
.
grid
(
row
=
1
,
column
=
0
,
sticky
=
NSEW
,
padx
=
5
)
# Basic entry modifiers.
self
.
modifier_checkbuttons
=
{}
column
=
0
for
modifier
,
variable
in
zip
(
self
.
modifiers
,
self
.
modifier_vars
):
label
=
self
.
modifier_label
.
get
(
modifier
,
modifier
)
check
=
Checkbutton
(
self
.
frameControlsB
asic
,
command
=
self
.
BuildKeyString
,
text
=
label
,
variable
=
variable
,
onvalue
=
modifier
,
offvalue
=
''
)
check
.
grid
(
row
=
0
,
column
=
column
,
padx
=
2
,
sticky
=
W
)
check
=
Checkbutton
(
self
.
frame_controls_b
asic
,
command
=
self
.
build_key_string
,
text
=
label
,
variable
=
variable
,
onvalue
=
modifier
,
offvalue
=
''
)
check
.
grid
(
row
=
0
,
column
=
column
,
padx
=
2
,
sticky
=
W
)
self
.
modifier_checkbuttons
[
modifier
]
=
check
column
+=
1
labelFnAdvice
=
Label
(
self
.
frameControlsBasic
,
justify
=
LEFT
,
text
=
\
"Select the desired modifier keys
\
n
"
+
"above, and the final key from the
\
n
"
+
"list on the right.
\
n
\
n
"
+
"Use upper case Symbols when using
\
n
"
+
"the Shift modifier. (Letters will be
\
n
"
+
"converted automatically.)"
)
labelFnAdvice
.
grid
(
row
=
1
,
column
=
0
,
columnspan
=
4
,
padx
=
2
,
sticky
=
W
)
self
.
listKeysFinal
=
Listbox
(
self
.
frameControlsBasic
,
width
=
15
,
height
=
10
,
selectmode
=
SINGLE
)
self
.
listKeysFinal
.
bind
(
'<ButtonRelease-1>'
,
self
.
FinalKeySelected
)
self
.
listKeysFinal
.
grid
(
row
=
0
,
column
=
4
,
rowspan
=
4
,
sticky
=
NS
)
scrollKeysFinal
=
Scrollbar
(
self
.
frameControlsBasic
,
orient
=
VERTICAL
,
command
=
self
.
listKeysFinal
.
yview
)
self
.
listKeysFinal
.
config
(
yscrollcommand
=
scrollKeysFinal
.
set
)
scrollKeysFinal
.
grid
(
row
=
0
,
column
=
5
,
rowspan
=
4
,
sticky
=
NS
)
self
.
buttonClear
=
Button
(
self
.
frameControlsBasic
,
text
=
'Clear Keys'
,
command
=
self
.
ClearKeySeq
)
self
.
buttonClear
.
grid
(
row
=
2
,
column
=
0
,
columnspan
=
4
)
labelTitleAdvanced
=
Label
(
self
.
frameKeySeqAdvanced
,
justify
=
LEFT
,
text
=
"Enter new binding(s) for '"
+
self
.
action
+
"' :
\
n
"
+
"(These bindings will not be checked for validity!)"
)
labelTitleAdvanced
.
pack
(
anchor
=
W
)
self
.
entryKeysAdvanced
=
Entry
(
self
.
frameKeySeqAdvanced
,
textvariable
=
self
.
keyString
)
self
.
entryKeysAdvanced
.
pack
(
fill
=
X
)
labelHelpAdvanced
=
Label
(
self
.
frameHelpAdvanced
,
justify
=
LEFT
,
# Basic entry help text.
help_basic
=
Label
(
self
.
frame_controls_basic
,
justify
=
LEFT
,
text
=
"Select the desired modifier keys
\
n
"
+
"above, and the final key from the
\
n
"
+
"list on the right.
\
n
\
n
"
+
"Use upper case Symbols when using
\
n
"
+
"the Shift modifier. (Letters will be
\
n
"
+
"converted automatically.)"
)
help_basic
.
grid
(
row
=
1
,
column
=
0
,
columnspan
=
4
,
padx
=
2
,
sticky
=
W
)
# Basic entry key list.
self
.
list_keys_final
=
Listbox
(
self
.
frame_controls_basic
,
width
=
15
,
height
=
10
,
selectmode
=
SINGLE
)
self
.
list_keys_final
.
bind
(
'<ButtonRelease-1>'
,
self
.
final_key_selected
)
self
.
list_keys_final
.
grid
(
row
=
0
,
column
=
4
,
rowspan
=
4
,
sticky
=
NS
)
scroll_keys_final
=
Scrollbar
(
self
.
frame_controls_basic
,
orient
=
VERTICAL
,
command
=
self
.
list_keys_final
.
yview
)
self
.
list_keys_final
.
config
(
yscrollcommand
=
scroll_keys_final
.
set
)
scroll_keys_final
.
grid
(
row
=
0
,
column
=
5
,
rowspan
=
4
,
sticky
=
NS
)
self
.
button_clear
=
Button
(
self
.
frame_controls_basic
,
text
=
'Clear Keys'
,
command
=
self
.
clear_key_seq
)
self
.
button_clear
.
grid
(
row
=
2
,
column
=
0
,
columnspan
=
4
)
# Advanced entry key sequence.
self
.
frame_keyseq_advanced
=
Frame
(
frame
)
self
.
frame_keyseq_advanced
.
grid
(
row
=
0
,
column
=
0
,
sticky
=
NSEW
,
padx
=
5
,
pady
=
5
)
advanced_title
=
Label
(
self
.
frame_keyseq_advanced
,
justify
=
LEFT
,
text
=
f"Enter new binding(s) for '
{
self
.
action
}
' :
\
n
"
+
"(These bindings will not be checked for validity!)"
)
advanced_title
.
pack
(
anchor
=
W
)
self
.
advanced_keys
=
Entry
(
self
.
frame_keyseq_advanced
,
textvariable
=
self
.
key_string
)
self
.
advanced_keys
.
pack
(
fill
=
X
)
# Advanced entry help text.
self
.
frame_help_advanced
=
Frame
(
frame
)
self
.
frame_help_advanced
.
grid
(
row
=
1
,
column
=
0
,
sticky
=
NSEW
,
padx
=
5
)
help_advanced
=
Label
(
self
.
frame_help_advanced
,
justify
=
LEFT
,
text
=
"Key bindings are specified using Tkinter keysyms as
\
n
"
+
"in these samples: <Control-f>, <Shift-F2>, <F12>,
\
n
"
"<Control-space>, <Meta-less>, <Control-Alt-Shift-X>.
\
n
"
...
...
@@ -140,13 +159,19 @@ class GetKeysDialog(Toplevel):
"is the 'do-nothing' keybinding.
\
n
\
n
"
+
"Multiple separate bindings for one action should be
\
n
"
+
"separated by a space, eg., <Alt-v> <Meta-v>."
)
labelHelpAdvanced
.
grid
(
row
=
0
,
column
=
0
,
sticky
=
NSEW
)
help_advanced
.
grid
(
row
=
0
,
column
=
0
,
sticky
=
NSEW
)
# Switch between basic and advanced.
self
.
button_level
=
Button
(
frame
,
command
=
self
.
toggle_level
,
text
=
'<< Basic Key Binding Entry'
)
self
.
button_level
.
grid
(
row
=
2
,
column
=
0
,
stick
=
EW
,
padx
=
5
,
pady
=
5
)
self
.
toggle_level
()
def
SetModifiersForP
latform
(
self
):
def
set_modifiers_for_p
latform
(
self
):
"""Determine list of names of key modifiers for this platform.
The names are used to build Tk bindings -- it doesn't matter if the
keyboard has these keys
, it matters if Tk understands them.
The
keyboard has these keys
; it matters if Tk understands them.
The
order is also important: key binding equality depends on it, so
config-keys.def must use the same ordering.
"""
...
...
@@ -154,118 +179,124 @@ class GetKeysDialog(Toplevel):
self
.
modifiers
=
[
'Shift'
,
'Control'
,
'Option'
,
'Command'
]
else
:
self
.
modifiers
=
[
'Control'
,
'Alt'
,
'Shift'
]
self
.
modifier_label
=
{
'Control'
:
'Ctrl'
}
# short name
def
ToggleLevel
(
self
):
if
self
.
buttonLevel
.
cget
(
'text'
)[:
8
]
==
'Advanced'
:
self
.
ClearKeySeq
()
self
.
buttonLevel
.
config
(
text
=
'<< Basic Key Binding Entry'
)
self
.
frameKeySeqAdvanced
.
lift
()
self
.
frameHelpAdvanced
.
lift
()
self
.
entryKeysAdvanced
.
focus_set
()
self
.
modifier_label
=
{
'Control'
:
'Ctrl'
}
# Short name.
def
toggle_level
(
self
):
"Toggle between basic and advanced keys."
if
self
.
button_level
.
cget
(
'text'
).
startswith
(
'Advanced'
):
self
.
clear_key_seq
()
self
.
button_level
.
config
(
text
=
'<< Basic Key Binding Entry'
)
self
.
frame_keyseq_advanced
.
lift
()
self
.
frame_help_advanced
.
lift
()
self
.
advanced_keys
.
focus_set
()
self
.
advanced
=
True
else
:
self
.
ClearKeyS
eq
()
self
.
button
L
evel
.
config
(
text
=
'Advanced Key Binding Entry >>'
)
self
.
frame
KeySeqB
asic
.
lift
()
self
.
frame
ControlsB
asic
.
lift
()
self
.
clear_key_s
eq
()
self
.
button
_l
evel
.
config
(
text
=
'Advanced Key Binding Entry >>'
)
self
.
frame
_keyseq_b
asic
.
lift
()
self
.
frame
_controls_b
asic
.
lift
()
self
.
advanced
=
False
def
FinalKeySelected
(
self
,
event
):
self
.
BuildKeyString
()
def
final_key_selected
(
self
,
event
):
"Handler for clicking on key in basic settings list."
self
.
build_key_string
()
def
BuildKeyString
(
self
):
keyList
=
modifiers
=
self
.
GetModifiers
()
finalKey
=
self
.
listKeysFinal
.
get
(
ANCHOR
)
if
finalKey
:
finalKey
=
self
.
TranslateKey
(
finalKey
,
modifiers
)
keyList
.
append
(
finalKey
)
self
.
keyString
.
set
(
'<'
+
'-'
.
join
(
keyList
)
+
'>'
)
def
build_key_string
(
self
):
"Create formatted string of modifiers plus the key."
keylist
=
modifiers
=
self
.
get_modifiers
()
final_key
=
self
.
list_keys_final
.
get
(
ANCHOR
)
if
final_key
:
final_key
=
self
.
translate_key
(
final_key
,
modifiers
)
keylist
.
append
(
final_key
)
self
.
key_string
.
set
(
f"<
{
'-'
.
join
(
keylist
)
}
>"
)
def
GetModifiers
(
self
):
modList
=
[
variable
.
get
()
for
variable
in
self
.
modifier_vars
]
return
[
mod
for
mod
in
modList
if
mod
]
def
get_modifiers
(
self
):
"Return ordered list of modifiers that have been selected."
mod_list
=
[
variable
.
get
()
for
variable
in
self
.
modifier_vars
]
return
[
mod
for
mod
in
mod_list
if
mod
]
def
ClearKeySeq
(
self
):
self
.
listKeysFinal
.
select_clear
(
0
,
END
)
self
.
listKeysFinal
.
yview
(
MOVETO
,
'0.0'
)
def
clear_key_seq
(
self
):
"Clear modifiers and keys selection."
self
.
list_keys_final
.
select_clear
(
0
,
END
)
self
.
list_keys_final
.
yview
(
MOVETO
,
'0.0'
)
for
variable
in
self
.
modifier_vars
:
variable
.
set
(
''
)
self
.
keyString
.
set
(
''
)
def
LoadFinalKeyList
(
self
):
#these tuples are also available for use in validity checks
self
.
functionKeys
=
(
'F1'
,
'F2'
,
'F3'
,
'F4'
,
'F5'
,
'F6'
,
'F7'
,
'F8'
,
'F9'
,
'F10'
,
'F11'
,
'F12'
)
self
.
alphanumKeys
=
tuple
(
string
.
ascii_lowercase
+
string
.
digits
)
self
.
punctuationKeys
=
tuple
(
'~!@#%^&*()_-+={}[]|;:,.<>/?'
)
self
.
whitespaceKeys
=
(
'Tab'
,
'Space'
,
'Return'
)
self
.
editKeys
=
(
'BackSpace'
,
'Delete'
,
'Insert'
)
self
.
moveKeys
=
(
'Home'
,
'End'
,
'Page Up'
,
'Page Down'
,
'Left Arrow'
,
'Right Arrow'
,
'Up Arrow'
,
'Down Arrow'
)
#make a tuple of most of the useful common 'final' keys
keys
=
(
self
.
alphanumKeys
+
self
.
punctuationKeys
+
self
.
functionKeys
+
self
.
whitespaceKeys
+
self
.
editKeys
+
self
.
moveKeys
)
self
.
listKeysFinal
.
insert
(
END
,
*
keys
)
def
TranslateKey
(
self
,
key
,
modifiers
):
"Translate from keycap symbol to the Tkinter keysym"
translateDict
=
{
'Space'
:
'space'
,
'~'
:
'asciitilde'
,
'!'
:
'exclam'
,
'@'
:
'at'
,
'#'
:
'numbersign'
,
'%'
:
'percent'
,
'^'
:
'asciicircum'
,
'&'
:
'ampersand'
,
'*'
:
'asterisk'
,
'('
:
'parenleft'
,
')'
:
'parenright'
,
'_'
:
'underscore'
,
'-'
:
'minus'
,
'+'
:
'plus'
,
'='
:
'equal'
,
'{'
:
'braceleft'
,
'}'
:
'braceright'
,
'['
:
'bracketleft'
,
']'
:
'bracketright'
,
'|'
:
'bar'
,
';'
:
'semicolon'
,
':'
:
'colon'
,
','
:
'comma'
,
'.'
:
'period'
,
'<'
:
'less'
,
'>'
:
'greater'
,
'/'
:
'slash'
,
'?'
:
'question'
,
'Page Up'
:
'Prior'
,
'Page Down'
:
'Next'
,
'Left Arrow'
:
'Left'
,
'Right Arrow'
:
'Right'
,
'Up Arrow'
:
'Up'
,
'Down Arrow'
:
'Down'
,
'Tab'
:
'Tab'
}
if
key
in
translateDict
:
key
=
translateDict
[
key
]
self
.
key_string
.
set
(
''
)
def
load_final_key_list
(
self
):
"Populate listbox of available keys."
# These tuples are also available for use in validity checks.
self
.
function_keys
=
(
'F1'
,
'F2'
,
'F3'
,
'F4'
,
'F5'
,
'F6'
,
'F7'
,
'F8'
,
'F9'
,
'F10'
,
'F11'
,
'F12'
)
self
.
alphanum_keys
=
tuple
(
string
.
ascii_lowercase
+
string
.
digits
)
self
.
punctuation_keys
=
tuple
(
'~!@#%^&*()_-+={}[]|;:,.<>/?'
)
self
.
whitespace_keys
=
(
'Tab'
,
'Space'
,
'Return'
)
self
.
edit_keys
=
(
'BackSpace'
,
'Delete'
,
'Insert'
)
self
.
move_keys
=
(
'Home'
,
'End'
,
'Page Up'
,
'Page Down'
,
'Left Arrow'
,
'Right Arrow'
,
'Up Arrow'
,
'Down Arrow'
)
# Make a tuple of most of the useful common 'final' keys.
keys
=
(
self
.
alphanum_keys
+
self
.
punctuation_keys
+
self
.
function_keys
+
self
.
whitespace_keys
+
self
.
edit_keys
+
self
.
move_keys
)
self
.
list_keys_final
.
insert
(
END
,
*
keys
)
@
staticmethod
def
translate_key
(
key
,
modifiers
):
"Translate from keycap symbol to the Tkinter keysym."
translate_dict
=
{
'Space'
:
'space'
,
'~'
:
'asciitilde'
,
'!'
:
'exclam'
,
'@'
:
'at'
,
'#'
:
'numbersign'
,
'%'
:
'percent'
,
'^'
:
'asciicircum'
,
'&'
:
'ampersand'
,
'*'
:
'asterisk'
,
'('
:
'parenleft'
,
')'
:
'parenright'
,
'_'
:
'underscore'
,
'-'
:
'minus'
,
'+'
:
'plus'
,
'='
:
'equal'
,
'{'
:
'braceleft'
,
'}'
:
'braceright'
,
'['
:
'bracketleft'
,
']'
:
'bracketright'
,
'|'
:
'bar'
,
';'
:
'semicolon'
,
':'
:
'colon'
,
','
:
'comma'
,
'.'
:
'period'
,
'<'
:
'less'
,
'>'
:
'greater'
,
'/'
:
'slash'
,
'?'
:
'question'
,
'Page Up'
:
'Prior'
,
'Page Down'
:
'Next'
,
'Left Arrow'
:
'Left'
,
'Right Arrow'
:
'Right'
,
'Up Arrow'
:
'Up'
,
'Down Arrow'
:
'Down'
,
'Tab'
:
'Tab'
}
if
key
in
translate_dict
:
key
=
translate_dict
[
key
]
if
'Shift'
in
modifiers
and
key
in
string
.
ascii_lowercase
:
key
=
key
.
upper
()
key
=
'Key-'
+
key
return
key
return
f'Key-
{
key
}
'
def
OK
(
self
,
event
=
None
):
keys
=
self
.
key
S
tring
.
get
().
strip
()
def
ok
(
self
,
event
=
None
):
keys
=
self
.
key
_s
tring
.
get
().
strip
()
if
not
keys
:
self
.
showerror
(
title
=
self
.
keyerror_title
,
parent
=
self
,
message
=
"No key specified."
)
return
if
(
self
.
advanced
or
self
.
KeysOK
(
keys
))
and
self
.
bind_ok
(
keys
):
if
(
self
.
advanced
or
self
.
keys_ok
(
keys
))
and
self
.
bind_ok
(
keys
):
self
.
result
=
keys
self
.
grab_release
()
self
.
destroy
()
def
C
ancel
(
self
,
event
=
None
):
self
.
result
=
''
def
c
ancel
(
self
,
event
=
None
):
self
.
result
=
''
self
.
grab_release
()
self
.
destroy
()
def
KeysOK
(
self
,
keys
):
'''
Validity check on user's 'basic' keybinding selection.
def
keys_ok
(
self
,
keys
):
"""
Validity check on user's 'basic' keybinding selection.
Doesn't check the string produced by the advanced dialog because
'modifiers' isn't set.
'''
finalKey
=
self
.
listKeysFinal
.
get
(
ANCHOR
)
modifiers
=
self
.
GetModifiers
()
keysOK
=
False
"""
final_key
=
self
.
list_keys_final
.
get
(
ANCHOR
)
modifiers
=
self
.
get_modifiers
()
title
=
self
.
keyerror_title
key_sequences
=
[
key
for
keylist
in
self
.
current
KeyS
equences
key_sequences
=
[
key
for
keylist
in
self
.
current
_key_s
equences
for
key
in
keylist
]
if
not
keys
.
endswith
(
'>'
):
self
.
showerror
(
title
,
parent
=
self
,
message
=
'Missing the final Key'
)
elif
(
not
modifiers
and
final
Key
not
in
self
.
functionKeys
+
self
.
moveK
eys
):
and
final
_key
not
in
self
.
function_keys
+
self
.
move_k
eys
):
self
.
showerror
(
title
=
title
,
parent
=
self
,
message
=
'No modifier key(s) specified.'
)
elif
(
modifiers
==
[
'Shift'
])
\
and
(
final
K
ey
not
in
self
.
function
Keys
+
self
.
moveK
eys
+
(
'Tab'
,
'Space'
)):
and
(
final
_k
ey
not
in
self
.
function
_keys
+
self
.
move_k
eys
+
(
'Tab'
,
'Space'
)):
msg
=
'The shift modifier by itself may not be used with'
\
' this key symbol.'
self
.
showerror
(
title
=
title
,
parent
=
self
,
message
=
msg
)
...
...
@@ -273,12 +304,11 @@ class GetKeysDialog(Toplevel):
msg
=
'This key combination is already in use.'
self
.
showerror
(
title
=
title
,
parent
=
self
,
message
=
msg
)
else
:
keysOK
=
True
return
keysOK
return
True
return
False
def
bind_ok
(
self
,
keys
):
"Return True if Tcl accepts the new keys else show message."
try
:
binding
=
self
.
bind
(
keys
,
lambda
:
None
)
except
TclError
as
err
:
...
...
Lib/idlelib/idle_test/htest.py
View file @
55698cc3
...
...
@@ -141,12 +141,11 @@ _editor_window_spec = {
"Best to close editor first."
}
# Update once issue21519 is resolved.
GetKeysDialog_spec
=
{
'file'
:
'config_key'
,
'kwds'
:
{
'title'
:
'Test keybindings'
,
'action'
:
'find-again'
,
'current
KeySequences'
:
[
''
]
,
'current
_key_sequences'
:
[[
'<Control-Key-g>'
,
'<Key-F3>'
,
'<Control-Key-G>'
]]
,
'_htest'
:
True
,
},
'msg'
:
"Test for different key modifier sequences.
\
n
"
...
...
Lib/idlelib/idle_test/test_config_key.py
View file @
55698cc3
"Test config_key, coverage
75
%"
"Test config_key, coverage
82
%"
from
idlelib
import
config_key
from
test.support
import
requires
...
...
@@ -9,15 +9,15 @@ from idlelib.idle_test.mock_tk import Mbox_func
class
ValidationTest
(
unittest
.
TestCase
):
"Test validation methods:
OK, KeysOK
, bind_ok."
"Test validation methods:
ok, keys_ok
, bind_ok."
class
Validator
(
config_key
.
GetKeysDialog
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
config_key
.
GetKeysDialog
.
__init__
(
self
,
*
args
,
**
kwargs
)
class
list
KeysF
inal
:
class
list
_keys_f
inal
:
get
=
Func
()
self
.
list
KeysFinal
=
listKeysF
inal
GetM
odifiers
=
Func
()
self
.
list
_keys_final
=
list_keys_f
inal
get_m
odifiers
=
Func
()
showerror
=
Mbox_func
()
@
classmethod
...
...
@@ -31,7 +31,7 @@ class ValidationTest(unittest.TestCase):
@
classmethod
def
tearDownClass
(
cls
):
cls
.
dialog
.
C
ancel
()
cls
.
dialog
.
c
ancel
()
cls
.
root
.
update_idletasks
()
cls
.
root
.
destroy
()
del
cls
.
dialog
,
cls
.
root
...
...
@@ -42,49 +42,49 @@ class ValidationTest(unittest.TestCase):
# A test that sets a non-blank modifier list should reset it to [].
def
test_ok_empty
(
self
):
self
.
dialog
.
key
S
tring
.
set
(
' '
)
self
.
dialog
.
OK
()
self
.
dialog
.
key
_s
tring
.
set
(
' '
)
self
.
dialog
.
ok
()
self
.
assertEqual
(
self
.
dialog
.
result
,
''
)
self
.
assertEqual
(
self
.
dialog
.
showerror
.
message
,
'No key specified.'
)
def
test_ok_good
(
self
):
self
.
dialog
.
key
S
tring
.
set
(
'<Key-F11>'
)
self
.
dialog
.
list
KeysF
inal
.
get
.
result
=
'F11'
self
.
dialog
.
OK
()
self
.
dialog
.
key
_s
tring
.
set
(
'<Key-F11>'
)
self
.
dialog
.
list
_keys_f
inal
.
get
.
result
=
'F11'
self
.
dialog
.
ok
()
self
.
assertEqual
(
self
.
dialog
.
result
,
'<Key-F11>'
)
self
.
assertEqual
(
self
.
dialog
.
showerror
.
message
,
''
)
def
test_keys_no_ending
(
self
):
self
.
assertFalse
(
self
.
dialog
.
KeysOK
(
'<Control-Shift'
))
self
.
assertFalse
(
self
.
dialog
.
keys_ok
(
'<Control-Shift'
))
self
.
assertIn
(
'Missing the final'
,
self
.
dialog
.
showerror
.
message
)
def
test_keys_no_modifier_bad
(
self
):
self
.
dialog
.
list
KeysF
inal
.
get
.
result
=
'A'
self
.
assertFalse
(
self
.
dialog
.
KeysOK
(
'<Key-A>'
))
self
.
dialog
.
list
_keys_f
inal
.
get
.
result
=
'A'
self
.
assertFalse
(
self
.
dialog
.
keys_ok
(
'<Key-A>'
))
self
.
assertIn
(
'No modifier'
,
self
.
dialog
.
showerror
.
message
)
def
test_keys_no_modifier_ok
(
self
):
self
.
dialog
.
list
KeysF
inal
.
get
.
result
=
'F11'
self
.
assertTrue
(
self
.
dialog
.
KeysOK
(
'<Key-F11>'
))
self
.
dialog
.
list
_keys_f
inal
.
get
.
result
=
'F11'
self
.
assertTrue
(
self
.
dialog
.
keys_ok
(
'<Key-F11>'
))
self
.
assertEqual
(
self
.
dialog
.
showerror
.
message
,
''
)
def
test_keys_shift_bad
(
self
):
self
.
dialog
.
list
KeysF
inal
.
get
.
result
=
'a'
self
.
dialog
.
GetM
odifiers
.
result
=
[
'Shift'
]
self
.
assertFalse
(
self
.
dialog
.
KeysOK
(
'<a>'
))
self
.
dialog
.
list
_keys_f
inal
.
get
.
result
=
'a'
self
.
dialog
.
get_m
odifiers
.
result
=
[
'Shift'
]
self
.
assertFalse
(
self
.
dialog
.
keys_ok
(
'<a>'
))
self
.
assertIn
(
'shift modifier'
,
self
.
dialog
.
showerror
.
message
)
self
.
dialog
.
GetM
odifiers
.
result
=
[]
self
.
dialog
.
get_m
odifiers
.
result
=
[]
def
test_keys_dup
(
self
):
for
mods
,
final
,
seq
in
(([],
'F12'
,
'<Key-F12>'
),
([
'Control'
],
'x'
,
'<Control-Key-x>'
),
([
'Control'
],
'X'
,
'<Control-Key-X>'
)):
with
self
.
subTest
(
m
=
mods
,
f
=
final
,
s
=
seq
):
self
.
dialog
.
list
KeysF
inal
.
get
.
result
=
final
self
.
dialog
.
GetM
odifiers
.
result
=
mods
self
.
assertFalse
(
self
.
dialog
.
KeysOK
(
seq
))
self
.
dialog
.
list
_keys_f
inal
.
get
.
result
=
final
self
.
dialog
.
get_m
odifiers
.
result
=
mods
self
.
assertFalse
(
self
.
dialog
.
keys_ok
(
seq
))
self
.
assertIn
(
'already in use'
,
self
.
dialog
.
showerror
.
message
)
self
.
dialog
.
GetM
odifiers
.
result
=
[]
self
.
dialog
.
get_m
odifiers
.
result
=
[]
def
test_bind_ok
(
self
):
self
.
assertTrue
(
self
.
dialog
.
bind_ok
(
'<Control-Shift-Key-a>'
))
...
...
Misc/NEWS.d/next/IDLE/2018-12-27-15-29-11.bpo-35598.FWOOm8.rst
0 → 100644
View file @
55698cc3
Apply PEP8 naming convention to config_key.py.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment