controls/IDBrowser.py
author Edouard Tisserant <edouard@beremiz.fr>
Thu, 05 Dec 2024 16:45:37 +0100
changeset 4061 e0dfe8b8db4a
parent 3759 f713566d5d01
permissions -rw-r--r--
py_ext: rework logic CSV reader FB output refresh logic.

Saving with CSV write FB now triggers CSV read FBs to refresh outputs immediately.
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
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 2537
diff changeset
     6
3759
f713566d5d01 convert sort and cmp functions to Python3
GP Orcullo <kinsamanka@gmail.com>
parents: 3750
diff changeset
     7
from operator import eq
2334
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
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
    14
2336
869a61616b42 Renamed IDManager control into IDBrowser, because dialog will be named IDManager
Edouard Tisserant
parents: 2335
diff changeset
    15
class IDBrowserModel(dv.PyDataViewIndexListModel):
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    16
    def __init__(self, project_path, columncount):
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    17
        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
    18
        self.columncount = columncount
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    19
        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
    20
        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
    21
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    22
    def _saveData(self):
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    23
        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
    24
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    25
    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
    26
        return "string"
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    27
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    28
    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
    29
        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
    30
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    31
    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
    32
        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
    33
        self._saveData()
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    34
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    35
    def GetColumnCount(self):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    36
        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
    37
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    38
    def GetCount(self):
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    39
        return len(self.data)
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
    40
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    41
    def Compare(self, item1, item2, col, ascending):
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
    42
        if not ascending:  # swap sort order?
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    43
            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
    44
        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
    45
        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
    46
        if col == 0:
3759
f713566d5d01 convert sort and cmp functions to Python3
GP Orcullo <kinsamanka@gmail.com>
parents: 3750
diff changeset
    47
            return eq(int(self.data[row1][col]), int(self.data[row2][col]))
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    48
        else:
3759
f713566d5d01 convert sort and cmp functions to Python3
GP Orcullo <kinsamanka@gmail.com>
parents: 3750
diff changeset
    49
            return eq(self.data[row1][col], self.data[row2][col])
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    50
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    51
    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
    52
        rows = list(rows)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    53
        rows.sort(reverse=True)
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
    54
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    55
        for row in rows:
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    56
            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
    57
            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
    58
            self.RowDeleted(row)
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    59
        self._saveData()
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
    60
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    61
    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
    62
        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
    63
        self.RowAppended()
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    64
        self._saveData()
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    65
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    66
    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
    67
        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
    68
        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
    69
            self.data = data
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
    70
            self.Reset(len(self.data))
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    71
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    72
    def Export(self, filepath):
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    73
        PSK.ExportIDs(self.project_path, filepath)
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
    74
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
    75
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
    76
colflags = dv.DATAVIEW_COL_RESIZABLE | dv.DATAVIEW_COL_SORTABLE
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
    77
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    78
2336
869a61616b42 Renamed IDManager control into IDBrowser, because dialog will be named IDManager
Edouard Tisserant
parents: 2335
diff changeset
    79
class IDBrowser(wx.Panel):
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
    80
    def __init__(self, parent, ctr, SelectURICallBack=None, SelectIDCallBack=None, **kwargs):
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
    81
        big = self.isManager = SelectURICallBack is None and SelectIDCallBack is None
2458
2a70d5240300 IDManager : small cosmetic fixes and cleanup.
Edouard Tisserant
parents: 2428
diff changeset
    82
        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
    83
                                                  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
    84
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    85
        self.SelectURICallBack = SelectURICallBack
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
    86
        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
    87
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    88
        dvStyle = wx.BORDER_THEME | dv.DV_ROW_LINES
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
    89
        if self.isManager:
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    90
            # 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
    91
            dvStyle |= dv.DV_MULTIPLE
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
    92
        self.dvc = dv.DataViewCtrl(self, style=dvStyle)
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
    93
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
    94
        def args(*a, **k):
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
    95
            return (a, k)
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    96
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
    97
        ColumnsDesc = [
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
    98
            args(_("ID"), COL_ID, width=70),
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
    99
            args(_("Last URI"), COL_URI, width=300 if big else 80),
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   100
            args(_("Description"), COL_DESC, width=300 if big else 200,
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   101
                 mode=dv.DATAVIEW_CELL_EDITABLE
2537
eb4a4cc41914 Fix various pylint and pep8 errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2492
diff changeset
   102
                 if self.isManager
eb4a4cc41914 Fix various pylint and pep8 errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2492
diff changeset
   103
                 else dv.DATAVIEW_CELL_INERT),
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   104
            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
   105
        ]
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   106
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
   107
        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
   108
        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
   109
2458
2a70d5240300 IDManager : small cosmetic fixes and cleanup.
Edouard Tisserant
parents: 2428
diff changeset
   110
        col_list = []
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   111
        for a, k in ColumnsDesc:
2458
2a70d5240300 IDManager : small cosmetic fixes and cleanup.
Edouard Tisserant
parents: 2428
diff changeset
   112
            col_list.append(
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   113
                self.dvc.AppendTextColumn(*a, **dict(k, flags=colflags)))
2458
2a70d5240300 IDManager : small cosmetic fixes and cleanup.
Edouard Tisserant
parents: 2428
diff changeset
   114
        col_list[COL_LAST].SetSortOrder(False)
