# 获取Qt的剪切板并绑定回调函数 self.clipboard = QApplication.clipboard() self.clipboard.dataChanged.connect(self.on_clipboard_changed)
# 回调函数 def on_clipboard_changed(self): data = self.clipboard.mimeData() if data.hasText(): word = data.text().strip() m = re.match(r'[a-zA-Z]+', word) if m: self.setWord(word) #self.setWindowFlags(self.windowFlags() & QtCore.Qt.WindowStaysOnTopHint) #self.setWindowState(self.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive) trans = queryWords(word) self.setTrans(trans) ''' tip the window content has changed, but cannot move the window to the forground''' self.activateWindow() else: print(word)
def queryWords(word):
''' 利用有道翻译查询单词 '''
url = 'http://dict.youdao.com/w/{}/'.format(word)
html = getURL(url)
soup = BeautifulSoup(html.text, 'html.parser')
trans_container = soup.find(class_='trans-container')
if not trans_container:
''' not found the translation '''
return [word]
trans_li = trans_container.find_all('li')
trans_data = [li.text.strip() for li in trans_li]
return trans_data
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有