|
3 | 3 | from kivy.uix.spinner import Spinner, SpinnerOption
|
4 | 4 | from kivy.uix.boxlayout import BoxLayout
|
5 | 5 | from kivy.uix.codeinput import CodeInput
|
| 6 | +from kivy.uix.behaviors import EmacsBehavior |
6 | 7 | from kivy.uix.popup import Popup
|
7 | 8 | from kivy.properties import ListProperty
|
8 | 9 | from kivy.core.window import Window
|
9 | 10 | from kivy.core.text import LabelBase
|
10 | 11 | from pygments import lexers
|
11 |
| - |
| 12 | +from pygame import font as fonts |
12 | 13 | import codecs
|
13 | 14 | import glob
|
14 | 15 | import os
|
@@ -57,6 +58,26 @@ def build(self):
|
57 | 58 | s.parentNode.insertBefore(po, s);
|
58 | 59 | })();
|
59 | 60 | </script>
|
| 61 | +----------------------Emacs key bindings--------------------- |
| 62 | +This CodeInput inherits from EmacsBehavior, so you can use Emacs key bindings |
| 63 | +if you want! To try out Emacs key bindings, set the "Key bindings" option to |
| 64 | +"Emacs". Experiment with the shortcuts below on some of the text in this window |
| 65 | +(just be careful not to delete the cheat sheet before you have made note of the |
| 66 | +commands!) |
| 67 | +
|
| 68 | +Shortcut Description |
| 69 | +-------- ----------- |
| 70 | +Control + a Move cursor to the beginning of the line |
| 71 | +Control + e Move cursor to the end of the line |
| 72 | +Control + f Move cursor one character to the right |
| 73 | +Control + b Move cursor one character to the left |
| 74 | +Alt + f Move cursor to the end of the word to the right |
| 75 | +Alt + b Move cursor to the start of the word to the left |
| 76 | +Alt + Backspace Delete text left of the cursor to the beginning of word |
| 77 | +Alt + d Delete text right of the cursor to the end of the word |
| 78 | +Alt + w Copy selection |
| 79 | +Control + w Cut selection |
| 80 | +Control + y Paste selection |
60 | 81 | '''
|
61 | 82 |
|
62 | 83 |
|
@@ -89,6 +110,13 @@ def cancel(self):
|
89 | 110 | self.dismiss()
|
90 | 111 |
|
91 | 112 |
|
| 113 | +class CodeInputWithBindings(EmacsBehavior, CodeInput): |
| 114 | + '''CodeInput with keybindings. |
| 115 | + To add more bindings, add behavior before CodeInput in class definition |
| 116 | + ''' |
| 117 | + pass |
| 118 | + |
| 119 | + |
92 | 120 | class CodeInputTest(App):
|
93 | 121 |
|
94 | 122 | files = ListProperty([None, ])
|
@@ -122,18 +150,24 @@ def build(self):
|
122 | 150 | text='File',
|
123 | 151 | values=('Open', 'SaveAs', 'Save', 'Close'))
|
124 | 152 | mnu_file.bind(text=self._file_menu_selected)
|
| 153 | + key_bindings = Spinner( |
| 154 | + text='Key bindings', |
| 155 | + values=('Default key bindings', 'Emacs key bindings')) |
| 156 | + key_bindings.bind(text=self._bindings_selected) |
125 | 157 |
|
126 | 158 | menu.add_widget(mnu_file)
|
127 | 159 | menu.add_widget(fnt_size)
|
128 | 160 | menu.add_widget(fnt_name)
|
129 | 161 | menu.add_widget(languages)
|
| 162 | + menu.add_widget(key_bindings) |
130 | 163 | b.add_widget(menu)
|
131 | 164 |
|
132 |
| - self.codeinput = CodeInput( |
133 |
| - |
| 165 | + self.codeinput = CodeInputWithBindings( |
134 | 166 | lexer=KivyLexer(),
|
135 | 167 | font_size=12,
|
136 |
| - text=example_text) |
| 168 | + text=example_text, |
| 169 | + active_key_bindings='default', |
| 170 | + ) |
137 | 171 |
|
138 | 172 | b.add_widget(self.codeinput)
|
139 | 173 |
|
@@ -169,6 +203,10 @@ def _file_menu_selected(self, instance, value):
|
169 | 203 | self.codeinput.text = ''
|
170 | 204 | Window.title = 'untitled'
|
171 | 205 |
|
| 206 | + def _bindings_selected(self, instance, value): |
| 207 | + value = value.split(' ')[0] |
| 208 | + self.codeinput.active_key_bindings = value.lower() |
| 209 | + |
172 | 210 | def on_files(self, instance, values):
|
173 | 211 | if not values[0]:
|
174 | 212 | return
|
|
0 commit comments