Skip to content

Commit

Permalink
add action to send text from browser to cropro
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsumoto-ren committed Mar 13, 2024
1 parent 0e30896 commit 236b47b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
16 changes: 16 additions & 0 deletions cropro.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from anki.models import NotetypeDict
from anki.notes import NoteId
from aqt import AnkiQt
from aqt.browser import Browser
from aqt.operations import QueryOp, CollectionOp
from aqt.qt import *
from aqt.utils import (
Expand Down Expand Up @@ -523,6 +524,19 @@ def on_profile_did_open(self):
self.populate_current_profile_decks()
self.populate_note_type_selection_combo()

def search_for(self, search_text: str) -> None:
self.show()
self.setFocus()
self.visible_search_bar().set_search_text(search_text)
self.visible_search_bar().search_requested.emit(search_text)

def setup_browser_menu(self, browser: Browser) -> None:
"""Add a browser entry"""
# This is the "Go" menu.
browser.form.menuJump.addSeparator()
action = browser.form.menuJump.addAction(f"Look up in {ADDON_NAME_SHORT}")
qconnect(action.triggered, lambda: self.search_for(browser.current_search()))


######################################################################
# Entry point
Expand All @@ -543,3 +557,5 @@ def init():
# react to anki's state changes
gui_hooks.profile_will_close.append(d.on_profile_will_close)
gui_hooks.profile_did_open.append(d.on_profile_did_open)
# add an action to the Browser's "Go" menu.
gui_hooks.browser_menus_did_init.append(d.setup_browser_menu)
9 changes: 6 additions & 3 deletions widgets/remote_search_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ def __init__(self):
self._setup_layout()
self._connect_elements()

def clear_search_text(self) -> None:
return self._keyword_edit.clear()

@property
def category_combo(self) -> QComboBox:
return self._category_combo
Expand All @@ -91,6 +88,12 @@ def jlpt_level_combo(self) -> QComboBox:
def search_text(self) -> str:
return self._keyword_edit.text().strip()

def set_search_text(self, search_text: str) -> None:
return self._keyword_edit.setText(search_text)

def clear_search_text(self) -> None:
return self._keyword_edit.clear()

def get_request_args(self) -> dict[str, str]:
args = {}
if keyword := self.search_text():
Expand Down
3 changes: 3 additions & 0 deletions widgets/search_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def other_profile_deck_combo(self) -> QComboBox:
def search_text(self) -> str:
return self._search_term_edit.text().strip()

def set_search_text(self, search_text: str) -> None:
return self._search_term_edit.setText(search_text)

def current_deck(self) -> NameId:
return self._other_profile_deck_combo.current_item()

Expand Down

0 comments on commit 236b47b

Please sign in to comment.