Grammalecte  Diff

Differences From Artifact [2c4ada79ef]:

To Artifact [a5205698ad]:


1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18










-
+







# Search
# by Olivier R.
# License: MPL 2

import unohelper
import uno
import traceback
import re

import helpers
import sw_strings
import sw_strings as ui
import grammalecte.graphspell as sc
import grammalecte.graphspell.ibdawg as ibdawg

from com.sun.star.task import XJobExecutor
from com.sun.star.awt import XActionListener


94
95
96
97
98
99
100
101

102
103
104
105
106
107
108

109
110
111
112
113
114
115
94
95
96
97
98
99
100

101
102
103
104
105
106
107

108
109
110
111
112
113
114
115







-
+






-
+







        for k, w in kwargs.items():
            setattr(xGridModel, k, w)
        self.xDialog.insertByName(name, xGridModel)
        return xGridModel

    def run (self, sLang, oPersonalDicJSON):
        # ui lang
        self.dUI = sw_strings.getUI(sLang)
        ui.selectLang(sLang)
        self.oPersonalDicJSON = oPersonalDicJSON

        # dialog
        self.xDialog = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialogModel', self.ctx)
        self.xDialog.Width = 350
        self.xDialog.Height = 305
        self.xDialog.Title = self.dUI.get('title', "#title#")
        self.xDialog.Title = ui.get('title')
        #xWindowSize = helpers.getWindowSize()
        #self.xDialog.PositionX = int((xWindowSize.Width / 2) - (self.xDialog.Width / 2))
        #self.xDialog.PositionY = int((xWindowSize.Height / 2) - (self.xDialog.Height / 2))

        # fonts
        xFDTitle = uno.createUnoStruct("com.sun.star.awt.FontDescriptor")
        xFDTitle.Height = 9
128
129
130
131
132
133
134
135
136


137
138

139
140
141
142


143
144

145
146
147


148
149
150

151
152
153
154



155
156
157

158
159
160
161
162
163
164
128
129
130
131
132
133
134


135
136
137

138
139
140


141
142
143

144
145


146
147
148
149

150
151



152
153
154
155
156

157
158
159
160
161
162
163
164







-
-
+
+

-
+


-
-
+
+

-
+

-
-
+
+


-
+

-
-
-
+
+
+


