我有这两个功能:
import Tkinter as tk
import math
import time
class Point:
def __init__(self, x=0, y=0):
self.x = x
self.y = y
class TachoMeter(tk.Tk):
def __init__(self, CenterPoint=Point(), LeftPoint=Point(), Radius=0, LeftBuffer=0, BottomBuffer=0, MIN_RPM=0,
MAX_RPM=0, canvas_height=0, canvas_width=0, *arg, **kwargs):
tk.Tk.__init__(self, *arg, **kwargs)
self.canvas = tk.Canvas(width=canvas_width, height=canvas_height)
self.canvas.pack(fill="both", expand=True)
self.CenterPoint = CenterPoint
self.MAX_RPM = MAX_RPM
self.MIN_RPM = MIN_RPM
self.LeftBuffer = LeftBuffer
self.BottomBuffer = BottomBuffer
self.Radius = Radius
self.Point_0 = LeftPoint
self._create_arc((LeftPoint.x, LeftPoint.y), (LeftPoint.x + 2 * Radius, LeftPoint.y))
self._rpmGauge()
def _create_arc(self, p0, p1):
extend_x = (self._distance(p0, p1) - (p1[0] - p0[0])) / 2
extend_y = (self._distance(p0, p1) - (p1[1] - p0[1])) / 2
startAngle = math.atan2(p0[0] - p1[0], p0[1] - p1[1]) * 180 / math.pi
self.canvas.create_arc(p0[0] - extend_x, p0[1] - extend_y, p1[0] + extend_x, p1[1] + extend_y, extent=180,
start=90 + startAngle)
self.canvas.create_arc(LeftPoint.x + Radius, LeftPoint.y, LeftPoint.x + Radius, LeftPoint.y - Radius)
def _distance(self, p0, p1):
return math.sqrt((p0[0] - p1[0]) ** 2 + (p0[1] - p1[1]) ** 2)
def _rpmGauge(self):
for x in range(180, 0, -1):
curTheta = float((math.pi * x) / 180)
curX = self.CenterPoint.x + (self.Radius * math.cos(curTheta))
curY = self.CenterPoint.y - (self.Radius * math.sin(curTheta))
self.line = self.canvas.create_line(self.CenterPoint.x, self.CenterPoint.y, int(curX), int(curY))
self.canvas.pack()
Radius = 400
acanvas_width = 500
acanvas_height = 600
LeftBuffer = 100
BottomBuffer = 100
CenterPoint = Point(LeftBuffer + Radius, acanvas_height - BottomBuffer)
LeftPoint = Point(LeftBuffer, acanvas_height - BottomBuffer)
MAX_RPM = 8000
MIN_RPM = 0
TACH = TachoMeter(CenterPoint, LeftPoint, Radius, LeftBuffer, BottomBuffer, MIN_RPM, MAX_RPM, acanvas_height,
acanvas_width)
TACH.mainloop()
},假); };
所以它只是将rangy.saveSelection()存储在数据库中,然后将其恢复并尝试在其第一个元素上进行rangy.restoreSelection。 console.log看起来不错,但我在控制台中收到错误:
错误:Rangy WrappedRange模块出错:createRange():参数必须是Window对象或DOM节点
答案 0 :(得分:-1)
rangy.saveSelection()在控制台中显示如下:
{win:undefined,rangeInfos:Array,restored:false}
请注意“win:undefined”
当我将其发送到数据库时,我使用
data:JSON.stringify({“rangyObject”:rangy.saveSelection()})
从数据库中检索它时,它看起来像:
{rangeInfos:Array,restored:false}
我能够使用序列化和反序列化函数来解决这个问题,但是这些函数不会创建带有它们创建的跨度的id,所以我遇到了另一个问题。