5 |
5 |
6 """ |
6 """ |
7 Module implementing a scheme access handler for Python resources. |
7 Module implementing a scheme access handler for Python resources. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt4.QtCore import QFile |
10 from PyQt4.QtCore import QFile, QByteArray |
11 |
11 |
12 from .SchemeAccessHandler import SchemeAccessHandler |
12 from .SchemeAccessHandler import SchemeAccessHandler |
13 |
13 |
14 from .NetworkReply import NetworkReply |
14 from .NetworkReply import NetworkReply |
15 from .NetworkProtocolUnknownErrorReply import NetworkProtocolUnknownErrorReply |
15 from .NetworkProtocolUnknownErrorReply import NetworkProtocolUnknownErrorReply |
16 |
16 |
|
17 import Helpviewer.HelpWindow |
|
18 |
17 |
19 |
18 class PyrcAccessHandler(SchemeAccessHandler): |
20 class PyrcAccessHandler(SchemeAccessHandler): |
19 """ |
21 """ |
20 Class implementing a scheme access handler for Python resources. |
22 Class implementing a scheme access handler for Python resources. |
21 """ |
23 """ |
|
24 _homePage = None |
|
25 _speedDialPage = None |
|
26 |
22 def createRequest(self, op, request, outgoingData=None): |
27 def createRequest(self, op, request, outgoingData=None): |
23 """ |
28 """ |
24 Protected method to create a request. |
29 Protected method to create a request. |
25 |
30 |
26 @param op the operation to be performed (QNetworkAccessManager.Operation) |
31 @param op the operation to be performed (QNetworkAccessManager.Operation) |
28 @param outgoingData reference to an IODevice containing data to be sent |
33 @param outgoingData reference to an IODevice containing data to be sent |
29 (QIODevice) |
34 (QIODevice) |
30 @return reference to the created reply object (QNetworkReply) |
35 @return reference to the created reply object (QNetworkReply) |
31 """ |
36 """ |
32 if request.url().toString() == "eric:home": |
37 if request.url().toString() == "eric:home": |
|
38 return NetworkReply(request, self.__createHomePage(), |
|
39 "text/html", self.parent()) |
|
40 elif request.url().toString() == "eric:speeddial": |
|
41 return NetworkReply(request, self.__createSpeedDialPage(), |
|
42 "text/html", self.parent()) |
|
43 |
|
44 return NetworkProtocolUnknownErrorReply("eric", self.parent()) |
|
45 |
|
46 def __createHomePage(self): |
|
47 """ |
|
48 Private method to create the Home page. |
|
49 |
|
50 @return prepared home page (QByteArray) |
|
51 """ |
|
52 if self._homePage is None: |
33 htmlFile = QFile(":/html/startPage.html") |
53 htmlFile = QFile(":/html/startPage.html") |
34 htmlFile.open(QFile.ReadOnly) |
54 htmlFile.open(QFile.ReadOnly) |
35 html = htmlFile.readAll() |
55 html = htmlFile.readAll() |
36 html = html.replace("@IMAGE@", "qrc:icons/ericWeb32.png") |
56 |
37 html = html.replace("@FAVICON@", "qrc:icons/ericWeb16.png") |
57 html.replace("@IMAGE@", "qrc:icons/ericWeb32.png") |
38 return NetworkReply(request, html, "text/html", self.parent()) |
58 html.replace("@FAVICON@", "qrc:icons/ericWeb16.png") |
|
59 |
|
60 self._homePage = html |
39 |
61 |
40 return NetworkProtocolUnknownErrorReply("eric", self.parent()) |
62 return QByteArray(self._homePage) |
|
63 |
|
64 def __createSpeedDialPage(self): |
|
65 """ |
|
66 Private method to create the Speeddial page. |
|
67 |
|
68 @return prepared speeddial page (QByteArray) |
|
69 """ |
|
70 if self._speedDialPage is None: |
|
71 htmlFile = QFile(":/html/speeddialPage.html") |
|
72 htmlFile.open(QFile.ReadOnly) |
|
73 html = htmlFile.readAll() |
|
74 |
|
75 html.replace("@FAVICON@", "qrc:icons/ericWeb16.png") |
|
76 html.replace("@IMG_PLUS@", "qrc:icons/plus.png") |
|
77 html.replace("@IMG_CLOSE@", "qrc:icons/close.png") |
|
78 html.replace("@IMG_EDIT@", "qrc:icons/edit.png") |
|
79 html.replace("@IMG_RELOAD@", "qrc:icons/reload.png") |
|
80 html.replace("@IMG_SETTINGS@", "qrc:icons/setting.png") |
|
81 html.replace("@LOADING-IMG@", "qrc:icons/loading.gif") |
|
82 html.replace("@BOX-BORDER@", "qrc:icons/box-border-small.png") |
|
83 |
|
84 html.replace("@JQUERY@", "qrc:javascript/jquery.js") |
|
85 html.replace("@JQUERY-UI@", "qrc:javascript/jquery-ui.js") |
|
86 |
|
87 html.replace("@SITE-TITLE@", self.trUtf8("Speed Dial")) |
|
88 html.replace("@URL@", self.trUtf8("URL")) |
|
89 html.replace("@TITLE@", self.trUtf8("Title")) |
|
90 html.replace("@APPLY@", self.trUtf8("Apply")) |
|
91 html.replace("@NEW-PAGE@", self.trUtf8("New Page")) |
|
92 html.replace("@TITLE-EDIT@", self.trUtf8("Edit")) |
|
93 html.replace("@TITLE-REMOVE@", self.trUtf8("Remove")) |
|
94 html.replace("@TITLE-RELOAD@", self.trUtf8("Reload")) |
|
95 html.replace("@TITLE-FETCHTITLE@", self.trUtf8("Load title from page")) |
|
96 html.replace("@SETTINGS-TITLE@", self.trUtf8("Speed Dial Settings")) |
|
97 html.replace("@ADD-TITLE@", self.trUtf8("Add New Page")) |
|
98 html.replace("@TXT_NRROWS@", self.trUtf8("Maximum pages in a row:")) |
|
99 html.replace("@TXT_SDSIZE@", self.trUtf8("Change size of pages:")) |
|
100 |
|
101 self._speedDialPage = html |
|
102 |
|
103 html = QByteArray(self._speedDialPage) |
|
104 dial = Helpviewer.HelpWindow.HelpWindow.speedDial() |
|
105 |
|
106 html.replace("@INITIAL-SCRIPT@", dial.initialScript()) |
|
107 html.replace("@ROW-PAGES@", str(dial.pagesInRow())) |
|
108 html.replace("@SD-SIZE@", str(dial.sdSize())) |
|
109 |
|
110 return html |