Add status and command bars to interface

This commit is contained in:
Ian Jauslin 2021-09-29 15:52:31 -04:00
parent 159ac83e86
commit ecad8ae8d6
5 changed files with 75 additions and 34 deletions

8
command_box.py Normal file
View File

@ -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)

View File

@ -229,36 +229,39 @@ class Cross_painter(Widget):
# respond to mouse down # respond to mouse down
def on_touch_down(self,touch): def on_touch_down(self,touch):
# create new cross # only respond to touch in area
if touch.button=="right": if self.collide_point(*touch.pos):
if self.check_interaction_any(Point(touch.x/Cross.size,touch.y/Cross.size),None): # create new cross
new=Cross(touch.x/Cross.size,touch.y/Cross.size) if touch.button=="right":
with self.canvas: if self.check_interaction_any(Point(touch.x/Cross.size,touch.y/Cross.size),None):
new.draw() new=Cross(touch.x/Cross.size,touch.y/Cross.size)
# add to list with self.canvas:
self.crosses.append(new) new.draw()
# add to list
self.crosses.append(new)
# select cross # select cross
if touch.button=="left": if touch.button=="left":
# unselect # unselect
if self.selected!=None: if self.selected!=None:
self.selected.selected=False self.selected.selected=False
# find cross under touch # find cross under touch
self.selected=self.find_cross(Point(touch.x/Cross.size,touch.y/Cross.size)) self.selected=self.find_cross(Point(touch.x/Cross.size,touch.y/Cross.size))
# select # select
if self.selected!=None: if self.selected!=None:
self.selected.selected=True self.selected.selected=True
# respond to drag # respond to drag
def on_touch_move(self,touch): def on_touch_move(self,touch):
# only move on left click if self.collide_point(*touch.pos):
if touch.button=="left" and self.selected!=None: # only move on left click
self.selected.pos=self.check_move(Point(touch.x/Cross.size,touch.y/Cross.size),self.selected) if touch.button=="left" and self.selected!=None:
# redraw self.selected.pos=self.check_move(Point(touch.x/Cross.size,touch.y/Cross.size),self.selected)
self.canvas.clear() # redraw
self.draw() self.canvas.clear()
self.draw()
# find the cross at position pos # find the cross at position pos

25
jam.kv
View File

@ -1,7 +1,22 @@
#: kivy 2.0.0 #: kivy 2.0.0
#<jam>: <Status_bar>:
# canvas: canvas:
# Rectangle: Color:
# pos: 0,0 rgb: 1,1,1
# size: self.width,self.height Rectangle:
pos: self.pos
size: self.size
size_hint_y: None
height: 20
<Command_box>:
canvas:
Color:
rgb: 0,0,0
Rectangle:
pos: self.pos
size: self.size
size_hint_y: None
height: 20

17
main.py
View File

@ -1,19 +1,26 @@
from kivy.app import App from kivy.app import App
from kivy.uix.widget import Widget from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.config import Config from kivy.config import Config
from cross import Cross,Cross_painter from cross import Cross,Cross_painter
from status_bar import Status_bar
from command_box import Command_box
# App class # App class
class Jam_app(App): class Jam_app(App):
# name of .kv file for main interface # name of .kv file for main interface
#kv_file="jam.kv" kv_file="jam.kv"
def build(self): def build(self):
parent=Widget() layout=BoxLayout(orientation="vertical")
self.cross_painter=Cross_painter() painter=Cross_painter()
parent.add_widget(self.cross_painter) status=Status_bar()
return parent command=Command_box()
layout.add_widget(painter)
layout.add_widget(status)
layout.add_widget(command)
return layout

8
status_bar.py Normal file
View File

@ -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)