+
+ def __del__( self ):
+ pass
+
+
+class SubTextFromMetaDial ( wx.Dialog ):
+
+ def __init__( self, parent, parametres ):
+ wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = _("Subcorpus"), pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE )
+ self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
+ bSizer1 = wx.BoxSizer( wx.VERTICAL )
+ fgSizer1 = wx.FlexGridSizer( 0, 2, 0, 0 )
+ fgSizer1.SetFlexibleDirection( wx.BOTH )
+ fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
+ self.m_staticText1 = wx.StaticText( self, wx.ID_ANY, _("Name"), wx.DefaultPosition, wx.DefaultSize, 0 )
+ self.m_staticText1.Wrap( -1 )
+ fgSizer1.Add( self.m_staticText1, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ self.subcorpusname = wx.TextCtrl( self, wx.ID_ANY, parametres['corpus_name'], wx.DefaultPosition, wx.Size( 300,-1 ), 0 )
+ fgSizer1.Add( self.subcorpusname, 0, wx.ALL, 5 )
+ self.m_staticText2 = wx.StaticText( self, wx.ID_ANY, _("Select one or more metadata"), wx.DefaultPosition, wx.DefaultSize, 0 )
+ self.m_staticText2.Wrap( -1 )
+ fgSizer1.Add( self.m_staticText2, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ m_listBox1Choices = parametres['meta']
+ self.m_listBox1 = wx.ListBox( self, wx.ID_ANY, wx.DefaultPosition, wx.Size( -1,-1 ), m_listBox1Choices, wx.LB_HSCROLL|wx.LB_MULTIPLE )
+ self.m_listBox1.SetMinSize( wx.Size( -1,200 ) )
+ self.m_listBox1.SetMaxSize( wx.Size( -1,500 ) )
+ fgSizer1.Add( self.m_listBox1, 0, wx.ALL|wx.EXPAND, 5 )
+ bSizer1.Add( fgSizer1, 1, wx.EXPAND, 5 )
+ m_sdbSizer1 = wx.StdDialogButtonSizer()
+ self.m_sdbSizer1OK = wx.Button( self, wx.ID_OK )
+ m_sdbSizer1.AddButton( self.m_sdbSizer1OK )
+ self.m_sdbSizer1Cancel = wx.Button( self, wx.ID_CANCEL )
+ m_sdbSizer1.AddButton( self.m_sdbSizer1Cancel )
+ m_sdbSizer1.Realize();
+ bSizer1.Add( m_sdbSizer1, 0, wx.EXPAND, 5 )
+ self.SetSizer( bSizer1 )
+ self.Layout()
+ bSizer1.Fit( self )
+ self.Centre( wx.BOTH )
+ self.Bind(wx.EVT_LISTBOX, self.onchoose, self.m_listBox1)
+ if not parametres.get('isempty', False) :
+ self.m_sdbSizer1OK.Enable(False)
+
+ def __del__( self ):
+ pass
+
+ def onchoose(self, evt):
+ if len(self.m_listBox1.GetSelections()) > 0 :
+ self.m_sdbSizer1OK.Enable(True)
+ else :
+ self.m_sdbSizer1OK.Enable(False)
+
+class BarGraphDialog ( wx.Dialog ):
+
+ def __init__( self, parent, width, height ):
+ wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = _("Preferences"), pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE )
+ self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
+ bSizer1 = wx.BoxSizer( wx.VERTICAL )
+ bSizer2 = wx.BoxSizer( wx.HORIZONTAL )
+ self.m_staticText1 = wx.StaticText( self, wx.ID_ANY, _("Size"), wx.DefaultPosition, wx.DefaultSize, 0 )
+ self.m_staticText1.Wrap( -1 )
+ bSizer2.Add( self.m_staticText1, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ sizeradioChoices = [ _("automatic"), _("manual") ]
+ self.sizeradio = wx.RadioBox( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, sizeradioChoices, 1, wx.RA_SPECIFY_COLS )
+ self.sizeradio.SetSelection( 0 )
+ bSizer2.Add( self.sizeradio, 0, wx.ALIGN_TOP|wx.ALL, 5 )
+ fgSizer1 = wx.FlexGridSizer( 0, 2, 0, 0 )
+ fgSizer1.SetFlexibleDirection( wx.BOTH )
+ fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
+ self.m_staticText2 = wx.StaticText( self, wx.ID_ANY, _("width"), wx.DefaultPosition, wx.DefaultSize, 0 )
+ self.m_staticText2.Wrap( -1 )
+ fgSizer1.Add( self.m_staticText2, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ self.widthsp = wx.SpinCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.SP_ARROW_KEYS, 0, 1000000, 600 )
+ fgSizer1.Add( self.widthsp, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ self.m_staticText3 = wx.StaticText( self, wx.ID_ANY, _("height"), wx.DefaultPosition, wx.DefaultSize, 0 )
+ self.m_staticText3.Wrap( -1 )
+ fgSizer1.Add( self.m_staticText3, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ self.heightsp = wx.SpinCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.SP_ARROW_KEYS, 1, 10000000, 400 )
+ fgSizer1.Add( self.heightsp, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ bSizer2.Add( fgSizer1, 1, wx.EXPAND, 5 )
+ bSizer1.Add( bSizer2, 1, wx.EXPAND, 5 )
+ bSizer3 = wx.BoxSizer( wx.HORIZONTAL )
+ self.m_staticText4 = wx.StaticText( self, wx.ID_ANY, _("Image format"), wx.DefaultPosition, wx.DefaultSize, 0 )
+ self.m_staticText4.Wrap( -1 )
+ bSizer3.Add( self.m_staticText4, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ formatChoices = [ "png", "svg" ]
+ self.format = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, formatChoices, 0 )
+ self.format.SetSelection( 0 )
+ bSizer3.Add( self.format, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ bSizer1.Add( bSizer3, 1, wx.EXPAND, 5 )
+ m_sdbSizer1 = wx.StdDialogButtonSizer()
+ self.m_sdbSizer1OK = wx.Button( self, wx.ID_OK )
+ m_sdbSizer1.AddButton( self.m_sdbSizer1OK )
+ self.m_sdbSizer1Cancel = wx.Button( self, wx.ID_CANCEL )
+ m_sdbSizer1.AddButton( self.m_sdbSizer1Cancel )
+ m_sdbSizer1.Realize();
+ bSizer1.Add( m_sdbSizer1, 0, wx.EXPAND, 5 )
+ self.SetSizer( bSizer1 )
+ self.Layout()
+ bSizer1.Fit( self )
+ self.Centre( wx.BOTH )
+ # Connect Events
+ self.sizeradio.Bind( wx.EVT_RADIOBOX, self.OnSizeRadio )
+ self.widthsp.SetValue(width)
+ self.heightsp.SetValue(height)
+ self.widthsp.Enable(False)
+ self.heightsp.Enable(False)
+ self.m_sdbSizer1OK.SetFocus()
+
+ def __del__( self ):
+ pass
+
+ # Virtual event handlers, overide them in your derived class
+ def OnSizeRadio( self, event ):
+ if self.sizeradio.GetSelection() == 0 :
+ self.widthsp.Enable(False)
+ self.heightsp.Enable(False)
+ else :
+ self.widthsp.Enable(True)
+ self.heightsp.Enable(True)
+ event.Skip()
+
+
+class ImageViewer ( wx.Frame ):
+
+ def __init__( self, parent, parametres, title, size ):
+ wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = title, pos = wx.DefaultPosition, size = size, style = wx.DEFAULT_FRAME_STYLE|wx.MAXIMIZE_BOX|wx.MINIMIZE_BOX|wx.STAY_ON_TOP|wx.TAB_TRAVERSAL )
+ self.ira = wx.GetApp().GetTopWindow()
+ self.SetIcon(self.ira._icon)
+ self.parametres = parametres
+ self.imageFile = self.parametres['tmpgraph']
+ if parametres['svg'] == 'TRUE' :
+ self.imagename = "image.svg"
+ else :
+ self.imagename = "image.png"
+ self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
+ bSizer1 = wx.BoxSizer( wx.VERTICAL )
+ self.m_panel1 = wx.ScrolledWindow(self, -1)# wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL|wx.TAB_TRAVERSAL|wx.VSCROLL )
+ self.m_panel1.SetScrollbars(1, 1, 200, 300)
+ bSizer2 = wx.BoxSizer( wx.VERTICAL )
+ if parametres['svg'] == 'FALSE' :
+ image = wx.Image(self.imageFile, wx.BITMAP_TYPE_PNG)
+ W = image.GetWidth()
+ H = image.GetHeight()
+ if W > 1000 :
+ W = 1000
+ if H > 800 :
+ H = 800
+ image = image.ConvertToBitmap()
+ self.m_bitmap1 = wx.StaticBitmap( self.m_panel1, wx.ID_ANY, image, wx.DefaultPosition, wx.DefaultSize, 0 )
+ bSizer2.Add( self.m_bitmap1, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ else :
+ link = hl.HyperLinkCtrl(self.m_panel1, wx.ID_ANY, "Click on this link", URL=self.imageFile )
+ bSizer2.Add( link, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ self.m_panel1.SetSizer( bSizer2 )
+ self.m_panel1.Layout()
+ bSizer2.Fit( self.m_panel1 )
+ bSizer1.Add( self.m_panel1, 1, wx.EXPAND |wx.ALL, 5 )
+ panel = wx.Panel(self, -1)
+ m_sdbSizer1 = wx.StdDialogButtonSizer()
+ self.m_sdbSizer1Save = wx.Button( panel, wx.ID_SAVE )
+ m_sdbSizer1.AddButton( self.m_sdbSizer1Save )
+ self.m_sdbSizer1Cancel = wx.Button( panel, wx.ID_CANCEL )
+ m_sdbSizer1.AddButton( self.m_sdbSizer1Cancel )
+ m_sdbSizer1.Realize();
+ panel.SetSizer( m_sdbSizer1 )
+ bSizer1.Add( panel, 0, wx.EXPAND, 5 )
+ self.SetSizer( bSizer1 )
+ self.Layout()
+ self.Centre( wx.BOTH )
+ if parametres['svg'] == 'FALSE' :
+ self.SetSize((W + 30,H + 30))
+ self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.m_sdbSizer1Cancel)
+ self.Bind(wx.EVT_BUTTON, self.OnSaveImage, self.m_sdbSizer1Save)
+
+ def __del__( self ):
+ pass
+
+ def OnCloseMe(self, event):
+ self.Destroy()
+
+ def OnSaveImage(self, event) :
+ dlg = wx.FileDialog(
+ self, message=_("Save as..."), defaultDir=self.parametres.get('pathout',os.getcwd()),
+ defaultFile= self.imagename, wildcard=self.parametres['wildcard'], style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT
+ )
+ dlg.SetFilterIndex(0)
+ dlg.CenterOnParent()
+ if dlg.ShowModal() == wx.ID_OK:
+ path = dlg.GetPath()
+ copyfile(self.imageFile, path)
+
+
+class BarFrame :
+
+ def __init__(self, ira, table, colnames, rownames, tree = False):
+ if not tree :
+ width = 100 + (10*len(rownames)) + (100 * len(colnames))
+ height = len(rownames) * 15
+ if height < 400 :
+ height = 400
+ else :
+ width = 500
+ height = (35 * len(colnames)) + (15 * len(rownames))
+ dial = BarGraphDialog(ira, width, height)
+ val = dial.ShowModal()
+ if val == wx.ID_OK :
+ tmpgraph = tempfile.mktemp(dir=ira.TEMPDIR)
+ if dial.format.GetSelection() == 0 :
+ svg = 'FALSE'
+ wildcard = "png|*.png"
+ fout = 'image.png'
+ else :
+ svg = 'TRUE'
+ wildcard = "svg|*.svg"
+ fout = 'image.svg'
+ pathout = ira.tree.page.pathout[fout]
+ parametres = {'width' : dial.widthsp.GetValue(),
+ 'height': dial.heightsp.GetValue(),
+ 'colnames' : colnames,
+ 'rownames' : rownames,
+ 'tmpgraph' : tmpgraph,
+ 'rgraph' : ira.RscriptsPath['Rgraph'],
+ 'svg' : svg,
+ 'wildcard' : wildcard,
+ 'pathout': pathout
+ }
+ if tree :
+ parametres['tree'] = tree
+ txt = barplot(table, parametres)
+ tmpscript = tempfile.mktemp(dir=ira.TEMPDIR)
+ with open(tmpscript,'w', encoding='utf8') as f :
+ f.write(txt)
+ exec_rcode(ira.RPath, tmpscript, wait = True)
+ win = ImageViewer(ira, parametres, _("Graphic"), size=(700, 500))
+ win.Show(True)
+ dial.Destroy()
+
+
+class ChronoFrame :
+
+ def __init__(self, ira, parametres, pathout, which = 'chi2'):
+ width = 800
+ height = 600
+ self.parametres = parametres
+ self.pathout = pathout
+ self.parent = ira
+ dial = BarGraphDialog(ira, width, height)
+ val = dial.ShowModal()
+ if val == wx.ID_OK :
+ tmpgraph = tempfile.mktemp(dir=ira.TEMPDIR)
+ if dial.format.GetSelection() == 0 :
+ svg = 'FALSE'
+ wildcard = "png|*.png"
+ else :
+ svg = 'TRUE'
+ wildcard = "svg|*.svg"
+ parametres = {'width' : dial.widthsp.GetValue(),
+ 'height': dial.heightsp.GetValue(),
+ 'tmpgraph' : tmpgraph,
+ 'svg' : svg,
+ 'wildcard' : wildcard}
+ self.parametres.update(parametres)
+ if which == 'chi2' :
+ script = ChronoChi2Script(self)
+ elif which == 'prop' :
+ script = ChronoPropScript(self)
+ elif which == 'gg' :
+ script = ChronoggScript(self)
+ script.make_script()
+ exec_rcode(ira.RPath, script.scriptout, wait = True)
+ win = ImageViewer(ira, self.parametres, _("Graphic"), size=(700, 500))
+ win.Show(True)
+ dial.Destroy()
+
+
+class MergeDialog ( wx.Dialog ):
+
+ def __init__( self, parent ):
+ wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE|wx.MINIMIZE_BOX )
+ self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
+ bSizer1 = wx.BoxSizer( wx.VERTICAL )
+ self.m_scrolledWindow1 = wx.ScrolledWindow( self, wx.ID_ANY, wx.DefaultPosition, wx.Size( 600,200 ), wx.HSCROLL|wx.VSCROLL )
+ self.m_scrolledWindow1.SetScrollRate( 5, 5 )
+ #self.m_scrolledWindow1.SetMinSize( wx.Size( 500,200 ) )
+ fgSizer2 = wx.FlexGridSizer( 0, 2, 0, 0 )
+ fgSizer2.AddGrowableCol( 1 )
+ fgSizer2.SetFlexibleDirection( wx.BOTH )
+ fgSizer2.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_ALL )
+ self.m_staticText3 = wx.StaticText( self.m_scrolledWindow1, wx.ID_ANY, "graphe 1", wx.DefaultPosition, wx.DefaultSize, 0 )
+ self.m_staticText3.Wrap( -1 )
+ fgSizer2.Add( self.m_staticText3, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ self.m_filePicker3 = wx.FilePickerCtrl( self.m_scrolledWindow1, wx.ID_ANY, wx.EmptyString, "Select a file", "*.*", wx.DefaultPosition, wx.DefaultSize, wx.FLP_DEFAULT_STYLE|wx.FLP_FILE_MUST_EXIST|wx.FLP_USE_TEXTCTRL )
+ self.m_filePicker3.SetMinSize( wx.Size( 400,-1 ) )
+ fgSizer2.Add( self.m_filePicker3, 1, wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND, 5 )
+ self.m_staticText4 = wx.StaticText( self.m_scrolledWindow1, wx.ID_ANY, "graphe 2", wx.DefaultPosition, wx.DefaultSize, 0 )
+ self.m_staticText4.Wrap( -1 )
+ fgSizer2.Add( self.m_staticText4, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ self.m_filePicker4 = wx.FilePickerCtrl( self.m_scrolledWindow1, wx.ID_ANY, wx.EmptyString, "Select a file", "*.*", wx.DefaultPosition, wx.DefaultSize, wx.FLP_DEFAULT_STYLE|wx.FLP_FILE_MUST_EXIST|wx.FLP_USE_TEXTCTRL )
+ self.m_filePicker4.SetMinSize( wx.Size( 400,-1 ) )
+ fgSizer2.Add( self.m_filePicker4, 1, wx.ALL|wx.EXPAND, 5 )
+ self.m_scrolledWindow1.SetSizer( fgSizer2 )
+ self.m_scrolledWindow1.Layout()
+ bSizer1.Add( self.m_scrolledWindow1, 0, wx.ALL, 5 )
+ self.button_add = wx.Button( self, wx.ID_ANY, "Add graphe", wx.DefaultPosition, wx.DefaultSize, 0 )
+ bSizer1.Add( self.button_add, 1, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
+ m_sdbSizer1 = wx.StdDialogButtonSizer()
+ self.m_sdbSizer1OK = wx.Button( self, wx.ID_OK )
+ m_sdbSizer1.AddButton( self.m_sdbSizer1OK )
+ self.m_sdbSizer1Cancel = wx.Button( self, wx.ID_CANCEL )
+ m_sdbSizer1.AddButton( self.m_sdbSizer1Cancel )
+ m_sdbSizer1.Realize();
+ bSizer1.Add( m_sdbSizer1, 1, wx.EXPAND, 5 )
+ self.SetSizer( bSizer1 )
+ self.Layout()
+ bSizer1.Fit( self )
+ self.Centre( wx.BOTH )
+ # Connect Events
+ self.button_add.Bind( wx.EVT_BUTTON, self.OnAddGraphe )
+ self.m_filePicker3.Bind(wx.EVT_FILEPICKER_CHANGED, self.OnFileChange)
+ self.m_filePicker4.Bind(wx.EVT_FILEPICKER_CHANGED, self.OnFileChange)
+ self.finish(fgSizer2, bSizer1)
+