From 6a7086412b04df74e126b239c25384b081c7e517 Mon Sep 17 00:00:00 2001 From: Mikhail Iudin Date: Sun, 12 Mar 2023 19:42:00 +0300 Subject: [PATCH] switch to pyqt6 --- README.md | 8 ++- interSubs.py | 168 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 109 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 36e8c2c..3f9d613 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Requirements * Xorg (ignore for Mac users) * composite manager; `xcompmgr` or sth. (ignore for Mac users) * python => 3.6 - * python-pyqt5 + * python-pyqt6 * python-numpy * python-beautifulsoup4 * python-requests @@ -109,8 +109,8 @@ Changelog * Tk is abandoned in favor of Qt. * Background can be fully transparent or semi/fully opaque. * Rendering is faster than with Tk. - * requires pyqt5 for python 3 - * `pip install pyqt5` / `pacman -S python-pyqt5` + * requires pyqt6 for python 3 + * `pip install pyqt6` / `pacman -S python-pyqt6` * requires composite manager for not solid bg; `xcompmgr` or sth. * tested on Openbox, i3, KDE(kwin). * On KDE(kwin) go to composite and uncheck "Allow applications to block compositing". [screenshot](https://iwf1.com/wordpress/wp-content/uploads/2017/09/Disable-applications-override-compositor-KDE.jpg) @@ -156,3 +156,5 @@ Changelog * in config `translation_function_name_full_sentence = 'google'` * 2.10 * Fixed google-translation +* 2.11 + * Switched to pyqt6 diff --git a/interSubs.py b/interSubs.py index 3c83062..d942af6 100644 --- a/interSubs.py +++ b/interSubs.py @@ -3,26 +3,30 @@ # v. 2.10 # Interactive subtitles for `mpv` for language learners. -import os, subprocess, sys -import random, re, time -import requests -import threading, queue -import calendar, math, base64 -import numpy import ast - -from bs4 import BeautifulSoup - -from urllib.parse import quote +import base64 +import calendar +import math +import os +import queue +import random +import re +import subprocess +import sys +import threading +import time +import warnings from json import loads +from urllib.parse import quote -import warnings +import numpy +import requests +from PyQt6.QtCore import Qt, QThread, QObject, pyqtSignal, pyqtSlot, QSize +from PyQt6.QtGui import QPalette, QPaintEvent, QPainter, QPainterPath, QFontMetrics, QColor, QPen, QBrush +from PyQt6.QtWidgets import QApplication, QFrame, QVBoxLayout, QHBoxLayout, QLabel, QSizePolicy, QWidget +from bs4 import BeautifulSoup from six.moves import urllib -from PyQt5.QtCore import Qt, QThread, QObject, pyqtSignal, pyqtSlot, QSize -from PyQt5.QtWidgets import QApplication, QFrame, QVBoxLayout, QHBoxLayout, QLabel, QSizePolicy, QWidget -from PyQt5.QtGui import QPalette, QPaintEvent, QPainter, QPainterPath, QFont, QFontMetrics, QColor, QPen, QBrush - pth = os.path.expanduser('~/.config/mpv/scripts/') os.chdir(pth) import interSubs_config as config @@ -58,7 +62,9 @@ def pons(word): pairs.append([pi[0], pi[1]]) except: p = requests.get(url, headers={ - 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36'}).text + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) ' + 'AppleWebKit/537.36 (KHTML, like Gecko) ' + 'Chrome/64.0.3282.167 Safari/537.36'}).text soup = BeautifulSoup(p, "lxml") trs = soup.find_all('dl') @@ -88,9 +94,12 @@ def pons(word): word_descr = soup.find_all('h2', class_='') if '' not in str(word_descr[0]): word_descr = re.sub('\n|\r|\t', ' ', word_descr[0].get_text()) - word_descr = re.sub(' +', ' ', word_descr).replace('<', '<').replace('>', '>').replace(' · ', - '·').replace( - ' , ', ', ').strip() + word_descr = re.sub(' +', ' ', word_descr) \ + .replace('<', '<') \ + .replace('>', '>') \ + .replace(' · ', '·') \ + .replace(' , ', ', ') \ + .strip() else: word_descr = '' except: @@ -179,7 +188,8 @@ def _update(self): code = code.encode().decode('unicode-escape') except AttributeError: raise Exception( - 'Could not find TKK token for this request.\nSee https://github.com/ssut/py-googletrans/issues/234 for more details.') + 'Could not find TKK token for this request.\n' + 'See https://github.com/ssut/py-googletrans/issues/234 for more details.') except: raise @@ -248,7 +258,7 @@ def _xr(self, a, b): while c < size_b - 2: d = b[c + 2] d = ord(d[0]) - 87 if 'a' <= d else int(d) - d = rshift(a, d) if '+' == b[c + 1] else a << d + d = self.rshift(a, d) if '+' == b[c + 1] else a << d a = a + d & 4294967295 if '+' == b[c] else a ^ d c += 3 @@ -465,7 +475,9 @@ def google(word): url = '{url}&tk={tk}'.format(url=url, tk=tk) p = requests.get(url, headers={ - 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36'}).text + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) ' + 'AppleWebKit/537.36 (KHTML, like Gecko) ' + 'Chrome/64.0.3282.167 Safari/537.36'}).text p = loads(p) try: @@ -523,7 +535,9 @@ def reverso(word): pairs.append([pi[0], pi[1]]) except: p = requests.get(url, headers={ - 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36'}).text + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) ' + 'AppleWebKit/537.36 (KHTML, like Gecko) ' + 'Chrome/64.0.3282.167 Safari/537.36'}).text soup = BeautifulSoup(p, "lxml") trs = soup.find_all(class_=re.compile('translation.*ltr.*')) @@ -567,7 +581,9 @@ def linguee(word): except: # p = open('/home/lom/d/1.html', encoding="ISO-8859-15").read() p = requests.get(url, headers={ - 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36'}).text + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) ' + 'AppleWebKit/537.36 (KHTML, like Gecko) ' + 'Chrome/64.0.3282.167 Safari/537.36'}).text soup = BeautifulSoup(p, "lxml") trs = soup.find_all('div', class_="lemma featured") @@ -608,7 +624,9 @@ def dict_cc(word): pairs.append([pi[0], pi[1]]) except: p = requests.get(url, headers={ - 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36'}).text + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) ' + 'AppleWebKit/537.36 (KHTML, like Gecko) ' + 'Chrome/64.0.3282.167 Safari/537.36'}).text p = re.sub('
\d*
', '', p) p = re.sub('\d*', '', p) @@ -640,7 +658,8 @@ def redensarten(word): return [], ['', ''] url = 'https://www.redensarten-index.de/suche.php?suchbegriff=' + quote( - word) + '&bool=relevanz&gawoe=an&suchspalte%5B%5D=rart_ou&suchspalte%5B%5D=rart_varianten_ou&suchspalte%5B%5D=erl_ou&suchspalte%5B%5D=erg_ou' + word) + '&bool=relevanz&gawoe=an&suchspalte%5B%5D=rart_ou&' \ + 'suchspalte%5B%5D=rart_varianten_ou&suchspalte%5B%5D=erl_ou&suchspalte%5B%5D=erg_ou' pairs = [] fname = 'urls/' + url.replace('/', "-") @@ -657,7 +676,9 @@ def redensarten(word): pairs.append([pi[0], pi[1]]) except: p = requests.get(url, headers={ - 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36'}) + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) ' + 'AppleWebKit/537.36 (KHTML, like Gecko) ' + 'Chrome/64.0.3282.167 Safari/537.36'}) p.encoding = 'utf-8' p = p.text @@ -693,7 +714,8 @@ def redensarten(word): def leo(word): language = config.lang_from if config.lang_from != 'de' else config.lang_to - url = "https://dict.leo.org/dictQuery/m-vocab/%sde/query.xml?tolerMode=nof&rmWords=off&rmSearch=on&searchLoc=0&resultOrder=basic&multiwordShowSingle=on&lang=de&search=%s" % ( + url = "https://dict.leo.org/dictQuery/m-vocab/%sde/query.xml?tolerMode=nof&rmWords=off&rmSearch=on&searchLoc=0" \ + "&resultOrder=basic&multiwordShowSingle=on&lang=de&search=%s" % ( language, word) pairs = [] @@ -846,7 +868,9 @@ def listen(word, type='gtts'): quote(word), config.lang_to, config.lang_from, config.lang_from) p = requests.get(url, headers={ - 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36'}).text + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) ' + 'AppleWebKit/537.36 (KHTML, like Gecko) ' + 'Chrome/64.0.3282.167 Safari/537.36'}).text x = re.findall('