1
# Copyright (c) 2007, Enthought, Inc.
4
# key_bindings.py -- Example of a code editor with a key bindings editor
6
#--[Imports]--------------------------------------------------------------------
8
import Button, Code, HasPrivateTraits, Str
11
import View, Item, Group, Handler, CodeEditor
13
from traitsui.key_bindings \
14
import KeyBinding, KeyBindings
16
#--[Code]-----------------------------------------------------------------------
18
key_bindings = KeyBindings(
19
KeyBinding( binding1 = 'Ctrl-s',
20
description = 'Save to a file',
21
method_name = 'save_file' ),
22
KeyBinding( binding1 = 'Ctrl-r',
23
description = 'Run script',
24
method_name = 'run_script' ),
25
KeyBinding( binding1 = 'Ctrl-k',
26
description = 'Edit key bindings',
27
method_name = 'edit_bindings' )
30
# Traits UI Handler class for bound methods
31
class CodeHandler ( Handler ):
33
def save_file ( self, info ):
34
info.object.status = "save file"
36
def run_script ( self, info ):
37
info.object.status = "run script"
39
def edit_bindings ( self, info ):
40
info.object.status = "edit bindings"
41
key_bindings.edit_traits()
43
class KBCodeExample ( HasPrivateTraits ):
47
kb = Button(label='Edit Key Bindings')
53
Item('status', style='readonly'),
55
orientation = 'vertical',
59
key_bindings = key_bindings,
60
title = 'Code Editor With Key Bindings',
63
handler = CodeHandler() )
65
def _kb_fired( self, event ):
66
key_bindings.edit_traits()
69
if __name__ == '__main__':
70
KBCodeExample().configure_traits()