From 8d483d055bb9be011a019d8b81007a64210668a7 Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Sat, 2 Oct 2021 17:38:26 -0400 Subject: [PATCH] Basic command prompt functionality --- command_box.py | 11 ----------- command_prompt.py | 30 ++++++++++++++++++++++++++++++ jam.kv | 4 +++- main.py | 8 +++++--- 4 files changed, 38 insertions(+), 15 deletions(-) delete mode 100644 command_box.py create mode 100644 command_prompt.py diff --git a/command_box.py b/command_box.py deleted file mode 100644 index c79fc46..0000000 --- a/command_box.py +++ /dev/null @@ -1,11 +0,0 @@ -from kivy.uix.label import Label - -class Command_box(Label): - - def __init__(self,app,**kwargs): - # app is used to share information between widgets - self.app=app - - # init Label - super(Command_box,self).__init__(**kwargs) - diff --git a/command_prompt.py b/command_prompt.py new file mode 100644 index 0000000..67eab68 --- /dev/null +++ b/command_prompt.py @@ -0,0 +1,30 @@ +from kivy.uix.label import Label +from kivy.core.window import Window + +class Command_prompt(Label): + + def __init__(self,app,**kwargs): + # app is used to share information between widgets + self.app=app + + # insert mode + self.insert=False + + # init Label + super(Command_prompt,self).__init__(**kwargs) + + self.keyboard = Window.request_keyboard(None,self,"text") + self.keyboard.bind(on_textinput=self.on_textinput,on_key_down=self.on_key_down) + + def on_key_down(self, keyboard, keycode, text, modifiers): + if self.insert: + if keycode[1]=="enter": + self.insert=False + self.text="" + + def on_textinput(self,window,text): + if self.insert: + self.text+=text + elif text==':': + self.text+=text + self.insert=True diff --git a/jam.kv b/jam.kv index 0b9e5c9..444ad73 100644 --- a/jam.kv +++ b/jam.kv @@ -12,9 +12,10 @@ text_size: self.size markup: True color: (0,0,0,1) + font_name: "RobotoMono-Regular" -: +: canvas.before: Color: rgb: 0,0,0 @@ -24,4 +25,5 @@ size_hint_y: None height: 20 text_size: self.size + font_name: "RobotoMono-Regular" diff --git a/main.py b/main.py index a76caa9..189e4d7 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ from kivy.config import Config from cross import Cross,Cross_painter from status_bar import Status_bar -from command_box import Command_box +from command_prompt import Command_prompt # App class class Jam_app(App): @@ -14,12 +14,14 @@ class Jam_app(App): def build(self): layout=BoxLayout(orientation="vertical") + self.painter=Cross_painter(self) self.status_bar=Status_bar(self) - self.command_box=Command_box(self) + self.command_prompt=Command_prompt(self) + layout.add_widget(self.painter) layout.add_widget(self.status_bar) - layout.add_widget(self.command_box) + layout.add_widget(self.command_prompt) return layout