- moved AntiScrollbar.conf to /etc/enigma2 to have it in the backups
[vuplus_dvbapp-plugin] / antiscrollbar / src / plugin.py
1 # (c) 2006 3c5x9, dream@3c5x9.de
2 # This Software is Free, use it where you want, when you want for whatever you want and modify it if you want. but don't remove my copyright!
3
4 from enigma import *
5 from Screens.Screen import Screen
6 from Screens.MessageBox import MessageBox
7 from Screens.InputBox import InputBox
8 from Screens.ChoiceBox import ChoiceBox
9 from Components.ActionMap import ActionMap, NumberActionMap
10 from Components.ScrollLabel import ScrollLabel
11 from Components.Label import Label
12 from Components.GUIComponent import *
13 from Components.MenuList import MenuList
14 from Components.Input import Input
15 from Screens.Console import Console
16 from Plugins.Plugin import PluginDescriptor
17 from Screens.ImageWizard import ImageWizard
18 import os,sys
19 from Plugins.Plugin import PluginDescriptor
20 #############
21 from enigma import ePoint, eSize, eServiceCenter
22 #############
23 import ConfigParser
24
25 ###############################################################################        
26 myname = "AntiScrollbar"     
27 myversion = "0.1"
28 ###############################################################################        
29 class AntiScrollMain(Screen):
30     step = 5    
31     def __init__(self, session, args = 0):
32         config = AntiScrollConfig()
33         try:
34           profil = config.getLastProfile()
35           self.size = [profil["sizex"],profil["sizey"]]
36           self.position = [profil["posx"],profil["posy"]]             
37         except Exception:
38           config.setProfile("standard",[200,200],[200,200])
39           config = AntiScrollConfig()          
40           profil = config.getProfile("standard")
41           
42         self.size = [profil["sizex"],profil["sizey"]]
43         self.position = [profil["posx"],profil["posy"]]           
44         ss  ="<screen position=\"%i,%i\" size=\"%i,%i\" title=\"%s\"  flags=\"wfNoBorder\" >" %(profil["posx"],profil["posy"],profil["sizex"],profil["sizey"],myname)
45         ss +="<widget name=\"label\" position=\"0,0\" size=\"%i,%i\"  backgroundColor=\"black\"  />" %(profil["sizex"],profil["sizey"])
46         ss +="</screen>"
47         self.skin = ss
48         self.session = session
49         Screen.__init__(self, session)
50         self.menu = args
51         self["label"] = Label()
52         self["actions"] = ActionMap(["WizardActions", "DirectionActions","MenuActions","NumberActions"], 
53             {
54              "ok":      self.go,
55              "back":    self.close,
56              "menu":    self.openmenu,
57              "down":    self.down,
58              "up":      self.up,
59              "left":    self.left,
60              "right":   self.right,
61              "2":       self.key2,
62              "8":       self.key8,
63              "4":       self.key4,
64              "6":       self.key6,
65              }, -1)
66
67
68     def go(self):
69       pass
70     def openmenu(self):
71       self.session.open(AntiScrollMenu,callback=self.menuCallback,size=self.size,position=self.position)
72     def menuCallback(self,size,position):
73       self.size = size
74       self.position = position
75       self.move(self.position[0],self.position[1])
76       self.resize(self.size[0],self.size[1])
77        
78     def key2(self):
79       self.size= [self.size[0],self.size[1]-self.step]
80       self.resize(self.size[0],self.size[1])
81     def key8(self):
82       self.size= [self.size[0],self.size[1]+self.step]
83       self.resize(self.size[0],self.size[1])
84     def key4(self):
85       self.size= [self.size[0]-self.step,self.size[1]]
86       self.resize(self.size[0],self.size[1])
87     def key6(self):
88       self.size= [self.size[0]+self.step,self.size[1]]
89       self.resize(self.size[0],self.size[1])
90     
91     def down(self):
92       self.position = [self.position[0],self.position[1]+self.step]
93       self.move(self.position[0],self.position[1])
94     def up(self):
95       self.position = [self.position[0],self.position[1]-self.step]
96       self.move(self.position[0],self.position[1])
97     def left(self):
98       self.position = [self.position[0]-self.step,self.position[1]]
99       self.move(self.position[0],self.position[1])
100     def right(self):
101       self.position = [self.position[0]+self.step,self.position[1]]
102       self.move(self.position[0],self.position[1])
103     
104     def move(self, x, y):
105       print "["+myname+"] moving to", str(x) + ":" + str(y)
106       self.instance.move(ePoint(x, y))
107           
108     def resize(self, w, h):
109       print "["+myname+"] resizing to", str(w) + "x" + str(h)
110       self.instance.resize(eSize(*(w, h)))
111       self["label"].instance.resize(eSize(*(w, h)))
112 #############################
113 class  AntiScrollMenu(Screen):
114   def __init__(self,session,callback=None,size=None,position=None,arg=0):
115     self.session = session
116     self.callBack = callback
117     self.size= size
118     self.position = position
119     ss  ="<screen position=\"200,200\" size=\"300,200\" title=\"%s Menu\" >" % myname
120     ss +="<widget name=\"menu\" position=\"0,0\" size=\"300,150\" scrollbarMode=\"showOnDemand\" />" 
121     ss +="<widget name=\"label\" position=\"0,150\" size=\"300,50\"  font=\"Regular;18\" valign=\"center\" halign=\"center\" />"
122     ss +="</screen>"
123     self.skin = ss
124     Screen.__init__(self,session)
125     list = []
126     list.append(("load Profile",self.load))
127     list.append(("save Profile",self.save))
128     list.append(("save new Profile",self.savenew))
129     self["menu"] = MenuList(list)
130     self["label"] = Label("written by 3c5x9, V"+myversion)
131     self["actions"] = ActionMap(["WizardActions", "DirectionActions","MenuActions","NumberActions"],
132             {
133              "ok": self.go,
134              "back": self.close,
135              }, -1)
136   def go(self):
137     selection = self["menu"].getCurrent()
138     selection[1]()
139   
140   def load(self):
141     config = AntiScrollConfig()
142     liste = []
143     for i in config.getProfiles():
144       liste.append((i,i))
145     self.session.openWithCallback(self.loadProfile,ChoiceBox,_("select Profile to load"),liste)
146     
147   def loadProfile(self,value):
148     if value is not None:
149       config = AntiScrollConfig()
150       profil = config.getProfile(value[1])
151       if profil is not False:
152         self.callBack([profil["sizex"],profil["sizey"]],[profil["posx"],profil["posy"]])
153   def savenew(self):
154     self.session.openWithCallback(self.profilnameEntered,InputBox, title=_("Please enter a name for the Profile"), text="Profil", maxSize=False, type=Input.TEXT)
155     
156   def profilnameEntered(self,value):
157     if value is not None:
158       config = AntiScrollConfig()
159       config.setProfile(value,self.size,self.position)   
160   def save(self):
161     config = AntiScrollConfig()
162     liste = []
163     for i in config.getProfiles():
164       liste.append((i,i))
165     self.session.openWithCallback(self.saveProfile,ChoiceBox,_("select Profile to save"),liste)
166   def saveProfile(self,value):
167     if value is not None:
168       config = AntiScrollConfig()
169       config.setProfile(value[1],self.size,self.position)
170                        
171                           
172 ##############################
173 class AntiScrollConfig:
174     configfile = "/etc/enigma2/AntiScrollbar.conf"
175     
176     def __init__(self):
177         self.configparser = ConfigParser.ConfigParser()
178         self.configparser.read(self.configfile)
179     def setLastProfile(self,name):
180         self.configparser.set(ConfigParser.DEFAULTSECT,"lastprofile",name)
181         self.writeConfig()
182     def getLastProfile(self):
183         last = self.configparser.get(ConfigParser.DEFAULTSECT,"lastprofile")    
184         return self.getProfile(last)
185     def getProfiles(self):
186         profiles=[]
187         sections = self.configparser.sections()
188         for section in sections:
189           profiles.append(section)
190         return profiles
191
192     def getProfile(self,name):
193       if self.configparser.has_section(name) is True:
194         print "loading profile ",name
195         l={}
196         l["sizex"] = int(self.configparser.get(name, "size_x"))
197         l["sizey"] = int(self.configparser.get(name, "size_y"))
198         l["posx"] = int(self.configparser.get(name, "position_x"))
199         l["posy"] = int(self.configparser.get(name, "position_y"))
200         self.setLastProfile(name)
201         return l
202       else:
203         print "couldnt find profil", name
204         return False
205     def setProfile(self,name,size,position):
206         try:
207           self.configparser.add_section(name)
208           self.configparser.set(name, "size_x",size[0])
209           self.configparser.set(name, "size_y",size[1])
210           self.configparser.set(name, "position_x",position[0])
211           self.configparser.set(name, "position_y",position[1])
212           self.writeConfig()
213           return True
214         except ConfigParser.DuplicateSectionError:
215           self.deleteProfile(name)
216           self.setProfile(name,size,position)
217                                                                                                     
218     def deleteProfile(self,name):
219         self.configparser.remove_section(name)
220         self.writeConfig()
221
222     def writeConfig(self):
223         fp = open(self.configfile,"w")
224         self.configparser.write(fp)
225         fp.close()
226                             
227     
228      
229 #############################
230 def main(session, **kwargs):
231   session.open(AntiScrollMain)
232 def Plugins(**kwargs):
233   return [PluginDescriptor(name=myname,description="overlay for scrolling bars",where = PluginDescriptor.WHERE_PLUGINMENU,fnc = main),
234           PluginDescriptor(name=myname,description="overlay for scrolling bars",where = PluginDescriptor.WHERE_EXTENSIONSMENU,fnc = main)]