Skip to content

Instantly share code, notes, and snippets.

@geojeff
Created May 4, 2013 14:37
Show Gist options
  • Save geojeff/5517681 to your computer and use it in GitHub Desktop.
Save geojeff/5517681 to your computer and use it in GitHub Desktop.
from kivy.uix.widget import Widget
from kivy.properties import ListProperty
from kivy.properties import FloatProperty
class GraphicsElement(Widget):
label = StringProperty('')
# label_containment is either ``inside`` or ``outside`` the element.
label_containment = OptionProperty(['inside', 'outside'])
# label_anchor is the anchor position, relative to the bounding box of the
# label text.
label_anchor = OptionProperty(['center', 'top_center', 'bottom_center',
'left_center', 'right_center', 'nw_corner', 'ne_corner', 'se_corner',
'sw_corner'])
# label_origin is the position of the label_anchor relative to the bounding
# box of the element.
label_origin = OptionProperty(['center', 'top_center', 'bottom_center',
'left_center', 'right_center', 'nw_corner', 'ne_corner', 'se_corner',
'sw_corner'])
# label_azimuth is the angle of the an imaginary line starting at
# label_origin, from 0 to 360 degrees, in the fashion of compass
# directions. The label_anchor is placed somewhere on this line.
label_azimuth = FloatProperty(0.0)
# label_margin is the distance from the element to the label_anchor along
# the label_azimuth line. The label positioning algorithm will place the
# label along the label_azimuth line, depending on
label_margin = FloatProperty(20.0)
line_color = ListProperty([0, 0, 0, 0])
fill_color = ListProperty([0, 0, 0, 0])
x = FloatProperty(10.0)
y = FloatProperty(10.0)
width = FloatProperty(10.0)
height = FloatProperty(10.0)
def __init__(self, **kwargs):
super(GraphicsElement, self).__init__(**kwargs)
self.bind(label_origin=self.reposition_label)
self.bind(label_azimuth=self.reposition_label)
self.bind(label_margin=self.reposition_label)
self.size_hint = (None, None)
def reposition_label(self, *args):
# Strike a line from label_origin at an angle of label_azimuth,
# attempting to place the label, using some increment. Find the place
# along the line that is optimal for label_containment, label_margin,
# etc.
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment