Skip to content

Commit

Permalink
harken: no history in telegram, do not recenter on activation
Browse files Browse the repository at this point in the history
  • Loading branch information
balta2ar committed Apr 12, 2024
1 parent af2130c commit aba84d6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def run(self):
'srst-anki-sync-notion=yatetradki.tools.anki_notion:main',
'srst-add-audio=yatetradki.tools.add_audio:main',
'srst-ordbok=yatetradki.uitools.ordbok.ordbok:main',
#'srst-harken=yatetradki.uitools.harken.harken:main',
'srst-dehyphen=yatetradki.uitools.dehyphen.dehyphen:main',
'srst-sayit=yatetradki.uitools.sayit.sayit:main',
'srst-textmarksman=yatetradki.uitools.textmarksman.textmarksman:main',
Expand Down
1 change: 1 addition & 0 deletions yatetradki/tools/telega.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def __init__(self, tg, chat_id):
self.tg = tg
self.chat_id = chat_id
def add(self, word):
return
logging.info('Telegram: adding word: %s', word)
word = word.strip().lower()
latest = self.tg.get_latest_message(chat_id=self.chat_id)
Expand Down
23 changes: 15 additions & 8 deletions yatetradki/uitools/harken/harken/harken.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
from aiohttp import web
from pydantic import BaseModel

import pkg_resources
ASSETS = pkg_resources.resource_filename('harken', 'assets')

logging.basicConfig(level=logging.DEBUG)
logging.info(f"Starting harken. ASSETS={ASSETS}")

MEDIA = ['.mp3', '.mp4', '.mkv', '.avi', '.webm', '.opus', '.ogg']
SUBS = ['.vtt']
Expand Down Expand Up @@ -148,7 +152,7 @@ async def list_media(request):
return web.json_response({'media_files': out})

async def serve_index(request):
content = open('assets/index.html', 'r').read()
content = open(join(ASSETS, 'index.html'), 'r').read()
return web.Response(text=content, content_type='text/html')

async def search_content(request):
Expand Down Expand Up @@ -329,20 +333,23 @@ def test_search():


def main():
global index
global MEDIA_DIR
parser = argparse.ArgumentParser()
parser.add_argument('media', help='Media directory', default=MEDIA_DIR)
args = parser.parse_args()

MEDIA_DIR = args.media
index = build_index()

app = web.Application()
app.router.add_get('/', serve_index)
app.router.add_get('/search_content', search_content)
app.router.add_get('/media/{file_name:.*}', fetch_media)
app.router.add_get('/media', list_media)
app.router.add_static('/assets/', 'assets')
app.router.add_static('/assets/', path=ASSETS, name='assets')

web.run_app(app, host="127.0.0.1", port=4000)

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('media', help='Media directory', default=MEDIA_DIR)
args = parser.parse_args()

MEDIA_DIR = args.media
index = build_index()
main()
1 change: 1 addition & 0 deletions yatetradki/uitools/harken/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pydantic==1.9.1
uvicorn==0.23.2
aiohttp>=3.9
9 changes: 5 additions & 4 deletions yatetradki/uitools/ordbok/ordbok.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def observe(self, on_show):

from yatetradki.reader.dsl import lookup as dsl_lookup
from yatetradki.uitools.index.search import search as index_search
from yatetradki.tools.telega import TdlibClient, WordLogger
#from yatetradki.tools.telega import TdlibClient, WordLogger
from yatetradki.utils import must_env

FORMAT = '%(asctime)-15s %(levelname)s %(message)s'
Expand All @@ -142,7 +142,8 @@ def observe(self, on_show):
WINDOW_WIDTH = 1300
WINDOW_HEIGHT = 800
UPDATE_DELAY = 1000
DIR = Path(dirname(__file__))
DIR = Path(expanduser(expandvars('$HOME/share/btsync/prg/srs-toolbelt/yatetradki/uitools/ordbok')))
#DIR = Path(dirname(__file__))
ICON_FILENAME = str(DIR / 'ordbok.png')
TEMPLATE_DIR = DIR / 'static' / 'html'
STATIC_DIR = DIR / 'static'
Expand Down Expand Up @@ -1438,7 +1439,7 @@ def unminimize(self):

def activate(self):
self.grab_clipboard()
self.center()
# self.center()
self.unminimize()
self.raise_()
self.show()
Expand Down Expand Up @@ -1886,7 +1887,7 @@ def main():
tray.show()

dog.observe(lambda: window.myActivate.emit())
track_history(window.myTranslate)
#track_history(window.myTranslate)

result = qtApp.exec()

Expand Down

0 comments on commit aba84d6

Please sign in to comment.