WebBrowser/WebBrowserSingleApplication.py

changeset 6623
c0882a599e18
child 6625
a67fee7bc09c
equal deleted inserted replaced
6622:3dfcbe478fd3 6623:c0882a599e18
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2018 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6
7 """
8 Module implementing the single application server and client for the web
9 browser.
10 """
11
12 from __future__ import unicode_literals
13
14 from PyQt5.QtCore import pyqtSignal
15
16 from Toolbox.SingleApplication import SingleApplicationClient, \
17 SingleApplicationServer
18
19 import Globals
20
21 ###########################################################################
22 ## define some module global stuff
23 ###########################################################################
24
25 SAFile = "eric6_browser"
26
27 # define the protocol tokens
28 SALoadUrl = 'LoadUrl'
29 SASearch = 'Search'
30
31
32 class WebBrowserSingleApplicationServer(SingleApplicationServer):
33 """
34 Class implementing the single application server embedded within the
35 Web Browser.
36
37 @signal loadUrl(str) emitted to load a URL
38 @signal search(str) emitted to search for a given word
39 """
40 loadUrl = pyqtSignal(str)
41 search = pyqtSignal(str)
42
43 def __init__(self):
44 """
45 Constructor
46 """
47 SingleApplicationServer.__init__(self, SAFile)
48
49 def handleCommand(self, command, arguments):
50 """
51 Public slot to handle the command sent by the client.
52
53 @param command command sent by the client
54 @type str
55 @param arguments list of command arguments
56 @type list of str
57 """
58 if command == SALoadUrl:
59 self.__saLoadUrl(arguments[0])
60
61 elif command == SASearch:
62 self.__saSearch(arguments[0])
63
64 def __saLoadUrl(self, url):
65 """
66 Private method to load an URL.
67
68 @param url URL to be loaded
69 @type str
70 """
71 self.loadUrl.emit(url)
72
73 def __saSearch(self, word):
74 """
75 Private method to search for a given word.
76
77 @param word word to be searched for
78 @type str
79 """
80 self.search.emit(word)
81
82
83 class WebBrowserSingleApplicationClient(SingleApplicationClient):
84 """
85 Class implementing the single application client of the Translations
86 Previewer.
87 """
88 def __init__(self):
89 """
90 Constructor
91 """
92 SingleApplicationClient.__init__(self, SAFile)
93
94 def processArgs(self, args):
95 """
96 Public method to process the command line args passed to the UI.
97
98 @param args list of files to open
99 """
100 # no args, return
101 if args is None:
102 return
103
104 if Globals.isWindowsPlatform():
105 argChars = ('-', '/')
106 else:
107 argChars = ('-', )
108
109 for arg in args:
110 if arg.startswith("--search="):
111 self.__search(arg.replace("--search=", ""))
112 elif not arg.startswith(argChars):
113 # it is an URL
114 self.__loadUrl(arg)
115
116 self.disconnect()
117
118 def __loadUrl(self, url):
119 """
120 Private method to send an URL to be loaded.
121
122 @param url URL to be loaded
123 @type str
124 """
125 self.sendCommand(SALoadUrl, [url])
126
127 def __search(self, word):
128 """
129 Private method to send a word to search for.
130
131 @param word to to be searched for
132 @type str
133 """
134 self.sendCommand(SASearch, [word])

eric ide

mercurial