Index: python-dsv-1.4.1/DSV/DSV.py =================================================================== --- python-dsv-1.4.1.orig/DSV/DSV.py 2010-01-26 20:35:23.000000000 -0500 +++ python-dsv-1.4.1/DSV/DSV.py 2010-01-26 20:37:59.000000000 -0500 @@ -2,6 +2,9 @@ DSV.py - Cliff Wells, 2002 Import/export DSV (delimiter separated values, a generalization of CSV). +2007-01-09: Modified by Joe Pham to accommodate + wxPython 2.8+ + Basic use: from DSV import DSV @@ -133,8 +136,14 @@ # import os # os.putenv('LANG', 'C') +##try: +## from wxPython import wx, grid +##except ImportError: +## wx = None + try: - from wxPython import wx, grid + import wx + import wx.grid as gridlib except ImportError: wx = None @@ -625,19 +634,19 @@ if wx is not None: # ------------------------------------------------------------------------------ - class ImportWizardPanel_Delimiters(wx.wxPanel): + class ImportWizardPanel_Delimiters(wx.Panel): """ CLASS(SUPERCLASS): - ImportWizardPanel_Delimiters(wx.wxPanel) + ImportWizardPanel_Delimiters(wx.Panel) DESCRIPTION: - A wx.wxPanel that provides a basic interface for validating and changing the + A wx.Panel that provides a basic interface for validating and changing the parameters for importing a delimited text file. Similar to MS Excel's CSV import wizard. Can be used in a series of wizards or embedded in an application. PROTOTYPE: ImportWizardPanel_Delimiters(parent, id, file, data, isValidCallback = None, - pos = wx.wxDefaultPosition, size = wx.wxDefaultSize, - style = wx.wxTAB_TRAVERSAL, name = 'ImportWizardPanel') + pos = wx.DefaultPosition, size = wx.DefaultSize, + style = wx.TAB_TRAVERSAL, name = 'ImportWizardPanel') ARGUMENTS: - parent is the parent window - id is the id of this wizard panel @@ -657,24 +666,24 @@ """ def __init__(self, parent, id, file, data, isValidCallback = None, - pos = wx.wxDefaultPosition, size = wx.wxDefaultSize, - style = wx.wxTAB_TRAVERSAL, name = "ImportWizardPanel"): - wx.wxPanel.__init__(self, parent, id, pos, size, style, name) - self.SetAutoLayout(wx.true) - mainSizer = wx.wxFlexGridSizer(3, 1) + pos = wx.DefaultPosition, size = wx.DefaultSize, + style = wx.TAB_TRAVERSAL, name = "ImportWizardPanel"): + wx.Panel.__init__(self, parent, id, pos, size, style, name) + self.SetAutoLayout(True) + mainSizer = wx.FlexGridSizer(3, 1) self.SetSizer(mainSizer) mainSizer.AddGrowableCol(0) - self.initialized = wx.false + self.initialized = False self.data = data self.isValidCallback = isValidCallback self.Validate = (isValidCallback and self.Validate) or self.BuildPreview - dlg = wx.wxProgressDialog("Import Wizard", + dlg = wx.ProgressDialog("Import Wizard", "Analyzing %s... Please wait." % file, 3, parent, - wx.wxPD_APP_MODAL | wx.wxPD_AUTO_HIDE) + wx.PD_APP_MODAL | wx.PD_AUTO_HIDE) textQualifier = guessTextQualifier(data) dlg.Update(1) newdata = organizeIntoLines(data, textQualifier = textQualifier, limit = 100) @@ -686,13 +695,13 @@ # ------------- msg = ("This screen lets you set the delimiters your data contains.\n" "You can see how your data is affected in the preview below.") - message1 = wx.wxStaticText(self, -1, msg) + message1 = wx.StaticText(self, -1, msg) # ------------- - delimiterBox = wx.wxBoxSizer(wx.wxHORIZONTAL) - delimStaticBox = wx.wxStaticBox(self, -1, "Delimiters") - delimStaticSizer = wx.wxStaticBoxSizer(delimStaticBox, wx.wxVERTICAL) - delimGridSizer = wx.wxFlexGridSizer(2, 3) + delimiterBox = wx.BoxSizer(wx.HORIZONTAL) + delimStaticBox = wx.StaticBox(self, -1, "Delimiters") + delimStaticSizer = wx.StaticBoxSizer(delimStaticBox, wx.VERTICAL) + delimGridSizer = wx.FlexGridSizer(2, 3) delims = { 'Tab': '\t', @@ -704,36 +713,36 @@ self.delimChecks = {} for label, value in delims.items(): - self.delimChecks[value] = wx.wxCheckBox(self, -1, label) - delimGridSizer.Add(self.delimChecks[value], 0, wx.wxALL, 3) + self.delimChecks[value] = wx.CheckBox(self, -1, label) + delimGridSizer.Add(self.delimChecks[value], 0, wx.ALL, 3) wx.EVT_CHECKBOX(self, self.delimChecks[value].GetId(), self.Validate) - otherSizer = wx.wxBoxSizer(wx.wxHORIZONTAL) + otherSizer = wx.BoxSizer(wx.HORIZONTAL) - self.delimChecks['Other'] = wx.wxCheckBox(self, -1, 'Other:') + self.delimChecks['Other'] = wx.CheckBox(self, -1, 'Other:') wx.EVT_CHECKBOX(self, self.delimChecks['Other'].GetId(), self.Validate) - self.otherDelim = wx.wxTextCtrl(self, -1, size = (20, -1)) + self.otherDelim = wx.TextCtrl(self, -1, size = (20, -1)) wx.EVT_TEXT(self, self.otherDelim.GetId(), self.OnCustomDelim) if self.delimChecks.has_key(delimiter): - self.delimChecks[delimiter].SetValue(wx.true) + self.delimChecks[delimiter].SetValue(True) elif delimiter is not None: - self.delimChecks['Other'].SetValue(wx.true) + self.delimChecks['Other'].SetValue(True) self.otherDelim.SetValue(delimiter) otherSizer.AddMany([ - (self.delimChecks['Other'], 0, wx.wxALL, 3), - (self.otherDelim, 0, wx.wxALIGN_CENTER), + (self.delimChecks['Other'], 0, wx.ALL, 3), + (self.otherDelim, 0, wx.ALIGN_CENTER), ]) delimGridSizer.Add(otherSizer) - delimStaticSizer.Add(delimGridSizer, 1, wx.wxEXPAND) - delimOtherSizer = wx.wxBoxSizer(wx.wxVERTICAL) - self.consecutiveDelimsAs1 = wx.wxCheckBox(self, -1, "Treat consecutive delimiters as one") - self.consecutiveDelimsAs1.Enable(wx.false) - tqSizer = wx.wxBoxSizer(wx.wxHORIZONTAL) - self.textQualifierChoice = wx.wxChoice(self, -1, choices = ['"', "'", "{None}"]) + delimStaticSizer.Add(delimGridSizer, 1, wx.EXPAND) + delimOtherSizer = wx.BoxSizer(wx.VERTICAL) + self.consecutiveDelimsAs1 = wx.CheckBox(self, -1, "Treat consecutive delimiters as one") + self.consecutiveDelimsAs1.Enable(False) + tqSizer = wx.BoxSizer(wx.HORIZONTAL) + self.textQualifierChoice = wx.Choice(self, -1, choices = ['"', "'", "{None}"]) wx.EVT_CHOICE(self, self.textQualifierChoice.GetId(), self.BuildPreview) if textQualifier is not None: self.textQualifierChoice.SetStringSelection(textQualifier) @@ -741,52 +750,52 @@ self.textQualifierChoice.SetStringSelection('{None}') tqSizer.AddMany([ - (wx.wxStaticText(self, -1, "Text qualifier:"), 0, wx.wxALIGN_RIGHT | wx.wxALIGN_CENTER_VERTICAL), - (self.textQualifierChoice, 0, wx.wxALL | wx.wxALIGN_LEFT | wx.wxALIGN_CENTER_VERTICAL, 5), + (wx.StaticText(self, -1, "Text qualifier:"), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL), + (self.textQualifierChoice, 0, wx.ALL | wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 5), ]) delimOtherSizer.AddMany([ - (self.consecutiveDelimsAs1, 1, wx.wxEXPAND | wx.wxALL, 5), - (tqSizer, 1, wx.wxALL | wx.wxALIGN_CENTER, 5), + (self.consecutiveDelimsAs1, 1, wx.EXPAND | wx.ALL, 5), + (tqSizer, 1, wx.ALL | wx.ALIGN_CENTER, 5), ]) delimiterBox.AddMany([ - (delimStaticSizer, 0, wx.wxALIGN_CENTER), - (delimOtherSizer, 0, wx.wxALIGN_CENTER), + (delimStaticSizer, 0, wx.ALIGN_CENTER), + (delimOtherSizer, 0, wx.ALIGN_CENTER), ]) delimStaticBox.Fit() # ------------- self.displayRows = 6 - previewSettingsBox = wx.wxBoxSizer(wx.wxHORIZONTAL) - self.hasHeaderRow = wx.wxCheckBox(self, -1, "First row is header") + previewSettingsBox = wx.BoxSizer(wx.HORIZONTAL) + self.hasHeaderRow = wx.CheckBox(self, -1, "First row is header") wx.EVT_CHECKBOX(self, self.hasHeaderRow.GetId(), self.BuildPreview) - if wx.wxPlatform in ('__WX.WXGTK__', '__WX.WXMSW__'): - # wx.wxSpinCtrl causes seg fault under GTK when is hit in text - use wx.wxSpinButton instead - self.previewRowsText = wx.wxTextCtrl(self, -1, str(self.displayRows), - size = (30, -1), style = wx.wxTE_PROCESS_ENTER) + if wx.Platform in ('__WX.WXGTK__', '__WX.WXMSW__'): + # wx.SpinCtrl causes seg fault under GTK when is hit in text - use wx.SpinButton instead + self.previewRowsText = wx.TextCtrl(self, -1, str(self.displayRows), + size = (30, -1), style = wx.TE_PROCESS_ENTER) h = self.previewRowsText.GetSize().height - self.previewRows = wx.wxSpinButton(self, -1, size = (-1, h), style = wx.wxSP_VERTICAL) + self.previewRows = wx.SpinButton(self, -1, size = (-1, h), style = wx.SP_VERTICAL) self.previewRows.SetRange(self.displayRows, 100) self.previewRows.SetValue(self.displayRows) wx.EVT_SPIN(self, self.previewRows.GetId(), self.OnSpinPreviewRows) wx.EVT_TEXT_ENTER(self, self.previewRowsText.GetId(), self.OnTextPreviewRows) else: - self.previewRows = wx.wxSpinCtrl(self, -1, str(self.displayRows), + self.previewRows = wx.SpinCtrl(self, -1, str(self.displayRows), min = self.displayRows, max = 100, size = (50, -1)) wx.EVT_SPINCTRL(self, self.previewRows.GetId(), self.BuildPreview) previewSettingsBox.AddMany([ - (self.hasHeaderRow, 1, wx.wxALL | wx.wxEXPAND, 5), - (wx.wxStaticText(self, -1, "Preview"), 0, wx.wxWEST | wx.wxALIGN_RIGHT | wx.wxALIGN_CENTER_VERTICAL, 10), + (self.hasHeaderRow, 1, wx.ALL | wx.EXPAND, 5), + (wx.StaticText(self, -1, "Preview"), 0, wx.WEST | wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 10), ]) - if wx.wxPlatform in ('__WX.WXGTK__', '__WX.WXMSW__'): - previewSettingsBox.Add(self.previewRowsText, 0, wx.wxALIGN_CENTER | wx.wxALL, 3) + if wx.Platform in ('__WX.WXGTK__', '__WX.WXMSW__'): + previewSettingsBox.Add(self.previewRowsText, 0, wx.ALIGN_CENTER | wx.ALL, 3) previewSettingsBox.AddMany([ - (self.previewRows, 0, wx.wxALIGN_CENTER | wx.wxALL, 3), - (wx.wxStaticText(self, -1, "rows"), 0, wx.wxALIGN_RIGHT | wx.wxALIGN_CENTER_VERTICAL), + (self.previewRows, 0, wx.ALIGN_CENTER | wx.ALL, 3), + (wx.StaticText(self, -1, "rows"), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL), ]) # ------------- @@ -804,28 +813,28 @@ hasHeaders = 0 cols = 1 - previewStaticBox = wx.wxStaticBox(self, -1, "Data Preview") - previewStaticSizer = wx.wxStaticBoxSizer(previewStaticBox, wx.wxVERTICAL) - self.preview = grid.wxGrid(self, -1) + previewStaticBox = wx.StaticBox(self, -1, "Data Preview") + previewStaticSizer = wx.StaticBoxSizer(previewStaticBox, wx.VERTICAL) + self.preview = gridlib.Grid(self, -1) self.preview.CreateGrid(self.displayRows, cols) - self.preview.SetDefaultRowSize(self.preview.GetCharHeight() + 4, wx.true) - self.preview.EnableEditing(wx.false) + self.preview.SetDefaultRowSize(self.preview.GetCharHeight() + 4, True) + self.preview.EnableEditing(False) self.preview.SetColLabelSize(0) self.preview.SetRowLabelSize(0) self.preview.SetMargins(1, 0) - self.initialized = wx.true + self.initialized = True self.BuildPreview() rowheight = self.preview.GetRowSize(0) + 2 self.preview.SetSize((-1, rowheight * self.displayRows)) - previewStaticSizer.Add(self.preview, 0, wx.wxALL | wx.wxEXPAND, 5) + previewStaticSizer.Add(self.preview, 0, wx.ALL | wx.EXPAND, 5) # ------------- mainSizer.AddMany([ - (message1, 0, wx.wxALL, 5), - (delimiterBox, 0, wx.wxALL, 5), - (previewSettingsBox, 0, wx.wxALL, 5), - (previewStaticSizer, 0, wx.wxALL | wx.wxEXPAND, 5), + (message1, 0, wx.ALL, 5), + (delimiterBox, 0, wx.ALL, 5), + (previewSettingsBox, 0, wx.ALL, 5), + (previewStaticSizer, 0, wx.ALL | wx.EXPAND, 5), ]) self.Layout() @@ -855,9 +864,9 @@ if not self.initialized: return # got triggered before initialization was completed - if wx.wxPlatform != '__WX.WXGTK__': - wx.wxBeginBusyCursor() # causes a spurious spin event under GTK - wx.wxYield() # allow controls to update first, in case of slow preview + if wx.Platform != '__WX.WXGTK__': + wx.BeginBusyCursor() # causes a spurious spin event under GTK + wx.Yield() # allow controls to update first, in case of slow preview self.preview.BeginBatch() self.preview.DeleteCols(0, self.preview.GetNumberCols()) self.preview.DeleteRows(0, self.preview.GetNumberRows()) @@ -892,7 +901,7 @@ for col in range(cols): try: self.preview.SetColLabelValue(col, str(previewData[0][col])) except: self.preview.SetColLabelValue(col, "") - # self.preview.AutoSizeColumns(wx.true) # size columns to headers + # self.preview.AutoSizeColumns(True) # size columns to headers else: self.preview.SetColLabelSize(0) @@ -902,13 +911,13 @@ except: pass # if not hasHeaders: - self.preview.AutoSizeColumns(wx.true) # size columns to data + self.preview.AutoSizeColumns(True) # size columns to data rowheight = self.preview.GetRowSize(0) self.preview.SetRowSize(0, rowheight) self.preview.EndBatch() - if wx.wxPlatform != '__WX.WXGTK__': - wx.wxEndBusyCursor() + if wx.Platform != '__WX.WXGTK__': + wx.EndBusyCursor() self.delimiters = delimiter self.textQualifier = textQualifier @@ -928,17 +937,17 @@ return self.hasHeaders # ------------------------------------------------------------------------------ - class ImportWizardDialog(wx.wxDialog): + class ImportWizardDialog(wx.Dialog): """ CLASS(SUPERCLASS): - ImportWizardDialog(wx.wxDialog) + ImportWizardDialog(wx.Dialog) DESCRIPTION: A dialog allowing the user to preview and change the options for importing a file. PROTOTYPE: ImportWizardDialog(parent, id, title, file, - pos = wx.wxDefaultPosition, size = wx.wxDefaultSize, - style = wx.wxDEFAULT_DIALOG_STYLE, name = 'ImportWizardDialog') + pos = wx.DefaultPosition, size = wx.DefaultSize, + style = wx.DEFAULT_DIALOG_STYLE, name = 'ImportWizardDialog') ARGUMENTS: - parent: the parent window - id: the id of this window @@ -955,22 +964,22 @@ """ def __init__(self, parent, id, title, file, - pos = wx.wxDefaultPosition, size = wx.wxDefaultSize, - style = wx.wxDEFAULT_DIALOG_STYLE, name = "ImportWizardDialog"): - wx.wxDialog.__init__(self, parent, id, title, pos, size, style, name) - self.SetAutoLayout(wx.true) + pos = wx.DefaultPosition, size = wx.DefaultSize, + style = wx.DEFAULT_DIALOG_STYLE, name = "ImportWizardDialog"): + wx.Dialog.__init__(self, parent, id, title, pos, size, style, name) + self.SetAutoLayout(True) self.file = file f = open(file, 'r') self.data = f.read() f.close() - sizer = wx.wxBoxSizer(wx.wxVERTICAL) + sizer = wx.BoxSizer(wx.VERTICAL) self.delimPanel = ImportWizardPanel_Delimiters(self, -1, file, self.data, self.ValidState) buttonBox = self.ButtonBox() sizer.AddMany([ - (self.delimPanel, 0, wx.wxALL, 5), - (buttonBox, 0, wx.wxSOUTH | wx.wxALIGN_CENTER_HORIZONTAL | wx.wxALIGN_TOP, 0), + (self.delimPanel, 0, wx.ALL, 5), + (buttonBox, 0, wx.SOUTH | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_TOP, 0), ]) self.SetSizer(sizer) @@ -980,15 +989,15 @@ self.Centre() def ButtonBox(self): - panel = wx.wxPanel(self, -1) - panel.SetAutoLayout(wx.true) - sizer = wx.wxBoxSizer(wx.wxHORIZONTAL) + panel = wx.Panel(self, -1) + panel.SetAutoLayout(True) + sizer = wx.BoxSizer(wx.HORIZONTAL) panel.SetSizer(sizer) - self.ok = wx.wxButton(panel, wx.wxID_OK, "Ok") - cancel = wx.wxButton(panel, wx.wxID_CANCEL, "Cancel") + self.ok = wx.Button(panel, wx.ID_OK, "Ok") + cancel = wx.Button(panel, wx.ID_CANCEL, "Cancel") sizer.AddMany([ - (self.ok, 0, wx.wxALIGN_TOP | wx.wxEAST | wx.wxSOUTH, 10), - (cancel, 0, wx.wxALIGN_TOP | wx.wxWEST | wx.wxSOUTH, 10), + (self.ok, 0, wx.ALIGN_TOP | wx.EAST | wx.SOUTH, 10), + (cancel, 0, wx.ALIGN_TOP | wx.WEST | wx.SOUTH, 10), ]) panel.Layout() panel.Fit() @@ -1002,11 +1011,11 @@ def ImportData(self, errorHandler = skipRow): delimiters, qualifier, hasHeaders = self.GetImportInfo() self.data = organizeIntoLines(self.data, textQualifier = qualifier) - dlg = wx.wxProgressDialog("Import DSV File", + dlg = wx.ProgressDialog("Import DSV File", self.file, 100, self, - wx.wxPD_CAN_ABORT | wx.wxPD_APP_MODAL | wx.wxPD_AUTO_HIDE) + wx.PD_CAN_ABORT | wx.PD_APP_MODAL | wx.PD_AUTO_HIDE) self.data = importDSV(self.data, delimiter = delimiters, textQualifier = qualifier, @@ -1034,12 +1043,12 @@ def demo(): - class SampleApp(wx.wxApp): + class SampleApp(wx.App): def OnInit(self): - dlg = wx.wxFileDialog(None, "Choose a file", ".", "", + dlg = wx.FileDialog(None, "Choose a file", ".", "", "CSV files (*.csv)|*.csv|Text files (*.txt)|*.txt|All files (*.*)|*.*", - wx.wxOPEN) - if dlg.ShowModal() == wx.wxID_OK: + wx.OPEN) + if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() dlg.Destroy() @@ -1049,7 +1058,7 @@ file.write("LINE %d: %s\n" % (linenumber, oldrow)) dlg = ImportWizardDialog(None, -1, 'CSV Import Wizard (v.%s)' % __version__, path) - if dlg.ShowModal() == wx.wxID_OK: + if dlg.ShowModal() == wx.ID_OK: results = dlg.ImportData(errorHandler = logErrors) dlg.Destroy() errorLog.close() @@ -1074,7 +1083,7 @@ else: dlg.Destroy() - return wx.true + return True app = SampleApp() app.MainLoop()