src/eric7/WebBrowser/ImageSearch/ImageSearchEngine.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
14 14
15 class ImageSearchEngine(QObject): 15 class ImageSearchEngine(QObject):
16 """ 16 """
17 Class implementing the image search engine. 17 Class implementing the image search engine.
18 """ 18 """
19
19 def __init__(self, parent=None): 20 def __init__(self, parent=None):
20 """ 21 """
21 Constructor 22 Constructor
22 23
23 @param parent reference to the parent object 24 @param parent reference to the parent object
24 @type QObject 25 @type QObject
25 """ 26 """
26 super().__init__(parent) 27 super().__init__(parent)
27 28
28 self.__searchEngineNames = ["Google", "TinEye", "Yandex"] 29 self.__searchEngineNames = ["Google", "TinEye", "Yandex"]
29 30
30 def searchEngine(self): 31 def searchEngine(self):
31 """ 32 """
32 Public method to get the name of the current search engine. 33 Public method to get the name of the current search engine.
33 34
34 @return name of the current search engine 35 @return name of the current search engine
35 @rtype str 36 @rtype str
36 """ 37 """
37 return Preferences.getWebBrowser("ImageSearchEngine") 38 return Preferences.getWebBrowser("ImageSearchEngine")
38 39
39 def setSearchEngine(self, searchEngine): 40 def setSearchEngine(self, searchEngine):
40 """ 41 """
41 Public method to set the current search engine. 42 Public method to set the current search engine.
42 43
43 @param searchEngine name of the search engine 44 @param searchEngine name of the search engine
44 @type str 45 @type str
45 """ 46 """
46 Preferences.setWebBrowser("ImageSearchEngine", searchEngine) 47 Preferences.setWebBrowser("ImageSearchEngine", searchEngine)
47 48
48 def searchEngineNames(self): 49 def searchEngineNames(self):
49 """ 50 """
50 Public method to get the list of supported search engines. 51 Public method to get the list of supported search engines.
51 52
52 @return list of supported search engines 53 @return list of supported search engines
53 @rtype list of str 54 @rtype list of str
54 """ 55 """
55 return self.__searchEngineNames[:] 56 return self.__searchEngineNames[:]
56 57
57 def getSearchQuery(self, imageUrl, searchEngine=None): 58 def getSearchQuery(self, imageUrl, searchEngine=None):
58 """ 59 """
59 Public method to get the image search query URL. 60 Public method to get the image search query URL.
60 61
61 @param imageUrl URL of the image to search for 62 @param imageUrl URL of the image to search for
62 @type QUrl 63 @type QUrl
63 @param searchEngine name of the image search engine to be used 64 @param searchEngine name of the image search engine to be used
64 @type str 65 @type str
65 @return search query URL 66 @return search query URL
66 @rtype QUrl 67 @rtype QUrl
67 """ 68 """
68 if not searchEngine: 69 if not searchEngine:
69 searchEngine = self.searchEngine() 70 searchEngine = self.searchEngine()
70 71
71 searchEngine_l = searchEngine.lower() 72 searchEngine_l = searchEngine.lower()
72 if searchEngine_l == "google": # __IGNORE_WARNING_Y116__ 73 if searchEngine_l == "google": # __IGNORE_WARNING_Y116__
73 return QUrl("https://www.google.com/searchbyimage?" 74 return QUrl(
74 "site=search&image_url={0}".format( 75 "https://www.google.com/searchbyimage?"
75 imageUrl.toString())) 76 "site=search&image_url={0}".format(imageUrl.toString())
77 )
76 elif searchEngine_l == "yandex": 78 elif searchEngine_l == "yandex":
77 return QUrl("https://yandex.com/images/search?" 79 return QUrl(
78 "&img_url={0}&rpt=imageview".format( 80 "https://yandex.com/images/search?"
79 imageUrl.toString())) 81 "&img_url={0}&rpt=imageview".format(imageUrl.toString())
82 )
80 elif searchEngine_l == "tineye": 83 elif searchEngine_l == "tineye":
81 return QUrl("http://www.tineye.com/search?url={0}".format( 84 return QUrl(
82 imageUrl.toString())) 85 "http://www.tineye.com/search?url={0}".format(imageUrl.toString())
86 )
83 else: 87 else:
84 return QUrl() 88 return QUrl()

eric ide

mercurial