From f9e68c68b63b86c6cdb940681e66231a856c21f9 Mon Sep 17 00:00:00 2001 From: acid-burn Date: Wed, 7 Oct 2009 16:05:42 +0200 Subject: [PATCH] CleanupWizard/plugin.py: - add configuration screen to mainmenu->system. It is now possible to enable/disable the CleanupWizard and also to manually define the free space threshold for the warning. --- .../Plugins/SystemPlugins/CleanupWizard/plugin.py | 118 +++++++++++++++++++-- 1 file changed, 112 insertions(+), 6 deletions(-) diff --git a/lib/python/Plugins/SystemPlugins/CleanupWizard/plugin.py b/lib/python/Plugins/SystemPlugins/CleanupWizard/plugin.py index 125f784..6667e3e 100755 --- a/lib/python/Plugins/SystemPlugins/CleanupWizard/plugin.py +++ b/lib/python/Plugins/SystemPlugins/CleanupWizard/plugin.py @@ -1,29 +1,135 @@ from Screens.Screen import Screen from Plugins.Plugin import PluginDescriptor from Components.PluginComponent import plugins -from Components.config import config +from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigYesNo, ConfigNumber +from Components.ConfigList import ConfigListScreen +from Components.ActionMap import ActionMap +from Components.Sources.StaticText import StaticText from CleanupWizard import checkFreeSpaceAvailable +config.plugins.cleanupwizard = ConfigSubsection() +config.plugins.cleanupwizard.enable = ConfigYesNo(default = True) +config.plugins.cleanupwizard.threshold = ConfigNumber(default = 2048) + freeSpace = checkFreeSpaceAvailable() print "[CleanupWizard] freeSpaceAvailable-->",freeSpace - if freeSpace is None: internalMemoryExceeded = 0 -elif int(freeSpace) <= 2048: +elif int(freeSpace) <= config.plugins.cleanupwizard.threshold.value: internalMemoryExceeded = 1 else: internalMemoryExceeded = 0 +class CleanupWizardConfiguration(Screen, ConfigListScreen): + + skin = """ + + + + + + + + + """ + + def __init__(self, session): + Screen.__init__(self, session) + self.session = session + self.EnableEntry = None + self.freeSpaceEntry = None + self.onChangedEntry = [ ] + self.setup_title = _("Cleanup Wizard") + + self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ], + { + "ok": self.keySave, + "cancel": self.keyCancel, + "red": self.keyCancel, + "green": self.keySave, + }, -2) + + self.list = [] + ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.changedEntry) + self.createSetup() + + self["key_red"] = StaticText(_("Close")) + self["key_green"] = StaticText(_("Save")) + self["status"] = StaticText() + self.onShown.append(self.setWindowTitle) + + def setWindowTitle(self): + self.setTitle(_("Cleanup Wizard settings")) + + def keyLeft(self): + ConfigListScreen.keyLeft(self) + self.newConfig() + + def keyRight(self): + ConfigListScreen.keyRight(self) + self.newConfig() + + def createSetup(self): + self.list = [] + self.EnableEntry = getConfigListEntry(_("Enable Cleanup Wizard?"), config.plugins.cleanupwizard.enable) + self.freeSpaceEntry = getConfigListEntry(_("Warn if free space drops below (kB):"), config.plugins.cleanupwizard.threshold) + self.list.append( self.EnableEntry ) + if config.plugins.cleanupwizard.enable.value is True: + self.list.append( self.freeSpaceEntry ) + + self["config"].list = self.list + self["config"].l.setList(self.list) + if not self.selectionChanged in self["config"].onSelectionChanged: + self["config"].onSelectionChanged.append(self.selectionChanged) + + def newConfig(self): + if self["config"].getCurrent() == self.EnableEntry: + self.createSetup() + + def selectionChanged(self): + current = self["config"].getCurrent() + if current == self.EnableEntry: + self["status"].setText(_("Decide if you want to enable or disable the Cleanup Wizard.")) + elif current == self.freeSpaceEntry: + self["status"].setText(_("Set available internal memory threshold for the warning.")) + + # for summary: + def changedEntry(self): + for x in self.onChangedEntry: + x() + self.selectionChanged() + + def getCurrentEntry(self): + return self["config"].getCurrent()[0] + + def getCurrentValue(self): + return str(self["config"].getCurrent()[1].getText()) + + def createSummary(self): + from Screens.Setup import SetupSummary + return SetupSummary + def CleanupWizard(*args, **kwargs): from CleanupWizard import CleanupWizard return CleanupWizard(*args, **kwargs) +def openconfig(session, **kwargs): + session.open(CleanupWizardConfiguration) + +def selSetup(menuid, **kwargs): + if menuid != "system": + return [ ] + + return [(_("Cleanup Wizard settings") + "...", openconfig, "cleanup_config", 71)] + def Plugins(**kwargs): list = [] - if not config.misc.firstrun.value: - if internalMemoryExceeded: - list.append(PluginDescriptor(name=_("Cleanup Wizard"), where = PluginDescriptor.WHERE_WIZARD, fnc=(1, CleanupWizard))) + list.append(PluginDescriptor(name=_("CleanupWizard"), description=_("Cleanup Wizard settings"),where=PluginDescriptor.WHERE_MENU, fnc=selSetup)) + if config.plugins.cleanupwizard.enable.value: + if not config.misc.firstrun.value: + if internalMemoryExceeded: + list.append(PluginDescriptor(name=_("Cleanup Wizard"), where = PluginDescriptor.WHERE_WIZARD, fnc=(1, CleanupWizard))) return list -- 2.7.4