Print position of selected cross in status bar
This commit is contained in:
parent
ecad8ae8d6
commit
7269e6e361
@ -2,7 +2,10 @@ from kivy.uix.label import Label
|
||||
|
||||
class Command_box(Label):
|
||||
|
||||
def __init__(self,**kwargs):
|
||||
def __init__(self,app,**kwargs):
|
||||
# app is used to share information between widgets
|
||||
self.app=app
|
||||
|
||||
# init Label
|
||||
super(Command_box,self).__init__(**kwargs)
|
||||
|
||||
|
7
cross.py
7
cross.py
@ -208,7 +208,7 @@ def cross_polar(t):
|
||||
# cross painter
|
||||
class Cross_painter(Widget):
|
||||
|
||||
def __init__(self,**kwargs):
|
||||
def __init__(self,app,**kwargs):
|
||||
|
||||
# list of crosses
|
||||
self.crosses=[]
|
||||
@ -216,6 +216,9 @@ class Cross_painter(Widget):
|
||||
# selected cross
|
||||
self.selected=None
|
||||
|
||||
# app is used to share information between widgets
|
||||
self.app=app
|
||||
|
||||
# init Widget
|
||||
super(Cross_painter,self).__init__(**kwargs)
|
||||
|
||||
@ -262,6 +265,8 @@ class Cross_painter(Widget):
|
||||
# redraw
|
||||
self.canvas.clear()
|
||||
self.draw()
|
||||
# report position in status bar
|
||||
self.app.status_bar.set_position(" {:05.2f} , {:05.2f}".format(self.selected.pos.x,self.selected.pos.y))
|
||||
|
||||
|
||||
# find the cross at position pos
|
||||
|
9
jam.kv
9
jam.kv
@ -1,7 +1,7 @@
|
||||
#: kivy 2.0.0
|
||||
|
||||
<Status_bar>:
|
||||
canvas:
|
||||
canvas.before:
|
||||
Color:
|
||||
rgb: 1,1,1
|
||||
Rectangle:
|
||||
@ -9,9 +9,13 @@
|
||||
size: self.size
|
||||
size_hint_y: None
|
||||
height: 20
|
||||
text_size: self.size
|
||||
markup: True
|
||||
color: (0,0,0,1)
|
||||
|
||||
|
||||
<Command_box>:
|
||||
canvas:
|
||||
canvas.before:
|
||||
Color:
|
||||
rgb: 0,0,0
|
||||
Rectangle:
|
||||
@ -19,4 +23,5 @@
|
||||
size: self.size
|
||||
size_hint_y: None
|
||||
height: 20
|
||||
text_size: self.size
|
||||
|
||||
|
12
main.py
12
main.py
@ -14,12 +14,12 @@ class Jam_app(App):
|
||||
|
||||
def build(self):
|
||||
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)
|
||||
self.painter=Cross_painter(self)
|
||||
self.status_bar=Status_bar(self)
|
||||
self.command_box=Command_box(self)
|
||||
layout.add_widget(self.painter)
|
||||
layout.add_widget(self.status_bar)
|
||||
layout.add_widget(self.command_box)
|
||||
return layout
|
||||
|
||||
|
||||
|
@ -1,8 +1,15 @@
|
||||
from kivy.uix.label import Label
|
||||
from kivy.graphics import Color,Rectangle
|
||||
from kivy.utils import escape_markup
|
||||
|
||||
class Status_bar(Label):
|
||||
|
||||
def __init__(self,**kwargs):
|
||||
def __init__(self,app,**kwargs):
|
||||
# app is used to share information between widgets
|
||||
self.app=app
|
||||
|
||||
# init Label
|
||||
super(Status_bar,self).__init__(**kwargs)
|
||||
|
||||
def set_position(self,string):
|
||||
self.text=escape_markup(string)
|
||||
|
Loading…
Reference in New Issue
Block a user