src/eric7/WebBrowser/WebBrowserSingleApplication.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
9 browser. 9 browser.
10 """ 10 """
11 11
12 from PyQt6.QtCore import pyqtSignal 12 from PyQt6.QtCore import pyqtSignal
13 13
14 from Toolbox.SingleApplication import ( 14 from Toolbox.SingleApplication import SingleApplicationClient, SingleApplicationServer
15 SingleApplicationClient, SingleApplicationServer
16 )
17 15
18 import Globals 16 import Globals
19 17
20 ########################################################################### 18 ###########################################################################
21 ## define some module global stuff 19 ## define some module global stuff
22 ########################################################################### 20 ###########################################################################
23 21
24 SAFile = "eric7_browser" 22 SAFile = "eric7_browser"
25 23
26 # define the protocol tokens 24 # define the protocol tokens
27 SALoadUrl = 'LoadUrl' 25 SALoadUrl = "LoadUrl"
28 SANewTab = 'NewTab' 26 SANewTab = "NewTab"
29 SASearch = 'Search' 27 SASearch = "Search"
30 SAShutdown = 'Shutdown' 28 SAShutdown = "Shutdown"
31 29
32 30
33 class WebBrowserSingleApplicationServer(SingleApplicationServer): 31 class WebBrowserSingleApplicationServer(SingleApplicationServer):
34 """ 32 """
35 Class implementing the single application server embedded within the 33 Class implementing the single application server embedded within the
36 Web Browser. 34 Web Browser.
37 35
38 @signal loadUrl(str) emitted to load an URL 36 @signal loadUrl(str) emitted to load an URL
39 @signal newTab(str) emitted to load an URL in a new tab 37 @signal newTab(str) emitted to load an URL in a new tab
40 @signal search(str) emitted to search for a given word 38 @signal search(str) emitted to search for a given word
41 @signal shutdown() emitted to shut down the browser 39 @signal shutdown() emitted to shut down the browser
42 """ 40 """
41
43 loadUrl = pyqtSignal(str) 42 loadUrl = pyqtSignal(str)
44 newTab = pyqtSignal(str) 43 newTab = pyqtSignal(str)
45 search = pyqtSignal(str) 44 search = pyqtSignal(str)
46 shutdown = pyqtSignal() 45 shutdown = pyqtSignal()
47 46
48 def __init__(self, name=""): 47 def __init__(self, name=""):
49 """ 48 """
50 Constructor 49 Constructor
51 50
52 @param name name to be used by the single application server 51 @param name name to be used by the single application server
53 @type str 52 @type str
54 """ 53 """
55 if not name: 54 if not name:
56 name = SAFile 55 name = SAFile
57 56
58 SingleApplicationServer.__init__(self, name) 57 SingleApplicationServer.__init__(self, name)
59 58
60 def handleCommand(self, command, arguments): 59 def handleCommand(self, command, arguments):
61 """ 60 """
62 Public slot to handle the command sent by the client. 61 Public slot to handle the command sent by the client.
63 62
64 @param command command sent by the client 63 @param command command sent by the client
65 @type str 64 @type str
66 @param arguments list of command arguments 65 @param arguments list of command arguments
67 @type list of str 66 @type list of str
68 """ 67 """
69 if command == SALoadUrl: 68 if command == SALoadUrl:
70 self.__saLoadUrl(arguments[0]) 69 self.__saLoadUrl(arguments[0])
71 70
72 elif command == SANewTab: 71 elif command == SANewTab:
73 self.__saNewTab(arguments[0]) 72 self.__saNewTab(arguments[0])
74 73
75 elif command == SASearch: 74 elif command == SASearch:
76 self.__saSearch(arguments[0]) 75 self.__saSearch(arguments[0])
77 76
78 elif command == SAShutdown: 77 elif command == SAShutdown:
79 self.__saShutdown() 78 self.__saShutdown()
80 79
81 def __saLoadUrl(self, url): 80 def __saLoadUrl(self, url):
82 """ 81 """
83 Private method to load an URL in a new tab. 82 Private method to load an URL in a new tab.
84 83
85 @param url URL to be loaded 84 @param url URL to be loaded
86 @type str 85 @type str
87 """ 86 """
88 self.loadUrl.emit(url) 87 self.loadUrl.emit(url)
89 88
90 def __saNewTab(self, url): 89 def __saNewTab(self, url):
91 """ 90 """
92 Private method to load an URL . 91 Private method to load an URL .
93 92
94 @param url URL to be loaded 93 @param url URL to be loaded
95 @type str 94 @type str
96 """ 95 """
97 self.newTab.emit(url) 96 self.newTab.emit(url)
98 97
99 def __saSearch(self, word): 98 def __saSearch(self, word):
100 """ 99 """
101 Private method to search for a given word. 100 Private method to search for a given word.
102 101
103 @param word word to be searched for 102 @param word word to be searched for
104 @type str 103 @type str
105 """ 104 """
106 self.search.emit(word) 105 self.search.emit(word)
107 106
108 def __saShutdown(self): 107 def __saShutdown(self):
109 """ 108 """
110 Private method to shut down the web browser. 109 Private method to shut down the web browser.
111 """ 110 """
112 self.shutdown.emit() 111 self.shutdown.emit()
114 113
115 class WebBrowserSingleApplicationClient(SingleApplicationClient): 114 class WebBrowserSingleApplicationClient(SingleApplicationClient):
116 """ 115 """
117 Class implementing the single application client of the web browser. 116 Class implementing the single application client of the web browser.
118 """ 117 """
118
119 def __init__(self, name=""): 119 def __init__(self, name=""):
120 """ 120 """
121 Constructor 121 Constructor
122 122
123 @param name name to be used by the single application server 123 @param name name to be used by the single application server
124 @type str 124 @type str
125 """ 125 """
126 if not name: 126 if not name:
127 name = SAFile 127 name = SAFile
128 128
129 SingleApplicationClient.__init__(self, name) 129 SingleApplicationClient.__init__(self, name)
130 130
131 def processArgs(self, args, disconnect=True): 131 def processArgs(self, args, disconnect=True):
132 """ 132 """
133 Public method to process the command line args passed to the UI. 133 Public method to process the command line args passed to the UI.
134 134
135 @param args list of command line arguments 135 @param args list of command line arguments
136 @type list of str 136 @type list of str
137 @param disconnect flag indicating to disconnect when done 137 @param disconnect flag indicating to disconnect when done
138 @type bool 138 @type bool
139 """ 139 """
140 # no args, return 140 # no args, return
141 if args is None: 141 if args is None:
142 return 142 return
143 143
144 argChars = ('-', '/') if Globals.isWindowsPlatform() else ('-', ) 144 argChars = ("-", "/") if Globals.isWindowsPlatform() else ("-",)
145 145
146 for arg in args: 146 for arg in args:
147 if arg.startswith("--search="): 147 if arg.startswith("--search="):
148 self.__search(arg.replace("--search=", "")) 148 self.__search(arg.replace("--search=", ""))
149 elif arg.startswith("--newtab="): 149 elif arg.startswith("--newtab="):
150 self.__newTab(arg.replace("--newtab=", "")) 150 self.__newTab(arg.replace("--newtab=", ""))
151 elif arg == "--shutdown": 151 elif arg == "--shutdown":
152 self.__shutdown() 152 self.__shutdown()
153 elif not arg.startswith(argChars): 153 elif not arg.startswith(argChars):
154 # it is an URL 154 # it is an URL
155 self.__loadUrl(arg) 155 self.__loadUrl(arg)
156 156
157 if disconnect: 157 if disconnect:
158 self.disconnect() 158 self.disconnect()
159 159
160 def __loadUrl(self, url): 160 def __loadUrl(self, url):
161 """ 161 """
162 Private method to send an URL to be loaded. 162 Private method to send an URL to be loaded.
163 163
164 @param url URL to be loaded 164 @param url URL to be loaded
165 @type str 165 @type str
166 """ 166 """
167 self.sendCommand(SALoadUrl, [url]) 167 self.sendCommand(SALoadUrl, [url])
168 168
169 def __newTab(self, url): 169 def __newTab(self, url):
170 """ 170 """
171 Private method to send an URL to be loaded in a new tab. 171 Private method to send an URL to be loaded in a new tab.
172 172
173 @param url URL to be loaded 173 @param url URL to be loaded
174 @type str 174 @type str
175 """ 175 """
176 self.sendCommand(SANewTab, [url]) 176 self.sendCommand(SANewTab, [url])
177 177
178 def __search(self, word): 178 def __search(self, word):
179 """ 179 """
180 Private method to send a word to search for. 180 Private method to send a word to search for.
181 181
182 @param word to to be searched for 182 @param word to to be searched for
183 @type str 183 @type str
184 """ 184 """
185 self.sendCommand(SASearch, [word]) 185 self.sendCommand(SASearch, [word])
186 186
187 def __shutdown(self): 187 def __shutdown(self):
188 """ 188 """
189 Private method to signal a shutdown request to the browser. 189 Private method to signal a shutdown request to the browser.
190 """ 190 """
191 self.sendCommand(SAShutdown, []) 191 self.sendCommand(SAShutdown, [])

eric ide

mercurial