author | Edouard Tisserant |
Wed, 14 Nov 2018 11:32:08 +0100 | |
changeset 2334 | d1470c052662 |
child 2335 | 4262256e1d28 |
permissions | -rw-r--r-- |
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 |
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 |
class IDManager(wx.Panel): |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
114 |
def __init__(self, parent, ctr, SelectURICallBack, *args, **kwargs): |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
115 |
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
|
116 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
117 |
self.isManager = SelectURICallBack is None |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
118 |
self.SelectURICallBack = SelectURICallBack |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
119 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
120 |
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
|
121 |
if self.isManager : |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
122 |
# 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
|
123 |
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
|
124 |
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
|
125 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
126 |
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
|
127 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
128 |
ColumnsDesc = [ |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
129 |
args(_("ID"), 0, width = 100), |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
130 |
args(_("Last URI"), 1, width = 80), |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
131 |
args(_("Description"), 2, width = 200, |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
132 |
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
|
133 |
if self.isManager |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
134 |
else dv.DATAVIEW_CELL_INERT), |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
135 |
args(_("Last connection"), 3, width = 100), |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
136 |
] |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
137 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
138 |
self.model = IDManagerModel( |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
139 |
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
|
140 |
len(ColumnsDesc)) |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
141 |
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
|
142 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
143 |
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
|
144 |
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
|
145 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
146 |
# TODO : when select, |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
147 |
# - 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
|
148 |
# - 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
|
149 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
150 |
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
|
151 |
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
|
152 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
153 |
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
|
154 |
if self.isManager : |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
155 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
156 |
# 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
|
157 |
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
|
158 |
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
|
159 |
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
|
160 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
161 |
# export all |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
162 |
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
|
163 |
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
|
164 |
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
|
165 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
166 |
# 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
|
167 |
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
|
168 |
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
|
169 |
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
|
170 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
171 |
else : |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
172 |
# selector mode |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
173 |
# 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
|
174 |
# TODO : disable use URI button until something selected |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
175 |
selectButton = wx.Button(self, label=_("Use last URI")) |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
176 |
self.Bind(wx.EVT_BUTTON, self.OnSelectButton, selectButton) |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
177 |
btnbox.Add(selectButton, 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
|
178 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
179 |
self.Sizer.Add(btnbox, 0, wx.TOP|wx.BOTTOM, 5) |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
180 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
185 |
# 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
|
186 |
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
|
187 |
_('Delete IDs'), |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
188 |
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
|
189 |
return |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
190 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
191 |
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
|
192 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
193 |
def OnSelectButton(self, evt): |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
194 |
# TODO : call SetURICallback with URI from curent selection. |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
195 |
wx.MessageBox(_('?'), |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
196 |
_('Mhe'), |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
197 |
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
|
198 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
199 |
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
|
200 |
# TODO |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
201 |
wx.MessageBox(_('?'), |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
202 |
_('Mhe'), |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
203 |
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
|
204 |
|
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
205 |
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
|
206 |
# TODO |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
207 |
wx.MessageBox(_('?'), |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
208 |
_('Mhe'), |
d1470c052662
Added early implementation of IDManager.py. For now only used to select ID in URIEditor
Edouard Tisserant
parents:
diff
changeset
|
209 |
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
|
210 |