controls/IDBrowser.py
author Edouard Tisserant
Fri, 25 Jan 2019 14:06:11 +0100
changeset 2483 6a7f92b84855
parent 2458 2a70d5240300
child 2492 7dd551ac2fa0
permissions -rw-r--r--
Split IDE's frame OnCloseFrame() into TryCloseFrame() and OnCloseFrame(), to help further customization
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 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
    41
        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
    42
            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
    43
        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
    44
        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
    45
        if col == 0:
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    46
            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
    47
        else:
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    48
            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
    49
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    50
    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
    51
        rows = list(rows)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    52
        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
    53
        
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    54
        for row in rows:
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    55
            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
    56
            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
    57
            self.RowDeleted(row)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    58
        self._saveData()
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    59
            
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    60
    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
    61
        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
    62
        self.RowAppended()
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    63
        self._saveData()
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    64
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    65
    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
    66
        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
    67
        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
    68
            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
    69
            self.Reset(len(self.data)) 
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    70
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    71
    def Export(self, filepath):
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    72
        PSK.ExportIDs(self.project_path, filepath)
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    73
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    74
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
    75
2336
869a61616b42 Renamed IDManager control into IDBrowser, because dialog will be named IDManager
Edouard Tisserant
parents: 2335
diff changeset
    76
class IDBrowser(wx.Panel):
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
    77
    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
    78
        big = self.isManager = SelectURICallBack is None and SelectIDCallBack is None 
2458
2a70d5240300 IDManager : small cosmetic fixes and cleanup.
Edouard Tisserant
parents: 2428
diff changeset
    79
        wx.Panel.__init__(self, parent, -1, size=(800 if big else 450,
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    80
                                                  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
    81
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    82
        self.SelectURICallBack = SelectURICallBack
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
    83
        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
    84
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    85
        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
    86
        if self.isManager :
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    87
            # 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
    88
            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
    89
        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
    90
                    
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    91
        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
    92
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    93
        ColumnsDesc = [
2458
2a70d5240300 IDManager : small cosmetic fixes and cleanup.
Edouard Tisserant
parents: 2428
diff changeset
    94
            args(_("ID"), COL_ID, width = 70),
2a70d5240300 IDManager : small cosmetic fixes and cleanup.
Edouard Tisserant
parents: 2428
diff changeset
    95
            args(_("Last URI"), COL_URI, width = 300 if big else 80),
2a70d5240300 IDManager : small cosmetic fixes and cleanup.
Edouard Tisserant
parents: 2428
diff changeset
    96
            args(_("Description"), COL_DESC, width = 300 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
    97
                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
    98
                       if self.isManager 
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    99
                       else dv.DATAVIEW_CELL_INERT),
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   100
            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
   101
        ]
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   102
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
   103
        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
   104
        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
   105
2458
2a70d5240300 IDManager : small cosmetic fixes and cleanup.
Edouard Tisserant
parents: 2428
diff changeset
   106
        col_list = []
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   107
        for a,k in ColumnsDesc:
2458
2a70d5240300 IDManager : small cosmetic fixes and cleanup.
Edouard Tisserant
parents: 2428
diff changeset
   108
            col_list.append(
2a70d5240300 IDManager : small cosmetic fixes and cleanup.
Edouard Tisserant
parents: 2428
diff changeset
   109
                self.dvc.AppendTextColumn(*a,**dict(k, flags = colflags)))
2a70d5240300 IDManager : small cosmetic fixes and cleanup.
Edouard Tisserant
parents: 2428
diff changeset
   110
        col_list[COL_LAST].SetSortOrder(False)
2a70d5240300 IDManager : small cosmetic fixes and cleanup.
Edouard Tisserant
parents: 2428
diff changeset
   111
2a70d5240300 IDManager : small cosmetic fixes and cleanup.
Edouard Tisserant
parents: 2428
diff changeset
   112
        # TODO : sort by last bvisit by default
2334
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
        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
   115
        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
   116
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   117
        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
   118
        if self.isManager :
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   119
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   120
            # 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
   121
            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
   122
            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
   123
            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
   124
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   125
            # export all
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   126
            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
   127
            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
   128
            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
   129
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   130
            # 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
   131
            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
   132
            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
   133
            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
   134
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   135
        else :
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   136
            # selector mode
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   137
            self.useURIButton = wx.Button(self, label=_("Use last URI"))
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   138
            self.Bind(wx.EVT_BUTTON, self.OnUseURIButton, self.useURIButton)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   139
            self.useURIButton.Disable()
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   140
            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
   141
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   142
        self.Sizer.Add(btnbox, 0, wx.TOP|wx.BOTTOM, 5)
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   143
        self.Bind(dv.EVT_DATAVIEW_SELECTION_CHANGED, self.OnSelectionChanged, self.dvc)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   144
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   145
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   146
    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
   147
        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
   148
        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
   149
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   150
        # 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
   151
        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
   152
                         _('Delete IDs'),
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   153
                             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
   154
            return
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   155
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   156
        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
   157
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   158
    def OnSelectionChanged(self, evt):
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   159
        if not self.isManager :
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   160
            items = self.dvc.GetSelections()
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   161
            somethingSelected = len(items) > 0
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   162
            self.useURIButton.Enable(somethingSelected)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   163
            if somethingSelected:
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   164
                row = self.model.GetRow(items[0])
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   165
                ID = self.model.GetValueByRow(row, COL_ID)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   166
                self.SelectIDCallBack(ID)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   167
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   168
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   169
    def OnUseURIButton(self, evt):
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   170
        row = self.model.GetRow(self.dvc.GetSelections()[0])
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   171
        URI = self.model.GetValueByRow(row, COL_URI)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   172
        if URI:
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   173
            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
   174
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   175
    def OnExportButton(self, evt):
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   176
        dialog = wx.FileDialog(self, _("Choose a file"),
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   177
                               wildcard = _("PSK ZIP files (*.zip)|*.zip"), 
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   178
                               style = wx.SAVE | wx.OVERWRITE_PROMPT)
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   179
        if dialog.ShowModal() == wx.ID_OK:
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   180
            self.model.Export(dialog.GetPath())
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   181
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
   182
    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
   183
        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
   184
        _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
   185
        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
   186
            _("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
   187
            (_("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
   188
             _("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
   189
             _("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
   190
             _("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
   191
             _("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
   192
             _("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
   193
             _("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
   194
             _("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
   195
             _("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
   196
            _("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
   197
            [_("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
   198
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
        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
   200
        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
   201
            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
   202
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
        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
   204
            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
   205
                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
   206
            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
   207
        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
   208
            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
   209
                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
   210
            return KEEP
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   211
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   212
    def OnImportButton(self, evt):
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   213
        dialog = wx.FileDialog(self, _("Choose a file"),
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   214
                               wildcard = _("PSK ZIP files (*.zip)|*.zip"), 
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   215
                               style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   216
        if dialog.ShowModal() == wx.ID_OK:
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   217
            self.model.Import(dialog.GetPath(),
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   218
                              self.ShouldIReplaceCallback)
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   219