dirssync_gui.py :  » Business-Application » Directories-Synchronizer » DirsSync-2.1rc2 » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Business Application » Directories Synchronizer 
Directories Synchronizer » DirsSync 2.1rc2 » dirssync_gui.py
#!/usr/bin/env python
# generated by wxGlade 0.3.1 on Fri Feb  6 09:46:50 2004

from wxPython.wx import *
import dirssync,os.path,pickle

__version__="2.1rc2"

def _(txt): return txt

#The 2 next variables list the input file type currently supported and their respective class name
#to stay compatible, always add to the end.
filetypes=['Dir','Zip','Ftp']
classtypes=['DirDesc','ZipDesc','FtpDesc']
availablemethods=["DateComp","SizeComp",'MD5Comp']
#TODO: adapt parameters to file type selection. desable delete for zip
comparisons_label=[_("Comparison based on the modification time"), _("Comparison based on size(Bigger is the winner)"),_("MD5 Comparison (one way only!!)")]
comparisons_desc=[_("\nThis is the standard comparison methode. \n\nModification time stamp of each file in locale repository and relote repositiry are compared; the most recently updated will win!!\n\nThis comparison method allows bi-directional comparison.\On some systems (some windows file systems) well synchronized files have a delta of 1 seconds for their 'modification time'; to avoid to resynchronize them, set the 'delta' parameter to 1.  "),_("\nThis is an alternative to 'modification time' where the bigger will win.\n\nThis comparison method allows bi-directionnal comparison.\n\nFeel free to set 'delta' to a comfortable value."),_("\nThis is 'content based' comparison method. MD5 is a digest algorithm (see also Internet RFC 1321) that gives you a fingger print of the file.\n\nThis method is UNI-directional!!!")]



wxInitAllImageHandlers()

def MyLogo(parent,id):
    return  wxStaticBitmap(parent,id,wxImage('DirsSync.png',wxBITMAP_TYPE_PNG).ConvertToBitmap())

def bool2str(val):
    if val: return _("Yes")
    else: return _("Non")

class Log(dirssync.Log,dirssync.Pickling):
    def write(self,txt):
        self.output.AppendText(self.format(txt))
        self.output.Update()
        wxYield()

def FTPDialog(self,params={}):
    dlg = wxDialog(self,-1,"FTP parameters",size=wxSize(300,350),style = wxDEFAULT_DIALOG_STYLE)
    BSvsizer = wxBoxSizer(wxVERTICAL)
    STtitle = wxStaticText(dlg, -1, "Fill in the FTP parameters")
    BSvsizer.Add(STtitle, 0, wxALIGN_CENTRE|wxALL, 5)
    box = wxBoxSizer(wxHORIZONTAL)
    SThost = wxStaticText(dlg, -1, "Host:")
    box.Add(SThost, 0, wxALIGN_CENTRE|wxALL, 5)
    params.setdefault('host','')
    TChost = wxTextCtrl(dlg, -1, params['host'], size=(80,-1))
    box.Add(TChost, 1, wxALIGN_CENTRE|wxALL, 5)
    BSvsizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5)
    box = wxBoxSizer(wxHORIZONTAL)
    STuser = wxStaticText(dlg, -1, "user:")
    box.Add(STuser, 0, wxALIGN_CENTRE|wxALL, 5)
    params.setdefault('user','')
    TCuser = wxTextCtrl(dlg, -1, params['user'], size=(80,-1))
    box.Add(TCuser, 1, wxALIGN_CENTRE|wxALL, 5)
    BSvsizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5)
    box = wxBoxSizer(wxHORIZONTAL)
    STpasswd = wxStaticText(dlg, -1, "password:")
    box.Add(STpasswd, 0, wxALIGN_CENTRE|wxALL, 5)
    params.setdefault('passwd','')
    params['passwd2']=params['passwd']
    TCpasswd = wxTextCtrl(dlg, -1, params['passwd'], size=(80,-1),style=wxTE_PASSWORD)
    box.Add(TCpasswd, 1, wxALIGN_CENTRE|wxALL, 5)
    BSvsizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5)
    box = wxBoxSizer(wxHORIZONTAL)
    STpasswd2 = wxStaticText(dlg, -1, "retype password:")
    box.Add(STpasswd2, 0, wxALIGN_CENTRE|wxALL, 5)
    TCpasswd2 = wxTextCtrl(dlg, -1, params['passwd2'], size=(80,-1),style=wxTE_PASSWORD)
    box.Add(TCpasswd2, 1, wxALIGN_CENTRE|wxALL, 5)
    BSvsizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5)
    box = wxBoxSizer(wxHORIZONTAL)
    STrootdir = wxStaticText(dlg, -1, "root dir:")
    box.Add(STrootdir, 0, wxALIGN_CENTRE|wxALL, 5)
    params.setdefault('rootdir','')
    TCrootdir = wxTextCtrl(dlg, -1, params['rootdir'], size=(80,-1))
    box.Add(TCrootdir, 1, wxALIGN_CENTRE|wxALL, 5)
    BSvsizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5)
    box = wxBoxSizer(wxHORIZONTAL)
    Bok = wxButton(dlg, wxID_OK, " OK ")
    Bok.SetDefault()
    box.Add(Bok, 0, wxALIGN_CENTRE|wxALL, 5)
    Bcancel = wxButton(dlg, wxID_CANCEL, " Cancel ")
    box.Add(Bcancel, 0, wxALIGN_CENTRE|wxALL, 5)
    BSvsizer.AddSizer(box, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5)
    dlg.SetSizer(BSvsizer)
    dlg.SetAutoLayout(True)
    BSvsizer.Fit(dlg)
    validinput=None
    dlg.Center()
    while validinput!=True:
        if dlg.ShowModal() == wxID_OK:
            if TCpasswd.GetValue()==TCpasswd2.GetValue():
                validinput=True
                vals={'host':TChost.GetValue(),'user':TCuser.GetValue(),'passwd':TCpasswd.GetValue(),'rootdir':TCrootdir.GetValue()}
            else:
                validinput=False
    STtitle.SetLabel("Password Inconsistency")
        else:
            vals=None
      validinput=True
    dlg.Destroy()
    return vals

