WebBrowser/WebBrowserSingleApplication.py

changeset 6625
a67fee7bc09c
parent 6623
c0882a599e18
child 6630
bddd12f27a4c
diff -r 9718755def80 -r a67fee7bc09c WebBrowser/WebBrowserSingleApplication.py
--- a/WebBrowser/WebBrowserSingleApplication.py	Wed Dec 12 19:43:53 2018 +0100
+++ b/WebBrowser/WebBrowserSingleApplication.py	Wed Dec 12 19:52:24 2018 +0100
@@ -26,7 +26,9 @@
 
 # define the protocol tokens
 SALoadUrl = 'LoadUrl'
+SANewTab = 'NewTab'
 SASearch = 'Search'
+SAShutdown = 'Shutdown'
 
 
 class WebBrowserSingleApplicationServer(SingleApplicationServer):
@@ -34,17 +36,27 @@
     Class implementing the single application server embedded within the
     Web Browser.
     
-    @signal loadUrl(str) emitted to load a URL
+    @signal loadUrl(str) emitted to load an URL
+    @signal newTab(str) emitted to load an URL in a new tab
     @signal search(str) emitted to search for a given word
+    @signal shutdown() emitted to shut down the browser
     """
     loadUrl = pyqtSignal(str)
+    newTab = pyqtSignal(str)
     search = pyqtSignal(str)
+    shutdown = pyqtSignal()
     
-    def __init__(self):
+    def __init__(self, name=""):
         """
         Constructor
+        
+        @param name name to be used by the single application server
+        @type str
         """
-        SingleApplicationServer.__init__(self, SAFile)
+        if not name:
+            name = SAFile
+        
+        SingleApplicationServer.__init__(self, name)
 
     def handleCommand(self, command, arguments):
         """
@@ -57,19 +69,34 @@
         """
         if command == SALoadUrl:
             self.__saLoadUrl(arguments[0])
-
+        
+        elif command == SANewTab:
+            self.__saNewTab(arguments[0])
+        
         elif command == SASearch:
             self.__saSearch(arguments[0])
+        
+        elif command == SAShutdown:
+            self.__saShutdown()
     
     def __saLoadUrl(self, url):
         """
-        Private method to load an URL.
+        Private method to load an URL in a new tab.
         
         @param url URL to be loaded
         @type str
         """
         self.loadUrl.emit(url)
     
+    def __saNewTab(self, url):
+        """
+        Private method to load an URL .
+        
+        @param url URL to be loaded
+        @type str
+        """
+        self.newTab.emit(url)
+    
     def __saSearch(self, word):
         """
         Private method to search for a given word.
@@ -78,6 +105,12 @@
         @type str
         """
         self.search.emit(word)
+    
+    def __saShutdown(self):
+        """
+        Private method to shut down the web browser.
+        """
+        self.shutdown.emit()
 
 
 class WebBrowserSingleApplicationClient(SingleApplicationClient):
@@ -85,17 +118,26 @@
     Class implementing the single application client of the Translations
     Previewer.
     """
-    def __init__(self):
+    def __init__(self, name=""):
         """
         Constructor
+        
+        @param name name to be used by the single application server
+        @type str
         """
-        SingleApplicationClient.__init__(self, SAFile)
+        if not name:
+            name = SAFile
         
-    def processArgs(self, args):
+        SingleApplicationClient.__init__(self, name)
+    
+    def processArgs(self, args, disconnect=True):
         """
         Public method to process the command line args passed to the UI.
         
-        @param args list of files to open
+        @param args list of command line arguments
+        @type list of str
+        @param disconnect flag indicating to disconnect when done
+        @type bool
         """
         # no args, return
         if args is None:
@@ -109,11 +151,16 @@
         for arg in args:
             if arg.startswith("--search="):
                 self.__search(arg.replace("--search=", ""))
+            elif arg.startswith("--newtab="):
+                self.__newTab(arg.replace("--newtab=", ""))
+            elif arg == "--shutdown":
+                self.__shutdown()
             elif not arg.startswith(argChars):
                 # it is an URL
                 self.__loadUrl(arg)
         
-        self.disconnect()
+        if disconnect:
+            self.disconnect()
     
     def __loadUrl(self, url):
         """
@@ -124,6 +171,15 @@
         """
         self.sendCommand(SALoadUrl, [url])
     
+    def __newTab(self, url):
+        """
+        Private method to send an URL to be loaded in a new tab.
+        
+        @param url URL to be loaded
+        @type str
+        """
+        self.sendCommand(SANewTab, [url])
+    
     def __search(self, word):
         """
         Private method to send a word to search for.
@@ -132,3 +188,9 @@
         @type str
         """
         self.sendCommand(SASearch, [word])
+    
+    def __shutdown(self):
+        """
+        Private method to signal a shutdown request to the browser.
+        """
+        self.sendCommand(SAShutdown, [])

eric ide

mercurial