X-Git-Url: https://git.cweiske.de/enigma2-curlytx.git/blobdiff_plain/51b645f28c1b9f5e955db225c28b864370755d70..e48506186af350ca4a97a5da3b89acb4a5858bb0:/src/CurlyTxSettings.py diff --git a/src/CurlyTxSettings.py b/src/CurlyTxSettings.py index 04277e4..583d9cd 100644 --- a/src/CurlyTxSettings.py +++ b/src/CurlyTxSettings.py @@ -3,49 +3,147 @@ from Components.ActionMap import ActionMap, NumberActionMap from Components.Sources.StaticText import StaticText from . import config -from Components.config import config, getConfigListEntry +from config import createPage +from Components.config import config, getConfigListEntry, ConfigSelection from Components.ConfigList import ConfigList, ConfigListScreen -class CurlyTxSettings(Screen, ConfigListScreen): +class CurlyTxSettings(ConfigListScreen, Screen): + skin = """ + + + + + + + + + + + """ def __init__(self, session): + self.skin = CurlyTxSettings.skin Screen.__init__(self, session) - self.skinName = [ "CurlyTxSettings", "Setup" ] + #self.skinName = [ "CurlyTxSettings", "Setup" ] self.setup_title = _("Settings") - self["actions"] = ActionMap(["SetupActions"], + self["actions"] = ActionMap(["SetupActions","ColorActions"], { "cancel": self.keyCancel, "save": self.keySave, - "ok": self.keySave - #fixme: open page editor + "ok": self.editPage, + "blue": self.deletePage, + "yellow": self.newPage }, -2) - self["key_red"] = StaticText(_("Cancel")) - self["key_green"] = StaticText(_("OK")) + self["key_red"] = StaticText(_("Cancel")) + self["key_green"] = StaticText(_("OK")) + self["key_yellow"] = StaticText(_("New")) + self["key_blue"] = StaticText(_("Delete")) - self.onChangedEntry = [ ] - ConfigListScreen.__init__(self, self.getConfigList(), session = self.session, on_change = self.changedEntry) + ConfigListScreen.__init__(self, self.getConfigList(), session = self.session) + self.onClose.append(self.abort) def getConfigList(self): - list = [] + #reload titles + config.plugins.CurlyTx.defaultPage = ConfigSelection( + [ + (x, x.title.value) for x in config.plugins.CurlyTx.pages] + ) + + list = [ + getConfigListEntry(_("Page:") + " " + x.title.value, x.uri) + for x in config.plugins.CurlyTx.pages + ] + list.append(getConfigListEntry(_("Default page"), config.plugins.CurlyTx.defaultPage)) list.append(getConfigListEntry(_("Show in main menu"), config.plugins.CurlyTx.menuMain)) list.append(getConfigListEntry(_("Menu title"), config.plugins.CurlyTx.menuTitle)) - # fixme: automatically set that - list.append(getConfigListEntry(_("Number of pages"), config.plugins.CurlyTx.pageCount)) - # fixme: other way? - #list.append(getConfigListEntry(_("Pages"), config.plugins.CurlyTx.pages)) return list - def changedEntry(self): - # fixme: needed? - for x in self.onChangedEntry: - x() - def keyLeft(self): ConfigListScreen.keyLeft(self) def keyRight(self): ConfigListScreen.keyRight(self) + def deletePage(self): + from Screens.MessageBox import MessageBox + self.session.openWithCallback( + self.deletePageConfirm, + MessageBox, + _("Really delete this page?\nIt cannot be recovered!") + ) + + def deletePageConfirm(self, result): + if not result: + return + + id = self["config"].getCurrentIndex() + del config.plugins.CurlyTx.pages[id] + + config.plugins.CurlyTx.pages.save() + + self["config"].setList(self.getConfigList()) + + def newPage(self): + from CurlyTxSettings import CurlyTxSettings + self.session.openWithCallback(self.pageEdited, CurlyTxPageEdit, createPage(), True) + + def editPage(self): + id = self["config"].getCurrentIndex() + if id < len(config.plugins.CurlyTx.pages): + self.session.openWithCallback( + self.pageEdited, CurlyTxPageEdit, + config.plugins.CurlyTx.pages[id], False + ) + + def pageEdited(self, page, new): + if not page: + return + + if new: + config.plugins.CurlyTx.pages.append(page) + + self["config"].setList(self.getConfigList()) + + + def keySave(self): + for i in range(0, len(config.plugins.CurlyTx.pages)): + config.plugins.CurlyTx.pages[i].save() + + config.plugins.CurlyTx.pages.save() + ConfigListScreen.keySave(self) + + def abort(self): + pass + + + +class CurlyTxPageEdit(Screen, ConfigListScreen): + def __init__(self, session, page, new = False): + Screen.__init__(self, session) + self.skinName = [ "CurlyTxPageEdit", "Setup" ] + + self["key_red"] = StaticText(_("Cancel")) + self["key_green"] = StaticText(_("OK")) + + self["setupActions"] = ActionMap(["SetupActions"], + { + "save": self.save, + "cancel": self.keyCancel + }, -1) + + self.page = page + self.new = new + list = [ + getConfigListEntry(_("Page URL"), page.uri), + getConfigListEntry(_("Title"), page.title), + ] + ConfigListScreen.__init__(self, list, session = self.session) + + def save(self): + self.close(self.page, self.new) + #FIXME: pass page to parent + def keyCancel(self): + self.close(None, self.new)