fix
[enigma2.git] / lib / python / Screens / HarddiskSetup.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.Harddisk import harddiskmanager                 #global harddiskmanager
4 from Components.MenuList import MenuList
5 from Components.Label import Label
6 from Components.Pixmap import Pixmap
7 from Screens.MessageBox import MessageBox
8 from enigma import eTimer
9
10 class HarddiskWait(Screen):
11         def doInit(self):
12                 self.timer.stop()
13                 result = self.hdd.initialize()
14                 self.close(result)
15
16         def __init__(self, session, hdd):
17                 Screen.__init__(self, session)
18                 self.hdd = hdd
19                 self["wait"] = Label(_("Initializing Harddisk..."));
20                 self.timer = eTimer()
21                 self.timer.timeout.get().append(self.doInit)
22                 self.timer.start(100)
23
24 class HarddiskSetup(Screen):
25         def __init__(self, session, hdd):
26                 Screen.__init__(self, session)
27                 self.hdd = hdd
28                 
29                 self["model"] = Label(_("Model: ") + hdd.model())
30                 self["capacity"] = Label(_("Capacity: ") + hdd.capacity())
31                 self["bus"] = Label(_("Bus: ") + hdd.bus())
32                 self["initialize"] = Pixmap()
33                 self["initializetext"] = Label(_("Initialize"))
34
35                 self["actions"] = ActionMap(["OkCancelActions"],
36                 {
37                         "ok": self.close,
38                         "cancel": self.close
39                 })
40                 
41                 self["shortcuts"] = ActionMap(["ShortcutActions"],
42                 {
43                         "red": self.hddInitialize
44                 })
45
46         def hddReady(self, result):
47                 print "Result: " + str(result)
48                 if (result != 0):
49                         self.session.open(MessageBox, _("Unable to initialize harddisk.\nPlease refer to the user manual.\nError: ") + str(self.hdd.errorList[0 - result]), MessageBox.TYPE_ERROR)
50                 else:
51                         self.close()
52                         
53         def hddInitialize(self):
54                 print "this will start the initialize now!"
55                 self.session.openWithCallback(self.hddReady, HarddiskWait, self.hdd)
56
57 class HarddiskSelection(Screen):
58         def __init__(self, session):
59                 Screen.__init__(self, session)
60                 
61                 if harddiskmanager.HDDCount() == 0:
62                         tlist = []
63                         tlist.append((_("no HDD found"), 0))
64                         self["hddlist"] = MenuList(tlist)
65                 else:                   
66                         self["hddlist"] = MenuList(harddiskmanager.HDDList())
67                 
68                 self["actions"] = ActionMap(["OkCancelActions"],
69                 {
70                         "ok": self.okbuttonClick ,
71                         "cancel": self.close
72                 })
73
74         def okbuttonClick(self):
75                 selection = self["hddlist"].getCurrent()
76                 if selection[1] != 0:
77                         self.session.open(HarddiskSetup, selection[1])