4.3.1r21
[enigma2.git] / usr / lib / enigma2 / python / Plugins / Extensions / Browser / Bookmarks.py
1 from enigma import getPrevAsciiCode
2
3 from Components.ActionMap import ActionMap, NumberActionMap
4 from Components.Sources.StaticText import StaticText
5 from Components.Label import Label
6
7 from Screens.Screen import Screen
8
9 from EnhancedInput import EnhancedInput
10 from BrowserDB import Bookmark
11
12 class BookmarkEditor(Screen):
13         skin = """
14                 <screen position="center,center" size="600,80"  title="Edit Bookmark">
15                         <widget source="nameTitle" render="Label" position="5,0" zPosition="1" size="90,30" font="Regular;22" halign="right" valign="bottom" backgroundColor="#000000" transparent="1" />
16                         <widget source="urlTitle" render="Label" position="5,40" zPosition="1" size="90,30" font="Regular;22" halign="right" valign="bottom" backgroundColor="#000000" transparent="1" />
17                         <widget name="name" position="100,0" size="450,30" font="Regular;22" halign="left" valign="bottom" backgroundColor="#000000" transparent="1"/>
18                         <widget name="url" position="100,40" size="450,30" font="Regular;22" halign="left" valign="bottom" backgroundColor="#000000" transparent="1"/>
19                         <widget name="nameActive" position="560,0" zPosition="1" size="40,30" font="Regular;22" halign="right" valign="bottom" backgroundColor="#000000" transparent="1" />
20                         <widget name="urlActive" position="560,40" zPosition="1" size="40,30" font="Regular;22" halign="right" valign="bottom" backgroundColor="#000000" transparent="1" />
21                 </screen>"""
22         
23         def __init__(self, session, bookmark = None):
24                 Screen.__init__(self, session)
25                 
26                 self.bookmark = bookmark
27                 if self.bookmark == None:
28                         self.bookmark = Bookmark()
29                 
30                 self["nameTitle"] = StaticText(_("Name:"))
31                 self["urlTitle"] = StaticText(_("Url:"))
32                 
33                 self["nameActive"] = Label("<")
34                 self["urlActive"] = Label("<")
35                 
36                 self.inputName = EnhancedInput( self.bookmark.name )
37                 self["name"] = self.inputName
38                 self.inputUrl = EnhancedInput( self.bookmark.url )
39                 self["url"] = self.inputUrl
40                 self.onShow.append(self.setKeyboardModeAscii)
41                 
42                 self["actions"] = ActionMap(["SimpleEditorActions"],
43                 {
44                         "ok" : self.__ok,
45                         "exit" : self.__cancel,
46                         "up" : self.__up,
47                         "down" : self.__down,
48                         "left" : self.__left,
49                         "right" : self.__right,
50                         "ascii" : self.__ascii,
51                         "delete" : self.__delete,
52                         "backspace" : self.__backspace
53                 })
54                 self["numberactions"] = NumberActionMap(["NumberActions"],
55                 {
56                         "1": self.__keyNumberGlobal,
57                         "2": self.__keyNumberGlobal,
58                         "3": self.__keyNumberGlobal,
59                         "4": self.__keyNumberGlobal,
60                         "5": self.__keyNumberGlobal,
61                         "6": self.__keyNumberGlobal,
62                         "7": self.__keyNumberGlobal,
63                         "8": self.__keyNumberGlobal,
64                         "9": self.__keyNumberGlobal,
65                         "0": self.__keyNumberGlobal
66                 })
67                 
68                 self.nameFocus = False
69                 self.onShow.append(self.__toggleInput)
70                 
71         def __ok(self):
72                 name = self.inputName.getText()
73                 url = self.inputUrl.getText() 
74                 if name != None and url != None and name != "" and url != "":
75                         self.bookmark.name = name
76                         self.bookmark.url = url
77                         self.close( self.bookmark )
78                 else:
79                         self.close(None)
80         
81         def __cancel(self):
82                 self.close(None)
83         
84         def __up(self):
85                 self.__toggleInput()
86         
87         def __down(self):
88                 self.__toggleInput()
89         
90         def __toggleInput(self):
91                 self.nameFocus = not self.nameFocus
92                 if self.nameFocus:
93                         self["nameActive"].show()
94                         self.inputName.end()
95                         self["urlActive"].hide()
96                         self.inputUrl.markNone()
97                 else:
98                         self["nameActive"].hide()
99                         self.inputName.markNone()
100                         self["urlActive"].show()
101                         self.inputUrl.end()
102         
103         def __left(self):
104                 if self.nameFocus:
105                         self.inputName.left()
106                 else:
107                         self.inputUrl.left()
108         
109         def __right(self):
110                 if self.nameFocus:
111                         self.inputName.right()
112                 else:
113                         self.inputUrl.right()
114         
115         def __delete(self):
116                 if self.nameFocus:
117                         self.inputName.delete()
118                 else:
119                         self.inputUrl.delete()
120                 
121         def __backspace(self):
122                 if self.nameFocus:
123                         self.inputName.deleteBackward()
124                 else:
125                         self.inputUrl.deleteBackward()
126         
127         def __keyNumberGlobal(self, number):
128                 if self.nameFocus:
129                         self.inputName.number(number)
130                 else:
131                         self.inputUrl.number(number)
132         
133         def __ascii(self):
134                 print "ASCII!"
135                 if self.nameFocus:
136                         self.inputName.handleAscii(getPrevAsciiCode())
137                 else:
138                         self.inputUrl.handleAscii(getPrevAsciiCode())
139