controls/IDBrowser.py
changeset 2428 e0f16317668e
parent 2340 decf52efb7f7
child 2458 2a70d5240300
equal deleted inserted replaced
2340:decf52efb7f7 2428:e0f16317668e
     6 from __future__ import absolute_import
     6 from __future__ import absolute_import
     7 import os
     7 import os
     8 import wx
     8 import wx
     9 import wx.dataview as dv
     9 import wx.dataview as dv
    10 import PSKManagement as PSK
    10 import PSKManagement as PSK
    11 from PSKManagement import COL_ID,COL_URI,COL_DESC,COL_LAST
    11 from PSKManagement import *
       
    12 from dialogs.IDMergeDialog import IDMergeDialog
    12 
    13 
    13 class IDBrowserModel(dv.PyDataViewIndexListModel):
    14 class IDBrowserModel(dv.PyDataViewIndexListModel):
    14     def __init__(self, project_path, columncount):
    15     def __init__(self, project_path, columncount):
    15         self.project_path = project_path
    16         self.project_path = project_path
    16         self.columncount = columncount
    17         self.columncount = columncount
    68         self.data.append(value)
    69         self.data.append(value)
    69         self.RowAppended()
    70         self.RowAppended()
    70         self._saveData()
    71         self._saveData()
    71 
    72 
    72     def Import(self, filepath, sircb):
    73     def Import(self, filepath, sircb):
    73         PSK.ImportIDs(self.project_path, filepath, sircb)
    74         data = PSK.ImportIDs(self.project_path, filepath, sircb)
       
    75         if data is not None:
       
    76             self.data = data
       
    77             self.Reset(len(self.data)) 
    74 
    78 
    75     def Export(self, filepath):
    79     def Export(self, filepath):
    76         PSK.ExportIDs(self.project_path, filepath)
    80         PSK.ExportIDs(self.project_path, filepath)
    77 
    81 
    78 colflags = dv.DATAVIEW_COL_RESIZABLE|dv.DATAVIEW_COL_SORTABLE
    82 colflags = dv.DATAVIEW_COL_RESIZABLE|dv.DATAVIEW_COL_SORTABLE
   182                                wildcard = _("PSK ZIP files (*.zip)|*.zip"), 
   186                                wildcard = _("PSK ZIP files (*.zip)|*.zip"), 
   183                                style = wx.SAVE | wx.OVERWRITE_PROMPT)
   187                                style = wx.SAVE | wx.OVERWRITE_PROMPT)
   184         if dialog.ShowModal() == wx.ID_OK:
   188         if dialog.ShowModal() == wx.ID_OK:
   185             self.model.Export(dialog.GetPath())
   189             self.model.Export(dialog.GetPath())
   186 
   190 
   187     def ShouldIReplaceCallback(self,some,stuff):
   191     def ShouldIReplaceCallback(self,existing,replacement):
   188         # TODO
   192         ID,URI,DESC,LAST = existing
   189         wx.MessageBox("TODO : ShouldIReplaceCallback")
   193         _ID,_URI,_DESC,_LAST = replacement
   190         return True
   194         dlg = IDMergeDialog(self, 
       
   195             _("Import IDs"), 
       
   196             (_("Replace information for ID {ID} ?") + "\n\n" +
       
   197              _("Existing:") + "\n    " +
       
   198              _("Description:") + " {DESC}\n    " +
       
   199              _("Last known URI:") + " {URI}\n    " +
       
   200              _("Last connection:") + " {LAST}\n\n" +
       
   201              _("Replacement:") + "\n    " +
       
   202              _("Description:") + " {_DESC}\n    " +
       
   203              _("Last known URI:") + " {_URI}\n    " +
       
   204              _("Last connection:") + " {_LAST}\n").format(**locals()),
       
   205             _("Do the same for following IDs"),
       
   206             [_("Replace"), _("Keep"),_("Cancel")])
       
   207 
       
   208         answer = dlg.ShowModal() # return value ignored as we have "Ok" only anyhow
       
   209         if answer == wx.ID_CANCEL:
       
   210             return CANCEL
       
   211 
       
   212         if dlg.OptionChecked():
       
   213             if answer == wx.ID_YES:
       
   214                 return REPLACE_ALL
       
   215             return KEEP_ALL
       
   216         else:
       
   217             if answer == wx.ID_YES:
       
   218                 return REPLACE
       
   219             return KEEP
   191 
   220 
   192     def OnImportButton(self, evt):
   221     def OnImportButton(self, evt):
   193         dialog = wx.FileDialog(self, _("Choose a file"),
   222         dialog = wx.FileDialog(self, _("Choose a file"),
   194                                wildcard = _("PSK ZIP files (*.zip)|*.zip"), 
   223                                wildcard = _("PSK ZIP files (*.zip)|*.zip"), 
   195                                style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
   224                                style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)