︙ | | | ︙ | |
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import helpers
import tfe_strings as ui
import grammalecte.graphspell as sc
from com.sun.star.awt import XActionListener
from com.sun.star.awt.grid import XGridSelectionListener
from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK, BUTTONS_YES_NO_CANCEL
# 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, ERRORBOX, QUERYBOX # MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX
def MessageBox (xDocument, sMsg, sTitle, nBoxType=INFOBOX, nBoxButtons=BUTTONS_OK):
xParentWin = xDocument.CurrentController.Frame.ContainerWindow
|
|
|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import helpers
import tfe_strings as ui
import grammalecte.graphspell as sc
from com.sun.star.awt import XActionListener
from com.sun.star.awt.grid import XGridSelectionListener
from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK, BUTTONS_YES_NO_CANCEL, BUTTONS_YES_NO
# 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, ERRORBOX, QUERYBOX # MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX
def MessageBox (xDocument, sMsg, sTitle, nBoxType=INFOBOX, nBoxButtons=BUTTONS_OK):
xParentWin = xDocument.CurrentController.Frame.ContainerWindow
|
︙ | | | ︙ | |
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
self.xNewRegex = self._addWidget('newregex', 'CheckBox', nX+305, nY1+22, 35, nHeight, Label = ui.get("regex"), HelpText=ui.get("regex_help"))
self.xNewCaseSens = self._addWidget('newcasesens', 'CheckBox', nX+340, nY1+22, 40, nHeight, Label = ui.get("casesens"), HelpText=ui.get("casesens_help"), State=True)
self._addWidget('add', 'Button', self.xDialog.Width-50, nY1+31, 40, 11, Label = ui.get('add'))
lColumns = [
{"Title": ui.get("name"), "ColumnWidth": 80},
{"Title": ui.get("pattern"), "ColumnWidth": 140},
{"Title": ui.get("repl"), "ColumnWidth": 140},
{"Title": ui.get("regex"), "ColumnWidth": 60},
{"Title": ui.get("casesens"), "ColumnWidth": 60},
]
self.xGridModel = self._addGrid("list_grid", nX, nY1+45, nWidth, 150, lColumns)
# Modify
self._addWidget("edit_entry", 'FixedLine', nX, nY2, nWidth, nHeight, Label = ui.get("edit_entry"), FontDescriptor = xFDTitle)
|
|
|
|
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
self.xNewRegex = self._addWidget('newregex', 'CheckBox', nX+305, nY1+22, 35, nHeight, Label = ui.get("regex"), HelpText=ui.get("regex_help"))
self.xNewCaseSens = self._addWidget('newcasesens', 'CheckBox', nX+340, nY1+22, 40, nHeight, Label = ui.get("casesens"), HelpText=ui.get("casesens_help"), State=True)
self._addWidget('add', 'Button', self.xDialog.Width-50, nY1+31, 40, 11, Label = ui.get('add'))
lColumns = [
{"Title": ui.get("name"), "ColumnWidth": 80},
{"Title": ui.get("pattern"), "ColumnWidth": 160},
{"Title": ui.get("repl"), "ColumnWidth": 120},
{"Title": ui.get("regex"), "ColumnWidth": 60},
{"Title": ui.get("casesens"), "ColumnWidth": 60},
]
self.xGridModel = self._addGrid("list_grid", nX, nY1+45, nWidth, 150, lColumns)
# Modify
self._addWidget("edit_entry", 'FixedLine', nX, nY2, nWidth, nHeight, Label = ui.get("edit_entry"), FontDescriptor = xFDTitle)
|
︙ | | | ︙ | |
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
self._addWidget('export', 'Button', nX+55, self.xDialog.Height-20, 50, 14, Label = ui.get('export'), FontDescriptor = xFDTitle, TextColor = 0x00AA00)
self._addWidget('delete_all', 'Button', nX + (self.xDialog.Width/2)-35, self.xDialog.Height-20, 70, 14, Label = ui.get('delete_all'), FontDescriptor = xFDTitle, TextColor = 0xAA0000)
self._addWidget('save_and_close', 'Button', self.xDialog.Width-110, self.xDialog.Height-20, 100, 14, Label = ui.get('save_and_close'), FontDescriptor = xFDTitle, TextColor = 0x00AA00)
# data
self.dRules = {}
self.iSelectedRow = -1
# load configuration
self.xGLOptionNode = helpers.getConfigSetting("/org.openoffice.Lightproof_${implname}/Other/", True)
self.loadRules()
# container
self.xContainer = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialog', self.ctx)
|
>
|
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
self._addWidget('export', 'Button', nX+55, self.xDialog.Height-20, 50, 14, Label = ui.get('export'), FontDescriptor = xFDTitle, TextColor = 0x00AA00)
self._addWidget('delete_all', 'Button', nX + (self.xDialog.Width/2)-35, self.xDialog.Height-20, 70, 14, Label = ui.get('delete_all'), FontDescriptor = xFDTitle, TextColor = 0xAA0000)
self._addWidget('save_and_close', 'Button', self.xDialog.Width-110, self.xDialog.Height-20, 100, 14, Label = ui.get('save_and_close'), FontDescriptor = xFDTitle, TextColor = 0x00AA00)
# data
self.dRules = {}
self.iSelectedRow = -1
self.nFieldMaxLen = 250
# load configuration
self.xGLOptionNode = helpers.getConfigSetting("/org.openoffice.Lightproof_${implname}/Other/", True)
self.loadRules()
# container
self.xContainer = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialog', self.ctx)
|
︙ | | | ︙ | |
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
|
def addRule (self):
if not self._checkRuleName(self.xNewName.Text):
MessageBox(self.xDocument, ui.get("name_error"), ui.get("name_error_title"), ERRORBOX)
return
if not self.xNewName.Text or not self.xNewPattern.Text:
MessageBox(self.xDocument, ui.get("name_and_replace_error"), ui.get("name_and_replace_error_title"), ERRORBOX)
return
sRuleName = self.xNewName.Text
if sRuleName in self.dRules:
MessageBox(self.xDocument, ui.get('add_name_error'), ui.get("add_name_error_title"), ERRORBOX)
return
self.dRules[sRuleName] = {
"sPattern": self.xNewPattern.Text,
"sRepl": self.xNewRepl.Text,
"bRegex": self.xNewRegex.State == 1,
"bCaseSens": self.xNewCaseSens.State == 1
}
xGridDataModel = self.xGridModel.GridDataModel
xGridDataModel.addRow(xGridDataModel.RowCount + 1, self._getValuesForRow(sRuleName))
self._clearAddFields()
def _getValuesForRow (self, sRuleName):
return (sRuleName, self.dRules[sRuleName]["sPattern"], self.dRules[sRuleName]["sRepl"], str(self.dRules[sRuleName]["bRegex"]), str(self.dRules[sRuleName]["bCaseSens"]))
def _checkRuleName (self, sRuleName):
return re.search(r"^\w[\w_#.,;!?-]*$", sRuleName)
def modifyRule (self):
if not self._checkRuleName(self.xEditName.Text):
MessageBox(self.xDocument, ui.get("name_error"), ui.get("name_error_title"), ERRORBOX)
return
sRuleName = self.xEditName.Text
if self.iSelectedRow < 0 or not sRuleName or not self.xEditPattern.Text:
MessageBox(self.xDocument, ui.get("name_and_replace_error"), ui.get("name_and_replace_error_title"), ERRORBOX)
return
if sRuleName != self.sSelectedRuleName and sRuleName in self.dRules:
MessageBox(self.xDocument, ui.get("modify_name_error"), ui.get("modify_name_error_title"), ERRORBOX)
return
try:
self.dRules[sRuleName] = {
"sPattern": self.xEditPattern.Text,
|
>
>
>
>
|
>
>
>
|
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
def addRule (self):
if not self._checkRuleName(self.xNewName.Text):
MessageBox(self.xDocument, ui.get("name_error"), ui.get("name_error_title"), ERRORBOX)
return
if not self.xNewName.Text or not self.xNewPattern.Text:
MessageBox(self.xDocument, ui.get("name_and_replace_error"), ui.get("name_and_replace_error_title"), ERRORBOX)
return
if len(self.xNewPattern.Text) > self.nFieldMaxLen or len(self.xNewRepl.Text) > self.nFieldMaxLen:
MessageBox(self.xDocument, ui.get("max_len_error"), ui.get("max_len_error_title"), ERRORBOX)
return
sRuleName = self.xNewName.Text
if sRuleName in self.dRules:
MessageBox(self.xDocument, ui.get('add_name_error'), ui.get("add_name_error_title"), ERRORBOX)
return
self.dRules[sRuleName] = {
"sPattern": self.xNewPattern.Text,
"sRepl": self.xNewRepl.Text,
"bRegex": self.xNewRegex.State == 1,
"bCaseSens": self.xNewCaseSens.State == 1
}
xGridDataModel = self.xGridModel.GridDataModel
xGridDataModel.addRow(xGridDataModel.RowCount + 1, self._getValuesForRow(sRuleName))
xGridDataModel.sortByColumn(0, True)
self._clearAddFields()
def _getValuesForRow (self, sRuleName):
return (sRuleName, self.dRules[sRuleName]["sPattern"], self.dRules[sRuleName]["sRepl"], str(self.dRules[sRuleName]["bRegex"]), str(self.dRules[sRuleName]["bCaseSens"]))
def _checkRuleName (self, sRuleName):
return re.search(r"^\w[\w_#.,;!?-]{,14}$", sRuleName)
def modifyRule (self):
if not self._checkRuleName(self.xEditName.Text):
MessageBox(self.xDocument, ui.get("name_error"), ui.get("name_error_title"), ERRORBOX)
return
sRuleName = self.xEditName.Text
if self.iSelectedRow < 0 or not sRuleName or not self.xEditPattern.Text:
MessageBox(self.xDocument, ui.get("name_and_replace_error"), ui.get("name_and_replace_error_title"), ERRORBOX)
return
if len(self.xEditPattern.Text) > self.nFieldMaxLen or len(self.xEditRepl.Text) > self.nFieldMaxLen:
MessageBox(self.xDocument, ui.get("max_len_error"), ui.get("max_len_error_title"), ERRORBOX)
return
if sRuleName != self.sSelectedRuleName and sRuleName in self.dRules:
MessageBox(self.xDocument, ui.get("modify_name_error"), ui.get("modify_name_error_title"), ERRORBOX)
return
try:
self.dRules[sRuleName] = {
"sPattern": self.xEditPattern.Text,
|
︙ | | | ︙ | |
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
self.xGridModel.GridDataModel.removeRow(self.iSelectedRow)
self.iSelectedRow = -1
del self.dRules[sRuleName]
except:
traceback.print_exc()
def deleteAll (self):
self.dRules.clear()
self.xGridModel.GridDataModel.removeAllRows()
@_waitPointer
def applyRule (self):
if self.xEditPattern.Text == "":
return
try:
xRD = self.xDocument.createReplaceDescriptor()
|
>
>
|
|
|
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
self.xGridModel.GridDataModel.removeRow(self.iSelectedRow)
self.iSelectedRow = -1
del self.dRules[sRuleName]
except:
traceback.print_exc()
def deleteAll (self):
nButton = MessageBox(self.xDocument, ui.get('delete_all_confirm'), ui.get('delete_all'), QUERYBOX, BUTTONS_YES_NO)
if nButton == 2: # ok
self.dRules.clear()
self.xGridModel.GridDataModel.removeAllRows()
@_waitPointer
def applyRule (self):
if self.xEditPattern.Text == "":
return
try:
xRD = self.xDocument.createReplaceDescriptor()
|
︙ | | | ︙ | |
375
376
377
378
379
380
381
382
383
384
385
386
387
388
|
sTFEditorOptions = xChild.getPropertyValue("tfe_rules")
if not sTFEditorOptions:
return
self.dRules = json.loads(sTFEditorOptions)
xGridDataModel = self.xGridModel.GridDataModel
for sRuleName in self.dRules:
xGridDataModel.addRow(xGridDataModel.RowCount + 1, self._getValuesForRow(sRuleName))
except:
sMessage = traceback.format_exc()
MessageBox(self.xDocument, sMessage, ui.get('error'), ERRORBOX)
@_waitPointer
def saveRules (self):
try:
|
>
|
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
|
sTFEditorOptions = xChild.getPropertyValue("tfe_rules")
if not sTFEditorOptions:
return
self.dRules = json.loads(sTFEditorOptions)
xGridDataModel = self.xGridModel.GridDataModel
for sRuleName in self.dRules:
xGridDataModel.addRow(xGridDataModel.RowCount + 1, self._getValuesForRow(sRuleName))
xGridDataModel.sortByColumn(0, True)
except:
sMessage = traceback.format_exc()
MessageBox(self.xDocument, sMessage, ui.get('error'), ERRORBOX)
@_waitPointer
def saveRules (self):
try:
|
︙ | | | ︙ | |
436
437
438
439
440
441
442
443
444
445
446
447
448
449
|
for sRuleName in self.dRules:
xGridDataModel.addRow(xGridDataModel.RowCount + 1, self._getValuesForRow(sRuleName))
else: # 3 = no
for sRuleName, dValues in dImportedRules.items():
if not sRuleName in self.dRules:
self.dRules[sRuleName] = dValues
xGridDataModel.addRow(xGridDataModel.RowCount + 1, self._getValuesForRow(sRuleName))
def exportRules (self):
if not self.dRules:
return
sText = json.dumps(self.dRules, ensure_ascii=False)
try:
xFilePicker = self.xSvMgr.createInstanceWithContext('com.sun.star.ui.dialogs.FilePicker', self.ctx) # other possibility: com.sun.star.ui.dialogs.SystemFilePicker
|
>
|
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
for sRuleName in self.dRules:
xGridDataModel.addRow(xGridDataModel.RowCount + 1, self._getValuesForRow(sRuleName))
else: # 3 = no
for sRuleName, dValues in dImportedRules.items():
if not sRuleName in self.dRules:
self.dRules[sRuleName] = dValues
xGridDataModel.addRow(xGridDataModel.RowCount + 1, self._getValuesForRow(sRuleName))
xGridDataModel.sortByColumn(0, True)
def exportRules (self):
if not self.dRules:
return
sText = json.dumps(self.dRules, ensure_ascii=False)
try:
xFilePicker = self.xSvMgr.createInstanceWithContext('com.sun.star.ui.dialogs.FilePicker', self.ctx) # other possibility: com.sun.star.ui.dialogs.SystemFilePicker
|
︙ | | | ︙ | |