eric7/WebBrowser/ImageSearch/ImageSearchEngine.py

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

eric ide

mercurial