def dirnamedisplay(dir,options):
    txt=""
    if options.has_key('host'): txt=options['host']
    if options.has_key('rootdir'): txt+=':'+options['rootdir']
    txt+=dir
    return txt


class MyFrame(wxFrame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = wxDEFAULT_FRAME_STYLE
        wxFrame.__init__(self, *args, **kwds)
        self.Notebook = wxNotebook(self, -1, style=0)
        self.OptionsPanel = wxPanel(self.Notebook, -1)
        self.LogPanel = wxPanel(self.Notebook, -1)
        self.TransferPanel = wxPanel(self.Notebook, -1)
        self.InputsPanel = wxPanel(self.Notebook, -1)
        
        # Menu Bar
        self.Frame_menubar = wxMenuBar()
        self.SetMenuBar(self.Frame_menubar)
        self.MnuFile = wxMenu()
        self.MnuFile.Append(11, _("New"), _("Clean current job cards"), wxITEM_NORMAL)
        self.MnuFile.Append(12, _("Open"), _("Open new job cards"), wxITEM_NORMAL)
        self.MnuFile.Append(13, _("Save"), _("Save current job cards"), wxITEM_NORMAL)
        self.MnuFile.AppendSeparator()
        self.MnuFile.Append(14, _("Exit"), _("Exit the application"), wxITEM_NORMAL)
        self.Frame_menubar.Append(self.MnuFile, _("File"))
        self.MnuHelp = wxMenu()
        self.MnuHelp.Append(21, _("About"), _("About DirsSync ..."), wxITEM_NORMAL)
        self.Frame_menubar.Append(self.MnuHelp, _("Help"))
        # Menu Bar end
        self.Frame_statusbar = self.CreateStatusBar(1, 0)
        self.MyLogo_1 = MyLogo(self.InputsPanel, -1)
        self.STLocal = wxStaticText(self.InputsPanel, -1, _("Local"))
        self.CLocalDir = wxChoice(self.InputsPanel,-1,choices=filetypes)
        self.STLocalDir = wxStaticText(self.InputsPanel, -1, _("Select local directory"))
        self.TCLocalDir = wxTextCtrl(self.InputsPanel, -1, "")
        self.BLocalDir = wxButton(self.InputsPanel, -1, _("..."))
        self.STLocalInclude = wxStaticText(self.InputsPanel, -1, _("Include Patterns / sub-directories"))
        self.TCLocalIncPatt = wxTextCtrl(self.InputsPanel, -1, _(".*,*"))
        self.TCLocalIncDirs = wxTextCtrl(self.InputsPanel, -1, "")
        self.STLocalExclude = wxStaticText(self.InputsPanel, -1, _("Exclude Patterns / sub-directories"))
        self.TCLocalExcPatt = wxTextCtrl(self.InputsPanel, -1, "")
        self.TCLocalExcDirs = wxTextCtrl(self.InputsPanel, -1, "")
        self.STRemote = wxStaticText(self.InputsPanel, -1, _("Remote"))
        self.CRemoteDir = wxChoice(self.InputsPanel,-1,choices=filetypes)
        self.STRemoteDir = wxStaticText(self.InputsPanel, -1, _("Select remote directory"))
        self.TCRemoteDir = wxTextCtrl(self.InputsPanel, -1, "")
        self.BRemoteDir = wxButton(self.InputsPanel, -1, _("..."))
        self.STRemoteInclude = wxStaticText(self.InputsPanel, -1, _("Include Patterns / sub-directories"))
        self.TCRemoteIncPatt = wxTextCtrl(self.InputsPanel, -1, _(".*,*"))
        self.TCRemoteIncDirs = wxTextCtrl(self.InputsPanel, -1, "")
        self.STRemoteExclude = wxStaticText(self.InputsPanel, -1, _("Exclude Patterns / sub-directories"))
        self.TCRemoteExcPatt = wxTextCtrl(self.InputsPanel, -1, "")
        self.TCRemoteExcDirs = wxTextCtrl(self.InputsPanel, -1, "")
        self.STOptions = wxStaticText(self.InputsPanel, -1, _("Options"))
        self.CBLocal2Remote = wxCheckBox(self.InputsPanel, -1, _("Local to Remote"))
        self.CBRemote2Local = wxCheckBox(self.InputsPanel, -1, _("Remote to Local"))
        self.CBDelete = wxCheckBox(self.InputsPanel, -1, _("Delete (One-way)"))
        self.TCMaxDelta = wxTextCtrl(self.InputsPanel, -1, "")
        self.STMaxDelta = wxStaticText(self.InputsPanel, -1, _("Max Delta"))
        self.CBCase = wxCheckBox(self.InputsPanel, -1, _("Case sensitive"))
        self.BAddJob = wxButton(self.InputsPanel, -1, _("Add Job"))
        self.BEditJob = wxButton(self.InputsPanel, -1, _("Edit Job"))
        self.BDeleteJob = wxButton(self.InputsPanel, -1, _("Delete Job"))
        self.BNext = wxButton(self.InputsPanel, -1, _("Next>>"))
        self.LCJobs = wxListCtrl(self.InputsPanel, -1, style=wxLC_REPORT|wxSUNKEN_BORDER)
        self.LCTransferList = wxListCtrl(self.TransferPanel, -1, style=wxLC_REPORT|wxSUNKEN_BORDER)
        self.BSynchronize = wxButton(self.TransferPanel, -1, _(" SYNCHONIZE "))
        self.TCError = wxTextCtrl(self.LogPanel, -1, "", style=wxTE_MULTILINE|wxHSCROLL|wxTE_RICH)
        self.TCLog = wxTextCtrl(self.LogPanel, -1, "", style=wxTE_MULTILINE|wxHSCROLL|wxTE_RICH)
        self.BClear = wxButton(self.LogPanel, -1, _("Clear"))
        self.CComparisonMethod = wxChoice(self.OptionsPanel, -1, choices=comparisons_label)
        self.STComparisonDescription=wxStaticText(self.OptionsPanel,-1,"")
        self.__set_properties()
        self.__do_layout()
        # end wxGlade
        self.__initialize()
        self.__set_event()

    def __set_properties(self):
        # begin wxGlade: MyFrame.__set_properties
        self.SetTitle(_("DirsSync2"))
        self.SetSize((732, 567))
        self.Frame_statusbar.SetStatusWidths([-1])
        # statusbar fields
        Frame_statusbar_fields = [""]
        for i in range(len(Frame_statusbar_fields)):
            self.Frame_statusbar.SetStatusText(Frame_statusbar_fields[i], i)
        self.STLocal.SetSize((50, 20))
        self.STRemote.SetSize((50, 20))
        self.BLocalDir.SetSize((20, 20))
        self.BRemoteDir.SetSize((20, 20))
        self.TCMaxDelta.SetSize((25, 20))
        self.BAddJob.Enable(0)
        self.BEditJob.Enable(0)
        self.BDeleteJob.Enable(0)
        self.BNext.SetSize((80, 60))
        self.BNext.Enable(0)
        self.CComparisonMethod.SetSelection(0)
        self.STComparisonDescription.SetLabel(comparisons_desc[0])
        # end wxGlade
        icon=wxIcon('dirssync.xpm',wxBITMAP_TYPE_XPM)
        self.SetIcon(icon)

    def __do_layout(self):
        # begin wxGlade: MyFrame.__do_layout
        Sizer_frame = wxBoxSizer(wxVERTICAL)
        Sizer_OptionsPanel = wxBoxSizer(wxVERTICAL)
        SizerComparisonMethod = wxStaticBoxSizer(wxStaticBox(self.OptionsPanel, -1, _("File comparison method")), wxVERTICAL)
        Sizer_LogPanel = wxBoxSizer(wxVERTICAL)
        Sizer_TransferPanel = wxBoxSizer(wxVERTICAL)
        Sizer_InputsPanel = wxFlexGridSizer(3, 1, 5, 0)
        Sizer_InputsPanel_Global = wxBoxSizer(wxVERTICAL)
        Sizer_InputsPanel_CMDs = wxBoxSizer(wxHORIZONTAL)
        Sizer_InputsPanel_CMDs_Cards = wxBoxSizer(wxHORIZONTAL)
        Sizer_InputsPanel_Options = wxBoxSizer(wxHORIZONTAL)
        Sizer_Parameters_MaxDelta = wxBoxSizer(wxHORIZONTAL)
        Sizer_InputsPanel_Remote = wxFlexGridSizer(1, 4, 0, 0)
        Sizer_InputsPanel_Remote_Exc_v = wxBoxSizer(wxVERTICAL)
        Sizer_InputsPanel_Remote_Exc_h = wxBoxSizer(wxHORIZONTAL)
        Sizer_InputsPanel_Remote_Inc_v = wxBoxSizer(wxVERTICAL)
        Sizer_InputsPanel_Remote_Inc_h = wxBoxSizer(wxHORIZONTAL)
        Sizer_InputsPanel_Remote_Dir_v = wxBoxSizer(wxVERTICAL)
        Sizer_InputsPanel_Remote_Dir_h = wxBoxSizer(wxHORIZONTAL)
        Sizer_inputsPanel_Local = wxFlexGridSizer(1, 4, 0, 0)
        Sizer_InputsPanel_Local_Exc_v = wxBoxSizer(wxVERTICAL)
        Sizer_InputsPanel_Local_Exc_h = wxBoxSizer(wxHORIZONTAL)
        Sizer_InputsPanel_Local_Inc_v = wxBoxSizer(wxVERTICAL)
        Sizer_InputsPanel_Local_Inc_h = wxBoxSizer(wxHORIZONTAL)
        Sizer_InputsPanel_Local_Dir_v = wxBoxSizer(wxVERTICAL)
        Sizer_InputsPanel_Local_Dir_h = wxBoxSizer(wxHORIZONTAL)
        Sizer_InputsPanel_Global.Add(self.MyLogo_1, 0, wxRIGHT|wxTOP|wxALIGN_RIGHT, 5)
        Sizer_inputsPanel_Local.Add(self.STLocal, 0, wxLEFT|wxALIGN_BOTTOM, 5)
        Sizer_InputsPanel_Local_Dir_v.Add(self.STLocalDir, 0, wxALL, 4)
        Sizer_InputsPanel_Local_Dir_h.Add(self.CLocalDir, 0, wxALL, 4)
        Sizer_InputsPanel_Local_Dir_h.Add(self.TCLocalDir, 1, wxLEFT, 0)
        Sizer_InputsPanel_Local_Dir_h.Add(self.BLocalDir, 0, 0, 0)
        Sizer_InputsPanel_Local_Dir_v.Add(Sizer_InputsPanel_Local_Dir_h, 1, wxEXPAND, 0)
        Sizer_inputsPanel_Local.Add(Sizer_InputsPanel_Local_Dir_v, 1, wxEXPAND, 0)
        Sizer_InputsPanel_Local_Inc_v.Add(self.STLocalInclude, 0, wxALL, 5)
        Sizer_InputsPanel_Local_Inc_h.Add(self.TCLocalIncPatt, 1, 0, 0)
        Sizer_InputsPanel_Local_Inc_h.Add(self.TCLocalIncDirs, 1, 0, 0)
        Sizer_InputsPanel_Local_Inc_v.Add(Sizer_InputsPanel_Local_Inc_h, 1, wxLEFT|wxEXPAND, 5)
        Sizer_inputsPanel_Local.Add(Sizer_InputsPanel_Local_Inc_v, 1, wxEXPAND, 0)
        Sizer_InputsPanel_Local_Exc_v.Add(self.STLocalExclude, 0, wxALL, 5)
        Sizer_InputsPanel_Local_Exc_h.Add(self.TCLocalExcPatt, 1, 0, 0)
        Sizer_InputsPanel_Local_Exc_h.Add(self.TCLocalExcDirs, 1, wxRIGHT, 5)
        Sizer_InputsPanel_Local_Exc_v.Add(Sizer_InputsPanel_Local_Exc_h, 1, wxLEFT|wxEXPAND, 5)
        Sizer_inputsPanel_Local.Add(Sizer_InputsPanel_Local_Exc_v, 1, wxEXPAND, 0)
        Sizer_inputsPanel_Local.AddGrowableCol(1)
        Sizer_inputsPanel_Local.AddGrowableCol(2)
        Sizer_inputsPanel_Local.AddGrowableCol(3)
        Sizer_InputsPanel_Global.Add(Sizer_inputsPanel_Local, 1, wxEXPAND, 0)
        Sizer_InputsPanel_Remote.Add(self.STRemote, 0, wxLEFT|wxALIGN_BOTTOM, 5)
        Sizer_InputsPanel_Remote_Dir_v.Add(self.STRemoteDir, 0, wxALL, 5)
        Sizer_InputsPanel_Remote_Dir_h.Add(self.CRemoteDir, 0, wxALL, 5)
        Sizer_InputsPanel_Remote_Dir_h.Add(self.TCRemoteDir, 1, wxLEFT, 0)
        Sizer_InputsPanel_Remote_Dir_h.Add(self.BRemoteDir, 0, 0, 0)
        Sizer_InputsPanel_Remote_Dir_v.Add(Sizer_InputsPanel_Remote_Dir_h, 1, wxEXPAND, 0)
        Sizer_InputsPanel_Remote.Add(Sizer_InputsPanel_Remote_Dir_v, 1, wxEXPAND, 0)
        Sizer_InputsPanel_Remote_Inc_v.Add(self.STRemoteInclude, 0, wxALL, 5)
        Sizer_InputsPanel_Remote_Inc_h.Add(self.TCRemoteIncPatt, 1, 0, 0)
        Sizer_InputsPanel_Remote_Inc_h.Add(self.TCRemoteIncDirs, 1, 0, 0)
        Sizer_InputsPanel_Remote_Inc_v.Add(Sizer_InputsPanel_Remote_Inc_h, 1, wxLEFT|wxEXPAND, 5)
        Sizer_InputsPanel_Remote.Add(Sizer_InputsPanel_Remote_Inc_v, 1, wxEXPAND, 0)
        Sizer_InputsPanel_Remote_Exc_v.Add(self.STRemoteExclude, 0, wxALL, 5)
        Sizer_InputsPanel_Remote_Exc_h.Add(self.TCRemoteExcPatt, 1, 0, 0)
        Sizer_InputsPanel_Remote_Exc_h.Add(self.TCRemoteExcDirs, 1, wxRIGHT, 5)
        Sizer_InputsPanel_Remote_Exc_v.Add(Sizer_InputsPanel_Remote_Exc_h, 1, wxLEFT|wxEXPAND, 5)
        Sizer_InputsPanel_Remote.Add(Sizer_InputsPanel_Remote_Exc_v, 1, wxEXPAND, 0)
        Sizer_InputsPanel_Remote.AddGrowableCol(1)
        Sizer_InputsPanel_Remote.AddGrowableCol(2)
        Sizer_InputsPanel_Remote.AddGrowableCol(3)
        Sizer_InputsPanel_Global.Add(Sizer_InputsPanel_Remote, 1, wxEXPAND, 0)
        Sizer_InputsPanel_Options.Add(self.STOptions, 0, wxRIGHT, 10)
        Sizer_InputsPanel_Options.Add(self.CBLocal2Remote, 0, wxLEFT|wxRIGHT, 5)
        Sizer_InputsPanel_Options.Add(self.CBRemote2Local, 0, wxLEFT|wxRIGHT, 5)
        Sizer_InputsPanel_Options.Add(self.CBDelete, 0, wxLEFT|wxRIGHT, 5)
        Sizer_Parameters_MaxDelta.Add(self.TCMaxDelta, 0, wxTOP, 2)
        Sizer_Parameters_MaxDelta.Add(self.STMaxDelta, 0, wxTOP, 2)
        Sizer_InputsPanel_Options.Add(Sizer_Parameters_MaxDelta, 0, wxLEFT|wxRIGHT|wxEXPAND, 5)
        Sizer_InputsPanel_Options.Add(self.CBCase, 0, wxLEFT|wxRIGHT, 5)
        Sizer_InputsPanel_Global.Add(Sizer_InputsPanel_Options, 1, wxTOP, 10)
        Sizer_InputsPanel_CMDs.Add(50, 20, 0, 0, 0)
        Sizer_InputsPanel_CMDs_Cards.Add(self.BAddJob, 0, wxLEFT|wxRIGHT|wxALIGN_BOTTOM, 5)
        Sizer_InputsPanel_CMDs_Cards.Add(self.BEditJob, 0, wxLEFT|wxRIGHT|wxALIGN_BOTTOM, 5)
        Sizer_InputsPanel_CMDs_Cards.Add(self.BDeleteJob, 0, wxLEFT|wxRIGHT|wxALIGN_BOTTOM, 5)
        Sizer_InputsPanel_CMDs.Add(Sizer_InputsPanel_CMDs_Cards, 1, wxEXPAND, 0)
        Sizer_InputsPanel_CMDs.Add(self.BNext, 0, wxRIGHT|wxBOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5)
        Sizer_InputsPanel_Global.Add(Sizer_InputsPanel_CMDs, 1, wxEXPAND, 0)
        Sizer_InputsPanel.Add(Sizer_InputsPanel_Global, 0, wxEXPAND, 0)
        Sizer_InputsPanel.Add(self.LCJobs, 2, wxEXPAND, 0)
        self.InputsPanel.SetAutoLayout(1)
        self.InputsPanel.SetSizer(Sizer_InputsPanel)
        Sizer_InputsPanel.Fit(self.InputsPanel)
        Sizer_InputsPanel.SetSizeHints(self.InputsPanel)
        Sizer_InputsPanel.AddGrowableRow(1)
        Sizer_InputsPanel.AddGrowableCol(0)
        Sizer_TransferPanel.Add(self.LCTransferList, 1, wxEXPAND, 0)
        Sizer_TransferPanel.Add(self.BSynchronize, 0, wxTOP|wxBOTTOM|wxALIGN_CENTER_HORIZONTAL, 10)
        self.TransferPanel.SetAutoLayout(1)
        self.TransferPanel.SetSizer(Sizer_TransferPanel)
        Sizer_TransferPanel.Fit(self.TransferPanel)
        Sizer_TransferPanel.SetSizeHints(self.TransferPanel)
        Sizer_LogPanel.Add(self.TCError, 1, wxEXPAND, 0)
        Sizer_LogPanel.Add(self.TCLog, 5, wxEXPAND, 0)
        Sizer_LogPanel.Add(self.BClear, 0, wxALL, 10)
        self.LogPanel.SetAutoLayout(1)
        self.LogPanel.SetSizer(Sizer_LogPanel)
        Sizer_LogPanel.Fit(self.LogPanel)
        Sizer_LogPanel.SetSizeHints(self.LogPanel)
        SizerComparisonMethod.Add(self.CComparisonMethod, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 0)
        SizerComparisonMethod.Add(self.STComparisonDescription, 1, wxEXPAND, 20)
        Sizer_OptionsPanel.Add(SizerComparisonMethod, 1, wxEXPAND, 5)
        self.OptionsPanel.SetAutoLayout(1)
        self.OptionsPanel.SetSizer(Sizer_OptionsPanel)
        Sizer_OptionsPanel.Fit(self.OptionsPanel)
        Sizer_OptionsPanel.SetSizeHints(self.OptionsPanel)
        self.Notebook.AddPage(self.InputsPanel, _("Inputs"))
        self.Notebook.AddPage(self.TransferPanel, _("Transfer list"))
        self.Notebook.AddPage(self.LogPanel, _("Log"))
        self.Notebook.AddPage(self.OptionsPanel, _("Options"))
        Sizer_frame.Add(wxNotebookSizer(self.Notebook), 1, wxEXPAND, 0)
        self.SetAutoLayout(1)
        self.SetSizer(Sizer_frame)
        self.Layout()
        # end wxGlade

    def __initialize(self):
        self.CBLocal2Remote.SetValue(True)
        self.CBRemote2Local.SetValue(True)
        self.CBCase.SetValue(True)
        self.TCMaxDelta.SetValue("0")
        self.jobslist=[]
        self.LCJobs.currentItemEdited=None
        self.LCJobs.InsertColumn(0,_("Local"))
        self.LCJobs.InsertColumn(1,_("Remote"))
        self.LCJobs.InsertColumn(2,_("Local to Remote"))
        self.LCJobs.InsertColumn(3,_("Remote to Local"))
        self.LCJobs.InsertColumn(4,_("Delete"))
        self.LCJobs.InsertColumn(5,_("Delta"))
        self.LCJobs.InsertColumn(6,_("Case"))
        self.LCJobs.SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER)
        self.LCJobs.SetColumnWidth(1, wxLIST_AUTOSIZE_USEHEADER)
        self.LCJobs.SetColumnWidth(2, wxLIST_AUTOSIZE_USEHEADER)
        self.LCJobs.SetColumnWidth(3, wxLIST_AUTOSIZE_USEHEADER)
        self.LCJobs.SetColumnWidth(4, wxLIST_AUTOSIZE_USEHEADER)
        self.LCJobs.SetColumnWidth(5, wxLIST_AUTOSIZE_USEHEADER)
        self.LCJobs.SetColumnWidth(6, wxLIST_AUTOSIZE_USEHEADER)
        self.LCTransferList.InsertColumn(0,_("Transfer"))
        self.LCTransferList.InsertColumn(1,_("Action"))
        self.LCTransferList.InsertColumn(2,_("File"))
        self.LCTransferList.InsertColumn(3,_("From"))
        self.LCTransferList.InsertColumn(4,_("To"))
        self.LCTransferList.InsertColumn(5,_("Comments"))
        self.jobedited=None
        self.CLocalDir.SetSelection(0)
        self.CRemoteDir.SetSelection(0)
        self.localoptions={}
        self.remoteoptions={}

    def __set_event(self):
        EVT_BUTTON(self,self.BLocalDir.GetId(),self.OnBLocalDir)
        EVT_BUTTON(self,self.BRemoteDir.GetId(),self.OnBRemoteDir)
        EVT_TEXT(self,self.TCLocalDir.GetId(),self.LCLocalorRemoteChanged)
        EVT_TEXT(self,self.TCRemoteDir.GetId(),self.LCLocalorRemoteChanged)
        EVT_BUTTON(self,self.BAddJob.GetId(),self.OnAddJob)
        EVT_LIST_ITEM_SELECTED(self, self.LCJobs.GetId(), self.OnLCJobsItemSelected)
        EVT_LIST_ITEM_DESELECTED(self, self.LCJobs.GetId(), self.OnLCJobsItemDeSelected)
        EVT_BUTTON(self,self.BEditJob.GetId(),self.OnEditJob)
        EVT_BUTTON(self,self.BDeleteJob.GetId(),self.OnDeleteJob)
        EVT_BUTTON(self,self.BNext.GetId(),self.OnNext)
        EVT_BUTTON(self,self.BClear.GetId(),self.OnClear)
        EVT_MENU(self,11,self.MnuNew)
        EVT_MENU(self,12,self.MnuOpen)
        EVT_MENU(self,13,self.MnuSave)
        EVT_MENU(self,14,self.MnuExit)
        EVT_MENU(self,21,self.MnuAbout)
        EVT_LIST_ITEM_SELECTED(self, self.LCTransferList.GetId(), self.OnLCTransferListItemSelected)
        EVT_LEFT_DCLICK(self.LCTransferList, self.OnLCTransferListDClick)
        EVT_BUTTON(self,self.BSynchronize.GetId(),self.OnSynchronize)
        EVT_CHOICE(self,self.CComparisonMethod.GetId(),self.OnComparisonMethod)
        

