-
- def dolayout(self):
- if os.path.exists(self.DictPathOut['liste_graph']) :
- list_graph = read_list_file(self.DictPathOut['liste_graph'])
- else :
- list_graph = [['','']]
- notebook_flags = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | aui.AUI_NB_TAB_MOVE | aui.AUI_NB_TAB_FLOAT
- self.tabsimi = aui.AuiNotebook(self.parent.nb, -1, wx.DefaultPosition)
- self.tabsimi.SetAGWWindowStyleFlag(notebook_flags)
- self.tabsimi.SetArtProvider(aui.ChromeTabArt())
- if 'corpus' in dir(self.Source) :
- self.tabsimi.corpus = self.Source.corpus
- self.graphpan = GraphPanelSimi(self.tabsimi, self.DictPathOut, list_graph)
- self.graphpan.Bind(wx.EVT_BUTTON, self.redosimi, self.graphpan.butafc)
- self.graphpan.Bind(wx.EVT_BUTTON, self.export, self.graphpan.butexport)
- self.tabsimi.AddPage(self.graphpan, 'Graph')
- self.parent.nb.AddPage(self.tabsimi, 'Analyse de graph')
- self.parent.ShowTab(True)
- self.parent.nb.SetSelection(self.parent.nb.GetPageCount() - 1)
-
- def export(self, evt) :
- fileout = os.path.join(os.path.dirname(self.DictPathOut['ira']), "graphout")
- format_graph = 'gml'
- i=1
- while os.path.exists(fileout + '_%i.' % i + format_graph) :
- i += 1
- fileout_graph = fileout + '_%i.' % i + format_graph
- fileout_table = fileout + '_table_%i.csv' % i
- Rtxt = """
- library(igraph)
- load("%s")
- fileout <- "%s"
- fileout.table <- "%s"
- format <- "%s"
- id <- (1:length(graph.simi$mat.eff)) - 1
- id <- paste(id, '.0', sep='')
- table.out <- cbind(Id=id, Label=id, Name=graph.simi$v.label, labelcex=graph.simi$label.cex, eff=graph.simi$mat.eff)
- write.graph(graph.simi$graph, fileout, format=format)
- write.csv2(table.out, file = fileout.table, row.names=FALSE)
- """ % (self.DictPathOut['RData'], ffr(fileout_graph), ffr(fileout_table), format_graph)
- tmpfile = tempfile.mktemp(dir=self.parent.TEMPDIR)
- with open(tmpfile, 'w') as f :
- f.write(Rtxt)
- res = exec_rcode(self.RPath, tmpfile, wait = False)
- check_Rresult(self.parent,res)
- print 'export', Rtxt
-
- def redosimi(self,evt) :
- if self.openfromprof :
- if 'cexfromchi' not in self.paramsimi:
- self.paramsimi['cexfromchi'] = False
- self.paramsimi['sfromchi'] = False
- self.dial = PrefSimi(self.parent, -1, self.paramsimi, self.types)
- self.dial.CenterOnParent()
- val = self.dial.ShowModal()
- if val == wx.ID_OK :
- self.paramsimi = self.make_param()
- self.dial.Destroy()
- if self.paramsimi.get('bystar',False) :
- variables = treat_var_mod(self.paramsimi['stars'])
- dial = OptLexi(self.parent)
- dial.listet = self.paramsimi['stars']
- var = [v for v in variables]
- dial.variables = var
- for et in var :
- dial.list_box_1.Append(et)
- dial.CenterOnParent()
- val = dial.ShowModal()
- if val == wx.ID_OK :
- if dial.choice.GetSelection() == 1 :
- listet = [dial.listet[i] for i in dial.list_box_1.GetSelections()]
- else :
- listet = variables[var[dial.list_box_1.GetSelections()[0]]]
- self.tableau.etline = self.Source.corpus.make_etline(listet)
-
- dlg = wx.ProgressDialog("Traitements",
- "Veuillez patienter...",
- maximum=2,
- parent=self.parent,
- style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT)
- dlg.Center()
- self.PrintScript()
- self.DoR(dlg)
- dlg.Destroy()
- self.make_ira()
- if self.paramsimi['type'] == 1:
- self.graphpan.sizer_3.Add(wx.StaticBitmap(self.graphpan.panel_1, -1, wx.Bitmap(self.filename, wx.BITMAP_TYPE_ANY)), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
- self.graphpan.sizer_3.Add(wx.StaticText(self.graphpan.panel_1,-1,self.txtgraph), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
- self.graphpan.sizer_3.Fit(self.graphpan.panel_1)
- self.graphpan.Layout()
- self.graphpan.panel_1.Scroll(0,self.graphpan.panel_1.GetScrollRange(wx.VERTICAL))
- else :
- self.dial.Destroy()
-
-
-class GraphPanelSimi(wx.Panel):
- def __init__(self,parent, dico, list_graph):
- wx.Panel.__init__(self,parent)
- self.afcnb = 1
- self.Dict = dico
- self.dirout = os.path.dirname(self.Dict['ira'])
- self.parent = self.GetParent()#parent
- self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "courier"))
- self.labels = []
- self.listimg = []
- self.tabsimi = self.parent.GetParent()
- self.ira = self.tabsimi.GetParent()
- self.panel_1 = wx.ScrolledWindow(self, -1, style=wx.TAB_TRAVERSAL)
- afc_img = wx.Image(os.path.join(self.ira.images_path,'button_simi.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
- self.butafc = wx.BitmapButton(self, -1, afc_img)
- export_img = wx.Image(os.path.join(self.ira.images_path,'button_export.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
- self.butexport = wx.BitmapButton(self, -1, export_img)
-
- for i in range(0,len(list_graph)):
- if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) :
- self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(os.path.join(self.dirout,list_graph[i][0]), wx.BITMAP_TYPE_ANY)))
- self.labels.append(wx.StaticText(self.panel_1, -1, list_graph[i][1]))
-
- self.__set_properties()
- self.__do_layout()
-
- def __set_properties(self):
- self.panel_1.EnableScrolling(True,True)
- #self.panel_1.SetSize((1000,1000))
- self.panel_1.SetScrollRate(20, 20)
-
- def __do_layout(self):
- self.sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
- self.sizer_2 = wx.BoxSizer(wx.VERTICAL)
- self.sizer_3 = wx.BoxSizer(wx.VERTICAL)
- self.sizer_2.Add(self.butafc, 0, 0, 0)
- self.sizer_2.Add(self.butexport, 0, 0, 0)
- for i in range(0, len(self.listimg)):
- self.sizer_3.Add(self.listimg[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
- self.sizer_3.Add(self.labels[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
- self.panel_1.SetSizer(self.sizer_3)
- self.sizer_1.Add(self.sizer_2, 0, wx.EXPAND, 0)
- self.sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0)
- self.SetSizer(self.sizer_1)