X-Git-Url: https://git.cweiske.de/enigma2-curlytx.git/blobdiff_plain/df305f9a301cfaaf923db087c95f59c94e861dd8..5a3881a8fa5611a7defe420be7d36611a35b999d:/src/CurlyTx.py diff --git a/src/CurlyTx.py b/src/CurlyTx.py index 8e18c0f..3e74c5e 100644 --- a/src/CurlyTx.py +++ b/src/CurlyTx.py @@ -7,21 +7,22 @@ from . import _ from Screens.Screen import Screen from Screens.HelpMenu import HelpableScreen -from Screens.MessageBox import MessageBox from Components.Label import Label from Components.ScrollLabel import ScrollLabel from Components.ActionMap import ActionMap from Components.Sources.StaticText import StaticText +from Tools import Directories from twisted.web import client from twisted.web.client import _makeGetterFactory, HTTPClientFactory from enigma import gFont from . import config +from config import createPage, loadDefaultPageOptions, feedPagesToConfig, feedSettingsToConfig, savePageConfig from Components.config import config import os -class CurlyTx(Screen,HelpableScreen): +class CurlyTx(Screen, HelpableScreen): skin = """ @@ -40,6 +41,7 @@ class CurlyTx(Screen,HelpableScreen): currentFontSize = 20 httpGetterFactory = None showingHeaders = False + staticPageFeedFile = 'curlytx-pagefeed.xml' def __init__(self, session, args = None): #self.skin = CurlyTx.skin @@ -72,10 +74,11 @@ class CurlyTx(Screen,HelpableScreen): self.loadHelp() self.loadButtons() - self.onLayoutFinish.append(self.afterLayout) + self.onFirstExecBegin.append(self.afterLayout) def afterLayout(self): self.setTextFont + self.loadStaticConfig() self.loadUrl(config.plugins.CurlyTx.defaultPage.value) def loadHelp(self): @@ -122,6 +125,11 @@ class CurlyTx(Screen,HelpableScreen): self["key_yellow"].setText(_("Prev")) self["key_blue"].setText(_("Next")) + if config.plugins.CurlyTx.enableSettings.getValue(): + self["key_red"].setText(_("Settings")) + else: + self["key_red"].setText("") + def pageUp(self): self["text"].pageUp() @@ -232,6 +240,9 @@ class CurlyTx(Screen,HelpableScreen): self.showingHeaders = True def showSettings(self): + if not config.plugins.CurlyTx.enableSettings.getValue(): + return + from CurlyTxSettings import CurlyTxSettings self.session.openWithCallback(self.onSettingsChanged, CurlyTxSettings) @@ -262,3 +273,33 @@ class CurlyTx(Screen,HelpableScreen): contextFactory=contextFactory, *args, **kwargs) return self.httpGetterFactory.deferred + + def loadStaticConfig(self): + """ + Always try to load the static config file from + /etc/enigma2/curlytx-pagefeed.xml + """ + staticFeedPath = Directories.resolveFilename(Directories.SCOPE_CONFIG, self.staticPageFeedFile) + if not os.path.exists(staticFeedPath): + return + + from AtomFeed import AtomFeed + AtomFeed( + 'file://' + staticFeedPath, + self.saveStaticConfig, self.loadStaticConfigFail + ) + + def loadStaticConfigFail(self, errorMessage): + """ Loading the page url feed failed somehow """ + from Screens.MessageBox import MessageBox + self.session.open( + MessageBox, + _("Error loading page feed:") + "\n\n" + str(errorMessage), + type = MessageBox.TYPE_ERROR + ) + + def saveStaticConfig(self, pages, settings): + feedPagesToConfig(pages) + feedSettingsToConfig(settings) + savePageConfig() + self.loadButtons()