controls/IDBrowser.py
changeset 2340 decf52efb7f7
parent 2339 48b4eba13064
child 2428 e0f16317668e
equal deleted inserted replaced
2339:48b4eba13064 2340:decf52efb7f7
     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 COL_ID,COL_URI,COL_DESC,COL_LAST
    12 
    12 
    13 class IDBrowserModel(dv.PyDataViewIndexListModel):
    13 class IDBrowserModel(dv.PyDataViewIndexListModel):
    14     def __init__(self, psk_path, columncount):
    14     def __init__(self, project_path, columncount):
    15         self.psk_path = psk_path
    15         self.project_path = project_path
    16         self.columncount = columncount
    16         self.columncount = columncount
    17         self.data = PSK.GetData(psk_path)
    17         self.data = PSK.GetData(project_path)
    18         dv.PyDataViewIndexListModel.__init__(self, len(self.data))
    18         dv.PyDataViewIndexListModel.__init__(self, len(self.data))
    19 
    19 
    20     def _saveData(self):
    20     def _saveData(self):
    21         PSK.SaveData(self.psk_path, self.data)
    21         PSK.SaveData(self.project_path, self.data)
    22 
    22 
    23     def GetColumnType(self, col):
    23     def GetColumnType(self, col):
    24         return "string"
    24         return "string"
    25 
    25 
    26     def GetValueByRow(self, row, col):
    26     def GetValueByRow(self, row, col):
    57     def DeleteRows(self, rows):
    57     def DeleteRows(self, rows):
    58         rows = list(rows)
    58         rows = list(rows)
    59         rows.sort(reverse=True)
    59         rows.sort(reverse=True)
    60         
    60         
    61         for row in rows:
    61         for row in rows:
    62             PSK.DeleteID(self.psk_path, self.data[row][COL_ID])
    62             PSK.DeleteID(self.project_path, self.data[row][COL_ID])
    63             del self.data[row]
    63             del self.data[row]
    64             self.RowDeleted(row)
    64             self.RowDeleted(row)
    65         self._saveData()
    65         self._saveData()
    66             
    66             
    67     def AddRow(self, value):
    67     def AddRow(self, value):
    68         self.data.append(value)
    68         self.data.append(value)
    69         self.RowAppended()
    69         self.RowAppended()
    70         self._saveData()
    70         self._saveData()
    71 
    71 
       
    72     def Import(self, filepath, sircb):
       
    73         PSK.ImportIDs(self.project_path, filepath, sircb)
       
    74 
       
    75     def Export(self, filepath):
       
    76         PSK.ExportIDs(self.project_path, filepath)
       
    77 
    72 colflags = dv.DATAVIEW_COL_RESIZABLE|dv.DATAVIEW_COL_SORTABLE
    78 colflags = dv.DATAVIEW_COL_RESIZABLE|dv.DATAVIEW_COL_SORTABLE
    73 
    79 
    74 class IDBrowser(wx.Panel):
    80 class IDBrowser(wx.Panel):
    75     def __init__(self, parent, ctr, SelectURICallBack=None, SelectIDCallBack=None, **kwargs):
    81     def __init__(self, parent, ctr, SelectURICallBack=None, SelectIDCallBack=None, **kwargs):
    76         wx.Panel.__init__(self, parent, -1, size=(400,200))
    82         big = self.isManager = SelectURICallBack is None and SelectIDCallBack is None 
       
    83         wx.Panel.__init__(self, parent, -1, size=(800 if big else 400,
       
    84                                                   600 if big else 200))
    77 
    85 
    78         self.isManager = SelectURICallBack is None and SelectIDCallBack is None 
       
    79         self.SelectURICallBack = SelectURICallBack
    86         self.SelectURICallBack = SelectURICallBack
    80         self.SelectIDCallBack = SelectIDCallBack
    87         self.SelectIDCallBack = SelectIDCallBack
    81 
    88 
    82         dvStyle = wx.BORDER_THEME | dv.DV_ROW_LINES
    89         dvStyle = wx.BORDER_THEME | dv.DV_ROW_LINES
    83         if self.isManager :
    90         if self.isManager :
    87                     
    94                     
    88         args = lambda *a,**k:(a,k)
    95         args = lambda *a,**k:(a,k)
    89 
    96 
    90         ColumnsDesc = [
    97         ColumnsDesc = [
    91             args(_("ID"), COL_ID, width = 100),
    98             args(_("ID"), COL_ID, width = 100),
    92             args(_("Last URI"), COL_URI, width = 80),
    99             args(_("Last URI"), COL_URI, width = 160 if big else 80),
    93             args(_("Description"), COL_DESC, width = 200, 
   100             args(_("Description"), COL_DESC, width = 200, 
    94                 mode = dv.DATAVIEW_CELL_EDITABLE 
   101                 mode = dv.DATAVIEW_CELL_EDITABLE 
    95                        if self.isManager 
   102                        if self.isManager 
    96                        else dv.DATAVIEW_CELL_INERT),
   103                        else dv.DATAVIEW_CELL_INERT),
    97             args(_("Last connection"),  COL_LAST, width = 100),
   104             args(_("Last connection"),  COL_LAST, width = 120),
    98         ]
   105         ]
    99 
   106 
   100         self.model = IDBrowserModel(ctr.ProjectPath, len(ColumnsDesc))
   107         self.model = IDBrowserModel(ctr.ProjectPath, len(ColumnsDesc))
   101         self.dvc.AssociateModel(self.model)
   108         self.dvc.AssociateModel(self.model)
   102 
   109 
   169         URI = self.model.GetValueByRow(row, COL_URI)
   176         URI = self.model.GetValueByRow(row, COL_URI)
   170         if URI:
   177         if URI:
   171             self.SelectURICallBack(URI)
   178             self.SelectURICallBack(URI)
   172 
   179 
   173     def OnExportButton(self, evt):
   180     def OnExportButton(self, evt):
   174         # TODO 
   181         dialog = wx.FileDialog(self, _("Choose a file"),
   175         wx.MessageBox(_('?'),
   182                                wildcard = _("PSK ZIP files (*.zip)|*.zip"), 
   176                       _('Mhe'),
   183                                style = wx.SAVE | wx.OVERWRITE_PROMPT)
   177                       wx.YES_NO | wx.CENTRE | wx.NO_DEFAULT)
   184         if dialog.ShowModal() == wx.ID_OK:
       
   185             self.model.Export(dialog.GetPath())
       
   186 
       
   187     def ShouldIReplaceCallback(self,some,stuff):
       
   188         # TODO
       
   189         wx.MessageBox("TODO : ShouldIReplaceCallback")
       
   190         return True
   178 
   191 
   179     def OnImportButton(self, evt):
   192     def OnImportButton(self, evt):
   180         # TODO 
   193         dialog = wx.FileDialog(self, _("Choose a file"),
   181         wx.MessageBox(_('?'),
   194                                wildcard = _("PSK ZIP files (*.zip)|*.zip"), 
   182                       _('Mhe'),
   195                                style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
   183                       wx.YES_NO | wx.CENTRE | wx.NO_DEFAULT)
   196         if dialog.ShowModal() == wx.ID_OK:
       
   197             self.model.Import(dialog.GetPath(),
       
   198                               self.ShouldIReplaceCallback)
   184 
   199