-
+







        nY0 = 5
        nY1 = nY0 + 20
        nY2 = nY1 + 60

        nHeight = 10

        #### Search
        self._addWidget("search_section", 'FixedLine', nX1, nY0, 120, nHeight, Label = self.dUI.get("search_section", "#err"), FontDescriptor = xFDTitle)
        self._addWidget("similar_search_section", 'FixedLine', nX1, nY1, 120, nHeight, Label = self.dUI.get("similar_search_section", "#err"), FontDescriptor = xFDSubTitle)
        self._addWidget("search_section", 'FixedLine', nX1, nY0, 120, nHeight, Label = ui.get("search_section"), FontDescriptor = xFDTitle)
        self._addWidget("similar_search_section", 'FixedLine', nX1, nY1, 120, nHeight, Label = ui.get("similar_search_section"), FontDescriptor = xFDSubTitle)
        self.xWord = self._addWidget('word', 'Edit', nX1, nY1+10, 100, nHeight)
        self._addWidget('similar_search_button', 'Button', nX1, nY1+22, 55, 12, Label = self.dUI.get('similar_search_button', "#err"), FontDescriptor = xFDSubTitle, TextColor = 0x005500)
        self._addWidget('similar_search_button', 'Button', nX1, nY1+22, 55, 12, Label = ui.get('similar_search_button'), FontDescriptor = xFDSubTitle, TextColor = 0x005500)


        self._addWidget("regex_search_section", 'FixedLine', nX1, nY2, 120, nHeight, Label = self.dUI.get("regex_search_section", "#err"), FontDescriptor = xFDSubTitle)
        self._addWidget('flexion_label', 'FixedText', nX1, nY2+10, 30, nHeight, Label = self.dUI.get('flexion', "#err"))
        self._addWidget("regex_search_section", 'FixedLine', nX1, nY2, 120, nHeight, Label = ui.get("regex_search_section"), FontDescriptor = xFDSubTitle)
        self._addWidget('flexion_label', 'FixedText', nX1, nY2+10, 30, nHeight, Label = ui.get('flexion'))
        self.xFlexion = self._addWidget('flexion', 'Edit', nX1+35, nY2+10, 85, nHeight)
        self._addWidget('tags_label', 'FixedText', nX1, nY2+22, 30, nHeight, Label = self.dUI.get('tags', "#err"))
        self._addWidget('tags_label', 'FixedText', nX1, nY2+22, 30, nHeight, Label = ui.get('tags'))
        self.xTags = self._addWidget('tags', 'Edit', nX1+35, nY2+22, 85, nHeight)
        self._addWidget('regex_search_button', 'Button', nX1, nY2+34, 55, 12, Label = self.dUI.get('regex_search_button', "#err"), FontDescriptor = xFDSubTitle, TextColor = 0x005500)
        self._addWidget('result_warning', 'FixedText', nX1, nY2+50, 120, nHeight*7, Label = self.dUI.get('result_warning', '#err'), MultiLine = True)
        self._addWidget('regex_search_button', 'Button', nX1, nY2+34, 55, 12, Label = ui.get('regex_search_button'), FontDescriptor = xFDSubTitle, TextColor = 0x005500)
        self._addWidget('result_warning', 'FixedText', nX1, nY2+50, 120, nHeight*7, Label = ui.get('result_warning'), MultiLine = True)

        #### Results
        self._addWidget("result_section", 'FixedLine', nX2, nY0, 200, nHeight, Label = self.dUI.get("result_section", "#err"), FontDescriptor = xFDTitle)
        self._addWidget("result_section", 'FixedLine', nX2, nY0, 200, nHeight, Label = ui.get("result_section"), FontDescriptor = xFDTitle)
        self.xGridModel = self._addGrid("list_grid_search", nX2, nY0+10, 200, 265, [
            {"Title": self.dUI.get("res_flexion", "#err"), "ColumnWidth": 70},
            {"Title": self.dUI.get("res_lemma", "#err"), "ColumnWidth": 60},
            {"Title": self.dUI.get("res_tags", "#err"), "ColumnWidth": 70}
            {"Title": ui.get("res_flexion"), "ColumnWidth": 70},
            {"Title": ui.get("res_lemma"), "ColumnWidth": 60},
            {"Title": ui.get("res_tags"), "ColumnWidth": 70}
        ])

        self._addWidget('close_button', 'Button', self.xDialog.Width-50, self.xDialog.Height-20, 40, 12, Label = self.dUI.get('close_button', "#err"), FontDescriptor = xFDSubTitle, TextColor = 0x550000)
        self._addWidget('close_button', 'Button', self.xDialog.Width-50, self.xDialog.Height-20, 40, 12, Label = ui.get('close_button'), FontDescriptor = xFDSubTitle, TextColor = 0x550000)

        # container
        self.xContainer = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialog', self.ctx)
        self.xContainer.setModel(self.xDialog)
        self.xGridControlSearch = self.xContainer.getControl('list_grid_search')
        self.xGridControlInfo = self.xContainer.getControl('list_grid_info')
        self.xContainer.getControl('similar_search_button').addActionListener(self)
191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
206
207
208
209
210
211

212
213
214
215
216
217

218
219
220
221
222
223
224
225
191
192
193
194
195
196
197

198
199
200
201
202
203
204
205
206
207
208
209
210

211
212
213
214
215
216

217
218
219
220
221
222
223
224
225







-
+












-
+





-
+








    @_waitPointer
    def searchSimilar (self):
        self.initSpellChecker()
        sWord = self.xWord.Text.strip()
        if sWord:
            xGridDataModel = self.xGridModel.GridDataModel
            xGridDataModel.removeAllRows()
            lResult = self.oSpellChecker.getSimilarEntries(sWord, 20);
            lResult = self.oSpellChecker.getSimilarEntries(sWord, 20)
            for i, aEntry in enumerate(lResult):
                xGridDataModel.addRow(i, aEntry)

    @_waitPointer
    def searchRegex (self):
        self.initSpellChecker()
        sFlexPattern = self.xFlexion.Text.strip()
        sTagsPattern = self.xTags.Text.strip()
        try:
            if sFlexPattern:
                re.compile(sFlexPattern)
        except:
            MessageBox(self.xDocument, self.dUI.get("regex_error_flexion", "#err"), self.dUI.get("error", "#err"), nBoxType=ERRORBOX)
            MessageBox(self.xDocument, ui.get("regex_error_flexion"), ui.get("error"), nBoxType=ERRORBOX)
            sFlexPattern = ""
        try:
            if sTagsPattern:
                re.compile(sTagsPattern)
        except:
            MessageBox(self.xDocument, self.dUI.get("regex_error_tags", "#err"), self.dUI.get("error", "#err"), nBoxType=ERRORBOX)
            MessageBox(self.xDocument, ui.get("regex_error_tags"), ui.get("error"), nBoxType=ERRORBOX)
            sTagsPattern = ""
        xGridDataModel = self.xGridModel.GridDataModel
        xGridDataModel.removeAllRows()
        for i, aEntry in enumerate(self.oSpellChecker.select(sFlexPattern, sTagsPattern)):
            xGridDataModel.addRow(i, aEntry)
            i += 1
            if i >= 2000:
                break