From ecad8ae8d624075448382676f7f5cabc7bfc046f Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Wed, 29 Sep 2021 15:52:31 -0400 Subject: [PATCH] Add status and command bars to interface --- command_box.py | 8 ++++++++ cross.py | 51 ++++++++++++++++++++++++++------------------------ jam.kv | 25 ++++++++++++++++++++----- main.py | 17 ++++++++++++----- status_bar.py | 8 ++++++++ 5 files changed, 75 insertions(+), 34 deletions(-) create mode 100644 command_box.py create mode 100644 status_bar.py diff --git a/command_box.py b/command_box.py new file mode 100644 index 0000000..b9927bb --- /dev/null +++ b/command_box.py @@ -0,0 +1,8 @@ +from kivy.uix.label import Label + +class Command_box(Label): + + def __init__(self,**kwargs): + # init Label + super(Command_box,self).__init__(**kwargs) + diff --git a/cross.py b/cross.py index 2b158cf..5c7bb76 100644 --- a/cross.py +++ b/cross.py @@ -229,36 +229,39 @@ class Cross_painter(Widget): # respond to mouse down def on_touch_down(self,touch): - # create new cross - if touch.button=="right": - if self.check_interaction_any(Point(touch.x/Cross.size,touch.y/Cross.size),None): - new=Cross(touch.x/Cross.size,touch.y/Cross.size) - with self.canvas: - new.draw() - # add to list - self.crosses.append(new) + # only respond to touch in area + if self.collide_point(*touch.pos): + # create new cross + if touch.button=="right": + if self.check_interaction_any(Point(touch.x/Cross.size,touch.y/Cross.size),None): + new=Cross(touch.x/Cross.size,touch.y/Cross.size) + with self.canvas: + new.draw() + # add to list + self.crosses.append(new) - # select cross - if touch.button=="left": - # unselect - if self.selected!=None: - self.selected.selected=False + # select cross + if touch.button=="left": + # unselect + if self.selected!=None: + self.selected.selected=False - # find cross under touch - self.selected=self.find_cross(Point(touch.x/Cross.size,touch.y/Cross.size)) - # select - if self.selected!=None: - self.selected.selected=True + # find cross under touch + self.selected=self.find_cross(Point(touch.x/Cross.size,touch.y/Cross.size)) + # select + if self.selected!=None: + self.selected.selected=True # respond to drag def on_touch_move(self,touch): - # only move on left click - if touch.button=="left" and self.selected!=None: - self.selected.pos=self.check_move(Point(touch.x/Cross.size,touch.y/Cross.size),self.selected) - # redraw - self.canvas.clear() - self.draw() + if self.collide_point(*touch.pos): + # only move on left click + if touch.button=="left" and self.selected!=None: + self.selected.pos=self.check_move(Point(touch.x/Cross.size,touch.y/Cross.size),self.selected) + # redraw + self.canvas.clear() + self.draw() # find the cross at position pos diff --git a/jam.kv b/jam.kv index 2e0feba..a572c4d 100644 --- a/jam.kv +++ b/jam.kv @@ -1,7 +1,22 @@ #: kivy 2.0.0 -#: -# canvas: -# Rectangle: -# pos: 0,0 -# size: self.width,self.height +: + canvas: + Color: + rgb: 1,1,1 + Rectangle: + pos: self.pos + size: self.size + size_hint_y: None + height: 20 + +: + canvas: + Color: + rgb: 0,0,0 + Rectangle: + pos: self.pos + size: self.size + size_hint_y: None + height: 20 + diff --git a/main.py b/main.py index f22cccb..d563c10 100644 --- a/main.py +++ b/main.py @@ -1,19 +1,26 @@ from kivy.app import App from kivy.uix.widget import Widget +from kivy.uix.boxlayout import BoxLayout from kivy.config import Config from cross import Cross,Cross_painter +from status_bar import Status_bar +from command_box import Command_box # App class class Jam_app(App): # name of .kv file for main interface - #kv_file="jam.kv" + kv_file="jam.kv" def build(self): - parent=Widget() - self.cross_painter=Cross_painter() - parent.add_widget(self.cross_painter) - return parent + layout=BoxLayout(orientation="vertical") + painter=Cross_painter() + status=Status_bar() + command=Command_box() + layout.add_widget(painter) + layout.add_widget(status) + layout.add_widget(command) + return layout diff --git a/status_bar.py b/status_bar.py new file mode 100644 index 0000000..f1d2741 --- /dev/null +++ b/status_bar.py @@ -0,0 +1,8 @@ +from kivy.uix.label import Label +from kivy.graphics import Color,Rectangle + +class Status_bar(Label): + + def __init__(self,**kwargs): + # init Label + super(Status_bar,self).__init__(**kwargs)