WebBrowser/WebBrowserSingleApplication.py

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

eric ide

mercurial