controls/IDManager.py
author Edouard Tisserant
Wed, 14 Nov 2018 14:09:18 +0100
changeset 2335 4262256e1d28
parent 2334 d1470c052662
permissions -rw-r--r--
IDManager.py : finished selector mode.
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
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    10
import json
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    11
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    12
def _GetInitialData(psk_path):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    13
    # [(ID, Desc, LastKnownURI, LastConnect)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    14
    data = []
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    15
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    16
    data_path = os.path.join(psk_path, 'management.json')
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    17
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    18
    if os.path.isdir(psk_path):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    19
        # load known keys metadata
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    20
        # {ID:(Desc, LastKnownURI, LastConnect)}
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    21
        recovered_data = json.loads(open(data_path).read()) \
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    22
                         if os.path.exists(data_path) else {}
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
        # go through all secret files available an build data
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    25
        # out of data recoverd from json and list of secret.
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    26
        # this implicitly filters IDs out of metadata who's
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    27
        # secret is missing
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    28
        psk_files = os.listdir(psk_path)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    29
        for filename in psk_files:
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    30
           if filename.endswith('.secret'):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    31
               ID = filename[:-7]  # strip filename extension
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    32
               meta = recovered_data.get(ID, 
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    33
                   ['', # default description
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    34
                    None, # last known URI
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    35
                    None])  # last connection date
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
               data.append([ID]+meta)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    38
    return 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 _DeleteID(psk_path, ID):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    41
    secret_path = os.path.join(psk_path, ID+'.secret')
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    42
    os.remove(secret_path)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    43
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    44
def _SaveData(psk_path, data):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    45
    if not os.path.isdir(psk_path):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    46
        os.mkdir(psk_path)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    47
    data_path = os.path.join(psk_path, 'management.json')
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    48
    to_store = {row[0]:row[1:] for row in data}
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    49
    with open(data_path, 'w') as f:
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    50
        f.write(json.dumps(to_store))
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    51
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    52
class IDManagerModel(dv.PyDataViewIndexListModel):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    53
    def __init__(self, psk_path, columncount):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    54
        self.psk_path = psk_path
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    55
        self.columncount = columncount
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    56
        self.data = _GetInitialData(psk_path)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    57
        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
    58
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    59
    def _saveData(self):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    60
        _SaveData(self.psk_path, self.data)
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
    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
    63
        return "string"
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    64
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    65
    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
    66
        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
    67
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    68
    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
    69
        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
    70
        self._saveData()
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    71
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    72
    def GetColumnCount(self):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    73
        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
    74
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    75
    def GetCount(self):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    76
        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
    77
    
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    78
    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
    79
        if col == 3:
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    80
            attr.SetColour('blue')
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    81
            attr.SetBold(True)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    82
            return True
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    83
        return False
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
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    86
    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
    87
        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
    88
            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
    89
        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
    90
        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
    91
        if col == 0:
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    92
            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
    93
        else:
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    94
            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
    95
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    96
    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
    97
        rows = list(rows)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    98
        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
    99
        
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   100
        for row in rows:
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   101
            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
   102
            _DeleteID(self.psk_path, ID)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   103
            self.RowDeleted(row)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   104
        self._saveData()
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   105
            
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   106
    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
   107
        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
   108
        self.RowAppended()
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   109
        self._saveData()
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   110
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   111
colflags = dv.DATAVIEW_COL_RESIZABLE|dv.DATAVIEW_COL_SORTABLE
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   112
COL_ID,COL_URI,COL_DESC,COL_LAST = range(4)
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
class IDManager(wx.Panel):
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   115
    def __init__(self, parent, ctr, SelectURICallBack=None, SelectIDCallBack=None, **kwargs):
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   116
        wx.Panel.__init__(self, parent, -1, size=(400,200))
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   117
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   118
        self.isManager = SelectURICallBack is None and SelectIDCallBack is None 
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   119
        self.SelectURICallBack = SelectURICallBack
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   120
        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
   121
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   122
        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
   123
        if self.isManager :
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   124
            # 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
   125
            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
   126
        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
   127
                    
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   128
        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
   129
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   130
        ColumnsDesc = [
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   131
            args(_("ID"), COL_ID, width = 100),
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   132
            args(_("Last URI"), COL_URI, width = 80),
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   133
            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
   134
                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
   135
                       if self.isManager 
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   136
                       else dv.DATAVIEW_CELL_INERT),
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   137
            args(_("Last connection"),  COL_LAST, width = 100),
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   138
        ]
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   139
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   140
        self.model = IDManagerModel(
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   141
            os.path.join(str(ctr.ProjectPath), 'psk'),
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   142
            len(ColumnsDesc))
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   143
        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
   144
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   145
        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
   146
            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
   147
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   148
        # TODO : when select,
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   149
        #  - 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
   150
        #  - 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
   151
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   152
        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
   153
        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
   154
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   155
        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
   156
        if self.isManager :
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   157
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   158
            # 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
   159
            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
   160
            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
   161
            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
   162
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   163
            # export all
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   164
            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
   165
            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
   166
            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
   167
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   168
            # 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
   169
            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
   170
            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
   171
            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
   172
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   173
        else :
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   174
            # selector mode
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   175
            # 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
   176
            # TODO : disable use URI button until something selected
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   177
            self.useURIButton = wx.Button(self, label=_("Use last URI"))
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   178
            self.Bind(wx.EVT_BUTTON, self.OnUseURIButton, self.useURIButton)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   179
            self.useURIButton.Disable()
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   180
            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
   181
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   182
        self.Sizer.Add(btnbox, 0, wx.TOP|wx.BOTTOM, 5)
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   183
        self.Bind(dv.EVT_DATAVIEW_SELECTION_CHANGED, self.OnSelectionChanged, self.dvc)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   184
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   185
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   186
    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
   187
        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
   188
        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
   189
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   190
        # 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
   191
        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
   192
                         _('Delete IDs'),
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   193
                             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
   194
            return
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   195
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   196
        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
   197
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   198
    def OnSelectionChanged(self, evt):
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   199
        if not self.isManager :
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   200
            items = self.dvc.GetSelections()
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   201
            somethingSelected = len(items) > 0
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   202
            self.useURIButton.Enable(somethingSelected)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   203
            if somethingSelected:
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   204
                row = self.model.GetRow(items[0])
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   205
                ID = self.model.GetValueByRow(row, COL_ID)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   206
                self.SelectIDCallBack(ID)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   207
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   208
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   209
    def OnUseURIButton(self, evt):
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   210
        row = self.model.GetRow(self.dvc.GetSelections()[0])
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   211
        URI = self.model.GetValueByRow(row, COL_URI)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   212
        if URI:
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   213
            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
   214
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   215
    def OnExportButton(self, evt):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   216
        # TODO 
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   217
        wx.MessageBox(_('?'),
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   218
                      _('Mhe'),
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   219
                      wx.YES_NO | wx.CENTRE | wx.NO_DEFAULT)
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):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   222
        # TODO 
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   223
        wx.MessageBox(_('?'),
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   224
                      _('Mhe'),
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   225
                      wx.YES_NO | wx.CENTRE | wx.NO_DEFAULT)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   226