2a70d5240300 IDManager : small cosmetic fixes and cleanup.
Edouard Tisserant
parents: 2428
diff changeset
   115
2a70d5240300 IDManager : small cosmetic fixes and cleanup.
Edouard Tisserant
parents: 2428
diff changeset
   116
        # 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
   117
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   118
        self.Sizer = wx.BoxSizer(wx.VERTICAL)
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   119
        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
   120
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   121
        btnbox = wx.BoxSizer(wx.HORIZONTAL)
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   122
        if self.isManager:
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   123
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   124
            # 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
   125
            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
   126
            self.Bind(wx.EVT_BUTTON, self.OnDeleteButton, deleteButton)
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   127
            btnbox.Add(deleteButton, 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
   128
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   129
            # export all
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   130
            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
   131
            self.Bind(wx.EVT_BUTTON, self.OnExportButton, exportButton)
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   132
            btnbox.Add(exportButton, 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
   133
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   134
            # 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
   135
            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
   136
            self.Bind(wx.EVT_BUTTON, self.OnImportButton, importButton)
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   137
            btnbox.Add(importButton, 0, wx.LEFT | wx.RIGHT, 5)
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   138
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   139
        else:
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   140
            # selector mode
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   141
            self.useURIButton = wx.Button(self, label=_("Use last URI"))
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   142
            self.Bind(wx.EVT_BUTTON, self.OnUseURIButton, self.useURIButton)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   143
            self.useURIButton.Disable()
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   144
            btnbox.Add(self.useURIButton, 0, wx.LEFT | wx.RIGHT, 5)
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   145
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   146
        self.Sizer.Add(btnbox, 0, wx.TOP | wx.BOTTOM, 5)
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   147
        self.Bind(dv.EVT_DATAVIEW_SELECTION_CHANGED, self.OnSelectionChanged, self.dvc)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   148
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   149
    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
   150
        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
   151
        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
   152
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   153
        # 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
   154
        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
   155
                         _('Delete IDs'),
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   156
                         wx.YES_NO | wx.CENTRE | wx.NO_DEFAULT) != wx.YES:
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   157
            return
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   158
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   159
        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
   160
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   161
    def OnSelectionChanged(self, evt):
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   162
        if not self.isManager:
2335
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   163
            items = self.dvc.GetSelections()
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   164
            somethingSelected = len(items) > 0
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   165
            self.useURIButton.Enable(somethingSelected)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   166
            if somethingSelected:
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   167
                row = self.model.GetRow(items[0])
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   168
                ID = self.model.GetValueByRow(row, COL_ID)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   169
                self.SelectIDCallBack(ID)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   170
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   171
    def OnUseURIButton(self, evt):
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   172
        row = self.model.GetRow(self.dvc.GetSelections()[0])
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   173
        URI = self.model.GetValueByRow(row, COL_URI)
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   174
        if URI:
4262256e1d28 IDManager.py : finished selector mode.
Edouard Tisserant
parents: 2334
diff changeset
   175
            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
   176
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   177
    def OnExportButton(self, evt):
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   178
        dialog = wx.FileDialog(self, _("Choose a file"),
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   179
                               wildcard=_("PSK ZIP files (*.zip)|*.zip"),
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   180
                               style=wx.SAVE | wx.OVERWRITE_PROMPT)
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   181
        if dialog.ShowModal() == wx.ID_OK:
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   182
            self.model.Export(dialog.GetPath())
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   183
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   184
    # pylint: disable=unused-variable
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   185
    def ShouldIReplaceCallback(self, existing, replacement):
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   186
        ID, URI, DESC, LAST = existing
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   187
        _ID, _URI, _DESC, _LAST = replacement
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   188
        dlg = IDMergeDialog(
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   189
            self,
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   190
            _("Import IDs"),
2428
e0f16317668e IDManager : finished Import/Export. Added merging capability to import (asks if particular ID is replaced during import). Added ESC as closing shortcut to IDManager dialog, and adjusted its size.
Edouard Tisserant
parents: 2340
diff changeset
   191
            (_("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
   192
             _("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
   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\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
   196
             _("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
   197
             _("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
   198
             _("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
   199
             _("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
   200
            _("Do the same for following IDs"),
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   201
            [_("Replace"), _("Keep"), _("Cancel")])
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   202
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   203
        answer = dlg.ShowModal()  # return value ignored as we have "Ok" only anyhow
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
   204
        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
   205
            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
   206
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
        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
   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_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
   210
            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
   211
        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
   212
            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
   213
                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
   214
            return KEEP
2334
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   215
d1470c052662 Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff changeset
   216
    def OnImportButton(self, evt):
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   217
        dialog = wx.FileDialog(self, _("Choose a file"),
2492
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   218
                               wildcard=_("PSK ZIP files (*.zip)|*.zip"),
7dd551ac2fa0 check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2458
diff changeset
   219
                               style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
2340
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   220
        if dialog.ShowModal() == wx.ID_OK:
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   221
            self.model.Import(dialog.GetPath(),
decf52efb7f7 IDManager: added import/export plus little cosmetic enhancements.
Edouard Tisserant
parents: 2339
diff changeset
   222
                              self.ShouldIReplaceCallback)