本文整理汇总了Python中tkinter.Canvas.scan_dragto方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.scan_dragto方法的具体用法?Python Canvas.scan_dragto怎么用?Python Canvas.scan_dragto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Canvas
的用法示例。
在下文中一共展示了Canvas.scan_dragto方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LpoView
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import scan_dragto [as 别名]
class LpoView(Frame):
""" This class implements a LPO widget.
This class use a canvas to draw the Hasse diagram of a LPO.
"""
def __init__(self, parent):
""" This method creates a new, emtpy LpoView. """
Frame.__init__(self, parent)
self.__parent = parent
self.__initUI()
self.__lpo = None
def __initUI(self):
""" Set up user interface. """
self.pack(fill=BOTH, expand=1)
self.__canvas = Canvas(self) # canvas for LPO
self.__canvas.pack(fill=BOTH, expand=1)
# Scroll with mouse drag gestures
self.__canvas.bind("<ButtonPress-1>", self.__scroll_start)
self.__canvas.bind("<B1-Motion>", self.__scroll_move)
def __scroll_start(self, event):
""" Scroll LPO with mouse gestures: Start of scroll event. """
self.__canvas.scan_mark(event.x, event.y)
def __scroll_move(self, event):
""" Scroll LPO with mouse gestures: Drag event. """
self.__canvas.scan_dragto(event.x, event.y, gain=1)
def showLpo(self, lpo_to_show):
""" This method show the given LPO in this LpoView. """
self.__lpo = lpo_to_show # set LPO reference
self.__drawLpo() # create LPO graph
def __drawLpo(self):
""" This method draws the LPO. """
# draw LPO arcs (arc layer is behind event layer)
for arc in self.__lpo.arcs:
# LPOs consists of all transitive arcs, the view shows only user defined arcs.
if arc.user_drawn == True:
self.__drawArc(arc)
# draw events
for id, event in self.__lpo.events.items():
self.__drawEvent(event)
def __drawEvent(self, event):
""" Draw the given event. """
self.__canvas.create_rectangle(event.position[0] - 10, event.position[1] - 10, event.position[0] + 10, event.position[1] + 10, outline="#000", fill="#AAAAAA", width=2)
self.__canvas.create_text(event.position[0], event.position[1] + 20, text=event.label)
def __drawArc(self, arc):
""" Draw the given arc. """
start_event = self.__lpo.events[arc.source] # get start event
end_event = self.__lpo.events[arc.target] # get end event
intersections = self.__calculateIntersections(start_event, end_event) # calculate intersection points
# start point of arc
start = start_event.position[0] + intersections[0][0], start_event.position[1] + intersections[0][1]
# end point of arc
end = end_event.position[0] + intersections[1][0], end_event.position[1] + intersections[1][1]
# create line with arrow head as end
self.__canvas.create_line(start[0], start[1], end[0], end[1], arrow=LAST, arrowshape=(8.6, 10, 5), width=2)
def __calculateIntersections(self, start, end):
""" Calculate intersection point of start and end events with the arc.
This method calculates two vectors which describe the intersection point of the arc from the
given start event to the given end event.
"""
# vector from the center of the start event to the center of the end event
vector = float(end.position[0] - start.position[0]), float(end.position[1] - start.position[1])
#calculate a factor to scale the x-component to 10px (half of side length)
fact = 1
if vector[0] != 0:
fact = 10 / math.fabs(vector[0])
# scale the vector
start_vector = vector[0] * fact, vector[1] * fact
# if y-component of vector is larger than 10px or x-component is 0, scale with y-component
if math.fabs(start_vector[1]) > 10 or vector[0] == 0:
fact = 10 / math.fabs(vector[1])
start_vector = vector[0] * fact, vector[1] * fact
#calculate intersection for arc end
if vector[0] != 0:
fact = 10 / math.fabs(vector[0])
end_vector = -vector[0] * fact, -vector[1] * fact
if math.fabs(end_vector[1]) > 10 or vector[0] == 0:
fact = 10 / math.fabs(vector[1])
end_vector = -vector[0] * fact, -vector[1] * fact
#.........这里部分代码省略.........