本文整理汇总了Python中handler.Handler.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Handler.draw方法的具体用法?Python Handler.draw怎么用?Python Handler.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类handler.Handler
的用法示例。
在下文中一共展示了Handler.draw方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Object
# 需要导入模块: from handler import Handler [as 别名]
# 或者: from handler.Handler import draw [as 别名]
class Object(Rectangle):
"""This class represents the parent of all draweable objects"""
def __init__(self):
# self.id = random.uniform(0, 999999999)
Rectangle.__init__(self)
self.handler = Handler()
self.magnetos = Magnetos()
self.offset = Point()
self.pivot = Point()
self.selected = False
self.resizing = False
self.direction = NONE
self.control = AUTOMATIC
self.z = 0
self.hints = False
from ui.canvas import Canvas
self.canvas = Canvas()
self.handler.is_testing = self.canvas.is_testing
self.dash = []
self.thickness = 1.0
self.fill_style = COLOR
self.fill_color = Color(0.25, 0.25, 0.25, 0.25)
self.stroke_color = Color(0.25, 0.25, 0.25, 1.0)
self.gradient = Gradient()
def get_properties(self):
return Rectangle.get_properties(self) + ["z", "fill_style", "fill_color", "stroke_color", "gradient"]
def post(self):
pass
def delete(self):
self.canvas.document.pages[0].children.remove(self)
def set_fill_style(self, fill_style):
self.fill_style = fill_style
# self.set_property("fill_style", fill_style)
if fill_style == COLOR:
self.set_fill_color()
elif fill_style == GRADIENT:
self.set_gradient()
def set_gradient(self, gradient=Gradient()): # ToDo: by name and from Canvas!
self.fill_style = GRADIENT
self.gradient = gradient
def set_fill_color(self, color=Color()):
self.fill_style = COLOR
self.fill_color = color
def set_stroke_color(self, color=Color()):
self.stroke_color = color
def draw_hints(self, context):
extent = 25.0
context.save()
context.new_path()
context.rectangle(self.x - extent, self.y - extent, extent, extent)
context.set_source_rgba(130 / 255.0, 130 / 255.0, 250 / 255.0, 0.25)
context.fill_preserve()
context.set_line_width(1)
context.set_source_rgb(130 / 255.0, 130 / 255.0, 250 / 255.0)
context.stroke()
context = pangocairo.CairoContext(context)
layout = pangocairo.CairoContext.create_layout(context)
if platform.system() == "Windows":
fontname = "Sans"
else:
fontname = "Ubuntu"
text = str(int(self.z))
length = len(text)
if length > 3:
size = 6
text = "..." + text[length - 1 : 4]
elif length > 2:
size = 8
elif length > 1:
size = 10
else:
size = 12
description = "%s Bold %d" % (fontname, size)
font = pango.FontDescription(description)
layout.set_justify(True)
layout.set_font_description(font)
layout.set_text(text)
context.set_source_rgb(0, 0, 0)
width, height = layout.get_size()
width /= pango.SCALE
height /= pango.SCALE
context.move_to(self.x - (extent + width) / 2, self.y - (extent + height) / 2)
context.show_layout(layout)
context.set_antialias(cairo.ANTIALIAS_DEFAULT)
context.restore()
#.........这里部分代码省略.........