toxygen_plugins/SearchPlugin/srch.py

52 lines
1.6 KiB
Python
Raw Normal View History

2016-07-19 20:34:30 +00:00
import plugin_super_class
2017-10-21 18:07:05 +00:00
from PyQt5 import QtGui, QtCore, QtWidgets
2016-07-19 20:34:30 +00:00
class SearchPlugin(plugin_super_class.PluginSuperClass):
def __init__(self, *args):
super(SearchPlugin, self).__init__('SearchPlugin', 'srch', *args)
def get_message_menu(self, menu, text):
2017-10-21 18:07:05 +00:00
google = QtWidgets.QAction(
QtWidgets.QApplication.translate("srch", "Find in Google"),
2016-07-19 20:34:30 +00:00
menu)
google.triggered.connect(lambda: self.google(text))
2017-10-21 18:07:05 +00:00
duck = QtWidgets.QAction(
QtWidgets.QApplication.translate("srch", "Find in DuckDuckGo"),
2016-07-19 20:34:30 +00:00
menu)
duck.triggered.connect(lambda: self.duck(text))
2017-10-21 18:07:05 +00:00
yandex = QtWidgets.QAction(
QtWidgets.QApplication.translate("srch", "Find in Yandex"),
2016-07-19 20:34:30 +00:00
menu)
yandex.triggered.connect(lambda: self.yandex(text))
2017-10-21 18:07:05 +00:00
bing = QtWidgets.QAction(
QtWidgets.QApplication.translate("srch", "Find in Bing"),
2016-07-19 20:34:30 +00:00
menu)
bing.triggered.connect(lambda: self.bing(text))
return [duck, google, yandex, bing]
def google(self, text):
url = QtCore.QUrl('https://www.google.com/search?q=' + text)
2017-10-21 18:07:05 +00:00
self.open_url(url)
2016-07-19 20:34:30 +00:00
def duck(self, text):
url = QtCore.QUrl('https://duckduckgo.com/?q=' + text)
2017-10-21 18:07:05 +00:00
self.open_url(url)
2016-07-19 20:34:30 +00:00
def yandex(self, text):
url = QtCore.QUrl('https://yandex.com/search/?text=' + text)
2017-10-21 18:07:05 +00:00
self.open_url(url)
2016-07-19 20:34:30 +00:00
def bing(self, text):
url = QtCore.QUrl('https://www.bing.com/search?q=' + text)
2017-10-21 18:07:05 +00:00
self.open_url(url)
def open_url(self, url):
2016-07-19 20:34:30 +00:00
QtGui.QDesktopServices.openUrl(url)
2017-10-21 18:07:05 +00:00