Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
update_evernote_query_notebook)
# Evernote Query: Use Notebook
evernote_query_use_notebook = QCheckBox(" ", self)
evernote_query_use_notebook.setChecked(mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_NOTEBOOK, False))
evernote_query_use_notebook.stateChanged.connect(update_evernote_query_use_notebook)
# Add Form Row for Notebook
hbox = QHBoxLayout()
hbox.addWidget(evernote_query_use_notebook)
hbox.addWidget(evernote_query_notebook)
form.addRow("Notebook:", hbox)
# Evernote Query: Note Title
evernote_query_note_title = QLineEdit()
evernote_query_note_title.setText(mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_NOTE_TITLE, ""))
evernote_query_note_title.connect(evernote_query_note_title,
SIGNAL("textEdited(QString)"),
update_evernote_query_note_title)
# Evernote Query: Use Note Title
evernote_query_use_note_title = QCheckBox(" ", self)
evernote_query_use_note_title.setChecked(mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_NOTE_TITLE, False))
evernote_query_use_note_title.stateChanged.connect(update_evernote_query_use_note_title)
# Add Form Row for Note Title
hbox = QHBoxLayout()
hbox.addWidget(evernote_query_use_note_title)
hbox.addWidget(evernote_query_note_title)
form.addRow("Note Title:", hbox)
# Evernote Query: Last Updated Type
def generate_evernote_query():
query = ""
tags = mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_TAGS, SETTINGS.EVERNOTE_QUERY_TAGS_DEFAULT_VALUE).split(",")
if mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_NOTEBOOK, False):
query += 'notebook:"%s" ' % mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_NOTEBOOK,
SETTINGS.EVERNOTE_QUERY_NOTEBOOK_DEFAULT_VALUE).strip()
if mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_ANY, True):
query += "any: "
if mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_NOTE_TITLE, False):
query_note_title = mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_NOTE_TITLE, "")
if not query_note_title[:1] + query_note_title[-1:] == '""':
query_note_title = '"%s"' % query_note_title
query += 'intitle:%s ' % query_note_title
if mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_TAGS, True):
for tag in tags:
query += "tag:%s " % tag.strip()
if mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_LAST_UPDATED, False):
query += " updated:%s " % evernote_query_last_updated_value_get_current_value()
if mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_SEARCH_TERMS, False):
query = ""
tags = mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_TAGS, SETTINGS.EVERNOTE_QUERY_TAGS_DEFAULT_VALUE).split(",")
if mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_NOTEBOOK, False):
query += 'notebook:"%s" ' % mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_NOTEBOOK,
SETTINGS.EVERNOTE_QUERY_NOTEBOOK_DEFAULT_VALUE).strip()
if mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_ANY, True):
query += "any: "
if mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_NOTE_TITLE, False):
query_note_title = mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_NOTE_TITLE, "")
if not query_note_title[:1] + query_note_title[-1:] == '""':
query_note_title = '"%s"' % query_note_title
query += 'intitle:%s ' % query_note_title
if mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_TAGS, True):
for tag in tags:
query += "tag:%s " % tag.strip()
if mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_LAST_UPDATED, False):
query += " updated:%s " % evernote_query_last_updated_value_get_current_value()
if mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_SEARCH_TERMS, False):
query += mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_SEARCH_TERMS, "")
return query
all_inactive = not (
search_terms_active or note_title_active or notebook_active or evernote_query_use_last_updated.isChecked())
if not search_terms:
evernote_query_use_search_terms.setEnabled(False)
evernote_query_use_search_terms.setChecked(False)
else:
evernote_query_use_search_terms.setEnabled(True)
evernote_query_use_search_terms.setChecked(mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_SEARCH_TERMS, True))
if not note_title:
evernote_query_use_note_title.setEnabled(False)
evernote_query_use_note_title.setChecked(False)
else:
evernote_query_use_note_title.setEnabled(True)
evernote_query_use_note_title.setChecked(mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_NOTE_TITLE, True))
if not notebook:
evernote_query_use_notebook.setEnabled(False)
evernote_query_use_notebook.setChecked(False)
else:
evernote_query_use_notebook.setEnabled(True)
evernote_query_use_notebook.setChecked(mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_NOTEBOOK, True))
if not tags and not all_inactive:
evernote_query_use_tags.setEnabled(False)
evernote_query_use_tags.setChecked(False)
else:
evernote_query_use_tags.setEnabled(True)
evernote_query_use_tags.setChecked(mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_TAGS, True))
if all_inactive and not tags:
evernote_query_tags.setText(SETTINGS.EVERNOTE_QUERY_TAGS_DEFAULT_VALUE)
def update_anki_deck_visibilities():
if not default_anki_deck.text():
anki_deck_evernote_notebook_integration.setChecked(True)
anki_deck_evernote_notebook_integration.setEnabled(False)
else:
anki_deck_evernote_notebook_integration.setEnabled(True)
anki_deck_evernote_notebook_integration.setChecked(
mw.col.conf.get(SETTINGS.ANKI_DECK_EVERNOTE_NOTEBOOK_INTEGRATION, True))
def import_from_evernote(auto_page_callback=None):
controller = Controller()
controller.evernote.initialize_note_store()
controller.auto_page_callback = auto_page_callback
if auto_page_callback:
controller.forceAutoPage = True
controller.currentPage = 1
else:
controller.forceAutoPage = False
controller.currentPage = mw.col.conf.get(SETTINGS.EVERNOTE_PAGINATION_CURRENT_PAGE, 1)
controller.proceed()
evernote_query_last_updated_type.setEnabled(True)
evernote_query_last_updated_value_absolute_date.setEnabled(True)
evernote_query_last_updated_value_absolute_time.setEnabled(True)
evernote_query_last_updated_value_relative_spinner.setEnabled(True)
absolute_date = QDate().fromString(mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_LAST_UPDATED_VALUE_ABSOLUTE_DATE,
"{:%Y %m %d}".format(datetime.now() - timedelta(days=7))),
'yyyy MM dd')
if index < EvernoteQueryLocationType.AbsoluteDate:
evernote_query_last_updated_value_absolute_date.setVisible(False)
evernote_query_last_updated_value_absolute_time.setVisible(False)
evernote_query_last_updated_value_relative_spinner.setVisible(True)
spinner_prefix = ['day', 'week', 'month', 'year'][index]
evernote_query_last_updated_value_relative_spinner.setPrefix(spinner_prefix)
evernote_query_last_updated_value_relative_spinner.setValue(
int(mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_LAST_UPDATED_VALUE_RELATIVE, 0)))
evernote_query_last_updated_value_stacked_layout.setCurrentIndex(0)
else:
evernote_query_last_updated_value_relative_spinner.setVisible(False)
evernote_query_last_updated_value_absolute_date.setVisible(True)
evernote_query_last_updated_value_absolute_date.setDate(absolute_date)
evernote_query_last_updated_value_stacked_layout.setCurrentIndex(1)
if index == EvernoteQueryLocationType.AbsoluteDate:
evernote_query_last_updated_value_absolute_time.setVisible(False)
evernote_query_last_updated_value_absolute_datetime.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
else:
absolute_time = QTime().fromString(mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_LAST_UPDATED_VALUE_ABSOLUTE_TIME,
"{:HH mm ss}".format(datetime.now())), 'HH mm ss')
evernote_query_last_updated_value_absolute_time.setTime(absolute_time)
evernote_query_last_updated_value_absolute_time.setVisible(True)
evernote_query_last_updated_value_absolute_datetime.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
evernote_query_use_search_terms.setEnabled(True)
evernote_query_use_search_terms.setChecked(mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_SEARCH_TERMS, True))
if not note_title:
evernote_query_use_note_title.setEnabled(False)
evernote_query_use_note_title.setChecked(False)
else:
evernote_query_use_note_title.setEnabled(True)
evernote_query_use_note_title.setChecked(mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_NOTE_TITLE, True))
if not notebook:
evernote_query_use_notebook.setEnabled(False)
evernote_query_use_notebook.setChecked(False)
else:
evernote_query_use_notebook.setEnabled(True)
evernote_query_use_notebook.setChecked(mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_NOTEBOOK, True))
if not tags and not all_inactive:
evernote_query_use_tags.setEnabled(False)
evernote_query_use_tags.setChecked(False)
else:
evernote_query_use_tags.setEnabled(True)
evernote_query_use_tags.setChecked(mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_TAGS, True))
if all_inactive and not tags:
evernote_query_tags.setText(SETTINGS.EVERNOTE_QUERY_TAGS_DEFAULT_VALUE)
evernote_query_use_note_title.setEnabled(True)
evernote_query_use_note_title.setChecked(mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_NOTE_TITLE, True))
if not notebook:
evernote_query_use_notebook.setEnabled(False)
evernote_query_use_notebook.setChecked(False)
else:
evernote_query_use_notebook.setEnabled(True)
evernote_query_use_notebook.setChecked(mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_NOTEBOOK, True))
if not tags and not all_inactive:
evernote_query_use_tags.setEnabled(False)
evernote_query_use_tags.setChecked(False)
else:
evernote_query_use_tags.setEnabled(True)
evernote_query_use_tags.setChecked(mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_USE_TAGS, True))
if all_inactive and not tags:
evernote_query_tags.setText(SETTINGS.EVERNOTE_QUERY_TAGS_DEFAULT_VALUE)
def evernote_query_last_updated_value_get_current_value():
index = mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_LAST_UPDATED_TYPE, 0)
if index < EvernoteQueryLocationType.AbsoluteDate:
spinner_text = ['day', 'week', 'month', 'year'][index]
spinner_val = mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_LAST_UPDATED_VALUE_RELATIVE, 0)
if spinner_val > 0: spinner_text += "-" + str(spinner_val)
return spinner_text
absolute_date_str = mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_LAST_UPDATED_VALUE_ABSOLUTE_DATE,
"{:%Y %m %d}".format(datetime.now() - timedelta(days=7))).replace(' ', '')
if index == EvernoteQueryLocationType.AbsoluteDate:
return absolute_date_str
absolute_time_str = mw.col.conf.get(SETTINGS.EVERNOTE_QUERY_LAST_UPDATED_VALUE_ABSOLUTE_TIME,
"{:HH mm ss}".format(datetime.now())).replace(' ', '')
return absolute_date_str + "'T'" + absolute_time_str