1 # -*- coding: utf-8 -*-
2 # CurlyTx configuration window
3 # Copyright (C) 2011 Christian Weiske <cweiske@cweiske.de>
4 # License: GPLv3 or later
8 from Screens.Screen import Screen
9 from Screens.HelpMenu import HelpableScreen
10 from Components.ActionMap import ActionMap, NumberActionMap
11 from Components.Sources.StaticText import StaticText
12 from Screens.MessageBox import MessageBox
15 from config import createPage, loadDefaultPageOptions, feedPagesToConfig, feedSettingsToConfig, savePageConfig
16 from Components.config import config, getConfigListEntry, ConfigSelection
17 from Components.ConfigList import ConfigList, ConfigListScreen
19 class CurlyTxSettings(ConfigListScreen, HelpableScreen, Screen):
21 <screen name="Setup" position="center,center" size="560,430" title="Settings">
22 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" transparent="1" alphatest="on" />
23 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" transparent="1" alphatest="on" />
24 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" transparent="1" alphatest="on" />
25 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" transparent="1" alphatest="on" />
26 <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
27 <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
28 <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#a08500" transparent="1" />
29 <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#18188b" transparent="1" />
30 <widget name="config" position="5,50" size="550,325" scrollbarMode="showOnDemand" />
33 def __init__(self, session):
34 self.skin = CurlyTxSettings.skin
35 Screen.__init__(self, session)
36 HelpableScreen.__init__(self)
37 #self.skinName = [ "CurlyTxSettings", "Setup" ]
38 self.setup_title = _("Settings")
40 self["actions"] = ActionMap(["SetupActions","ColorActions"],
42 "cancel": self.keyCancel,
45 "yellow": self.newPage,
46 "blue": self.deletePage
49 self["key_red"] = StaticText(_("Cancel"))
50 self["key_green"] = StaticText(_("OK"))
51 self["key_yellow"] = StaticText(_("New"))
52 self["key_blue"] = StaticText(_("Delete"))
54 ConfigListScreen.__init__(self, self.getConfigList(), session = self.session)
58 def getConfigList(self):
60 loadDefaultPageOptions()
61 cfg = config.plugins.CurlyTx
64 getConfigListEntry(_("Page:") + " " + x.title.value, x.uri)
68 list.append(getConfigListEntry(_("Default page"), cfg.defaultPage))
69 list.append(getConfigListEntry(_("Show in main menu"), cfg.menuMain))
70 list.append(getConfigListEntry(_("Show in extensions menu"), cfg.menuExtensions))
71 list.append(getConfigListEntry(_("Menu title"), cfg.menuTitle))
72 list.append(getConfigListEntry(_("Page feed URL"), cfg.feedUrl))
76 self.helpList.append((
77 self["actions"], "SetupActions",
78 [("cancel", _("Dismiss all setting changes"))]))
79 self.helpList.append((
80 self["actions"], "SetupActions",
81 [("save", _("Save settings and close screen"))]))
82 self.helpList.append((
83 self["actions"], "SetupActions",
84 [("ok", _("Edit selected page"))]))
85 self.helpList.append((
86 self["actions"], "SetupActions",
87 [("ok", _("Load pages from feed"))]))
88 self.helpList.append((
89 self["actions"], "ColorActions",
90 [("yellow", _("Add new page"))]))
91 self.helpList.append((
92 self["actions"], "ColorActions",
93 [("blue", _("Delete selected page"))]))
96 ConfigListScreen.keyLeft(self)
99 ConfigListScreen.keyRight(self)
101 def deletePage(self):
102 pageCount = len(config.plugins.CurlyTx.pages)
103 if pageCount == 0 or self["config"].getCurrentIndex() >= pageCount:
106 from Screens.MessageBox import MessageBox
107 self.session.openWithCallback(
108 self.deletePageConfirm,
110 _("Really delete this page?\nIt cannot be recovered!")
113 def deletePageConfirm(self, result):
117 id = self["config"].getCurrentIndex()
118 del config.plugins.CurlyTx.pages[id]
120 config.plugins.CurlyTx.pages.save()
122 self["config"].setList(self.getConfigList())
125 from CurlyTxSettings import CurlyTxSettings
126 self.session.openWithCallback(self.pageEdited, CurlyTxPageEdit, createPage(), True)
129 id = self["config"].getCurrentIndex()
130 if id < len(config.plugins.CurlyTx.pages):
131 self.session.openWithCallback(
132 self.pageEdited, CurlyTxPageEdit,
133 config.plugins.CurlyTx.pages[id], False
135 elif config.plugins.CurlyTx.feedUrl.value:
136 from AtomFeed import AtomFeed
138 config.plugins.CurlyTx.feedUrl.value,
139 self.feedPagesReceived, self.feedPagesFail
143 MessageBox, _("No page feed URL defined"), MessageBox.TYPE_ERROR
146 def pageEdited(self, page, new):
151 config.plugins.CurlyTx.pages.append(page)
153 self["config"].setList(self.getConfigList())
155 def feedPagesReceived(self, pages, settings):
156 feedPagesToConfig(pages)
157 feedSettingsToConfig(settings)
158 self["config"].setList(self.getConfigList())
160 def feedPagesFail(self, errorMessage):
161 """ Downloading the page url feed failed somehow """
164 _("Error loading page feed:") + "\n\n" + str(errorMessage),
165 MessageBox.TYPE_ERROR
170 ConfigListScreen.keySave(self)
172 def cancelConfirm(self, result):
173 """Overwriting ConfigListScreen.cancelConfirm to call cancelAll method"""
181 for x in self["config"].list:
184 #restore old page configuration
185 cfg = config.plugins.CurlyTx
187 for i in cfg.pages.stored_values:
188 cfg.pages.append(createPage())
192 class CurlyTxPageEdit(Screen, ConfigListScreen):
193 def __init__(self, session, page, new = False):
194 Screen.__init__(self, session)
195 self.skinName = [ "CurlyTxPageEdit", "Setup" ]
197 self["key_red"] = StaticText(_("Cancel"))
198 self["key_green"] = StaticText(_("OK"))
200 self["setupActions"] = ActionMap(["SetupActions"],
203 "cancel": self.keyCancel
209 getConfigListEntry(_("Page URL"), page.uri),
210 getConfigListEntry(_("Title"), page.title),
211 getConfigListEntry(_("Font size"), page.fontSize),
213 ConfigListScreen.__init__(self, list, session = self.session)
216 self.close(self.page, self.new)
219 self.close(None, self.new)