python tkmessagebox_Python tkSimpleDialog.askstring方法代码示例

# 需要导入模块: import tkSimpleDialog [as 别名]

# 或者: from tkSimpleDialog import askstring [as 别名]

def grow_until(self, disp_node, stop_condition=None, levels=0):

# Find condition to stop growing

if stop_condition is None:

stop_condition = tkd.askstring("Stop Condition", "Enter lambda "

"function which returns True when stop condition is met.\n"

"Parameters are:\n - u, the node's name, and \n "

"- d, the data dictionary.\n\nExample: "

"d['color']=='red' \nwould grow until a red node is found.")

if stop_condition is None: return

data_node = self.dispG.node[disp_node]['dataG_id']

existing_data_nodes = set([ v['dataG_id']

for k,v in self.dispG.node.items() ])

max_iters = 10

stop_node = None # Node which met stop condition

grow_nodes = set([data_node]) # New nodes

# Iterate until we find a node that matches the stop condition (or,

# worst case, we reach max iters)

for i in range(1,max_iters+1):

old_grow_nodes = grow_nodes.copy()

grow_nodes.clear()

for n in old_grow_nodes:

grow_graph = self._neighbors(n, levels=i)

grow_nodes = grow_nodes.union(set(grow_graph.nodes())) - \

existing_data_nodes - old_grow_nodes

if len(grow_nodes) == 0:

# Start out next iteration with the entire graph

grow_nodes = existing_data_nodes.copy()

continue

for u in grow_nodes:

d = self.dataG.node[u]

try:

stop = eval(stop_condition, {'u':u, 'd':d})

except Exception as e:

tkm.showerror("Invalid Stop Condition",

"Evaluating the stop condition\n\n" +

stop_condition + "\n\nraise the following " +

"exception:\n\n" + str(e))

return

if stop:

stop_node = u

break

if stop_node is not None:

break

if stop_node is None:

tkm.showerror("Stop Condition Not Reached", "Unable to find a node "

"which meet the stop condition within %d levels."%i)

return

## Grow the number of times it took to find the node

#self.grow_node(disp_node, i)

# Find shortest path to stop_node

self.plot_path(data_node, stop_node, levels=levels, add_to_exsting=True)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值