cleanup imports
[enigma2-plugins.git] / vlcplayer / src / plugin.py
1 from Plugins.Plugin import PluginDescriptor
2 from Components.ActionMap import ActionMap
3 from Components.Label import Label
4 from Components.Button import Button
5 from Screens.MessageBox import MessageBox
6 from Screens.Screen import Screen
7 from enigma import eServiceCenter
8 from VlcFileList import VlcFileList
9 from VlcConfig import VLCSettings, VLCServerConfig
10 from VlcPlayer import VlcPlayer
11
12 class VlcBrowser(Screen):
13         skin = """
14                 <screen position="80,100" size="560,400" title="VLC Video Player" >
15                         <widget name="currentdir" position="10,10" size="550,20" font="Regular;18"/>
16                         <widget name="filelist" position="10,35" size="550,310"  scrollbarMode="showOnDemand"/>
17                         <ePixmap name="red"    position="0,355"   zPosition="4" size="140,40" pixmap="Nemesis.SkinSuite.Shared/key-red.png" transparent="1" alphatest="on" />
18                         <ePixmap name="green"  position="140,355" zPosition="4" size="140,40" pixmap="Nemesis.SkinSuite.Shared/key-green.png" transparent="1" alphatest="on" />
19                         <ePixmap name="yellow" position="280,355" zPosition="4" size="140,40" pixmap="Nemesis.SkinSuite.Shared/key-yellow.png" transparent="1" alphatest="on" />
20                         <ePixmap name="blue"   position="420,355" zPosition="4" size="140,40" pixmap="Nemesis.SkinSuite.Shared/key-blue.png" transparent="1" alphatest="on" />
21                         <widget name="key_red" position="0,355" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
22                         <widget name="key_green" position="140,355" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
23                         <widget name="key_yellow" position="280,355" zPosition="5" size="140,40" valign="center" halign="center"  font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
24                         <widget name="key_blue" position="420,355" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
25                 </screen>"""
26
27         defaultFilter = "(?i)\.(avi|mpeg|mpg|divx|xvid|mov|ts|vob)$"
28         
29         def __init__(self, session):
30                 self.session = session
31                 self.serviceHandler = eServiceCenter.getInstance()
32                 self.oldService = self.session.nav.getCurrentlyPlayingServiceReference()
33                 self.session.nav.stopService()
34                 self.filelist = VlcFileList(self.defaultFilter)
35
36                 Screen.__init__(self, session)
37                 self["currentdir"] = Label("Loading Serverlist...")
38                 self["filelist"] = self.filelist
39                 self["key_red"] = Button("filter off")
40                 self["key_green"] = Button("serverlist")
41                 self["key_yellow"] = Button("edit server")
42                 self["key_blue"] = Button(_("settings"))
43                 self["actions"] = ActionMap(["WizardActions", "MenuActions", "ShortcutActions", "MoviePlayerActions"], 
44                         {
45                          "back":        self.close, 
46                          "red":         self.keyFilter, 
47                          "green":       self.keyServerlist, 
48                          "yellow":      self.keyEditServer, 
49                          "blue":        self.keySettings, 
50                          "up":          self.up, 
51                          "down":        self.down, 
52                          "left":        self.left, 
53                          "right":       self.right, 
54                          "ok":          self.ok, 
55                          }, -1)
56
57                 self.onLayoutFinish.append(self.keyServerlist)
58                 self.onClose.append(self.__onClose)
59
60         def keyServerlist(self):
61                 self.changeDir(None)
62
63         def keyFilter(self):
64                 if self.filelist.matchingPattern is None:
65                         self.filelist.matchingPattern = self.defaultFilter
66                         self["key_red"].setText("filter off")
67                 else:
68                         self.filelist.matchingPattern = None
69                         self["key_red"].setText("filter on")
70                 dir = self.filelist.getCurrentDirectory()
71                 self.changeDir(dir)
72
73         def keyEditServer(self):
74                 servernum = None
75                 if self.filelist.current_server is None:
76                         if self.filelist.getSelection() is not None:
77                                 path, isdir = self.filelist.getSelection()
78                                 if isdir:
79                                         servernum = int(path[0:path.find(":")])
80                 else:
81                         servernum = self.filelist.current_server
82                 self.session.openWithCallback(self.refresh, VLCServerConfig, servernum)
83
84         def keySettings(self):
85                 self.session.open(VLCSettings)
86
87         def up(self):
88                 self.filelist.up()
89
90         def down(self):
91                 self.filelist.down()
92
93         def left(self):
94                 self.filelist.pageUp()
95
96         def right(self):
97                 self.filelist.pageDown()
98         
99         def ok(self):
100                 if self.filelist.getSelection() is not None:
101                         path, isdir = self.filelist.getSelection()
102                         if path is None:
103                                 self.session.openWithCallback(self.refresh, VLCServerConfig, None)
104                         elif isdir:
105                                 self.changeDir(path)
106                         else:
107                                 servernum, path = path.split(":", 1)
108                                 servernum = int(servernum)
109                                 dlg = self.session.open(VlcPlayer)
110                                 dlg.playfile(servernum, path)
111
112         def __onClose(self):
113                 self.session.nav.playService(self.oldService)
114
115         def refresh(self):
116                 self.changeDir(None)
117         
118         def changeDir(self, dir):
119                 try:
120                         self.filelist.changeDir(dir, self.filelist.getCurrentDirectory())
121                 except Exception, e:
122                         self.session.open(
123                                 MessageBox, _("Error contacting server %s:\n%s" % (dir, e)), MessageBox.TYPE_ERROR)
124                         return
125                 dir = self.filelist.getCurrentDirectory()
126                 if dir is None:
127                         self["currentdir"].setText("Serverlist")
128                 else:
129                         dir = self.filelist.current_path
130                         if len(dir) >= 50:
131                                 dir = "..." + dir[-50:]
132                         self["currentdir"].setText(dir)
133
134 #
135 #-------------------------------------------------------------------------------------------
136 #
137 def main(session, **kwargs):
138         session.open(VlcBrowser)
139
140 def Plugins(**kwargs):
141         return PluginDescriptor(
142                 name="VLC Video Player", 
143                 description="VLC Video Player", 
144                 where = [ PluginDescriptor.WHERE_MOVIELIST, PluginDescriptor.WHERE_PLUGINMENU ],
145                 fnc = main)