本文整理汇总了Python中nltk.draw.util.CanvasWidget类的典型用法代码示例。如果您正苦于以下问题:Python CanvasWidget类的具体用法?Python CanvasWidget怎么用?Python CanvasWidget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CanvasWidget类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, canvas, label, subtrees, **attribs):
"""
:type node:
:type subtrees: list(CanvasWidgetI)
"""
self._label = label
self._subtrees = subtrees
# Attributes
self._horizontal = 0
self._roof = 0
self._xspace = 10
self._yspace = 15
self._ordered = False
# Create canvas objects.
self._lines = [canvas.create_line(0, 0, 0, 0, fill='#006060') for c in subtrees]
self._polygon = canvas.create_polygon(
0, 0, fill='', state='hidden', outline='#006060'
)
# Register child widgets (label + subtrees)
self._add_child_widget(label)
for subtree in subtrees:
self._add_child_widget(subtree)
# Are we currently managing?
self._managing = False
CanvasWidget.__init__(self, canvas, **attribs)
开发者ID:prz3m,项目名称:kind2anki,代码行数:30,代码来源:tree.py
示例2: __setitem__
def __setitem__(self, attr, value):
canvas = self.canvas()
if attr == 'roof':
self._roof = value
if self._roof:
for l in self._lines: canvas.itemconfig(l, state='hidden')
canvas.itemconfig(self._polygon, state='normal')
else:
for l in self._lines: canvas.itemconfig(l, state='normal')
canvas.itemconfig(self._polygon, state='hidden')
elif attr == 'orientation':
if value == 'horizontal': self._horizontal = 1
elif value == 'vertical': self._horizontal = 0
else:
raise ValueError('orientation must be horizontal or vertical')
elif attr == 'color':
for l in self._lines: canvas.itemconfig(l, fill=value)
canvas.itemconfig(self._polygon, outline=value)
elif isinstance(attr, tuple) and attr[0] == 'color':
# Set the color of an individual line.
l = self._lines[int(attr[1])]
canvas.itemconfig(l, fill=value)
elif attr == 'fill':
canvas.itemconfig(self._polygon, fill=value)
elif attr == 'width':
canvas.itemconfig(self._polygon, {attr:value})
for l in self._lines: canvas.itemconfig(l, {attr:value})
elif attr in ('xspace', 'yspace'):
if attr == 'xspace': self._xspace = value
elif attr == 'yspace': self._yspace = value
self.update(self._label)
elif attr == 'ordered':
self._ordered = value
else:
CanvasWidget.__setitem__(self, attr, value)
开发者ID:DrDub,项目名称:nltk,代码行数:35,代码来源:tree.py
示例3: __init__
def __init__(self, canvas, node, subtrees, **attribs):
"""
:type node:
:type subtrees: list of C{CanvasWidgetI}
"""
self._node = node
self._subtrees = subtrees
# Attributes
self._horizontal = 0
self._roof = 0
self._xspace = 10
self._yspace = 15
self._ordered = False
# Create canvas objects.
self._lines = [canvas.create_line(0, 0, 0, 0, fill="#006060") for c in subtrees]
self._polygon = canvas.create_polygon(0, 0, fill="", state="hidden", outline="#006060")
# Register child widgets (node + subtrees)
self._add_child_widget(node)
for subtree in subtrees:
self._add_child_widget(subtree)
# Are we currently managing?
self._managing = False
CanvasWidget.__init__(self, canvas, **attribs)
开发者ID:gijs,项目名称:nltk,代码行数:28,代码来源:tree.py
示例4: __getitem__
def __getitem__(self, attr):
if attr[:5] == 'node_':
return self._nodeattribs.get(attr[5:], None)
elif attr[:5] == 'leaf_':
return self._leafattribs.get(attr[5:], None)
elif attr[:4] == 'loc_':
return self._locattribs.get(attr[4:], None)
elif attr == 'line_color':
return self._line_color
elif attr == 'line_width':
return self._line_width
elif attr == 'roof_color':
return self._roof_color
elif attr == 'roof_fill':
return self._roof_fill
elif attr == 'shapeable':
return self._shapeable
elif attr == 'xspace':
return self._xspace
elif attr == 'yspace':
return self._yspace
elif attr == 'orientation':
return self._orientation
else:
return CanvasWidget.__getitem__(self, attr)
开发者ID:prz3m,项目名称:kind2anki,代码行数:25,代码来源:tree.py
示例5: __setitem__
def __setitem__(self, attr, value):
canvas = self.canvas()
if attr is "roof":
self._roof = value
if self._roof:
for l in self._lines:
canvas.itemconfig(l, state="hidden")
canvas.itemconfig(self._polygon, state="normal")
else:
for l in self._lines:
canvas.itemconfig(l, state="normal")
canvas.itemconfig(self._polygon, state="hidden")
elif attr == "orientation":
if value == "horizontal":
self._horizontal = 1
elif value == "vertical":
self._horizontal = 0
else:
raise ValueError("orientation must be horizontal or vertical")
elif attr == "color":
for l in self._lines:
canvas.itemconfig(l, fill=value)
canvas.itemconfig(self._polygon, outline=value)
elif isinstance(attr, tuple) and attr[0] == "color":
# Set the color of an individual line.
l = self._lines[int(attr[1])]
canvas.itemconfig(l, fill=value)
elif attr == "fill":
canvas.itemconfig(self._polygon, fill=value)
elif attr == "width":
canvas.itemconfig(self._polygon, {attr: value})
for l in self._lines:
canvas.itemconfig(l, {attr: value})
elif attr in ("xspace", "yspace"):
if attr == "xspace":
self._xspace = value
elif attr == "yspace":
self._yspace = value
self.update(self._node)
elif attr == "ordered":
self._ordered = value
else:
CanvasWidget.__setitem__(self, attr, value)
开发者ID:gijs,项目名称:nltk,代码行数:43,代码来源:tree.py
示例6: __getitem__
def __getitem__(self, attr):
if attr == 'roof': return self._roof
elif attr == 'width':
return self.canvas().itemcget(self._polygon, attr)
elif attr == 'color':
return self.canvas().itemcget(self._polygon, 'outline')
elif isinstance(attr, tuple) and attr[0] == 'color':
l = self._lines[int(attr[1])]
return self.canvas().itemcget(l, 'fill')
elif attr == 'xspace': return self._xspace
elif attr == 'yspace': return self._yspace
elif attr == 'orientation':
if self._horizontal: return 'horizontal'
else: return 'vertical'
elif attr == 'ordered':
return self._ordered
else:
return CanvasWidget.__getitem__(self, attr)
开发者ID:DrDub,项目名称:nltk,代码行数:18,代码来源:tree.py
注:本文中的nltk.draw.util.CanvasWidget类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论