1 from Screens.Screen import Screen
2 from Plugins.Plugin import PluginDescriptor
3 from Components.PluginComponent import plugins
4 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigYesNo, ConfigNumber
5 from Components.ConfigList import ConfigListScreen
6 from Components.ActionMap import ActionMap
7 from Components.Sources.StaticText import StaticText
8 from CleanupWizard import checkFreeSpaceAvailable
10 config.plugins.cleanupwizard = ConfigSubsection()
11 config.plugins.cleanupwizard.enable = ConfigYesNo(default = True)
12 config.plugins.cleanupwizard.threshold = ConfigNumber(default = 2048)
14 freeSpace = checkFreeSpaceAvailable()
15 print "[CleanupWizard] freeSpaceAvailable-->",freeSpace
18 internalMemoryExceeded = 0
19 elif int(freeSpace) <= config.plugins.cleanupwizard.threshold.value:
20 internalMemoryExceeded = 1
22 internalMemoryExceeded = 0
24 class CleanupWizardConfiguration(Screen, ConfigListScreen):
27 <screen name="CleanupWizardConfiguration" position="center,center" size="560,440" title="CleanupWizard settings" >
28 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
29 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
30 <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" />
31 <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" />
32 <widget name="config" zPosition="2" position="5,50" size="550,300" scrollbarMode="showOnDemand" transparent="1" />
33 <ePixmap pixmap="skin_default/div-h.png" position="0,390" zPosition="10" size="560,2" transparent="1" alphatest="on" />
34 <widget source="status" render="Label" position="10,400" size="540,40" zPosition="10" font="Regular;20" halign="center" valign="center" backgroundColor="#25062748" transparent="1"/>
37 def __init__(self, session):
38 Screen.__init__(self, session)
39 self.session = session
40 self.EnableEntry = None
41 self.freeSpaceEntry = None
42 self.onChangedEntry = [ ]
43 self.setup_title = _("Cleanup Wizard")
45 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
48 "cancel": self.keyCancel,
49 "red": self.keyCancel,
50 "green": self.keySave,
54 ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.changedEntry)
57 self["key_red"] = StaticText(_("Close"))
58 self["key_green"] = StaticText(_("Save"))
59 self["status"] = StaticText()
60 self.onShown.append(self.setWindowTitle)
62 def setWindowTitle(self):
63 self.setTitle(_("Cleanup Wizard settings"))
66 ConfigListScreen.keyLeft(self)
70 ConfigListScreen.keyRight(self)
73 def createSetup(self):
75 self.EnableEntry = getConfigListEntry(_("Enable Cleanup Wizard?"), config.plugins.cleanupwizard.enable)
76 self.freeSpaceEntry = getConfigListEntry(_("Warn if free space drops below (kB):"), config.plugins.cleanupwizard.threshold)
77 self.list.append( self.EnableEntry )
78 if config.plugins.cleanupwizard.enable.value is True:
79 self.list.append( self.freeSpaceEntry )
81 self["config"].list = self.list
82 self["config"].l.setList(self.list)
83 if not self.selectionChanged in self["config"].onSelectionChanged:
84 self["config"].onSelectionChanged.append(self.selectionChanged)
87 if self["config"].getCurrent() == self.EnableEntry:
90 def selectionChanged(self):
91 current = self["config"].getCurrent()
92 if current == self.EnableEntry:
93 self["status"].setText(_("Decide if you want to enable or disable the Cleanup Wizard."))
94 elif current == self.freeSpaceEntry:
95 self["status"].setText(_("Set available internal memory threshold for the warning."))
98 def changedEntry(self):
99 for x in self.onChangedEntry:
101 self.selectionChanged()
103 def getCurrentEntry(self):
104 return self["config"].getCurrent()[0]
106 def getCurrentValue(self):
107 return str(self["config"].getCurrent()[1].getText())
109 def createSummary(self):
110 from Screens.Setup import SetupSummary
114 def CleanupWizard(*args, **kwargs):
115 from CleanupWizard import CleanupWizard
116 return CleanupWizard(*args, **kwargs)
118 def openconfig(session, **kwargs):
119 session.open(CleanupWizardConfiguration)
121 def selSetup(menuid, **kwargs):
122 if menuid != "system":
125 return [(_("Cleanup Wizard settings"), openconfig, "cleanup_config", 71)]
127 def Plugins(**kwargs):
129 list.append(PluginDescriptor(name=_("CleanupWizard"), description=_("Cleanup Wizard settings"),where=PluginDescriptor.WHERE_MENU, needsRestart = False, fnc=selSetup))
130 if config.plugins.cleanupwizard.enable.value:
131 if not config.misc.firstrun.value:
132 if internalMemoryExceeded:
133 list.append(PluginDescriptor(name=_("Cleanup Wizard"), where = PluginDescriptor.WHERE_WIZARD, needsRestart = False, fnc=(1, CleanupWizard)))