Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
55698cc3
Kaydet (Commit)
55698cc3
authored
Ara 28, 2018
tarafından
Cheryl Sabella
Kaydeden (comit)
Terry Jan Reedy
Ara 28, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-35598: IDLE: Update config_key.py with PEP8 names (GH-11330)
A few other changes make the code easier to follow.
üst
0133f9fc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
217 additions
and
187 deletions
+217
-187
config_key.py
Lib/idlelib/config_key.py
+191
-161
htest.py
Lib/idlelib/idle_test/htest.py
+1
-2
test_config_key.py
Lib/idlelib/idle_test/test_config_key.py
+24
-24
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
Dosyayı görüntüle @
55698cc3
...
@@ -13,39 +13,42 @@ class GetKeysDialog(Toplevel):
...
@@ -13,39 +13,42 @@ class GetKeysDialog(Toplevel):
# Dialog title for invalid key sequence
# Dialog title for invalid key sequence
keyerror_title
=
'Key Sequence Error'
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
):
*
,
_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
action - string, the name of the virtual event these keys will be
mapped to
mapped to
currentKeys - list, a list of all key sequence lists currently mapped
current_key_sequences - list, a list of all key sequence lists
to virtual events, for overlap checking
currently mapped to virtual events, for overlap checking
_utest - bool, do not wait when running unittest
_htest - bool, change box location when running htest
_htest - bool, change box location when running htest
_utest - bool, do not wait when running unittest
"""
"""
Toplevel
.
__init__
(
self
,
parent
)
Toplevel
.
__init__
(
self
,
parent
)
self
.
withdraw
()
#hide while setting geometry
self
.
withdraw
()
# Hide while setting geometry.
self
.
configure
(
borderwidth
=
5
)
self
.
configure
(
borderwidth
=
5
)
self
.
resizable
(
height
=
F
ALSE
,
width
=
FALSE
)
self
.
resizable
(
height
=
F
alse
,
width
=
False
)
self
.
title
(
title
)
self
.
title
(
title
)
self
.
transient
(
parent
)
self
.
transient
(
parent
)
self
.
grab_set
()
self
.
grab_set
()
self
.
protocol
(
"WM_DELETE_WINDOW"
,
self
.
C
ancel
)
self
.
protocol
(
"WM_DELETE_WINDOW"
,
self
.
c
ancel
)
self
.
parent
=
parent
self
.
parent
=
parent
self
.
action
=
action
self
.
action
=
action
self
.
current
KeySequences
=
currentKeyS
equences
self
.
current
_key_sequences
=
current_key_s
equences
self
.
result
=
''
self
.
result
=
''
self
.
keyString
=
StringVar
(
self
)
self
.
key_string
=
StringVar
(
self
)
self
.
keyString
.
set
(
''
)
self
.
key_string
.
set
(
''
)
self
.
SetModifiersForPlatform
()
# set self.modifiers, self.modifier_label
# Set self.modifiers, self.modifier_label.
self
.
set_modifiers_for_platform
()
self
.
modifier_vars
=
[]
self
.
modifier_vars
=
[]
for
modifier
in
self
.
modifiers
:
for
modifier
in
self
.
modifiers
:
variable
=
StringVar
(
self
)
variable
=
StringVar
(
self
)
variable
.
set
(
''
)
variable
.
set
(
''
)
self
.
modifier_vars
.
append
(
variable
)
self
.
modifier_vars
.
append
(
variable
)
self
.
advanced
=
False
self
.
advanced
=
False
self
.
CreateW
idgets
()
self
.
create_w
idgets
()
self
.
LoadFinalKeyL
ist
()
self
.
load_final_key_l
ist
()
self
.
update_idletasks
()
self
.
update_idletasks
()
self
.
geometry
(
self
.
geometry
(
"+
%
d+
%
d"
%
(
"+
%
d+
%
d"
%
(
...
@@ -54,83 +57,99 @@ class GetKeysDialog(Toplevel):
...
@@ -54,83 +57,99 @@ class GetKeysDialog(Toplevel):
parent
.
winfo_rooty
()
+
parent
.
winfo_rooty
()
+
((
parent
.
winfo_height
()
/
2
-
self
.
winfo_reqheight
()
/
2
)
((
parent
.
winfo_height
()
/
2
-
self
.
winfo_reqheight
()
/
2
)
if
not
_htest
else
150
)
if
not
_htest
else
150
)
)
)
#
centre dialog over parent (or below htest box)
)
)
#
Center dialog over parent (or below htest box).
if
not
_utest
:
if
not
_utest
:
self
.
deiconify
()
#geometry set, unhide
self
.
deiconify
()
# Geometry set, unhide.
self
.
wait_window
()
self
.
wait_window
()
def
showerror
(
self
,
*
args
,
**
kwargs
):
def
showerror
(
self
,
*
args
,
**
kwargs
):
# Make testing easier. Replace in #30751.
# Make testing easier. Replace in #30751.
messagebox
.
showerror
(
*
args
,
**
kwargs
)
messagebox
.
showerror
(
*
args
,
**
kwargs
)
def
CreateWidgets
(
self
):
def
create_widgets
(
self
):
frameMain
=
Frame
(
self
,
borderwidth
=
2
,
relief
=
SUNKEN
)
frame
=
Frame
(
self
,
borderwidth
=
2
,
relief
=
SUNKEN
)
frameMain
.
pack
(
side
=
TOP
,
expand
=
TRUE
,
fill
=
BOTH
)
frame
.
pack
(
side
=
TOP
,
expand
=
True
,
fill
=
BOTH
)
frameButtons
=
Frame
(
self
)
frameButtons
.
pack
(
side
=
BOTTOM
,
fill
=
X
)
frame_buttons
=
Frame
(
self
)
self
.
buttonOK
=
Button
(
frameButtons
,
text
=
'OK'
,
frame_buttons
.
pack
(
side
=
BOTTOM
,
fill
=
X
)
width
=
8
,
command
=
self
.
OK
)
self
.
buttonOK
.
grid
(
row
=
0
,
column
=
0
,
padx
=
5
,
pady
=
5
)
self
.
button_ok
=
Button
(
frame_buttons
,
text
=
'OK'
,
self
.
buttonCancel
=
Button
(
frameButtons
,
text
=
'Cancel'
,
width
=
8
,
command
=
self
.
ok
)
width
=
8
,
command
=
self
.
Cancel
)
self
.
button_ok
.
grid
(
row
=
0
,
column
=
0
,
padx
=
5
,
pady
=
5
)
self
.
buttonCancel
.
grid
(
row
=
0
,
column
=
1
,
padx
=
5
,
pady
=
5
)
self
.
button_cancel
=
Button
(
frame_buttons
,
text
=
'Cancel'
,
self
.
frameKeySeqBasic
=
Frame
(
frameMain
)
width
=
8
,
command
=
self
.
cancel
)
self
.
frameKeySeqAdvanced
=
Frame
(
frameMain
)
self
.
button_cancel
.
grid
(
row
=
0
,
column
=
1
,
padx
=
5
,
pady
=
5
)
self
.
frameControlsBasic
=
Frame
(
frameMain
)
self
.
frameHelpAdvanced
=
Frame
(
frameMain
)
# Basic entry key sequence.
self
.
frameKeySeqAdvanced
.
grid
(
row
=
0
,
column
=
0
,
sticky
=
NSEW
,
padx
=
5
,
pady
=
5
)
self
.
frame_keyseq_basic
=
Frame
(
frame
)
self
.
frameKeySeqBasic
.
grid
(
row
=
0
,
column
=
0
,
sticky
=
NSEW
,
padx
=
5
,
pady
=
5
)
self
.
frame_keyseq_basic
.
grid
(
row
=
0
,
column
=
0
,
sticky
=
NSEW
,
self
.
frameKeySeqBasic
.
lift
()
padx
=
5
,
pady
=
5
)
self
.
frameHelpAdvanced
.
grid
(
row
=
1
,
column
=
0
,
sticky
=
NSEW
,
padx
=
5
)
basic_title
=
Label
(
self
.
frame_keyseq_basic
,
self
.
frameControlsBasic
.
grid
(
row
=
1
,
column
=
0
,
sticky
=
NSEW
,
padx
=
5
)
text
=
f
"New keys for '{self.action}' :"
)
self
.
frameControlsBasic
.
lift
()
basic_title
.
pack
(
anchor
=
W
)
self
.
buttonLevel
=
Button
(
frameMain
,
command
=
self
.
ToggleLevel
,
text
=
'Advanced Key Binding Entry >>'
)
basic_keys
=
Label
(
self
.
frame_keyseq_basic
,
justify
=
LEFT
,
self
.
buttonLevel
.
grid
(
row
=
2
,
column
=
0
,
stick
=
EW
,
padx
=
5
,
pady
=
5
)
textvariable
=
self
.
key_string
,
relief
=
GROOVE
,
labelTitleBasic
=
Label
(
self
.
frameKeySeqBasic
,
borderwidth
=
2
)
text
=
"New keys for '"
+
self
.
action
+
"' :"
)
basic_keys
.
pack
(
ipadx
=
5
,
ipady
=
5
,
fill
=
X
)
labelTitleBasic
.
pack
(
anchor
=
W
)
labelKeysBasic
=
Label
(
self
.
frameKeySeqBasic
,
justify
=
LEFT
,
# Basic entry controls.
textvariable
=
self
.
keyString
,
relief
=
GROOVE
,
borderwidth
=
2
)
self
.
frame_controls_basic
=
Frame
(
frame
)
labelKeysBasic
.
pack
(
ipadx
=
5
,
ipady
=
5
,
fill
=
X
)
self
.
frame_controls_basic
.
grid
(
row
=
1
,
column
=
0
,
sticky
=
NSEW
,
padx
=
5
)
# Basic entry modifiers.
self
.
modifier_checkbuttons
=
{}
self
.
modifier_checkbuttons
=
{}
column
=
0
column
=
0
for
modifier
,
variable
in
zip
(
self
.
modifiers
,
self
.
modifier_vars
):
for
modifier
,
variable
in
zip
(
self
.
modifiers
,
self
.
modifier_vars
):
label
=
self
.
modifier_label
.
get
(
modifier
,
modifier
)
label
=
self
.
modifier_label
.
get
(
modifier
,
modifier
)
check
=
Checkbutton
(
self
.
frameControlsB
asic
,
check
=
Checkbutton
(
self
.
frame_controls_b
asic
,
command
=
self
.
BuildKeyString
,
command
=
self
.
build_key_string
,
text
=
label
,
text
=
label
,
variable
=
variable
,
onvalue
=
modifier
,
offvalue
=
''
)
variable
=
variable
,
onvalue
=
modifier
,
offvalue
=
''
)
check
.
grid
(
row
=
0
,
column
=
column
,
padx
=
2
,
sticky
=
W
)
check
.
grid
(
row
=
0
,
column
=
column
,
padx
=
2
,
sticky
=
W
)
self
.
modifier_checkbuttons
[
modifier
]
=
check
self
.
modifier_checkbuttons
[
modifier
]
=
check
column
+=
1
column
+=
1
labelFnAdvice
=
Label
(
self
.
frameControlsBasic
,
justify
=
LEFT
,
text
=
\
# Basic entry help text.
"Select the desired modifier keys
\n
"
+
help_basic
=
Label
(
self
.
frame_controls_basic
,
justify
=
LEFT
,
"above, and the final key from the
\n
"
+
text
=
"Select the desired modifier keys
\n
"
+
"list on the right.
\n\n
"
+
"above, and the final key from the
\n
"
+
"Use upper case Symbols when using
\n
"
+
"list on the right.
\n\n
"
+
"the Shift modifier. (Letters will be
\n
"
+
"Use upper case Symbols when using
\n
"
+
"converted automatically.)"
)
"the Shift modifier. (Letters will be
\n
"
+
labelFnAdvice
.
grid
(
row
=
1
,
column
=
0
,
columnspan
=
4
,
padx
=
2
,
sticky
=
W
)
"converted automatically.)"
)
self
.
listKeysFinal
=
Listbox
(
self
.
frameControlsBasic
,
width
=
15
,
height
=
10
,
help_basic
.
grid
(
row
=
1
,
column
=
0
,
columnspan
=
4
,
padx
=
2
,
sticky
=
W
)
selectmode
=
SINGLE
)
self
.
listKeysFinal
.
bind
(
'<ButtonRelease-1>'
,
self
.
FinalKeySelected
)
# Basic entry key list.
self
.
listKeysFinal
.
grid
(
row
=
0
,
column
=
4
,
rowspan
=
4
,
sticky
=
NS
)
self
.
list_keys_final
=
Listbox
(
self
.
frame_controls_basic
,
width
=
15
,
scrollKeysFinal
=
Scrollbar
(
self
.
frameControlsBasic
,
orient
=
VERTICAL
,
height
=
10
,
selectmode
=
SINGLE
)
command
=
self
.
listKeysFinal
.
yview
)
self
.
list_keys_final
.
bind
(
'<ButtonRelease-1>'
,
self
.
final_key_selected
)
self
.
listKeysFinal
.
config
(
yscrollcommand
=
scrollKeysFinal
.
set
)
self
.
list_keys_final
.
grid
(
row
=
0
,
column
=
4
,
rowspan
=
4
,
sticky
=
NS
)
scrollKeysFinal
.
grid
(
row
=
0
,
column
=
5
,
rowspan
=
4
,
sticky
=
NS
)
scroll_keys_final
=
Scrollbar
(
self
.
frame_controls_basic
,
self
.
buttonClear
=
Button
(
self
.
frameControlsBasic
,
orient
=
VERTICAL
,
text
=
'Clear Keys'
,
command
=
self
.
ClearKeySeq
)
command
=
self
.
list_keys_final
.
yview
)
self
.
buttonClear
.
grid
(
row
=
2
,
column
=
0
,
columnspan
=
4
)
self
.
list_keys_final
.
config
(
yscrollcommand
=
scroll_keys_final
.
set
)
labelTitleAdvanced
=
Label
(
self
.
frameKeySeqAdvanced
,
justify
=
LEFT
,
scroll_keys_final
.
grid
(
row
=
0
,
column
=
5
,
rowspan
=
4
,
sticky
=
NS
)
text
=
"Enter new binding(s) for '"
+
self
.
action
+
"' :
\n
"
+
self
.
button_clear
=
Button
(
self
.
frame_controls_basic
,
"(These bindings will not be checked for validity!)"
)
text
=
'Clear Keys'
,
labelTitleAdvanced
.
pack
(
anchor
=
W
)
command
=
self
.
clear_key_seq
)
self
.
entryKeysAdvanced
=
Entry
(
self
.
frameKeySeqAdvanced
,
self
.
button_clear
.
grid
(
row
=
2
,
column
=
0
,
columnspan
=
4
)
textvariable
=
self
.
keyString
)
self
.
entryKeysAdvanced
.
pack
(
fill
=
X
)
# Advanced entry key sequence.
labelHelpAdvanced
=
Label
(
self
.
frameHelpAdvanced
,
justify
=
LEFT
,
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
"
+
text
=
"Key bindings are specified using Tkinter keysyms as
\n
"
+
"in these samples: <Control-f>, <Shift-F2>, <F12>,
\n
"
"in these samples: <Control-f>, <Shift-F2>, <F12>,
\n
"
"<Control-space>, <Meta-less>, <Control-Alt-Shift-X>.
\n
"
"<Control-space>, <Meta-less>, <Control-Alt-Shift-X>.
\n
"
...
@@ -140,13 +159,19 @@ class GetKeysDialog(Toplevel):
...
@@ -140,13 +159,19 @@ class GetKeysDialog(Toplevel):
"is the 'do-nothing' keybinding.
\n\n
"
+
"is the 'do-nothing' keybinding.
\n\n
"
+
"Multiple separate bindings for one action should be
\n
"
+
"Multiple separate bindings for one action should be
\n
"
+
"separated by a space, eg., <Alt-v> <Meta-v>."
)
"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.
"""Determine list of names of key modifiers for this platform.
The names are used to build Tk bindings -- it doesn't matter if the
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
order is also important: key binding equality depends on it, so
config-keys.def must use the same ordering.
config-keys.def must use the same ordering.
"""
"""
...
@@ -154,118 +179,124 @@ class GetKeysDialog(Toplevel):
...
@@ -154,118 +179,124 @@ class GetKeysDialog(Toplevel):
self
.
modifiers
=
[
'Shift'
,
'Control'
,
'Option'
,
'Command'
]
self
.
modifiers
=
[
'Shift'
,
'Control'
,
'Option'
,
'Command'
]
else
:
else
:
self
.
modifiers
=
[
'Control'
,
'Alt'
,
'Shift'
]
self
.
modifiers
=
[
'Control'
,
'Alt'
,
'Shift'
]
self
.
modifier_label
=
{
'Control'
:
'Ctrl'
}
# short name
self
.
modifier_label
=
{
'Control'
:
'Ctrl'
}
# Short name.
def
ToggleLevel
(
self
):
def
toggle_level
(
self
):
if
self
.
buttonLevel
.
cget
(
'text'
)[:
8
]
==
'Advanced'
:
"Toggle between basic and advanced keys."
self
.
ClearKeySeq
()
if
self
.
button_level
.
cget
(
'text'
)
.
startswith
(
'Advanced'
):
self
.
buttonLevel
.
config
(
text
=
'<< Basic Key Binding Entry'
)
self
.
clear_key_seq
()
self
.
frameKeySeqAdvanced
.
lift
()
self
.
button_level
.
config
(
text
=
'<< Basic Key Binding Entry'
)
self
.
frameHelpAdvanced
.
lift
()
self
.
frame_keyseq_advanced
.
lift
()
self
.
entryKeysAdvanced
.
focus_set
()
self
.
frame_help_advanced
.
lift
()
self
.
advanced_keys
.
focus_set
()
self
.
advanced
=
True
self
.
advanced
=
True
else
:
else
:
self
.
ClearKeyS
eq
()
self
.
clear_key_s
eq
()
self
.
button
L
evel
.
config
(
text
=
'Advanced Key Binding Entry >>'
)
self
.
button
_l
evel
.
config
(
text
=
'Advanced Key Binding Entry >>'
)
self
.
frame
KeySeqB
asic
.
lift
()
self
.
frame
_keyseq_b
asic
.
lift
()
self
.
frame
ControlsB
asic
.
lift
()
self
.
frame
_controls_b
asic
.
lift
()
self
.
advanced
=
False
self
.
advanced
=
False
def
FinalKeySelected
(
self
,
event
):
def
final_key_selected
(
self
,
event
):
self
.
BuildKeyString
()
"Handler for clicking on key in basic settings list."
self
.
build_key_string
()
def
BuildKeyString
(
self
):
def
build_key_string
(
self
):
keyList
=
modifiers
=
self
.
GetModifiers
()
"Create formatted string of modifiers plus the key."
finalKey
=
self
.
listKeysFinal
.
get
(
ANCHOR
)
keylist
=
modifiers
=
self
.
get_modifiers
()
if
finalKey
:
final_key
=
self
.
list_keys_final
.
get
(
ANCHOR
)
finalKey
=
self
.
TranslateKey
(
finalKey
,
modifiers
)
if
final_key
:
keyList
.
append
(
finalKey
)
final_key
=
self
.
translate_key
(
final_key
,
modifiers
)
self
.
keyString
.
set
(
'<'
+
'-'
.
join
(
keyList
)
+
'>'
)
keylist
.
append
(
final_key
)
self
.
key_string
.
set
(
f
"<{'-'.join(keylist)}>"
)
def
GetModifiers
(
self
):
def
get_modifiers
(
self
):
modList
=
[
variable
.
get
()
for
variable
in
self
.
modifier_vars
]
"Return ordered list of modifiers that have been selected."
return
[
mod
for
mod
in
modList
if
mod
]
mod_list
=
[
variable
.
get
()
for
variable
in
self
.
modifier_vars
]
return
[
mod
for
mod
in
mod_list
if
mod
]
def
ClearKeySeq
(
self
):
def
clear_key_seq
(
self
):
self
.
listKeysFinal
.
select_clear
(
0
,
END
)
"Clear modifiers and keys selection."
self
.
listKeysFinal
.
yview
(
MOVETO
,
'0.0'
)
self
.
list_keys_final
.
select_clear
(
0
,
END
)
self
.
list_keys_final
.
yview
(
MOVETO
,
'0.0'
)
for
variable
in
self
.
modifier_vars
:
for
variable
in
self
.
modifier_vars
:
variable
.
set
(
''
)
variable
.
set
(
''
)
self
.
keyString
.
set
(
''
)
self
.
key_string
.
set
(
''
)
def
LoadFinalKeyList
(
self
):
def
load_final_key_list
(
self
):
#these tuples are also available for use in validity checks
"Populate listbox of available keys."
self
.
functionKeys
=
(
'F1'
,
'F2'
,
'F3'
,
'F4'
,
'F5'
,
'F6'
,
'F7'
,
'F8'
,
'F9'
,
# These tuples are also available for use in validity checks.
'F10'
,
'F11'
,
'F12'
)
self
.
function_keys
=
(
'F1'
,
'F2'
,
'F3'
,
'F4'
,
'F5'
,
'F6'
,
self
.
alphanumKeys
=
tuple
(
string
.
ascii_lowercase
+
string
.
digits
)
'F7'
,
'F8'
,
'F9'
,
'F10'
,
'F11'
,
'F12'
)
self
.
punctuationKeys
=
tuple
(
'~!@#
%
^&*()_-+={}[]|;:,.<>/?'
)
self
.
alphanum_keys
=
tuple
(
string
.
ascii_lowercase
+
string
.
digits
)
self
.
whitespaceKeys
=
(
'Tab'
,
'Space'
,
'Return'
)
self
.
punctuation_keys
=
tuple
(
'~!@#
%
^&*()_-+={}[]|;:,.<>/?'
)
self
.
editKeys
=
(
'BackSpace'
,
'Delete'
,
'Insert'
)
self
.
whitespace_keys
=
(
'Tab'
,
'Space'
,
'Return'
)
self
.
moveKeys
=
(
'Home'
,
'End'
,
'Page Up'
,
'Page Down'
,
'Left Arrow'
,
self
.
edit_keys
=
(
'BackSpace'
,
'Delete'
,
'Insert'
)
'Right Arrow'
,
'Up Arrow'
,
'Down Arrow'
)
self
.
move_keys
=
(
'Home'
,
'End'
,
'Page Up'
,
'Page Down'
,
'Left Arrow'
,
#make a tuple of most of the useful common 'final' keys
'Right Arrow'
,
'Up Arrow'
,
'Down Arrow'
)
keys
=
(
self
.
alphanumKeys
+
self
.
punctuationKeys
+
self
.
functionKeys
+
# Make a tuple of most of the useful common 'final' keys.
self
.
whitespaceKeys
+
self
.
editKeys
+
self
.
moveKeys
)
keys
=
(
self
.
alphanum_keys
+
self
.
punctuation_keys
+
self
.
function_keys
+
self
.
listKeysFinal
.
insert
(
END
,
*
keys
)
self
.
whitespace_keys
+
self
.
edit_keys
+
self
.
move_keys
)
self
.
list_keys_final
.
insert
(
END
,
*
keys
)
def
TranslateKey
(
self
,
key
,
modifiers
):
"Translate from keycap symbol to the Tkinter keysym"
@staticmethod
translateDict
=
{
'Space'
:
'space'
,
def
translate_key
(
key
,
modifiers
):
'~'
:
'asciitilde'
,
'!'
:
'exclam'
,
'@'
:
'at'
,
'#'
:
'numbersign'
,
"Translate from keycap symbol to the Tkinter keysym."
'
%
'
:
'percent'
,
'^'
:
'asciicircum'
,
'&'
:
'ampersand'
,
'*'
:
'asterisk'
,
translate_dict
=
{
'Space'
:
'space'
,
'('
:
'parenleft'
,
')'
:
'parenright'
,
'_'
:
'underscore'
,
'-'
:
'minus'
,
'~'
:
'asciitilde'
,
'!'
:
'exclam'
,
'@'
:
'at'
,
'#'
:
'numbersign'
,
'+'
:
'plus'
,
'='
:
'equal'
,
'{'
:
'braceleft'
,
'}'
:
'braceright'
,
'
%
'
:
'percent'
,
'^'
:
'asciicircum'
,
'&'
:
'ampersand'
,
'['
:
'bracketleft'
,
']'
:
'bracketright'
,
'|'
:
'bar'
,
';'
:
'semicolon'
,
'*'
:
'asterisk'
,
'('
:
'parenleft'
,
')'
:
'parenright'
,
':'
:
'colon'
,
','
:
'comma'
,
'.'
:
'period'
,
'<'
:
'less'
,
'>'
:
'greater'
,
'_'
:
'underscore'
,
'-'
:
'minus'
,
'+'
:
'plus'
,
'='
:
'equal'
,
'/'
:
'slash'
,
'?'
:
'question'
,
'Page Up'
:
'Prior'
,
'Page Down'
:
'Next'
,
'{'
:
'braceleft'
,
'}'
:
'braceright'
,
'Left Arrow'
:
'Left'
,
'Right Arrow'
:
'Right'
,
'Up Arrow'
:
'Up'
,
'['
:
'bracketleft'
,
']'
:
'bracketright'
,
'|'
:
'bar'
,
'Down Arrow'
:
'Down'
,
'Tab'
:
'Tab'
}
';'
:
'semicolon'
,
':'
:
'colon'
,
','
:
'comma'
,
'.'
:
'period'
,
if
key
in
translateDict
:
'<'
:
'less'
,
'>'
:
'greater'
,
'/'
:
'slash'
,
'?'
:
'question'
,
key
=
translateDict
[
key
]
'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
:
if
'Shift'
in
modifiers
and
key
in
string
.
ascii_lowercase
:
key
=
key
.
upper
()
key
=
key
.
upper
()
key
=
'Key-'
+
key
return
f
'Key-{key}'
return
key
def
OK
(
self
,
event
=
None
):
def
ok
(
self
,
event
=
None
):
keys
=
self
.
key
S
tring
.
get
()
.
strip
()
keys
=
self
.
key
_s
tring
.
get
()
.
strip
()
if
not
keys
:
if
not
keys
:
self
.
showerror
(
title
=
self
.
keyerror_title
,
parent
=
self
,
self
.
showerror
(
title
=
self
.
keyerror_title
,
parent
=
self
,
message
=
"No key specified."
)
message
=
"No key specified."
)
return
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
.
result
=
keys
self
.
grab_release
()
self
.
grab_release
()
self
.
destroy
()
self
.
destroy
()
def
C
ancel
(
self
,
event
=
None
):
def
c
ancel
(
self
,
event
=
None
):
self
.
result
=
''
self
.
result
=
''
self
.
grab_release
()
self
.
grab_release
()
self
.
destroy
()
self
.
destroy
()
def
KeysOK
(
self
,
keys
):
def
keys_ok
(
self
,
keys
):
'''
Validity check on user's 'basic' keybinding selection.
"""
Validity check on user's 'basic' keybinding selection.
Doesn't check the string produced by the advanced dialog because
Doesn't check the string produced by the advanced dialog because
'modifiers' isn't set.
'modifiers' isn't set.
"""
'''
final_key
=
self
.
list_keys_final
.
get
(
ANCHOR
)
finalKey
=
self
.
listKeysFinal
.
get
(
ANCHOR
)
modifiers
=
self
.
get_modifiers
()
modifiers
=
self
.
GetModifiers
()
keysOK
=
False
title
=
self
.
keyerror_title
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
]
for
key
in
keylist
]
if
not
keys
.
endswith
(
'>'
):
if
not
keys
.
endswith
(
'>'
):
self
.
showerror
(
title
,
parent
=
self
,
self
.
showerror
(
title
,
parent
=
self
,
message
=
'Missing the final Key'
)
message
=
'Missing the final Key'
)
elif
(
not
modifiers
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
,
self
.
showerror
(
title
=
title
,
parent
=
self
,
message
=
'No modifier key(s) specified.'
)
message
=
'No modifier key(s) specified.'
)
elif
(
modifiers
==
[
'Shift'
])
\
elif
(
modifiers
==
[
'Shift'
])
\
and
(
final
K
ey
not
in
and
(
final
_k
ey
not
in
self
.
function
Keys
+
self
.
moveK
eys
+
(
'Tab'
,
'Space'
)):
self
.
function
_keys
+
self
.
move_k
eys
+
(
'Tab'
,
'Space'
)):
msg
=
'The shift modifier by itself may not be used with'
\
msg
=
'The shift modifier by itself may not be used with'
\
' this key symbol.'
' this key symbol.'
self
.
showerror
(
title
=
title
,
parent
=
self
,
message
=
msg
)
self
.
showerror
(
title
=
title
,
parent
=
self
,
message
=
msg
)
...
@@ -273,12 +304,11 @@ class GetKeysDialog(Toplevel):
...
@@ -273,12 +304,11 @@ class GetKeysDialog(Toplevel):
msg
=
'This key combination is already in use.'
msg
=
'This key combination is already in use.'
self
.
showerror
(
title
=
title
,
parent
=
self
,
message
=
msg
)
self
.
showerror
(
title
=
title
,
parent
=
self
,
message
=
msg
)
else
:
else
:
keysOK
=
True
return
True
return
keysOK
return
False
def
bind_ok
(
self
,
keys
):
def
bind_ok
(
self
,
keys
):
"Return True if Tcl accepts the new keys else show message."
"Return True if Tcl accepts the new keys else show message."
try
:
try
:
binding
=
self
.
bind
(
keys
,
lambda
:
None
)
binding
=
self
.
bind
(
keys
,
lambda
:
None
)
except
TclError
as
err
:
except
TclError
as
err
:
...
...
Lib/idlelib/idle_test/htest.py
Dosyayı görüntüle @
55698cc3
...
@@ -141,12 +141,11 @@ _editor_window_spec = {
...
@@ -141,12 +141,11 @@ _editor_window_spec = {
"Best to close editor first."
"Best to close editor first."
}
}
# Update once issue21519 is resolved.
GetKeysDialog_spec
=
{
GetKeysDialog_spec
=
{
'file'
:
'config_key'
,
'file'
:
'config_key'
,
'kwds'
:
{
'title'
:
'Test keybindings'
,
'kwds'
:
{
'title'
:
'Test keybindings'
,
'action'
:
'find-again'
,
'action'
:
'find-again'
,
'current
KeySequences'
:
[
''
]
,
'current
_key_sequences'
:
[[
'<Control-Key-g>'
,
'<Key-F3>'
,
'<Control-Key-G>'
]]
,
'_htest'
:
True
,
'_htest'
:
True
,
},
},
'msg'
:
"Test for different key modifier sequences.
\n
"
'msg'
:
"Test for different key modifier sequences.
\n
"
...
...
Lib/idlelib/idle_test/test_config_key.py
Dosyayı görüntüle @
55698cc3
"Test config_key, coverage
75
%
"
"Test config_key, coverage
82
%
"
from
idlelib
import
config_key
from
idlelib
import
config_key
from
test.support
import
requires
from
test.support
import
requires
...
@@ -9,15 +9,15 @@ from idlelib.idle_test.mock_tk import Mbox_func
...
@@ -9,15 +9,15 @@ from idlelib.idle_test.mock_tk import Mbox_func
class
ValidationTest
(
unittest
.
TestCase
):
class
ValidationTest
(
unittest
.
TestCase
):
"Test validation methods:
OK, KeysOK
, bind_ok."
"Test validation methods:
ok, keys_ok
, bind_ok."
class
Validator
(
config_key
.
GetKeysDialog
):
class
Validator
(
config_key
.
GetKeysDialog
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
config_key
.
GetKeysDialog
.
__init__
(
self
,
*
args
,
**
kwargs
)
config_key
.
GetKeysDialog
.
__init__
(
self
,
*
args
,
**
kwargs
)
class
list
KeysF
inal
:
class
list
_keys_f
inal
:
get
=
Func
()
get
=
Func
()
self
.
list
KeysFinal
=
listKeysF
inal
self
.
list
_keys_final
=
list_keys_f
inal
GetM
odifiers
=
Func
()
get_m
odifiers
=
Func
()
showerror
=
Mbox_func
()
showerror
=
Mbox_func
()
@classmethod
@classmethod
...
@@ -31,7 +31,7 @@ class ValidationTest(unittest.TestCase):
...
@@ -31,7 +31,7 @@ class ValidationTest(unittest.TestCase):
@classmethod
@classmethod
def
tearDownClass
(
cls
):
def
tearDownClass
(
cls
):
cls
.
dialog
.
C
ancel
()
cls
.
dialog
.
c
ancel
()
cls
.
root
.
update_idletasks
()
cls
.
root
.
update_idletasks
()
cls
.
root
.
destroy
()
cls
.
root
.
destroy
()
del
cls
.
dialog
,
cls
.
root
del
cls
.
dialog
,
cls
.
root
...
@@ -42,49 +42,49 @@ class ValidationTest(unittest.TestCase):
...
@@ -42,49 +42,49 @@ class ValidationTest(unittest.TestCase):
# A test that sets a non-blank modifier list should reset it to [].
# A test that sets a non-blank modifier list should reset it to [].
def
test_ok_empty
(
self
):
def
test_ok_empty
(
self
):
self
.
dialog
.
key
S
tring
.
set
(
' '
)
self
.
dialog
.
key
_s
tring
.
set
(
' '
)
self
.
dialog
.
OK
()
self
.
dialog
.
ok
()
self
.
assertEqual
(
self
.
dialog
.
result
,
''
)
self
.
assertEqual
(
self
.
dialog
.
result
,
''
)
self
.
assertEqual
(
self
.
dialog
.
showerror
.
message
,
'No key specified.'
)
self
.
assertEqual
(
self
.
dialog
.
showerror
.
message
,
'No key specified.'
)
def
test_ok_good
(
self
):
def
test_ok_good
(
self
):
self
.
dialog
.
key
S
tring
.
set
(
'<Key-F11>'
)
self
.
dialog
.
key
_s
tring
.
set
(
'<Key-F11>'
)
self
.
dialog
.
list
KeysF
inal
.
get
.
result
=
'F11'
self
.
dialog
.
list
_keys_f
inal
.
get
.
result
=
'F11'
self
.
dialog
.
OK
()
self
.
dialog
.
ok
()
self
.
assertEqual
(
self
.
dialog
.
result
,
'<Key-F11>'
)
self
.
assertEqual
(
self
.
dialog
.
result
,
'<Key-F11>'
)
self
.
assertEqual
(
self
.
dialog
.
showerror
.
message
,
''
)
self
.
assertEqual
(
self
.
dialog
.
showerror
.
message
,
''
)
def
test_keys_no_ending
(
self
):
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
)
self
.
assertIn
(
'Missing the final'
,
self
.
dialog
.
showerror
.
message
)
def
test_keys_no_modifier_bad
(
self
):
def
test_keys_no_modifier_bad
(
self
):
self
.
dialog
.
list
KeysF
inal
.
get
.
result
=
'A'
self
.
dialog
.
list
_keys_f
inal
.
get
.
result
=
'A'
self
.
assertFalse
(
self
.
dialog
.
KeysOK
(
'<Key-A>'
))
self
.
assertFalse
(
self
.
dialog
.
keys_ok
(
'<Key-A>'
))
self
.
assertIn
(
'No modifier'
,
self
.
dialog
.
showerror
.
message
)
self
.
assertIn
(
'No modifier'
,
self
.
dialog
.
showerror
.
message
)
def
test_keys_no_modifier_ok
(
self
):
def
test_keys_no_modifier_ok
(
self
):
self
.
dialog
.
list
KeysF
inal
.
get
.
result
=
'F11'
self
.
dialog
.
list
_keys_f
inal
.
get
.
result
=
'F11'
self
.
assertTrue
(
self
.
dialog
.
KeysOK
(
'<Key-F11>'
))
self
.
assertTrue
(
self
.
dialog
.
keys_ok
(
'<Key-F11>'
))
self
.
assertEqual
(
self
.
dialog
.
showerror
.
message
,
''
)
self
.
assertEqual
(
self
.
dialog
.
showerror
.
message
,
''
)
def
test_keys_shift_bad
(
self
):
def
test_keys_shift_bad
(
self
):
self
.
dialog
.
list
KeysF
inal
.
get
.
result
=
'a'
self
.
dialog
.
list
_keys_f
inal
.
get
.
result
=
'a'
self
.
dialog
.
GetM
odifiers
.
result
=
[
'Shift'
]
self
.
dialog
.
get_m
odifiers
.
result
=
[
'Shift'
]
self
.
assertFalse
(
self
.
dialog
.
KeysOK
(
'<a>'
))
self
.
assertFalse
(
self
.
dialog
.
keys_ok
(
'<a>'
))
self
.
assertIn
(
'shift modifier'
,
self
.
dialog
.
showerror
.
message
)
self
.
assertIn
(
'shift modifier'
,
self
.
dialog
.
showerror
.
message
)
self
.
dialog
.
GetM
odifiers
.
result
=
[]
self
.
dialog
.
get_m
odifiers
.
result
=
[]
def
test_keys_dup
(
self
):
def
test_keys_dup
(
self
):
for
mods
,
final
,
seq
in
(([],
'F12'
,
'<Key-F12>'
),
for
mods
,
final
,
seq
in
(([],
'F12'
,
'<Key-F12>'
),
([
'Control'
],
'x'
,
'<Control-Key-x>'
),
([
'Control'
],
'x'
,
'<Control-Key-x>'
),
([
'Control'
],
'X'
,
'<Control-Key-X>'
)):
([
'Control'
],
'X'
,
'<Control-Key-X>'
)):
with
self
.
subTest
(
m
=
mods
,
f
=
final
,
s
=
seq
):
with
self
.
subTest
(
m
=
mods
,
f
=
final
,
s
=
seq
):
self
.
dialog
.
list
KeysF
inal
.
get
.
result
=
final
self
.
dialog
.
list
_keys_f
inal
.
get
.
result
=
final
self
.
dialog
.
GetM
odifiers
.
result
=
mods
self
.
dialog
.
get_m
odifiers
.
result
=
mods
self
.
assertFalse
(
self
.
dialog
.
KeysOK
(
seq
))
self
.
assertFalse
(
self
.
dialog
.
keys_ok
(
seq
))
self
.
assertIn
(
'already in use'
,
self
.
dialog
.
showerror
.
message
)
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
):
def
test_bind_ok
(
self
):
self
.
assertTrue
(
self
.
dialog
.
bind_ok
(
'<Control-Shift-Key-a>'
))
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
Dosyayı görüntüle @
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