def onCheck(self, event): '''Do check on script, format script if correct.''' script = self.m_text_script.GetValue().strip() ### Get strict status here. strict_status = False if script[:6].lower() == 'strict': strict_status = True try: g = ExtParser.parse_string(script.encode('utf8')) ### Hack the strcit status cause bug of pydot. g.set_strict(strict_status) g = ExtGraph.ExtGraph(obj_dict=g.obj_dict) except ExtParser.ParseException, err: pos = self.m_text_script.XYToPosition(0, err.lineno-1) w = self.m_text_script.GetLineLength(err.lineno-1) self.m_text_script.SetFocus() self.m_text_script.SetSelection(pos, pos+w) wx.MessageBox("Parse Script Error.\n"+20*"-"+"\n%s"%err, 'Parse script error') return
def onOK(self, event): ''' If script is ok, store script in graph objcet and return to main window. Else highlight the error line in editor. ''' script = self.m_text_script.GetValue().strip() ### Get strict status here. strict_status = False if script[:6].lower() == 'strict': strict_status = True try: g = ExtParser.parse_string(script.encode('utf8')) ### Hack the strcit status cause bug of pydot. g.set_strict(strict_status) self.graph = ExtGraph.ExtGraph(obj_dict=g.obj_dict) self.EndModal(wx.ID_OK) except ExtParser.ParseException, err: pos = self.m_text_script.XYToPosition(0, err.lineno-1) w = self.m_text_script.GetLineLength(err.lineno-1) self.m_text_script.SetFocus() self.m_text_script.SetSelection(pos, pos+w) wx.MessageBox("Parse Script Error.\n"+20*"-"+"\n%s"%err, 'Parse script error')
def onCheck(self, event): '''Do check on script, format script if correct.''' script = self.m_text_script.GetValue().strip() ### Get strict status here. strict_status = False if script[:6].lower() == 'strict': strict_status = True try: g = ExtParser.parse_string(script) ### Hack the strcit status cause bug of pydot. g.set_strict(strict_status) g = ExtGraph.ExtGraph(obj_dict=g.obj_dict) except ExtParser.ParseException as err: pos = self.m_text_script.XYToPosition(0, err.lineno - 1) w = self.m_text_script.GetLineLength(err.lineno - 1) self.m_text_script.SetFocus() self.m_text_script.SetSelection(pos, pos + w) wx.MessageBox("Parse Script Error.\n" + 20 * "-" + "\n%s" % err, 'Parse script error') return self.SetScript(g.EG_to_string()) return
def onOK(self, event): ''' If script is ok, store script in graph objcet and return to main window. Else highlight the error line in editor. ''' script = self.m_text_script.GetValue().strip() ### Get strict status here. strict_status = False if script[:6].lower() == 'strict': strict_status = True try: g = ExtParser.parse_string(script) ### Hack the strcit status cause bug of pydot. g.set_strict(strict_status) self.graph = ExtGraph.ExtGraph(obj_dict=g.obj_dict) self.EndModal(wx.ID_OK) except ExtParser.ParseException as err: pos = self.m_text_script.XYToPosition(0, err.lineno - 1) w = self.m_text_script.GetLineLength(err.lineno - 1) self.m_text_script.SetFocus() self.m_text_script.SetSelection(pos, pos + w) wx.MessageBox("Parse Script Error.\n" + 20 * "-" + "\n%s" % err, 'Parse script error') return
def __init__(self, graph_name='G', obj_dict=None, template_file=None): pydot.Dot.__init__(self, graph_name=graph_name, obj_dict=obj_dict) # If create empty new graph... if (obj_dict is None): ### Some default setting. try: if template_file is None: g = ExtParser.parse_file(TEMPLATE_DOT) else: g = ExtParser.parse_file(template_file) except: g = ExtParser.parse_string(INIT_SCRIPT) self.obj_dict = g.obj_dict # If create graph from parsing program... else: # Now check if wildcard nodes existed in every graph and subgraph. self.__check_wildcard_existed() ### Important!!! To make "pydot.Graph.toString()" working correct. self.set_parent_graph(self) ### ------------------------------------------------------------- self.refresh_bitmap() return
def __init__(self, graph_name="G", obj_dict=None, template_file=None): pydot.Dot.__init__(self, graph_name=graph_name, obj_dict=obj_dict) # If create empty new graph... if obj_dict is None: ### Some default setting. try: if template_file is None: g = ExtParser.parse_file(TEMPLATE_DOT) else: g = ExtParser.parse_file(template_file) except: g = ExtParser.parse_string(INIT_SCRIPT) self.obj_dict = g.obj_dict # If create graph from parsing program... else: # Now check if wildcard nodes existed in every graph and subgraph. self.__check_wildcard_existed() ### Important!!! To make "pydot.Graph.toString()" working correct. self.set_parent_graph(self) ### ------------------------------------------------------------- self.refresh_bitmap() return
def create_empty_subgraph(self, name): sg = pydot.Subgraph() sg.set_name(name) g = ExtParser.parse_string(INIT_SCRIPT_SUBGRAPH) sg.obj_dict['nodes'] = g.obj_dict['nodes'] return sg
def create_empty_subgraph(self, name): sg = pydot.Subgraph() sg.set_name(name) g = ExtParser.parse_string(INIT_SCRIPT_SUBGRAPH) sg.obj_dict["nodes"] = g.obj_dict["nodes"] return sg
def gen_arrow_image(arrowtype, out_filepath): script = ''' digraph G { rankdir=LR; edge [colorscheme="blues3", color=3]; // node [style="invis"]; node [fontname="sans-serif", colorscheme="x11", fontsize=12, color="lightgray", fontcolor="lightgray", style=" ", penwidth=0.5]; "n1" [label="A"]; "n2" [label="B"]; "n1" -> "n2" [arrowhead="dot"]; } ''' g = ExtParser.parse_string(script) e1 = g.get_edge('"n1"', '"n2"') e1.get_attributes()['arrowhead'] = add_double_quote('%s'%arrowtype) g.write(out_filepath, 'dot', 'png') return