mirror of https://github.com/kivy/kivy.git
Add a keybinding to the Kivy textarea to render when ctrl-S is pressed.
This commit is contained in:
parent
c093c82400
commit
a10a513133
|
@ -148,7 +148,7 @@
|
||||||
id: bl
|
id: bl
|
||||||
orientation: "vertical"
|
orientation: "vertical"
|
||||||
size_hint: .4, 1
|
size_hint: .4, 1
|
||||||
TextInput:
|
KivyRenderTextInput:
|
||||||
text_size: self.width-20, self.height-20
|
text_size: self.width-20, self.height-20
|
||||||
font_name: "DroidSansMono.ttf"
|
font_name: "DroidSansMono.ttf"
|
||||||
valign: "top"
|
valign: "top"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from kivy.app import App
|
from kivy.app import App
|
||||||
from kivy.factory import Factory
|
from kivy.factory import Factory
|
||||||
from kivy.lang import Builder, Parser, ParserException
|
from kivy.lang import Builder, Parser, ParserException
|
||||||
|
@ -7,6 +8,7 @@ from kivy.properties import ObjectProperty
|
||||||
from kivy.uix.boxlayout import BoxLayout
|
from kivy.uix.boxlayout import BoxLayout
|
||||||
from kivy.uix.popup import Popup
|
from kivy.uix.popup import Popup
|
||||||
from kivy.uix.label import Label
|
from kivy.uix.label import Label
|
||||||
|
from kivy.uix.textinput import TextInput
|
||||||
|
|
||||||
'''List of classes that need to be instantiated in the factory from .kv files.
|
'''List of classes that need to be instantiated in the factory from .kv files.
|
||||||
'''
|
'''
|
||||||
|
@ -53,6 +55,25 @@ for class_name in CONTAINER_CLASSES:
|
||||||
globals()[class_name] = type(class_name, (Container,), {})
|
globals()[class_name] = type(class_name, (Container,), {})
|
||||||
|
|
||||||
|
|
||||||
|
@factoryable
|
||||||
|
class KivyRenderTextInput(TextInput):
|
||||||
|
def _keyboard_on_key_down(self, window, keycode, text, modifiers):
|
||||||
|
is_osx = sys.platform == 'darwin'
|
||||||
|
# Keycodes on OSX:
|
||||||
|
ctrl, cmd = 64, 1024
|
||||||
|
key, key_str = keycode
|
||||||
|
|
||||||
|
if text and not key in (self.interesting_keys.keys() + [27]):
|
||||||
|
# This allows *either* ctrl *or* cmd, but not both.
|
||||||
|
if modifiers == ['ctrl'] or (is_osx and modifiers == ['meta']):
|
||||||
|
if key == ord('s'):
|
||||||
|
self.parent.parent.parent.change_kv(True)
|
||||||
|
return
|
||||||
|
|
||||||
|
super(KivyRenderTextInput, self)._keyboard_on_key_down(
|
||||||
|
window, keycode, text, modifiers)
|
||||||
|
|
||||||
|
|
||||||
class Catalog(BoxLayout):
|
class Catalog(BoxLayout):
|
||||||
'''Catalog of widgets. This is the root widget of the app. It contains
|
'''Catalog of widgets. This is the root widget of the app. It contains
|
||||||
a tabbed pain of widgets that can be displayed and a textbox where .kv
|
a tabbed pain of widgets that can be displayed and a textbox where .kv
|
||||||
|
|
Loading…
Reference in New Issue