Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def addMenu(fullPath):
if not hasattr(mw, 'customMenus'):
mw.customMenus = {}
if len(fullPath.split('::')) == 2:
menuPath, submenuPath = fullPath.split('::')
hasSubmenu = True
else:
menuPath = fullPath
hasSubmenu = False
if menuPath not in mw.customMenus:
menu = QMenu('&' + menuPath, mw)
mw.customMenus[menuPath] = menu
mw.form.menubar.insertMenu(mw.form.menuTools.menuAction(), menu)
if hasSubmenu and (fullPath not in mw.customMenus):
submenu = QMenu('&' + submenuPath, mw)
mw.customMenus[fullPath] = submenu
mw.customMenus[menuPath].addMenu(submenu)
def detect_note_model(self):
delete_evernoteTagsToRemove = mw.col.conf.get(ank.SETTINGS.DELETE_EVERNOTE_TAGS_TO_IMPORT, True)
if ank.FIELDS.CONTENT in self.fields and "{{c1::" in self.fields[ank.FIELDS.CONTENT]:
self.model_name = ank.MODELS.EVERNOTE_CLOZE
elif ank.EVERNOTE.TAG.REVERSIBLE in self.tags:
self.model_name = ank.MODELS.EVERNOTE_REVERSIBLE
if delete_evernoteTagsToRemove: self.tags.remove(ank.EVERNOTE.TAG.REVERSIBLE)
elif ank.EVERNOTE.TAG.REVERSE_ONLY in self.tags:
model_name = ank.MODELS.EVERNOTE_REVERSE_ONLY
if delete_evernoteTagsToRemove: self.tags.remove(ank.EVERNOTE.TAG.REVERSE_ONLY)
def _update_JS(webview):
""" Updates the symbol list in the Javascript file. """
json = mw.ins_sym_manager.get_JSON()
webview.eval("insert_symbols.setMatchList(%s)" % json)
mw.col.decks.select(did)
model = mw.col.models.byName(modelName)
if not model:
model = mw.col.models.new(modelName)
mw.col.models.add(model)
template = mw.col.models.newTemplate("Default")
mw.col.models.addTemplate(model, template)
model['did'] = did
deck = mw.col.decks.get(did)
deck['mid'] = model['id']
mw.col.decks.save(deck)
airtable = AirtableImporter(mw.col, table, view, Config["key"], app_key)
airtable.updateModel(model)
airtable.initMapping()
airtable.run()
def show_options(browser = None, model_id = -1, callback = None, *args, **kwargs):
'''open options window'''
parent = mw if browser is None else browser
config.read()
opt_dialog = OptionsDialog(parent, u'Options', model_id)
opt_dialog.activateWindow()
opt_dialog.raise_()
result = opt_dialog.exec_()
opt_dialog.destroy()
if result == QDialog.Accepted:
if isinstance(callback, types.FunctionType):
callback(*args, **kwargs)
elif result == 1001:
show_fm_dialog(parent)
elif result == 1002:
show_dm_dialog(parent)
added_highlights = []
note_adder = NoteAdder(mw.col, config, added_highlights)
for clipping in clippings_to_add:
note_was_added = note_adder.try_add(clipping)
if note_was_added:
num_added += 1
if clipping.added:
last_added = clipping.added
with open(added_highlights_path, encoding='utf-8', mode='w') as added_highlights_file:
json.dump(list(note_adder.added_normalized_contents), added_highlights_file)
if last_added:
config['last_added'] = parse_clipping_added(last_added).isoformat()
mw.addonManager.writeConfig(__name__, config)
def info():
if num_added:
yield f'{num_added} new highlights imported'
num_duplicates = len(clippings_to_add) - num_added
if num_duplicates:
yield f'{num_duplicates} duplicate highlights ignored'
num_old_highlights = len(highlight_clippings) - len(clippings_to_add)
if num_old_highlights:
yield f'{num_old_highlights} old highlights ignored'
num_not_highlights = len(clippings) - len(highlight_clippings)
if num_not_highlights:
yield f'{num_not_highlights} non-highlight clippings ignored'
def ts_setup_menu():
"""
Initialize menu. If there is an entity "View" in top level menu
(shared with other plugins, like "Zoom" of R. Sieker) options of
the addon will be placed there. In other case it creates that menu.
"""
global ts_menu_switch
try:
mw.addon_view_menu
except AttributeError:
mw.addon_view_menu = QMenu(_(u"&View"), mw)
mw.form.menubar.insertMenu(mw.form.menuTools.menuAction(),
mw.addon_view_menu)
mw.ts_menu = QMenu(_('&Touchscreen'), mw)
mw.addon_view_menu.addMenu(mw.ts_menu)
ts_menu_switch = QAction(_('&Enable touchscreen mode'), mw, checkable=True)
ts_menu_color = QAction(_('Set &pen color'), mw)
ts_menu_width = QAction(_('Set pen &width'), mw)
ts_menu_opacity = QAction(_('Set pen &opacity'), mw)
ts_menu_about = QAction(_('&About...'), mw)
ts_toggle_seq = QKeySequence("Ctrl+r")
ts_menu_switch.setShortcut(ts_toggle_seq)
def show(self):
dialog = QDialog(mw)
zoomScrollLayout = QHBoxLayout()
zoomScrollLayout.addWidget(self._getZoomGroupBox())
zoomScrollLayout.addWidget(self._getScrollGroupBox())
zoomScrollTab = QWidget()
zoomScrollTab.setLayout(zoomScrollLayout)
tabWidget = QTabWidget()
tabWidget.setUsesScrollButtons(False)
tabWidget.addTab(self._getGeneralTab(), 'General')
tabWidget.addTab(self._getExtractionTab(), 'Extraction')
tabWidget.addTab(self._getHighlightTab(), 'Formatting')
tabWidget.addTab(self._getSchedulingTab(), 'Scheduling')
tabWidget.addTab(self._getImportingTab(), 'Importing')
tabWidget.addTab(self._getQuickKeysTab(), 'Quick Keys')