controls/IDBrowser.py
author Edouard Tisserant
Tue, 20 Nov 2018 11:32:42 +0100
changeset 2339 48b4eba13064
parent 2336 869a61616b42
child 2340 decf52efb7f7
permissions -rw-r--r--
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.
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
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
    11
from PSKManagement import COL_ID,COL_URI,COL_DESC,COL_LAST
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    12
2336
869a61616b42 Renamed IDManager control into IDBrowser, because dialog will be named IDManager
Edouard Tisserant
parents: 2335
diff changeset
    13
class IDBrowserModel(dv.PyDataViewIndexListModel):
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    14
    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
    15
        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
    16
        self.columncount = columncount
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
    17
        self.data = PSK.GetData(psk_path)
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    18
        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
    19
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    20
    def _saveData(self):
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
    21
        PSK.SaveData(self.psk_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
    22
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    23
    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
    24
        return "string"
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    25
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    26
    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
    27
        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
    28
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    29
    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
    30
        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
    31
        self._saveData()
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    32
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    33
    def GetColumnCount(self):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    34
        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
    35
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    36
    def GetCount(self):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    37
        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
    38
    
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    39
    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
    40
        if col == 3:
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    41
            attr.SetColour('blue')
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    42
            attr.SetBold(True)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    43
            return True
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    44
        return False
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    45
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
    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
    48
        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
    49
            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
    50
        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
    51
        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
    52
        if col == 0:
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    53
            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
    54
        else:
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    55
            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
    56
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    57
    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
    58
        rows = list(rows)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    59
        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
    60
        
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    61
        for row in rows:
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
    62
            PSK.DeleteID(self.psk_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
    63
            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
    64
            self.RowDeleted(row)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    65
        self._saveData()
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    66
            
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    67
    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
    68
        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
    69
        self.RowAppended()
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
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
    73
2336
869a61616b42 Renamed IDManager control into IDBrowser, because dialog will be named IDManager
Edouard Tisserant
parents: 2335
diff changeset
    74
class IDBrowser(wx.Panel):
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
    75
    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
    76
        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
    77
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
    78
        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
    79
        self.SelectURICallBack = SelectURICallBack
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
    80
        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
    81
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    82
        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
    83
        if self.isManager :
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    84
            # 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
    85
            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
    86
        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
    87
                    
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    88
        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
    89
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    90
        ColumnsDesc = [
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
    91
            args(_("ID"), COL_ID, width = 100),
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
    92
            args(_("Last URI"), COL_URI, width = 80),
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
    93
            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
    94
                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
    95
                       if self.isManager 
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    96
                       else dv.DATAVIEW_CELL_INERT),
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
    97
            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
    98
        ]
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    99
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
   100
        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
   101
        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
   102
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   103
        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
   104
            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
   105
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   106
        # TODO : when select,
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   107
        #  - 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
   108
        #  - 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
   109
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   110
        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
   111
        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
   112
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   113
        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
   114
        if self.isManager :
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   115
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   116
            # 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
   117
            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
   118
            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
   119
            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
   120
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   121
            # export all
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   122
            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
   123
            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
   124
            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
   125
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   126
            # 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
   127
            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
   128
            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
   129
            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
   130
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   131
        else :
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   132
            # selector mode
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   133
            # 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
   134
            # TODO : disable use URI button until something selected
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   135
            self.useURIButton = wx.Button(self, label=_("Use last URI"))
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   136
            self.Bind(wx.EVT_BUTTON, self.OnUseURIButton, self.useURIButton)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   137
            self.useURIButton.Disable()
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   138
            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
   139
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   140
        self.Sizer.Add(btnbox, 0, wx.TOP|wx.BOTTOM, 5)
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   141
        self.Bind(dv.EVT_DATAVIEW_SELECTION_CHANGED, self.OnSelectionChanged, self.dvc)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   142
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   143
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   144
    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
   145
        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
   146
        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
   147
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   148
        # 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
   149
        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
   150
                         _('Delete IDs'),
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   151
                             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
   152
            return
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   153
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   154
        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
   155
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   156
    def OnSelectionChanged(self, evt):
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   157
        if not self.isManager :
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   158
            items = self.dvc.GetSelections()
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   159
            somethingSelected = len(items) > 0
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   160
            self.useURIButton.Enable(somethingSelected)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   161
            if somethingSelected:
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   162
                row = self.model.GetRow(items[0])
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   163
                ID = self.model.GetValueByRow(row, COL_ID)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   164
                self.SelectIDCallBack(ID)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   165
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   166
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   167
    def OnUseURIButton(self, evt):
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   168
        row = self.model.GetRow(self.dvc.GetSelections()[0])
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   169
        URI = self.model.GetValueByRow(row, COL_URI)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   170
        if URI:
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   171
            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
   172
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   173
    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
   174
        # TODO 
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   175
        wx.MessageBox(_('?'),
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   176
                      _('Mhe'),
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   177
                      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
   178
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   179
    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
   180
        # TODO 
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   181
        wx.MessageBox(_('?'),
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   182
                      _('Mhe'),
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   183
                      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
   184