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