def EG_append_edge(self, name_pair, root_graph=None): "Add edge to 'root_graph' only by node-names of the edge." nameA = to_unicode(name_pair[0].strip()) nameB = to_unicode(name_pair[1].strip()) if root_graph is None: root_graph = self ### Check unique. e = self.EG_get_edge_by_names((nameA, nameB), root_graph=root_graph) if not (e is None): raise Exception( 'Unique error. The edge with same names was existed in the graph.' ) nameA = add_double_quote(nameA) nameB = add_double_quote(nameB) e = pydot.Edge(src=nameA, dst=nameB) root_graph.add_edge(e) self.__check_wildcard_existed() self.refresh_bitmap() return e
def EG_append_edge(self, name_pair, root_graph=None): "Add edge to 'root_graph' only by node-names of the edge." nameA = to_unicode(name_pair[0].strip()) nameB = to_unicode(name_pair[1].strip()) if root_graph is None: root_graph = self ### Check unique. e = self.EG_get_edge_by_names((nameA, nameB), root_graph=root_graph) if not (e is None): raise Exception("Unique error. The edge with same names was existed in the graph.") nameA = add_double_quote(nameA) nameB = add_double_quote(nameB) e = pydot.Edge(src=nameA, dst=nameB) root_graph.add_edge(e) self.__check_wildcard_existed() self.refresh_bitmap() return e
def EG_append_edge(self, name_pair, root_graph=None): "Add edge to 'root_graph' only by node-names of the edge." nameA = to_unicode(name_pair[0].strip()) nameB = to_unicode(name_pair[1].strip()) if root_graph is None: root_graph = self ### Check unique. e = self.EG_get_edge_by_names((nameA, nameB), root_graph=root_graph) if not(e is None): raise Exception('Unique error. The edge with same names was existed in the graph.') nameA = add_double_quote(nameA) nameB = add_double_quote(nameB) if root_graph.get_node(nameA)[0].get_shape() == jawalker.BuildDictionariesFromDOT.ENTITY_SHAPE and root_graph.get_node(nameB)[0].get_shape() == jawalker.BuildDictionariesFromDOT.ATTRIBUTE_SHAPE: e = pydot.Edge(src=nameB, dst=nameA, color=jawalker.BuildDictionariesFromDOT.ATTRIBUTE_EDGE) elif root_graph.get_node(nameB)[0].get_shape() == jawalker.BuildDictionariesFromDOT.ENTITY_SHAPE and root_graph.get_node(nameA)[0].get_shape() == jawalker.BuildDictionariesFromDOT.ATTRIBUTE_SHAPE: e = pydot.Edge(src=nameA, dst=nameB, color=jawalker.BuildDictionariesFromDOT.ATTRIBUTE_EDGE) else: e = pydot.Edge(src=nameA, dst=nameB) root_graph.add_edge(e) self.__check_wildcard_existed() self.refresh_bitmap() return e
def onPGChanged(self, event): _, _, item = self.GetSelectedItem() if item is None: raise Exception("Sth strange happend! Can't find item to store attrs.") return p = event.GetProperty() if (not p) or (not p.IsEnabled()): ### No property in event or a group parent. return ### Get attr from property control. key = str(p.GetName()) ### Important!!! Make sure 'key' not unicode. if key.find('.') > 0: ### If child of a group. key = key.split('.')[-1] v = p.GetValue() if isinstance(v, basestring): v = v.strip().encode('utf8') elif isinstance(v, types.BooleanType): v = str(v).lower() else: v = str(v) ### Update attr. uv = to_unicode(v); udv = to_unicode(p.GetDefaultValue()) if uv == '' or uv == udv: try: del item.get_attributes()[key] except: pass # Restore the display value to default. p.SetValue(p.GetDefaultValue()) v = p.GetDefaultValue() else: item.get_attributes()[key] = add_double_quote(v) ### Change PG background if value is different from default. if uv == udv: p.SetBackgroundColour(self.m_tree.GetBackgroundColour(), -1) else: p.SetBackgroundColour('#ffffc0', -1) ### Update view. self.is_data_changed = True self.update_graph() return
def onPGChanged(self, event): _, _, item = self.GetSelectedItem() if item is None: raise Exception("Sth strange happend! Can't find item to store attrs.") return p = event.GetProperty() if (not p) or (not p.IsEnabled()): ### No property in event or a group parent. return ### Get attr from property control. key = str(p.GetName()) ### Important!!! Make sure 'key' not unicode. if key.find('.') > 0: ### If child of a group. key = key.split('.')[-1] v = p.GetValue() if isinstance(v, str): v = v.strip() elif isinstance(v, bool): v = str(v).lower() else: v = str(v) ### Update attr. uv = to_unicode(v); udv = to_unicode(str(p.GetDefaultValue())) if uv == '' or uv.lower() == udv.lower(): try: del item.get_attributes()[key] except: pass # Restore the display value to default. p.SetValue(p.GetDefaultValue()) v = p.GetDefaultValue() else: item.get_attributes()[key] = add_double_quote(v) ### Change PG background if value is different from default. if uv == udv: p.SetBackgroundColour(self.m_tree.GetBackgroundColour(), -1) else: p.SetBackgroundColour('#ffffc0', -1) ### Update view. self.is_data_changed = True self.update_graph() return
def EG_append_ER_node(self, nodename, root_graph=None, type=0, color=None ): "Add node to 'root_graph' only by name." uname = to_unicode(nodename.strip()) if root_graph is None: root_graph = self # Check unique. n = self.EG_get_node_by_name(uname, root_graph=root_graph) if not (n is None): raise Exception('Unique error. The node with name "%s" was existed in the graph.' % uname) uname = add_double_quote(uname) attributes ={} if not (color is None or color <= 0): attributes["style"] = '\"filled\"' attributes["fillcolor"] = self.node_color[color] if color == 2: attributes["fontcolor"]= jawalker.BuildDictionariesFromDOT.TARGET_FONT_COLOR if type == 1: attributes["orientation"] = u"45.0" elif type == 3: attributes["peripheries"] = u"2" attributes["shape"] = self.node_shape[type] n = pydot.Node(name =uname, **attributes) root_graph.add_node(n) self.__check_wildcard_existed() self.refresh_bitmap() return n
def EG_remove_edge(self, name_pair, root_graph=None): "Remove edge from root_graph by end points name of the edge." if root_graph is None: root_graph = self nameA = add_double_quote(to_unicode(name_pair[0])) nameB = add_double_quote(to_unicode(name_pair[1])) try: del root_graph.obj_dict["edges"][(nameA, nameB)] except: pass self.refresh_bitmap() return
def EG_remove_edge(self, name_pair, root_graph=None): "Remove edge from root_graph by end points name of the edge." if root_graph is None: root_graph = self nameA = add_double_quote(to_unicode(name_pair[0])) nameB = add_double_quote(to_unicode(name_pair[1])) try: del root_graph.obj_dict['edges'][(nameA, nameB)] except: pass self.refresh_bitmap() return
def parse_file(fn): script = open(fn).read() script = to_unicode(script) return parse_string(script)
def parse_file(fn): from DEUtils import to_unicode script = open(fn).read() script = to_unicode(script) return parse_string(script)
def EG_remove_subgraph(self, name, root_graph=None): "Remove subgraph from root_graph by name." if root_graph is None: root_graph = self sg_name = add_double_quote(to_unicode(name)) try: del root_graph.obj_dict['subgraphs'][sg_name] except: pass self.refresh_bitmap() return
def EG_remove_subgraph(self, name, root_graph=None): "Remove subgraph from root_graph by name." if root_graph is None: root_graph = self sg_name = add_double_quote(to_unicode(name)) try: del root_graph.obj_dict["subgraphs"][sg_name] except: pass self.refresh_bitmap() return
def EG_append_subgraph(self, graphname, root_graph=None): "Add node to 'root_graph' only by name." uname = to_unicode(graphname.strip()) if root_graph is None: root_graph = self # Check unique. n = self.EG_get_subgraph_by_name(uname) if not (n is None): raise Exception('Unique error. The subgraph with name "%s" was existed in the graph.' % uname) uname = add_double_quote(uname) sg = self.create_empty_subgraph(uname) root_graph.add_subgraph(sg) self.refresh_bitmap() return sg
def EG_append_subgraph(self, graphname, root_graph=None): "Add node to 'root_graph' only by name." uname = to_unicode(graphname.strip()) if root_graph is None: root_graph = self # Check unique. n = self.EG_get_subgraph_by_name(uname) if not(n is None): raise Exception('Unique error. The subgraph with name "%s" was existed in the graph.'%uname) uname = add_double_quote(uname) sg = self.create_empty_subgraph(uname) root_graph.add_subgraph(sg) self.refresh_bitmap() return sg
def EG_append_node(self, nodename, attr=None, root_graph=None): "Add node to 'root_graph' only by name." uname = to_unicode(nodename.strip()) if root_graph is None: root_graph = self # Check unique. n = self.EG_get_node_by_name(uname, root_graph=root_graph) if not(n is None): raise Exception('Unique error. The node with name "%s" was existed in the graph.'%uname) uname = add_double_quote(uname) n = pydot.Node(uname,attr) root_graph.add_node(n) self.__check_wildcard_existed() self.refresh_bitmap() return n
def EG_append_node(self, nodename, root_graph=None): "Add node to 'root_graph' only by name." uname = to_unicode(nodename.strip()) if root_graph is None: root_graph = self # Check unique. n = self.EG_get_node_by_name(uname, root_graph=root_graph) if not (n is None): raise Exception('Unique error. The node with name "%s" was existed in the graph.' % uname) uname = add_double_quote(uname) n = pydot.Node(uname) root_graph.add_node(n) self.__check_wildcard_existed() self.refresh_bitmap() return n
def onItemSelected(self, event): # If no item selected. selected_id = self.m_tree.GetSelection() if not selected_id.IsOk(): return i_name, i_type, item = self.GetSelectedItem() # Change the title of pg. _tail = '' if i_name in ['node', 'edge']: ### Change the wildcard item's type. i_type = i_name _tail = '(wildcard)' if selected_id == self.m_tree.GetRootItem(): _tail = '(global graph)' pg_title = i_type.capitalize() + ' Properties'+_tail self.m_staticText_pg.SetLabelText(pg_title) ### Read attrs from data_graph. data_attrs = {} if not item is None: data_attrs = item.get_attributes() ### Build PGManager. pm = self.m_pgManager1 pm.Clear() pm.AddPage() ### Very important!!! No-page would cause some strange thing happened. # Get attrs structure of the graph item. cates, _, attrs_dict = AttrsDef.get_dot_attr_structure(i_type) # Append pg items. for _c in cates: cat = wxpg.PropertyCategory(_c) pm.Append(cat) g_dict = attrs_dict[_c] groups = g_dict.keys(); # groups.sort() for _g in groups: a_list = g_dict[_g] if not _g is None: g_attr = wxpg.StringProperty(_g, value='<composed>') ### Magic string to compose child value. g_attr.Enable(False) g_attr.SetHelpString('attributes group of "%s", click left plus to expand.'%_g) g_id = pm.Append(g_attr) for a_name in a_list: pg = ExtPG.buildPG(a_name, i_type) if _g is None: pm.Append(pg) else: pm.AppendIn(g_id, pg) # Set attr value read from data_graph. if a_name in data_attrs.keys(): v = data_attrs[a_name] pg.SetValue(remove_double_quote(to_unicode(v).decode('utf8'))) # Set background to blue if attr value is different from default. pg.SetBackgroundColour('#ffffc0', -1) #if not _g is None: # pm.Collapse(g_attr) return
def onItemSelected(self, event): # If no item selected. selected_id = self.m_tree.GetSelection() if not selected_id.IsOk(): return i_name, i_type, item = self.GetSelectedItem() # Change the title of pg. _tail = '' if i_name in ['node', 'edge']: ### Change the wildcard item's type. i_type = i_name _tail = '(wildcard)' if selected_id == self.m_tree.GetRootItem(): _tail = '(global graph)' pg_title = i_type.capitalize() + ' Properties'+_tail self.m_staticText_pg.SetLabelText(pg_title) ### Read attrs from data_graph. data_attrs = {} if not item is None: data_attrs = item.get_attributes() ### Build PGManager. pm = self.m_pgManager1 pm.Clear() pm.AddPage() ### Very important!!! No-page would cause some strange thing happened. # Get attrs structure of the graph item. cates, _, attrs_dict = AttrsDef.get_dot_attr_structure(i_type) # Append pg items. for _c in cates: cat = wxpg.PropertyCategory(_c) pm.Append(cat) g_dict = attrs_dict[_c] groups = g_dict.keys(); # groups.sort() for _g in groups: a_list = g_dict[_g] if not _g is None: g_attr = wxpg.StringProperty(_g, value='<composed>') ### Magic string to compose child value. g_attr.Enable(False) g_attr.SetHelpString('attributes group of "%s", click left plus to expand.'%_g) g_id = pm.Append(g_attr) for a_name in a_list: pg = ExtPG.buildPG(a_name, i_type) if _g is None: pm.Append(pg) else: pm.AppendIn(g_id, pg) # Set attr value read from data_graph. if a_name in data_attrs.keys(): v = data_attrs[a_name] pg.SetValue(remove_double_quote(to_unicode(v))) # Set background to blue if attr value is different from default. pg.SetBackgroundColour('#ffffc0', -1) if not _g is None: pm.Collapse(_g) if cates.index(_c): pm.Collapse(_c) return