本文整理汇总了Python中CNC.Block.load方法的典型用法代码示例。如果您正苦于以下问题:Python Block.load方法的具体用法?Python Block.load怎么用?Python Block.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CNC.Block
的用法示例。
在下文中一共展示了Block.load方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paste
# 需要导入模块: from CNC import Block [as 别名]
# 或者: from CNC.Block import load [as 别名]
def paste(self, event=None):
try: clipboard = self.selection_get(selection='CLIPBOARD')
except: return
ypos = self.yview()[0]
# paste them after the last selected item
# bid,lid push them to self so it can be accessed from addLines()
# python3 might fix this with the inner scope
try:
self.__bid, self.__lid = self._items[self.curselection()[-1]]
except:
try:
self.__bid, self.__lid = self._items[-1]
except:
self.__bid = 0
self.__lid = None
selitems = []
undoinfo = []
def addLines(lines):
for line in lines.splitlines():
# Create a new block
if self.__lid is None:
self.__bid += 1
self.__lid = sys.maxint
block = Block()
undoinfo.append(self.gcode.addBlockUndo(self.__bid,block))
selitems.append((self.__bid, None))
else:
block = self.gcode.blocks[self.__bid]
if self.__lid == sys.maxint:
selitems.append((self.__bid, len(block)))
else:
self.__lid += 1
selitems.append((self.__bid, self.__lid))
undoinfo.append(self.gcode.insLineUndo(self.__bid, self.__lid, line))
try:
# try to unpickle it
unpickler = pickle.Unpickler(StringIO(clipboard))
try:
while True:
obj = unpickler.load()
if isinstance(obj,tuple):
block = Block.load(obj)
self.__bid += 1
undoinfo.append(self.gcode.addBlockUndo(self.__bid, block))
selitems.append((self.__bid,None))
self.__lid = None
else:
addLines(obj)
except EOFError:
pass
except pickle.UnpicklingError:
# Paste as text
addLines(clipboard)
if not undoinfo: return
self.gcode.addUndo(undoinfo)
self.selection_clear(0,END)
self.fill()
self.yview_moveto(ypos)
self.select(selitems, clear=True)
#self.selection_set(ACTIVE)
#self.see(ACTIVE)
self.app.event_generate("<<Modified>>")