# end of class MyFrame

#Menu
    def MnuNew(self,event):
        self.LCJobs.DeleteAllItems()
        self.jobslist=[]
        self.TCError.Clear()
        self.TCLog.Clear()
        self.LCTransferList.DeleteAllItems()
        self.cleanInputsPanelTCs()
        self.jobedited=None

    def MnuOpen(self,event):
        if self.jobedited!=None:
            dlgW = wxMessageDialog(self, "You will looze the current Job card edited. Do you want to continue ?", "Warning", wxYES | wxNO | wxICON_EXCLAMATION)
            if dlgW.ShowModal()!=wxID_YES:
                dlgW.Destroy()
                return
            dlgW.Destroy()
        dlg = wxFileDialog(self, _("Choose a file"), ".", "", "*.sync", wxOPEN)
        if dlg.ShowModal() == wxID_OK:
            self.MnuNew(event)
            f=open(dlg.GetPath(),"r")
            self.jobslist=pickle.load(f)
            #self.IntoListCtrl(listdirs)
            f.close()
        dlg.Destroy()
        i=0
        for job in self.jobslist:
            self.LCJobs.InsertStringItem(i, dirnamedisplay(job.local.dir,job.local.options) )
            self.LCJobs.SetStringItem(i,1, dirnamedisplay(job.remote.dir,job.remote.options) )
            self.LCJobs.SetColumnWidth(0, wxLIST_AUTOSIZE)
            self.LCJobs.SetColumnWidth(1, wxLIST_AUTOSIZE)
            self.LCJobs.SetStringItem(i,2, bool2str(job.options['local2remote']))
            self.LCJobs.SetStringItem(i,3, bool2str(job.options['remote2local']))
            self.LCJobs.SetStringItem(i,4, bool2str(job.options['delete']))
            self.LCJobs.SetStringItem(i,5, str(job.options['delta']))
            self.LCJobs.SetStringItem(i,6, bool2str(job.options['casesensitive']))
            #we must re-assign loggin class because this was not pickled
            job.local._info=Log(self.TCLog)
            job.remote._info=Log(self.TCLog)
            job.local._error=Log(self.TCError)
            job.remote._error=Log(self.TCError)
            i+=1

        self.BNext.Enable(1)

    def MnuSave(self,event):
        if self.jobedited!=None:
            dlgW = wxMessageDialog(self, "You will looze the current Job card edited. Do you want to continue ?", "Warning", wxYES | wxNO | wxICON_EXCLAMATION)
            if dlgW.ShowModal()!=wxID_YES:
                dlgW.Destroy()
                return
            dlgW.Destroy()
        dlg = wxFileDialog(self, _("Choose a file"), ".", "", "*.sync", wxSAVE | wxOVERWRITE_PROMPT )
        if dlg.ShowModal() == wxID_OK:
            #listdirs = self.FromListCtrl()
            f=open(dlg.GetPath(),"w")
            pickle.dump(self.jobslist,f)
            f.close()
        dlg.Destroy()
    def MnuExit(self,event):
        if self.jobedited!=None:
            dlgW = wxMessageDialog(self, "You will looze the current Job card edited. Do you want to continue ?", "Warning", wxYES | wxNO | wxICON_EXCLAMATION)
            if dlgW.ShowModal()!=wxID_YES:
                dlgW.Destroy()
                return
            dlgW.Destroy()
        self.Close()
    def MnuAbout(self,event):
        dlg = wxMessageDialog(self, 'Directories Synchronizer %s is a Python and wxPython application\nwritten by Vincent Delft under the GPL license!\n\nFeel free to propose your ideas to improve this application\nby visiting http://DirsSync.sourceforge.net\nor\nby sending a Email at vincent_delft@yahoo.com' % __version__,
              'About Directories Synchronizer', wxOK | wxICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()

#PanelInputs 
    def cleanInputsPanelTCs(self):
        self.TCLocalDir.SetValue('')
        self.TCRemoteDir.SetValue('')
        self.TCLocalIncPatt.SetValue('.*,*')
        self.TCRemoteIncPatt.SetValue('.*,*')
        self.TCLocalExcPatt.SetValue('')
        self.TCRemoteExcPatt.SetValue('')
        self.TCLocalIncDirs.SetValue('')
        self.TCRemoteIncDirs.SetValue('')
        self.TCLocalExcDirs.SetValue('')
        self.TCRemoteExcDirs.SetValue('')
        self.CBLocal2Remote.SetValue(True)
        self.CBRemote2Local.SetValue(True)
        self.CBCase.SetValue(True)
        self.CBDelete.SetValue(False)
        self.TCMaxDelta.SetValue("0")
        self.CLocalDir.SetSelection(0)
        self.CRemoteDir.SetSelection(0)

    def OnBLocalDir(self,event):
        if self.CLocalDir.GetStringSelection()=="Dir":
            dlg = wxDirDialog(self,"Select a directory",defaultPath=self.TCLocalDir.GetValue())
            if dlg.ShowModal() == wxID_OK:
                self.TCLocalDir.SetValue(dlg.GetPath())
            dlg.Destroy()
        if self.CLocalDir.GetStringSelection()=="Zip":
            dlg = wxFileDialog(self,"Select a zip file",defaultFile=self.TCLocalDir.GetValue(),wildcard="*.zip",style=wxOPEN|wxCHANGE_DIR)
            if dlg.ShowModal() == wxID_OK:
                self.TCLocalDir.SetValue(dlg.GetPath())
            dlg.Destroy()
        if self.CLocalDir.GetStringSelection()=="Ftp":
            res=FTPDialog(self,self.localoptions)
            if res: self.localoptions=res
    def OnBRemoteDir(self,event):
        if self.CRemoteDir.GetStringSelection()=="Dir":
            dlg = wxDirDialog(self,"Select a directory",defaultPath=self.TCRemoteDir.GetValue())
            if dlg.ShowModal() == wxID_OK:
                self.TCRemoteDir.SetValue(dlg.GetPath())
            dlg.Destroy()
        if self.CRemoteDir.GetStringSelection()=="Zip":
            dlg = wxFileDialog(self,"Select a zip file",defaultFile=self.TCRemoteDir.GetValue(),wildcard="*.zip",style=wxOPEN)
            if dlg.ShowModal() == wxID_OK:
                self.TCRemoteDir.SetValue(dlg.GetPath())
            dlg.Destroy()
        if self.CRemoteDir.GetStringSelection()=="Ftp":
            res=FTPDialog(self,self.remoteoptions)
            if res: self.remoteoptions=res

    def LCLocalorRemoteChanged(self,event):
        self._validate_paths()
        if self.TCLocalDir.GetValue() and self.TCRemoteDir.GetValue(): 
            self.BAddJob.Enable(1)
        
    def _validate_paths(self):
        if self.TCLocalDir.GetValue().strip() and (self.TCLocalDir.GetValue() == self.TCRemoteDir.GetValue()):
            msg = _("The local and remote directories are the same")
            title=_("Input mismatch")
            dlgW = wxMessageDialog(self, msg, title, wxOK | wxICON_EXCLAMATION)
            dlgW.ShowModal()
            dlgW.Destroy()
            

    def OnAddJob(self,event):
        msg=None
        if not self.TCLocalDir.GetValue():
            msg = _("Local is empty. Can you update ?")
        if not self.TCRemoteDir.GetValue():
            msg = _("Remote is empty. Can you update ?")
        if (self.CBLocal2Remote.GetValue()==0 and self.CBRemote2Local.GetValue()==0):
            msg = _("Wake UP!!!!\nDirsSync must to know if you want synchronise from Locale to remote and/or remote to local. Thanks")
        if (self.CBLocal2Remote.GetValue() and self.CBRemote2Local.GetValue() and self.CBDelete.GetValue()):
            msg = _("Delete is a one way delete!!!\nPlease select 'local to remote' OR 'remote to local'")
        if msg:
            title=_("Input mismatch")
            dlgW = wxMessageDialog(self, msg, title, wxOK | wxICON_EXCLAMATION)
            dlgW.ShowModal()
            dlgW.Destroy()
            return
                
        incpatt=self.TCLocalIncPatt.GetValue().split(',')
        incdirs=self.TCLocalIncDirs.GetValue().split(',')
        excpatt=self.TCLocalExcPatt.GetValue().split(',')
        excdirs=self.TCLocalExcDirs.GetValue().split(',')
        dirlocal=eval('dirssync.%s(self.TCLocalDir.GetValue(),include_patt=incpatt,include_dirs=incdirs,exclude_patt=excpatt,exclude_dirs=excdirs,info=Log(self.TCLog),error=Log(self.TCError),options=self.localoptions)' % (classtypes[self.CLocalDir.GetSelection()]))
        incpatt=self.TCRemoteIncPatt.GetValue().split(',')
        incdirs=self.TCRemoteIncDirs.GetValue().split(',')
        excpatt=self.TCRemoteExcPatt.GetValue().split(',')
        excdirs=self.TCRemoteExcDirs.GetValue().split(',')
        dirremote=eval('dirssync.%s(self.TCRemoteDir.GetValue(),include_patt=incpatt,include_dirs=incdirs,exclude_patt=excpatt,exclude_dirs=excdirs,info=Log(self.TCLog),error=Log(self.TCError),options=self.remoteoptions)' % (classtypes[self.CRemoteDir.GetSelection()]))
        options=self.get_options()
        if self.jobedited!=None:
            x=self.jobedited
            self.LCJobs.SetStringItem(x,0, dirnamedisplay(self.TCLocalDir.GetValue(),self.localoptions) )
            self.LCJobs.SetStringItem(x,1, dirnamedisplay(self.TCRemoteDir.GetValue(),self.remoteoptions) )
            self.LCJobs.SetStringItem(x,2, bool2str(options['local2remote']))
            self.LCJobs.SetStringItem(x,3, bool2str(options['remote2local']))
            self.LCJobs.SetStringItem(x,4, bool2str(options['delete']))
            self.LCJobs.SetStringItem(x,5, str(options['delta']))
            self.LCJobs.SetStringItem(x,6, bool2str(options['casesensitive']))
            self.jobslist[x]=dirssync.Job(dirlocal,dirremote,options)
            self.jobedited=None
        else:
            x=self.LCJobs.GetItemCount()
            self.LCJobs.InsertStringItem(x, dirnamedisplay(self.TCLocalDir.GetValue(),self.localoptions) )
            self.LCJobs.SetStringItem(x,1, dirnamedisplay(self.TCRemoteDir.GetValue(),self.remoteoptions) )
            self.LCJobs.SetStringItem(x,2, bool2str(options['local2remote']))
            self.LCJobs.SetStringItem(x,3, bool2str(options['remote2local']))
            self.LCJobs.SetStringItem(x,4, bool2str(options['delete']))
            self.LCJobs.SetStringItem(x,5, str(options['delta']))
            self.LCJobs.SetStringItem(x,6, bool2str(options['casesensitive']))
            self.jobslist.append( dirssync.Job(dirlocal,dirremote,options))
        self.LCJobs.SetColumnWidth(0, wxLIST_AUTOSIZE)
        self.LCJobs.SetColumnWidth(1, wxLIST_AUTOSIZE)
        self.cleanInputsPanelTCs()
        self.BAddJob.Enable(0)
        self.LCJobs.currentItemEdited=None
        self.BNext.Enable(1)
    def OnLCJobsItemSelected(self,event):
        self.BEditJob.Enable(1)
        self.BDeleteJob.Enable(1)
        self.LCJobs.currentItemSelected=event.m_itemIndex
    def OnLCJobsItemDeSelected(self,event):
        self.BEditJob.Enable(0)
        self.BDeleteJob.Enable(0)
        self.LCJobs.currentItemSelected=None
    def get_options(self):
        result={}
        result['local2remote']=self.CBLocal2Remote.GetValue()
        result['remote2local']=self.CBRemote2Local.GetValue()
        result['delete']=self.CBDelete.GetValue()
        result['delta']=int(self.TCMaxDelta.GetValue())
        result['casesensitive']=self.CBCase.GetValue()
        return result
    def OnEditJob(self,event):
        if self.jobedited!=None:
            dlgW = wxMessageDialog(self, "You will looze the current Job card edited. Do you want to continue ?", "Warning", wxYES | wxNO | wxICON_EXCLAMATION)
            if dlgW.ShowModal()!=wxID_YES:
                dlgW.Destroy()
                return
            dlgW.Destroy()
        n=self.LCJobs.currentItemEdited=self.LCJobs.currentItemSelected
        job=self.jobslist[n]
        loc_inputs=job.getlocalinputs()
        rem_inputs=job.getremoteinputs()
        self.CLocalDir.SetSelection(classtypes.index(job.local.__class__.__name__))
        self.CRemoteDir.SetSelection(classtypes.index(job.remote.__class__.__name__))
        options=job.options
        self.TCLocalDir.SetValue(loc_inputs['dir'])
        self.TCRemoteDir.SetValue(rem_inputs['dir'])
        self.TCLocalIncPatt.SetValue(",".join(loc_inputs['include_patt']))
        self.TCRemoteIncPatt.SetValue(",".join(rem_inputs['include_patt']))
        self.TCLocalExcPatt.SetValue(",".join(loc_inputs['exclude_patt']))
        self.TCRemoteExcPatt.SetValue(",".join(rem_inputs['exclude_patt']))
        self.TCLocalIncDirs.SetValue(",".join(loc_inputs['include_dirs']))
        self.TCRemoteIncDirs.SetValue(",".join(rem_inputs['include_dirs']))
        self.TCLocalExcDirs.SetValue(",".join(loc_inputs['exclude_dirs']))
        self.TCRemoteExcDirs.SetValue(",".join(rem_inputs['exclude_dirs']))
        self.CBLocal2Remote.SetValue(options['local2remote'])
        self.CBRemote2Local.SetValue(options['remote2local'])
        self.CBDelete.SetValue(options['delete'])
        self.TCMaxDelta.SetValue(str(options['delta']))
        self.CBCase.SetValue(options['casesensitive'])
  if job.local.__class__.__name__==classtypes[2]:
      self.localoptions=job.local.options
  if job.remote.__class__.__name__==classtypes[2]:
      self.remoteoptions=job.remote.options
  
        self.jobedited=n

    def OnDeleteJob(self,event):
        if self.jobedited!=None:
            dlgW = wxMessageDialog(self, "You will looze the current Job card edited. Do you want to continue ?", "Warning", wxYES | wxNO | wxICON_EXCLAMATION)
            if dlgW.ShowModal()!=wxID_YES:
                dlgW.Destroy()
                return
            dlgW.Destroy()
        selection=self.LCJobs.currentItemSelected
        self.LCJobs.DeleteItem(selection)
        self.jobslist.pop(int(selection))
        if self.LCJobs.GetItemCount()==0:
            self.BNext.Enable(0)
    def OnNext(self,event):
        if self.jobedited!=None:
            dlgW = wxMessageDialog(self, "You will looze the current Job card edited. Do you want to continue ?", "Warning", wxYES | wxNO | wxICON_EXCLAMATION)
            if dlgW.ShowModal()!=wxID_YES:
                dlgW.Destroy()
                return
            dlgW.Destroy()
        self.LCTransferList.DeleteAllItems()
        self.Notebook.SetSelection(2)
        self.comp=[]
        for job in self.jobslist:
            comp=eval('dirssync.%s(job,info=Log(self.TCLog),error=Log(self.TCError))' % availablemethods[self.CComparisonMethod.GetSelection()] )
            self.comp.append(comp)
            comp.init()
            Log(self.TCLog).write('Initialising connections to local and/or remote (if any)')
            results=comp.getResults()
            Log(self.TCLog).write("Preparing results for display:  ")
            #we must remove the \n (or \r\n for Windows)
            pos_from=self.TCLog.GetLastPosition()-2
            i=0
            for res in results:
                txt="%2.2d%%" % ((i+1)*100.0/len(results))
                pos_to=self.TCLog.GetLastPosition()
                self.TCLog.Replace(pos_from,pos_to,txt)
                wxYield()
                self.LCTransferList.InsertStringItem(i,_("yes"))
                self.LCTransferList.SetStringItem(i,1,res[5])
                self.LCTransferList.SetStringItem(i,2,res[0].file)
                self.LCTransferList.SetStringItem(i,3,res[4])
                self.LCTransferList.SetStringItem(i,4,res[1])
                i+=1
                self.LCTransferList.SetColumnWidth(1, wxLIST_AUTOSIZE)
                self.LCTransferList.SetColumnWidth(2, wxLIST_AUTOSIZE)
                self.LCTransferList.SetColumnWidth(3, wxLIST_AUTOSIZE)
                self.LCTransferList.SetColumnWidth(4, wxLIST_AUTOSIZE)
            self.TCLog.AppendText('\n')
            comp.close()
        Log(self.TCLog).write("Analysis complete!!")
        self.Notebook.SetSelection(1)

#TransferList
    def OnLCTransferListItemSelected(self,event):
        self.LCTransferList.currentItemSelected = event.m_itemIndex

    def OnLCTransferListDClick(self,event):
        if self.LCTransferList.GetItemText(self.LCTransferList.currentItemSelected)==_("yes"):
            OppositeValue = _("no")
        else:
            OppositeValue = _("yes")

        self.LCTransferList.SetItemText(self.LCTransferList.currentItemSelected,OppositeValue)

    def OnSynchronize(self,event):
        self.Notebook.SetSelection(2)
        actions=[]
        for i in range(self.LCTransferList.GetItemCount()):
            if self.LCTransferList.GetItemText(i)==_("yes"):
                actions.append(1)
            else:
                actions.append(0)
        i=0
        for comp in self.comp:
            comp.init()
            results=comp.sync(actions[i:i+len(comp)])
            for res in results:
                self.LCTransferList.SetStringItem(i,5,res)
                self.LCTransferList.SetColumnWidth(5, wxLIST_AUTOSIZE)
                i+=1
            comp.close()
            Log(self.TCLog).write("Closing connections to local and/or remote (if any)")
        Log(self.TCLog).write("Transfert complete!!")
        if self.TCError.IsModified():
            self.Notebook.SetSelection(2)
        else:
            self.Notebook.SetSelection(1)

#Options
    def OnClear(self,event):
        self.TCLog.Clear()
        self.TCError.Clear()

    def OnComparisonMethod(self,event):
        self.STComparisonDescription.SetLabel(comparisons_desc[self.CComparisonMethod.GetSelection()])

# vim:et
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.