from Components.ActionMap import ActionMap
from Components.Sources.StaticText import StaticText
from twisted.web import client
+from twisted.web.client import _makeGetterFactory, HTTPClientFactory
+from enigma import gFont
from . import config
from Components.config import config
currentUrl = None
currentPage = None
+ currentFontSize = 20
+ httpGetterFactory = None
+ showingHeaders = False
def __init__(self, session, args = None):
#self.skin = CurlyTx.skin
self["actions"] = ActionMap(
- ["WizardActions", "ColorActions", "InputActions"], {
+ ["WizardActions", "ColorActions", "InputActions", "InfobarEPGActions"], {
"ok": self.close,
"back": self.close,
"up": self.pageUp,
"red": self.showSettings,
"green": self.reload,
"yellow": self.prevPage,
- "blue": self.nextPage
+ "blue": self.nextPage,
+
+ "showEventInfo": self.showHeader
}, -1)
self.loadHelp()
self.loadButtons()
self.loadUrl(config.plugins.CurlyTx.defaultPage.value)
+ self.onLayoutFinish.append(self.setTextFont)
def loadHelp(self):
self.helpList.append((
self.helpList.append((
self["actions"], "WizardActions",
[("down", _("Scroll page contents down"))]))
+ self.helpList.append((
+ self["actions"], "InfobarEPGActions",
+ [("showEventInfo", _("Show HTTP response headers"))]))
self.helpList.append((
self["actions"], "ColorActions",
[("red", _("Show program settings"))]))
self.loadNoPage()
return
+ cfg = config.plugins.CurlyTx
+ pageCount = len(cfg.pages)
pageId = int(pageId)
- if pageId > (len(config.plugins.CurlyTx.pages) - 1):
- if len(config.plugins.CurlyTx.pages) == 0:
+ if pageId > (pageCount - 1):
+ if len(cfg.pages) == 0:
self.loadNoPage()
else:
self["text"].setText("Invalid page " + pageId);
return
- url = config.plugins.CurlyTx.pages[pageId].uri.value
- title = config.plugins.CurlyTx.pages[pageId].title.value
+ url = cfg.pages[pageId].uri.value
+ title = cfg.pages[pageId].title.value
+
+ if pageCount > 1:
+ title = "{0} [{1}/{2}]".format(title, pageId + 1, pageCount)
+
self.currentPage = pageId
self.currentUrl = url
+ self.currentFontSize = cfg.pages[pageId].fontSize.value
self.setTitle(title)
+ self.setTextFont()
self["text"].setText("Loading ...\n" + url);
- client.getPage(url).addCallback(self.urlLoaded).addErrback(self.urlFailed, url)
+ self.getPageWebClient(url).addCallback(self.urlLoaded).addErrback(self.urlFailed, url)
+
+ def setTextFont(self):
+ if self["text"].long_text is not None:
+ self["text"].long_text.setFont(gFont("Console", self.currentFontSize))
def urlLoaded(self, html):
self["text"].setText(html)
def loadNoPage(self):
self["text"].setText("Go and add a page in the settings");
+ def showHeader(self):
+ if self.showingHeaders:
+ self["text"].setText(self.pageContent)
+ self.pageContent = None
+ self.showingHeaders = False
+ else:
+ headers = "HTTP response headers for\n" + self.currentUrl + "\n\n"
+ for (k, v) in self.httpGetterFactory.response_headers.items():
+ headers += k + ": " + ("\n" + k + ": ").join(v) + "\n"
+ self.pageContent = self["text"].getText()
+ self["text"].setText(headers)
+ self.showingHeaders = True
+
def showSettings(self):
from CurlyTxSettings import CurlyTxSettings
self.session.openWithCallback(self.onSettingsChanged, CurlyTxSettings)
elif self.currentPage == None:
self.currentPage = 0
self.loadUrl(self.currentPage)
+
+
+ def getPageWebClient(self, url, contextFactory=None, *args, **kwargs):
+ """
+ Download a web page as a string.
+
+ COPY OF twisted.web.client.getPage to store the factory
+
+ Download a page. Return a deferred, which will callback with a
+ page (as a string) or errback with a description of the error.
+
+ See L{HTTPClientFactory} to see what extra arguments can be passed.
+ """
+ self.httpGetterFactory = _makeGetterFactory(
+ url,
+ HTTPClientFactory,
+ contextFactory=contextFactory,
+ *args, **kwargs)
+ return self.httpGetterFactory.deferred