-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py
503 lines (383 loc) · 19.4 KB
/
config.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
#!/usr/bin/env python
__license__ = 'GPL v3'
__copyright__ = '2020, un_pogaz <[email protected]>'
try:
load_translations()
except NameError:
pass # load_translations() added in calibre 1.9
from collections import defaultdict, OrderedDict
from functools import partial
from typing import Any
try:
from qt.core import (
Qt, QCheckBox, QFormLayout, QGridLayout, QGroupBox, QHBoxLayout,
QLabel, QLineEdit, QPushButton, QScrollArea, QSizePolicy,
QVBoxLayout, QWidget,
)
except ImportError:
from PyQt5.Qt import (
Qt, QCheckBox, QFormLayout, QGridLayout, QGroupBox, QHBoxLayout,
QLabel, QLineEdit, QPushButton, QScrollArea, QSizePolicy,
QVBoxLayout, QWidget,
)
from calibre.gui2.widgets2 import Dialog
from .common_utils import debug_print, get_icon, GUI, PREFS_json, regex, CALIBRE_VERSION
from .common_utils.dialogs import KeyboardConfigDialogButton
from .common_utils.widgets import ImageTitleLayout, KeyValueComboBox, SelectNotesWidget
PLUGIN_ICON = 'images/plugin.png'
NOTES_ICON = 'images/notes.png'
class KEY:
KEEP_URL = 'KeepUrl'
HEADINGS = 'Headings'
FONT_WEIGHT = 'FontWeight'
DEL_ITALIC = 'RemoveItalic'
DEL_UNDER = 'RemoveUnderline'
DEL_STRIKE = 'RemoveStrikethrough'
FORCE_JUSTIFY = 'ForceJustify'
LIST_ALIGN = 'ListAlign'
ID_CLASS = 'ID_Class'
CSS_KEEP_ACTIVE = 'CSStoKeepActive'
CSS_KEEP = 'CSStoKeep'
DEL_FORMATTING = 'RemoveFormatting'
MARKDOWN = 'Markdown'
DOUBLE_BR = 'DoubleBR'
SINGLE_BR = 'SingleBR'
EMPTY_PARA = 'EmptyParagraph'
IMG_TAG = 'ImgTag'
CUSTOM_COLUMN = 'CustomColumn'
NOTES_SETTINGS = 'NotesSettings'
KEEP_URL = OrderedDict([
('keep', _('Keep URL')),
('del', _('Delete URL'))])
HEADINGS = OrderedDict([
('conv', _('Converte to a paragraph')),
('bolder', _('Converte to a paragraph but keep the bold')),
('none', _('No change'))])
FONT_WEIGHT = OrderedDict([
('trunc', _('Round the Weights value to the hundred')),
('bold', _("Round to Bold (value 'bold')")),
('none', _('Do not change the Weights')),
('del', _('Delete Weights'))])
FONT_WEIGHT_ALT = _('Round to Bold (value 600)')
FORCE_JUSTIFY = OrderedDict([
('all', _('Force the justification (replace "center" and "right")')),
('empty', _('Justification for indeterminate text (keep "center" and "right")')),
('none', _('No change')),
('del', _('Delete all alignment'))])
LIST_ALIGN = OrderedDict([
('keep', _("Use the 'Justification' setting")),
('del', _('Delete the alignment in lists'))])
ID_CLASS = OrderedDict([
('id', _('Delete "id" attribut')),
('class', _('Delete "class" attribut')),
('id_class', _('Delete "id" and "class" attribut')),
('none', _('No change'))])
MARKDOWN = OrderedDict([
('always', _('Convert in all comments (not recomanded)')),
('try', _('Convert only from a plain text comment')),
('none', _('No change'))])
DOUBLE_BR = OrderedDict([
('empty', _('Create a empty paragraph')),
('new', _('Create a new paragraph')),
('none', _('No change'))])
SINGLE_BR = OrderedDict([
('para', _('Create a new paragraph')),
('space', _('Replace with space')),
('none', _('No change'))])
EMPTY_PARA = OrderedDict([
('merge', _('Merge in a single empty paragraph')),
('none', _('No change')),
('del', _('Delete empty paragraph'))])
IMG_TAG = OrderedDict([
('keep', _('Keep images')),
('del', _('Delete images'))])
# Set defaults
_defaults = {}
_defaults[KEY.KEEP_URL] = 'keep'
_defaults[KEY.HEADINGS] = 'none'
_defaults[KEY.FONT_WEIGHT] = 'bold'
_defaults[KEY.DEL_ITALIC] = False
_defaults[KEY.DEL_UNDER] = False
_defaults[KEY.DEL_STRIKE] = False
_defaults[KEY.FORCE_JUSTIFY] = 'empty'
_defaults[KEY.LIST_ALIGN] = 'del'
_defaults[KEY.ID_CLASS] = 'id_class'
_defaults[KEY.CSS_KEEP_ACTIVE] = True
_defaults[KEY.CSS_KEEP] = ''
_defaults[KEY.DEL_FORMATTING] = False
_defaults[KEY.MARKDOWN] = 'try'
_defaults[KEY.DOUBLE_BR] = 'new'
_defaults[KEY.SINGLE_BR] = 'none'
_defaults[KEY.EMPTY_PARA] = 'merge'
_defaults[KEY.IMG_TAG] = 'del'
# This is where all preferences for this plugin are stored
PREFS = PREFS_json()
PREFS.defaults = _defaults.copy()
PREFS.defaults[KEY.CUSTOM_COLUMN] = False
PREFS.defaults[KEY.NOTES_SETTINGS] = _defaults.copy()
PREFS.defaults[KEY.NOTES_SETTINGS][KEY.IMG_TAG] = 'keep'
PREFS.defaults[KEY.NOTES_SETTINGS][KEY.CSS_KEEP] = 'float'
#fix a imcompatibility betwen multiple Calibre version
CALIBRE_VERSIONS_BOLD = CALIBRE_VERSION < (4,0,0) or CALIBRE_VERSION >= (6,0,0)
if not CALIBRE_VERSIONS_BOLD:
FONT_WEIGHT['bold'] = FONT_WEIGHT_ALT
if CALIBRE_VERSION >= (6,0,0):
del FONT_WEIGHT['trunc']
if PREFS[KEY.FONT_WEIGHT] == 'trunc':
PREFS[KEY.FONT_WEIGHT] = 'bold'
if CALIBRE_VERSION >= (7,0,0):
CALIBRE_HAS_NOTES = True
else:
CALIBRE_HAS_NOTES = False
def css_clean_rules(css: str) -> str:
#remove space and invalid character
css = regex.loop(r'[.*!()?+<>\\]', r'', css.lower())
css = regex.loop(r'([,;:\n\r]|\s{2,})', r' ', css)
css = regex.simple(r'^\s*(.*?)\s*$', r'\1', css)
# split to table, remove duplicate and sorted
css = sorted(set(css.split(' ')))
# return into string
return ' '.join(css)
class CommonOptions(QWidget):
def __init__(self, prefs: dict, parent: QWidget=None):
QWidget.__init__(self, parent=parent)
size_policy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Maximum)
layout = QVBoxLayout(self)
self.setLayout(layout)
# -- options HTML --
groupboxHTML = QGroupBox(self)
layout.addWidget(groupboxHTML)
layoutHTML = QVBoxLayout(groupboxHTML)
groupboxHTML.setLayout(layoutHTML)
layout_gridHTML = QGridLayout()
layoutHTML.addLayout(layout_gridHTML)
layout_gridHTML.addWidget(QLabel(_('Hyperlink:'), self), 0, 0)
self.comboBoxKEEP_URL = KeyValueComboBox(KEEP_URL, prefs[KEY.KEEP_URL], parent=groupboxHTML)
layout_gridHTML.addWidget(self.comboBoxKEEP_URL, 1, 0)
layout_gridHTML.addWidget(QLabel(_('Headings:'), self), 0, 1)
self.comboBoxHEADINGS = KeyValueComboBox(HEADINGS, prefs[KEY.HEADINGS], parent=groupboxHTML)
layout_gridHTML.addWidget(self.comboBoxHEADINGS, 1, 1)
layout_gridHTML.addWidget(QLabel(' ', self), 2, 0)
self.comboBoxFONT_WEIGHT = KeyValueComboBox(FONT_WEIGHT, prefs[KEY.FONT_WEIGHT], parent=groupboxHTML)
layout_gridHTML.addWidget(self.comboBoxFONT_WEIGHT, 3, 0)
self.checkBoxDEL_ITALIC = QCheckBox(_('Remove Italic'), groupboxHTML)
self.checkBoxDEL_ITALIC.setChecked(prefs[KEY.DEL_ITALIC])
layout_gridHTML.addWidget(self.checkBoxDEL_ITALIC, 3, 1)
self.checkBoxDEL_UNDER = QCheckBox(_('Remove Underline'), groupboxHTML)
self.checkBoxDEL_UNDER.setChecked(prefs[KEY.DEL_UNDER])
layout_gridHTML.addWidget(self.checkBoxDEL_UNDER, 4, 0)
self.checkBoxDEL_STRIKE = QCheckBox(_('Remove Strikethrough'), groupboxHTML)
self.checkBoxDEL_STRIKE.setChecked(prefs[KEY.DEL_STRIKE])
layout_gridHTML.addWidget(self.checkBoxDEL_STRIKE, 4, 1)
layoutHTML.addWidget(QLabel(' ', groupboxHTML))
layout_formHTML = QFormLayout()
layout_formHTML.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.ExpandingFieldsGrow)
layout_formHTML.setFormAlignment(Qt.AlignRight)
layoutHTML.addLayout(layout_formHTML)
self.comboBoxFORCE_JUSTIFY = KeyValueComboBox(FORCE_JUSTIFY, prefs[KEY.FORCE_JUSTIFY], parent=groupboxHTML)
layout_formHTML.addRow(_('Justification:'), self.comboBoxFORCE_JUSTIFY)
self.comboBoxFORCE_JUSTIFY.setSizePolicy(size_policy)
self.comboBoxLIST_ALIGN = KeyValueComboBox(LIST_ALIGN, prefs[KEY.LIST_ALIGN], parent=groupboxHTML)
layout_formHTML.addRow(_('List alignment:'), self.comboBoxLIST_ALIGN)
self.comboBoxLIST_ALIGN.setSizePolicy(size_policy)
self.comboBoxID_CLASS = KeyValueComboBox(ID_CLASS, prefs[KEY.ID_CLASS], parent=groupboxHTML)
layout_formHTML.addRow(QLabel(_('ID & CLASS attributs:')), self.comboBoxID_CLASS)
self.comboBoxID_CLASS.setSizePolicy(size_policy)
layout_formHTML.addWidget(QLabel(' ', self))
self.checkBoxCSS_KEEP_ACTIVE = QCheckBox(_('CSS rule to keep:'), groupboxHTML)
self.lineEditCSS_KEEP = QLineEdit(groupboxHTML)
layout_formHTML.addRow(self.checkBoxCSS_KEEP_ACTIVE, self.lineEditCSS_KEEP)
self.lineEditCSS_KEEP_initial_text = self.lineEditCSS_KEEP_last_text = prefs[KEY.CSS_KEEP]
self.lineEditCSS_KEEP.setToolTip(_('Custom CSS rules to keep in addition to the basic ones. Rules separated by a space.'))
self.lineEditCSS_KEEP.setSizePolicy(size_policy)
def action_checkBoxCSS_KEEP_ACTIVE(num):
b = self.checkBoxCSS_KEEP_ACTIVE.isChecked()
self.lineEditCSS_KEEP.setEnabled(b)
if b:
self.lineEditCSS_KEEP.setText(self.lineEditCSS_KEEP_last_text)
else:
self.lineEditCSS_KEEP_last_text = self.lineEditCSS_KEEP.text()
self.lineEditCSS_KEEP.setText(_('All CSS rules are keep.'))
self.checkBoxCSS_KEEP_ACTIVE.stateChanged.connect(action_checkBoxCSS_KEEP_ACTIVE)
self.checkBoxCSS_KEEP_ACTIVE.setChecked(prefs[KEY.CSS_KEEP_ACTIVE])
action_checkBoxCSS_KEEP_ACTIVE(-1)
self.lineEditCSS_KEEP_last_text = self.lineEditCSS_KEEP_initial_text
def action_checkBoxDEL_FORMATTING(num):
b = not self.checkBoxDEL_FORMATTING.isChecked()
self.comboBoxKEEP_URL.setEnabled(b)
self.comboBoxHEADINGS.setEnabled(b)
self.comboBoxFONT_WEIGHT.setEnabled(b)
self.checkBoxDEL_ITALIC.setEnabled(b)
self.checkBoxDEL_UNDER.setEnabled(b)
self.checkBoxDEL_STRIKE.setEnabled(b)
self.comboBoxFORCE_JUSTIFY.setEnabled(b)
self.comboBoxLIST_ALIGN.setEnabled(b)
self.comboBoxID_CLASS.setEnabled(b)
self.checkBoxCSS_KEEP_ACTIVE.setEnabled(b)
self.lineEditCSS_KEEP.setEnabled(self.checkBoxCSS_KEEP_ACTIVE.isChecked())
if not b:
self.lineEditCSS_KEEP.setEnabled(False)
self.checkBoxDEL_FORMATTING = QCheckBox(_('Remove all formatting'), self)
self.checkBoxDEL_FORMATTING.stateChanged.connect(action_checkBoxDEL_FORMATTING)
self.checkBoxDEL_FORMATTING.setChecked(prefs[KEY.DEL_FORMATTING])
layout.addWidget(self.checkBoxDEL_FORMATTING)
# ------
layout.addWidget(QLabel(' ', self))
# -- options TEXT --
groupboxTEXT = QGroupBox(self)
layout.addWidget(groupboxTEXT)
layoutTEXT = QFormLayout(groupboxTEXT)
layoutTEXT.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.ExpandingFieldsGrow)
layoutTEXT.setFormAlignment(Qt.AlignRight)
groupboxTEXT.setLayout(layoutTEXT)
self.comboBoxMARKDOWN = KeyValueComboBox(MARKDOWN, prefs[KEY.MARKDOWN], parent=groupboxTEXT)
layoutTEXT.addRow(_('Markdown:'), self.comboBoxMARKDOWN)
self.comboBoxMARKDOWN.setToolTip(_('Try to convert the Markdown strings to HTML'))
self.comboBoxMARKDOWN.setSizePolicy(size_policy)
self.comboBoxDOUBLE_BR = KeyValueComboBox(DOUBLE_BR, prefs[KEY.DOUBLE_BR], parent=groupboxTEXT)
layoutTEXT.addRow(_("Multiple 'Line Return' in a paragraph:"), self.comboBoxDOUBLE_BR)
self.comboBoxDOUBLE_BR.setSizePolicy(size_policy)
self.comboBoxSINGLE_BR = KeyValueComboBox(SINGLE_BR, prefs[KEY.SINGLE_BR])
layoutTEXT.addRow(_("Single 'Line Return' in a paragraph:"), self.comboBoxSINGLE_BR)
self.comboBoxSINGLE_BR.setToolTip(_('This operation is applied after "Multiple \'Line Return\' in a paragraph"\n'+
'and before "Multiple empty paragraph"'))
self.comboBoxSINGLE_BR.setSizePolicy(size_policy)
self.comboBoxEMPTY_PARA = KeyValueComboBox(EMPTY_PARA, prefs[KEY.EMPTY_PARA], parent=groupboxTEXT)
layoutTEXT.addRow(_('Multiple empty paragraph:'), self.comboBoxEMPTY_PARA)
self.comboBoxEMPTY_PARA.setSizePolicy(size_policy)
self.comboBoxIMG_TAG = KeyValueComboBox(IMG_TAG, prefs[KEY.IMG_TAG], parent=groupboxTEXT)
layoutTEXT.addRow(_('Images:'), self.comboBoxIMG_TAG)
self.comboBoxIMG_TAG.setSizePolicy(size_policy)
def get_option(self) -> dict:
prefs = {}
prefs[KEY.KEEP_URL] = self.comboBoxKEEP_URL.selected_key()
prefs[KEY.HEADINGS] = self.comboBoxHEADINGS.selected_key()
prefs[KEY.FONT_WEIGHT] = self.comboBoxFONT_WEIGHT.selected_key()
prefs[KEY.DEL_ITALIC] = self.checkBoxDEL_ITALIC.isChecked()
prefs[KEY.DEL_UNDER] = self.checkBoxDEL_UNDER.isChecked()
prefs[KEY.DEL_STRIKE] = self.checkBoxDEL_STRIKE.isChecked()
prefs[KEY.FORCE_JUSTIFY] = self.comboBoxFORCE_JUSTIFY.selected_key()
prefs[KEY.LIST_ALIGN] = self.comboBoxLIST_ALIGN.selected_key()
prefs[KEY.ID_CLASS] = self.comboBoxID_CLASS.selected_key()
prefs[KEY.CSS_KEEP_ACTIVE] = self.checkBoxCSS_KEEP_ACTIVE.isChecked()
if prefs[KEY.CSS_KEEP_ACTIVE]:
prefs[KEY.CSS_KEEP] = css_clean_rules(self.lineEditCSS_KEEP.text())
else:
prefs[KEY.CSS_KEEP] = css_clean_rules(self.lineEditCSS_KEEP_initial_text)
prefs[KEY.DEL_FORMATTING] = self.checkBoxDEL_FORMATTING.isChecked()
prefs[KEY.MARKDOWN] = self.comboBoxMARKDOWN.selected_key()
prefs[KEY.DOUBLE_BR] = self.comboBoxDOUBLE_BR.selected_key()
prefs[KEY.SINGLE_BR] = self.comboBoxSINGLE_BR.selected_key()
prefs[KEY.EMPTY_PARA] = self.comboBoxEMPTY_PARA.selected_key()
prefs[KEY.IMG_TAG] = self.comboBoxIMG_TAG.selected_key()
return prefs
class ConfigWidget(QWidget):
def __init__(self):
QWidget.__init__(self)
layout = QVBoxLayout()
self.setLayout(layout)
if CALIBRE_VERSION < (6,26,0):
# Make dialog box scrollable (for smaller screens)
scrollable = QScrollArea()
scrollcontent = QWidget()
scrollable.setWidget(scrollcontent)
scrollable.setWidgetResizable(True)
layout.addWidget(scrollable)
layout = QVBoxLayout()
scrollcontent.setLayout(layout)
title_layout = ImageTitleLayout(PLUGIN_ICON, _('Comments Cleaner Options'))
layout.addLayout(title_layout)
# --- options ---
self.options = CommonOptions(PREFS, parent=self)
layout.addWidget(self.options)
# --- Custom columns ---
self.checkBoxCUSTOM_COLUMN = QCheckBox(_('Apply to others custom HTML columns'), self)
self.checkBoxCUSTOM_COLUMN.setChecked(PREFS[KEY.CUSTOM_COLUMN])
layout.addWidget(self.checkBoxCUSTOM_COLUMN)
# --- Buttons ---
layout.addWidget(QLabel(' ', self))
button_layout = QHBoxLayout()
layout.addLayout(button_layout)
button_layout.addWidget(KeyboardConfigDialogButton(parent=self))
if CALIBRE_HAS_NOTES:
button_layout.addWidget(NoteConfigDialogButton(self))
button_layout.addStretch(-1)
layout.addStretch(-1)
def save_settings(self):
with PREFS:
prefs = self.options.get_option()
prefs[KEY.CUSTOM_COLUMN] = self.checkBoxCUSTOM_COLUMN.isChecked()
PREFS.update(prefs)
debug_print('Save settings:', prefs, '\n')
class NoteConfigDialogButton(QPushButton):
def __init__(self, parent=None):
QPushButton.__init__(self, get_icon(NOTES_ICON), _('Notes Cleaner Options'), parent)
self.setToolTip(_('Edit the options for the notes cleaner action'))
self.clicked.connect(self.edit_notes_options)
def edit_notes_options(self):
d = ConfigNotesDialog()
d.exec()
class ConfigNotesDialog(Dialog):
def __init__(self):
Dialog.__init__(self,
title=_('Customize') + ' ' + _('Notes Cleaner'),
name='plugin config dialog:User Action Interface:Notes Cleaner',
parent=GUI,
)
def setup_ui(self):
v = QVBoxLayout(self)
scrollable = QScrollArea()
v.addWidget(scrollable)
v.addWidget(self.bb)
# Make dialog box scrollable (for smaller screens)
scrollcontent = QWidget()
scrollable.setWidget(scrollcontent)
scrollable.setWidgetResizable(True)
layout = QVBoxLayout()
scrollcontent.setLayout(layout)
title_layout = ImageTitleLayout(NOTES_ICON, _('Notes Cleaner Options'))
layout.addLayout(title_layout)
prefs = PREFS[KEY.NOTES_SETTINGS].copy()
# --- options ---
self.options = CommonOptions(prefs, parent=self)
layout.addWidget(self.options)
# --- Keyboard shortcuts ---
layout.addWidget(QLabel(' ', self))
button_layout = QHBoxLayout()
layout.addLayout(button_layout)
button_layout.addWidget(KeyboardConfigDialogButton(parent=self))
button_layout.addStretch(-1)
layout.addStretch(-1)
def accept(self):
with PREFS:
prefs = self.options.get_option()
PREFS[KEY.NOTES_SETTINGS].update(prefs)
debug_print('Notes settings:', prefs, '\n')
Dialog.accept(self)
class SelectNotesDialog(Dialog):
def __init__(self, book_ids=[]):
self.book_ids = book_ids
self.selected_notes = {}
Dialog.__init__(self,
title=_('Select Notes to clean'),
name='plugin config dialog:User Action Interface:Select Notes to clean',
parent=GUI,
)
def setup_ui(self):
layout = QVBoxLayout(self)
self.tree_view = SelectNotesWidget(book_ids=self.book_ids)
layout.addWidget(self.tree_view)
self.tree_view.update_texts(
tooltip=_('Subset of Notes associate to the currently selected books'),
zero_book=_('No books selected'),
zero_values=_('No notes for {:d} selected books'),
has_book_values=_('Notes for {:d} selected books'),
)
button_layout = QHBoxLayout()
layout.addLayout(button_layout)
button_layout.addWidget(NoteConfigDialogButton(self))
button_layout.addStretch(-1)
layout.addWidget(self.bb)
def accept(self):
self.selected_notes = self.tree_view.get_selected()
Dialog.accept(self)