WebBrowser/ImageSearch/ImageSearchEngine.py

changeset 4955
8a966fc19ce3
child 4956
1496516b0f2c
equal deleted inserted replaced
4954:36e92a908f3f 4955:8a966fc19ce3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the image search engine.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import QObject, QUrl
13
14 import Preferences
15
16 class ImageSearchEngine(QObject):
17 """
18 Class implementing the image search engine.
19 """
20 def __init__(self, parent=None):
21 """
22 Constructor
23
24 @param parent reference to the parent object
25 @type QObject
26 """
27 super(ImageSearchEngine, self).__init__(parent)
28
29 self.__searchEngine = Preferences.getWebBrowser("ImmageSearchEngine")
30
31 def searchEngine(self):
32 """
33 Public method to get the name of the current search engine.
34 """
35 return self.__searchEngine
36
37 def setSearchEngine(self, searchEngine):
38 """
39 Public method to set the current search engine.
40
41 @param searchEngine name of the search engine
42 @type str
43 """
44 self.__searchEngine = searchEngine
45 Preferences.setWebBrowser("ImmageSearchEngine", searchEngine)
46
47 def getSearchQuery(self, imageUrl, searchEngine=None):
48 """
49 Public method to get the image search query URL.
50
51 @param imageUrl URL of the image to search for
52 @type QUrl
53 @param searchEngine name of the image search engine to be used
54 @type str
55 @return search query URL
56 @rtype QUrl
57 """
58 if not searchEngine:
59 searchEngine = self.__searchEngine
60
61 searchEngine_l = searchEngine.lower()
62 if searchEngine_l == "google":
63 return QUrl("https://www.google.com/searchbyimage?"
64 "site=search&image_url={0}".format(
65 imageUrl.toString()))
66 elif searchEngine_l == "yandex":
67 return QUrl("https://yandex.com/images/search?"
68 "&img_url={0}&rpt=imageview".format(
69 imageUrl.toString()))
70 elif searchEngine_l == "tineye":
71 return QUrl("http://www.tineye.com/search?url={0}".format(
72 imageUrl.toString()))
73 else:
74 return QUrl()

eric ide

mercurial