def do_ask_pat(fun, pattern): global the_ui with uu.RunContext(the_ui): try: pat_evs = ev.parse(pattern) except: raise iu.IvyError(None, 'syntax error') fun(pat_evs)
def add_rel_lit(self, dlg, entry): with uu.RunContext(self): # with ivy_logic.UnsortedContext(): # lit = to_literal(entry.get()) sig = ivy_logic.sig.copy() with sig: for c in used_constants_clauses(self.g.state): if not isinstance(c.sort, ivy_logic.EnumeratedSort): # print "found constant {!r}".format(c) ivy_logic.add_symbol(str(c), c.sort) for c in used_constants_clauses(self.g.constraints): if not isinstance(c.sort, ivy_logic.EnumeratedSort): # print "found constant {!r}".format(c) ivy_logic.add_symbol(str(c), c.sort) lit = to_literal(entry.get()) # lit = ivy_logic.sortify(lit) dlg.destroy() # print "add_rel_lit: {}".format(lit) self.g.new_relation(lit) if self.update_callback != None: self.update_callback()
def remember_aux(self, dlg, entry, *args): with uu.RunContext(self): name = entry.get() dlg.destroy() self.parent.remember_graph(name, self.g.copy())
def rebuild(self): ## print "rebuild" with uu.RunContext(self): tk = self.tk g = self.g g.recompute() tk.eval('set graph [dotnew digraph forcelabels true]') handle_to_node = dict() handle_to_edge = dict() self.node_to_handle = dict() if hasattr(self, 'mark'): del self.mark i = 0 sorted_nodes = self.sort_nodes( [n for n in g.all_nodes if n.status != "false"]) node_labels = self.get_node_labels(sorted_nodes) sort_colors = dict((sort, line_color(i)) for i, sort in enumerate(ivy_logic.sig.sorts)) # make subgraphs for sorts sort_graph = {} for sort in ivy_logic.sig.sorts: if self.make_subgraphs(): sg = tk.eval('$graph addsubgraph cluster_' + sort + ' rank min') else: sg = '$graph' sort_graph[sort] = sg for n in sorted_nodes: if n.status != "false": p = n.name # print "rebuild: p = {}, type(p) = {}".format(p,type(p)) shape = "doubleoctagon" if n.summary else "octagon" labels = make_node_label(n) + node_labels[n.name] # labels = node_labels[n.name] if not labels: labels = [str(n.sort)] label = '\n'.join(labels) penwidth = '4.0' if n.status == 'true' else '2.0' color = sort_colors[n.sort.name] handle = tk.eval(sort_graph[n.sort.name] + ' addnode {' + p + '} label {' + label + '} shape ' + shape + ' fontsize 10 penwidth ' + penwidth + ' color ' + color) handle = 'node' + str(i + 1) if handle.startswith( 'node0x') else handle i += 1 handle_to_node[handle] = n self.node_to_handle[n.name] = handle ## print "relations: %s" % g.relations i = 0 for idx, r in enumerate(g.relations): if r.arity() != 2: continue ena = self.get_enabled(r) if any(e.get() for e in ena[0:2]): # avoid computing edges we don't need transitive = ena[3].get() r.properties['reflexive'] = transitive r.properties['transitive'] = transitive for (x, y), status in r.get_edges(): style = {'true': 0, 'undef': 1, 'false': 2}[status] if ena[style].get(): style = ["solid", "dotted", "dashed"][style] weight = '10' if transitive else '0' ge = '$graph addedge {' + x.name + '} {' + y.name + '} style ' + style + ' color {' + line_color( idx) + '} penwidth 2.0 weight ' + weight handle = tk.eval(ge) handle = 'edge' + str(i + 1) if handle.startswith( 'edge0x') else handle i += 1 rl = ~r.rel_lit if status == 'false' else r.rel_lit handle_to_edge[handle] = (rl, x.name, y.name) tk.eval('eval [$graph render ' + self._w + ' DOT]') if not g.constraints.is_true(): bb = self.bbox(ALL) ## print "bbox: {}".format(bb) if not bb or bb == None: # what does bbox return if canvas is empty? bb = (3, 3, 3, 3) # put text somewhere if empty canvas text = [ 'Constraints:\n' + '\n'.join( repr(clause) for clause in g.constraints.conjuncts()) ] self.create_text((bb[0], bb[3]), anchor=NW, text=text) self.config(scrollregion=self.bbox(ALL)) tk.eval(self._w + ' configure -scrollregion [' + self._w + ' bbox all]') for x in handle_to_node: n = handle_to_node[x] self.tag_bind("0" + x, "<Button-1>", lambda y, n=n: self.left_click_node(y, n)) self.tag_bind("1" + x, "<Button-1>", lambda y, n=n: self.left_click_node(y, n)) for x in handle_to_edge: r, h, t = handle_to_edge[x] ## print "r,h,t: %s %s %s" % (r,h,t) self.tag_bind( "0" + x, "<Button-1>", lambda y, r=r, h=h, t=t: self.left_click_edge(y, r, h, t)) self.tag_bind( "1" + x, "<Button-1>", lambda y, r=r, h=h, t=t: self.left_click_edge(y, r, h, t)) self.edge_popup = Menu(tk, tearoff=0) self.edge_popup.add_command(label="Empty", command=self.empty_edge) self.edge_popup.add_command(label="Materialize", command=self.materialize_edge) self.edge_popup.add_command(label="Dematerialize", command=self.dematerialize_edge)