1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
+
+
+
+
+
+
+
+
+
+
+
+
+
|
# Lexicon Editor
# by Olivier R.
# License: MPL 2
import unohelper
import uno
import json
import re
import os
import traceback
import helpers
import lxe_strings
import grammalecte.graphspell as sc
import grammalecte.graphspell.dawg as dawg
import grammalecte.graphspell.ibdawg as ibdawg
import grammalecte.fr.conj as conj
import grammalecte.fr.conj_generator as conjgen
import SearchWords
import TagsInfo
from com.sun.star.task import XJobExecutor
from com.sun.star.awt import XActionListener
from com.sun.star.awt import XKeyListener
from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK
# BUTTONS_OK, BUTTONS_OK_CANCEL, BUTTONS_YES_NO, BUTTONS_YES_NO_CANCEL, BUTTONS_RETRY_CANCEL, BUTTONS_ABORT_IGNORE_RETRY
# DEFAULT_BUTTON_OK, DEFAULT_BUTTON_CANCEL, DEFAULT_BUTTON_RETRY, DEFAULT_BUTTON_YES, DEFAULT_BUTTON_NO, DEFAULT_BUTTON_IGNORE
from com.sun.star.awt.MessageBoxType import INFOBOX # MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX
def MessageBox (xDocument, sMsg, sTitle, nBoxType=INFOBOX, nBoxButtons=BUTTONS_OK):
xParentWin = xDocument.CurrentController.Frame.ContainerWindow
ctx = uno.getComponentContext()
xToolkit = ctx.ServiceManager.createInstanceWithContext("com.sun.star.awt.Toolkit", ctx)
xMsgBox = xToolkit.createMessageBox(xParentWin, nBoxType, nBoxButtons, sTitle, sMsg)
return xMsgBox.execute()
def _waitPointer (funcDecorated):
def wrapper (*args, **kwargs):
# self is the first parameter if the decorator is applied on a object
self = args[0]
# before
|
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
+
+
|
self.xContainer.getControl('information_button').setActionCommand('TagsInfo')
self.xContainer.getControl('add_button').addActionListener(self)
self.xContainer.getControl('add_button').setActionCommand('Add')
self.xContainer.getControl('delete_button').addActionListener(self)
self.xContainer.getControl('delete_button').setActionCommand('Delete')
self.xContainer.getControl('save_button').addActionListener(self)
self.xContainer.getControl('save_button').setActionCommand('Save')
self.xContainer.getControl('export_button').addActionListener(self)
self.xContainer.getControl('export_button').setActionCommand('Export')
self.xContainer.getControl('close_button').addActionListener(self)
self.xContainer.getControl('close_button').setActionCommand('Close')
self.xContainer.setVisible(False)
xToolkit = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.ExtToolkit', self.ctx)
self.xContainer.createPeer(xToolkit, None)
self.xContainer.execute()
|
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
+
+
|
self.deleteSelectedEntries()
elif xActionEvent.ActionCommand == "Save":
self.saveLexicon()
elif xActionEvent.ActionCommand == "Import":
self.importDictionary()
elif xActionEvent.ActionCommand == "Export":
self.exportDictionary()
elif xActionEvent.ActionCommand == 'Info':
pass
elif xActionEvent.ActionCommand == "Close":
self.xContainer.endExecute()
except:
traceback.print_exc()
# XKeyListener
def keyPressed (self, xKeyEvent):
|
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
|
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
|
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
+
+
+
|
self.xGridControlLex.deselectAllRows()
self.xNumLex.Label = str(xGridDataModel.RowCount)
@_waitPointer
def importDictionary (self):
pass
@_waitPointer
def exportDictionary (self):
try:
spfExported = os.path.join(os.environ['USERPROFILE'], "fr.personal.json")
xChild = self.xSettingNode.getByName("o_fr")
sJSON = xChild.getPropertyValue("personal_dic")
if sJSON:
with open(spfExported, "w", encoding="utf-8") as hDst:
hDst.write(sJSON)
sMessage = self.dUI.get('export_message', "#err_msg: %s") % spfExported
else:
sMessage = self.dUI.get('empty_dictionary', "#err")
except:
sMessage = traceback.format_exc()
MessageBox(self.xDocument, sMessage, self.dUI.get('export_title', "#err"))
# FilePicker doesn’t work at all…
xFilePicker = self.xSvMgr.createInstanceWithContext('com.sun.star.ui.dialogs.SystemFilePicker', self.ctx)
xFilePicker.appendFilter("Supported files", "*.json; *.bdic")
#xFilePicker = self.xSvMgr.createInstanceWithContext('com.sun.star.ui.dialogs.SystemFilePicker', self.ctx)
#xFilePicker.appendFilter("Supported files", "*.json; *.bdic")
#xFilePicker.setDisplayDirectory("")
#xFilePicker.setMultiSelectionMode(True)
nResult = xFilePicker.execute()
if nResult == 1:
pass
#nResult = xFilePicker.execute()
#if nResult == 1:
#pass
#lFile = xFilePicker.getSelectedFiles()
#lFile = xFilePicker.getFiles()
#g_ImplementationHelper = unohelper.ImplementationHelper()
#g_ImplementationHelper.addImplementation(LexiconEditor, 'net.grammalecte.LexiconEditor', ('com.sun.star.task.Job',))
|