controls/IDBrowser.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Fri, 23 Nov 2018 00:45:51 +0100
changeset 2430 65ff9a309ff3
parent 2428 e0f16317668e
child 2458 2a70d5240300
permissions -rw-r--r--
Fixed regression in connecting to LOCAL:// targets
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
     1
#!/usr/bin/env python
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
     3
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
     4
# See COPYING file for copyrights details.
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
     5
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
     6
from __future__ import absolute_import
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
     7
import os
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
     8
import wx
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
     9
import wx.dataview as dv
2339
48b4eba13064 IDManager : refactored a bit, moved some code into PSKManagement.py. Now captures URI and PSK on new PYRO(S) and propose them when editing URI. Import/export still to be implemented.
Edouard Tisserant
parents: 2336
diff changeset
    10
import PSKManagement as PSK
2428
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
    11
from PSKManagement import *
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
    12
from dialogs.IDMergeDialog import IDMergeDialog
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    13
2336
869a61616b42 Renamed IDManager control into IDBrowser, because dialog will be named IDManager
Edouard Tisserant
parents: 2335
diff changeset
    14
class IDBrowserModel(dv.PyDataViewIndexListModel):
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    15
    def __init__(self, project_path, columncount):
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    16
        self.project_path = project_path
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    17
        self.columncount = columncount
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    18
        self.data = PSK.GetData(project_path)
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    19
        dv.PyDataViewIndexListModel.__init__(self, len(self.data))
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    20
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    21
    def _saveData(self):
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    22
        PSK.SaveData(self.project_path, self.data)
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    23
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    24
    def GetColumnType(self, col):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    25
        return "string"
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    26
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    27
    def GetValueByRow(self, row, col):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    28
        return self.data[row][col]
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    29
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    30
    def SetValueByRow(self, value, row, col):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    31
        self.data[row][col] = value
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    32
        self._saveData()
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    33
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    34
    def GetColumnCount(self):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    35
        return len(self.data[0]) if self.data else self.columncount
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    36
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    37
    def GetCount(self):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    38
        return len(self.data)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    39
    
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    40
    def GetAttrByRow(self, row, col, attr):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    41
        if col == 3:
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    42
            attr.SetColour('blue')
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    43
            attr.SetBold(True)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    44
            return True
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    45
        return False
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    46
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    47
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    48
    def Compare(self, item1, item2, col, ascending):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    49
        if not ascending: # swap sort order?
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    50
            item2, item1 = item1, item2
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    51
        row1 = self.GetRow(item1)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    52
        row2 = self.GetRow(item2)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    53
        if col == 0:
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    54
            return cmp(int(self.data[row1][col]), int(self.data[row2][col]))
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    55
        else:
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    56
            return cmp(self.data[row1][col], self.data[row2][col])
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    57
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    58
    def DeleteRows(self, rows):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    59
        rows = list(rows)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    60
        rows.sort(reverse=True)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    61
        
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    62
        for row in rows:
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    63
            PSK.DeleteID(self.project_path, self.data[row][COL_ID])
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    64
            del self.data[row]
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    65
            self.RowDeleted(row)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    66
        self._saveData()
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    67
            
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    68
    def AddRow(self, value):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    69
        self.data.append(value)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    70
        self.RowAppended()
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    71
        self._saveData()
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    72
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    73
    def Import(self, filepath, sircb):
2428
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
    74
        data = PSK.ImportIDs(self.project_path, filepath, sircb)
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
    75
        if data is not None:
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
    76
            self.data = data
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
    77
            self.Reset(len(self.data)) 
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    78
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    79
    def Export(self, filepath):
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    80
        PSK.ExportIDs(self.project_path, filepath)
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    81
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    82
colflags = dv.DATAVIEW_COL_RESIZABLE|dv.DATAVIEW_COL_SORTABLE
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    83
2336
869a61616b42 Renamed IDManager control into IDBrowser, because dialog will be named IDManager
Edouard Tisserant
parents: 2335
diff changeset
    84
class IDBrowser(wx.Panel):
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
    85
    def __init__(self, parent, ctr, SelectURICallBack=None, SelectIDCallBack=None, **kwargs):
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    86
        big = self.isManager = SelectURICallBack is None and SelectIDCallBack is None 
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    87
        wx.Panel.__init__(self, parent, -1, size=(800 if big else 400,
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    88
                                                  600 if big else 200))
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    89
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    90
        self.SelectURICallBack = SelectURICallBack
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
    91
        self.SelectIDCallBack = SelectIDCallBack
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    92
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    93
        dvStyle = wx.BORDER_THEME | dv.DV_ROW_LINES
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    94
        if self.isManager :
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    95
            # no multiple selection in selector mode
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    96
            dvStyle |= dv.DV_MULTIPLE
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    97
        self.dvc = dv.DataViewCtrl(self, style = dvStyle)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    98
                    
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    99
        args = lambda *a,**k:(a,k)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   100
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   101
        ColumnsDesc = [
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   102
            args(_("ID"), COL_ID, width = 100),
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   103
            args(_("Last URI"), COL_URI, width = 160 if big else 80),
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   104
            args(_("Description"), COL_DESC, width = 200, 
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   105
                mode = dv.DATAVIEW_CELL_EDITABLE 
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   106
                       if self.isManager 
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   107
                       else dv.DATAVIEW_CELL_INERT),
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   108
            args(_("Last connection"),  COL_LAST, width = 120),
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   109
        ]
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   110
2339
48b4eba13064 IDManager : refactored a bit, moved some code into PSKManagement.py. Now captures URI and PSK on new PYRO(S) and propose them when editing URI. Import/export still to be implemented.
Edouard Tisserant
parents: 2336
diff changeset
   111
        self.model = IDBrowserModel(ctr.ProjectPath, len(ColumnsDesc))
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   112
        self.dvc.AssociateModel(self.model)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   113
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   114
        for a,k in ColumnsDesc:
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   115
            self.dvc.AppendTextColumn(*a,**dict(k, flags = colflags))
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   116
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   117
        # TODO : when select,
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   118
        #  - update ID field of scheme editor
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   119
        #  - enable use URI button
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   120
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   121
        self.Sizer = wx.BoxSizer(wx.VERTICAL) 
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   122
        self.Sizer.Add(self.dvc, 1, wx.EXPAND)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   123
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   124
        btnbox = wx.BoxSizer(wx.HORIZONTAL)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   125
        if self.isManager :
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   126
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   127
            # deletion of secret and metadata
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   128
            deleteButton = wx.Button(self, label=_("Delete ID"))
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   129
            self.Bind(wx.EVT_BUTTON, self.OnDeleteButton, deleteButton)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   130
            btnbox.Add(deleteButton, 0, wx.LEFT|wx.RIGHT, 5)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   131
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   132
            # export all
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   133
            exportButton = wx.Button(self, label=_("Export all"))
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   134
            self.Bind(wx.EVT_BUTTON, self.OnExportButton, exportButton)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   135
            btnbox.Add(exportButton, 0, wx.LEFT|wx.RIGHT, 5)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   136
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   137
            # import with a merge -> duplicates are asked for
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   138
            importButton = wx.Button(self, label=_("Import"))
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   139
            self.Bind(wx.EVT_BUTTON, self.OnImportButton, importButton)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   140
            btnbox.Add(importButton, 0, wx.LEFT|wx.RIGHT, 5)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   141
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   142
        else :
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   143
            # selector mode
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   144
            # use last known URI button
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   145
            # TODO : disable use URI button until something selected
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   146
            self.useURIButton = wx.Button(self, label=_("Use last URI"))
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   147
            self.Bind(wx.EVT_BUTTON, self.OnUseURIButton, self.useURIButton)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   148
            self.useURIButton.Disable()
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   149
            btnbox.Add(self.useURIButton, 0, wx.LEFT|wx.RIGHT, 5)
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   150
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   151
        self.Sizer.Add(btnbox, 0, wx.TOP|wx.BOTTOM, 5)
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   152
        self.Bind(dv.EVT_DATAVIEW_SELECTION_CHANGED, self.OnSelectionChanged, self.dvc)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   153
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   154
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   155
    def OnDeleteButton(self, evt):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   156
        items = self.dvc.GetSelections()
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   157
        rows = [self.model.GetRow(item) for item in items]
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   158
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   159
        # Ask if user really wants to delete
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   160
        if wx.MessageBox(_('Are you sure to delete selected IDs?'),
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   161
                         _('Delete IDs'),
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   162
                             wx.YES_NO | wx.CENTRE | wx.NO_DEFAULT) != wx.YES:
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   163
            return
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   164
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   165
        self.model.DeleteRows(rows)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   166
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   167
    def OnSelectionChanged(self, evt):
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   168
        if not self.isManager :
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   169
            items = self.dvc.GetSelections()
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   170
            somethingSelected = len(items) > 0
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   171
            self.useURIButton.Enable(somethingSelected)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   172
            if somethingSelected:
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   173
                row = self.model.GetRow(items[0])
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   174
                ID = self.model.GetValueByRow(row, COL_ID)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   175
                self.SelectIDCallBack(ID)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   176
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   177
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   178
    def OnUseURIButton(self, evt):
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   179
        row = self.model.GetRow(self.dvc.GetSelections()[0])
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   180
        URI = self.model.GetValueByRow(row, COL_URI)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   181
        if URI:
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   182
            self.SelectURICallBack(URI)
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   183
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   184
    def OnExportButton(self, evt):
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   185
        dialog = wx.FileDialog(self, _("Choose a file"),
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   186
                               wildcard = _("PSK ZIP files (*.zip)|*.zip"), 
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   187
                               style = wx.SAVE | wx.OVERWRITE_PROMPT)
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   188
        if dialog.ShowModal() == wx.ID_OK:
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   189
            self.model.Export(dialog.GetPath())
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   190
2428
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   191
    def ShouldIReplaceCallback(self,existing,replacement):
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   192
        ID,URI,DESC,LAST = existing
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   193
        _ID,_URI,_DESC,_LAST = replacement
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   194
        dlg = IDMergeDialog(self, 
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   195
            _("Import IDs"), 
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   196
            (_("Replace information for ID {ID} ?") + "\n\n" +
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   197
             _("Existing:") + "\n    " +
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   198
             _("Description:") + " {DESC}\n    " +
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   199
             _("Last known URI:") + " {URI}\n    " +
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   200
             _("Last connection:") + " {LAST}\n\n" +
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   201
             _("Replacement:") + "\n    " +
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   202
             _("Description:") + " {_DESC}\n    " +
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   203
             _("Last known URI:") + " {_URI}\n    " +
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   204
             _("Last connection:") + " {_LAST}\n").format(**locals()),
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   205
            _("Do the same for following IDs"),
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   206
            [_("Replace"), _("Keep"),_("Cancel")])
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   207
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   208
        answer = dlg.ShowModal() # return value ignored as we have "Ok" only anyhow
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   209
        if answer == wx.ID_CANCEL:
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   210
            return CANCEL
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   211
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   212
        if dlg.OptionChecked():
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   213
            if answer == wx.ID_YES:
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   214
                return REPLACE_ALL
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   215
            return KEEP_ALL
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   216
        else:
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   217
            if answer == wx.ID_YES:
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   218
                return REPLACE
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   219
            return KEEP
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   220
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   221
    def OnImportButton(self, evt):
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   222
        dialog = wx.FileDialog(self, _("Choose a file"),
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   223
                               wildcard = _("PSK ZIP files (*.zip)|*.zip"), 
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   224
                               style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   225
        if dialog.ShowModal() == wx.ID_OK:
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   226
            self.model.Import(dialog.GetPath(),
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   227
                              self.ShouldIReplaceCallback)
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   228