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!
4 from Screens.Screen import Screen
5 from Screens.InputBox import InputBox
6 from Screens.ChoiceBox import ChoiceBox
7 from Components.ActionMap import ActionMap
8 from Components.Label import Label
9 from Components.MenuList import MenuList
10 from Components.Input import Input
11 from Plugins.Plugin import PluginDescriptor
13 from enigma import ePoint, eSize
15 from ConfigParser import ConfigParser, DEFAULTSECT, DuplicateSectionError
17 ###############################################################################
18 myname = "AntiScrollbar"
20 ###############################################################################
21 class AntiScrollMain(Screen):
23 def __init__(self, session, args = 0):
24 config = AntiScrollConfig()
26 profil = config.getLastProfile()
27 self.size = [profil["sizex"],profil["sizey"]]
28 self.position = [profil["posx"],profil["posy"]]
30 config.setProfile("standard",[200,200],[200,200])
31 config = AntiScrollConfig()
32 profil = config.getProfile("standard")
34 self.size = [profil["sizex"],profil["sizey"]]
35 self.position = [profil["posx"],profil["posy"]]
36 ss ="<screen position=\"%i,%i\" size=\"%i,%i\" title=\"%s\" flags=\"wfNoBorder\" >" %(profil["posx"],profil["posy"],profil["sizex"],profil["sizey"],myname)
37 ss +="<widget name=\"label\" position=\"0,0\" size=\"%i,%i\" backgroundColor=\"black\" />" %(profil["sizex"],profil["sizey"])
40 self.session = session
41 Screen.__init__(self, session)
43 self["label"] = Label()
44 self["actions"] = ActionMap(["WizardActions", "DirectionActions","MenuActions","NumberActions"],
48 "menu": self.openmenu,
63 self.session.open(AntiScrollMenu,callback=self.menuCallback,size=self.size,position=self.position)
64 def menuCallback(self,size,position):
66 self.position = position
67 self.move(self.position[0],self.position[1])
68 self.resize(self.size[0],self.size[1])
71 self.size= [self.size[0],self.size[1]-self.step]
72 self.resize(self.size[0],self.size[1])
74 self.size= [self.size[0],self.size[1]+self.step]
75 self.resize(self.size[0],self.size[1])
77 self.size= [self.size[0]-self.step,self.size[1]]
78 self.resize(self.size[0],self.size[1])
80 self.size= [self.size[0]+self.step,self.size[1]]
81 self.resize(self.size[0],self.size[1])
84 self.position = [self.position[0],self.position[1]+self.step]
85 self.move(self.position[0],self.position[1])
87 self.position = [self.position[0],self.position[1]-self.step]
88 self.move(self.position[0],self.position[1])
90 self.position = [self.position[0]-self.step,self.position[1]]
91 self.move(self.position[0],self.position[1])
93 self.position = [self.position[0]+self.step,self.position[1]]
94 self.move(self.position[0],self.position[1])
97 print "["+myname+"] moving to", str(x) + ":" + str(y)
98 self.instance.move(ePoint(x, y))
100 def resize(self, w, h):
101 print "["+myname+"] resizing to", str(w) + "x" + str(h)
102 self.instance.resize(eSize(*(w, h)))
103 self["label"].instance.resize(eSize(*(w, h)))
104 #############################
105 class AntiScrollMenu(Screen):
106 def __init__(self,session,callback=None,size=None,position=None,arg=0):
107 self.session = session
108 self.callBack = callback
110 self.position = position
111 ss ="<screen position=\"200,200\" size=\"300,200\" title=\"%s Menu\" >" % myname
112 ss +="<widget name=\"menu\" position=\"0,0\" size=\"300,150\" scrollbarMode=\"showOnDemand\" />"
113 ss +="<widget name=\"label\" position=\"0,150\" size=\"300,50\" font=\"Regular;18\" valign=\"center\" halign=\"center\" />"
116 Screen.__init__(self,session)
118 list.append(("load Profile",self.load))
119 list.append(("save Profile",self.save))
120 list.append(("save new Profile",self.savenew))
121 self["menu"] = MenuList(list)
122 self["label"] = Label("written by 3c5x9, V"+myversion)
123 self["actions"] = ActionMap(["WizardActions", "DirectionActions","MenuActions","NumberActions"],
129 selection = self["menu"].getCurrent()
133 config = AntiScrollConfig()
135 for i in config.getProfiles():
137 self.session.openWithCallback(self.loadProfile,ChoiceBox,_("select Profile to load"),liste)
139 def loadProfile(self,value):
140 if value is not None:
141 config = AntiScrollConfig()
142 profil = config.getProfile(value[1])
143 if profil is not False:
144 self.callBack([profil["sizex"],profil["sizey"]],[profil["posx"],profil["posy"]])
146 self.session.openWithCallback(self.profilnameEntered,InputBox, title=_("Please enter a name for the Profile"), text="Profil", maxSize=False, type=Input.TEXT)
148 def profilnameEntered(self,value):
149 if value is not None:
150 config = AntiScrollConfig()
151 config.setProfile(value,self.size,self.position)
153 config = AntiScrollConfig()
155 for i in config.getProfiles():
157 self.session.openWithCallback(self.saveProfile,ChoiceBox,_("select Profile to save"),liste)
158 def saveProfile(self,value):
159 if value is not None:
160 config = AntiScrollConfig()
161 config.setProfile(value[1],self.size,self.position)
164 ##############################
165 class AntiScrollConfig:
166 configfile = "/etc/enigma2/AntiScrollbar.conf"
169 self.configparser = ConfigParser()
170 self.configparser.read(self.configfile)
171 def setLastProfile(self,name):
172 self.configparser.set(DEFAULTSECT,"lastprofile",name)
174 def getLastProfile(self):
175 last = self.configparser.get(DEFAULTSECT,"lastprofile")
176 return self.getProfile(last)
177 def getProfiles(self):
179 sections = self.configparser.sections()
180 for section in sections:
181 profiles.append(section)
184 def getProfile(self,name):
185 if self.configparser.has_section(name) is True:
186 print "loading profile ",name
188 l["sizex"] = int(self.configparser.get(name, "size_x"))
189 l["sizey"] = int(self.configparser.get(name, "size_y"))
190 l["posx"] = int(self.configparser.get(name, "position_x"))
191 l["posy"] = int(self.configparser.get(name, "position_y"))
192 self.setLastProfile(name)
195 print "couldnt find profil", name
197 def setProfile(self,name,size,position):
199 self.configparser.add_section(name)
200 self.configparser.set(name, "size_x",size[0])
201 self.configparser.set(name, "size_y",size[1])
202 self.configparser.set(name, "position_x",position[0])
203 self.configparser.set(name, "position_y",position[1])
206 except DuplicateSectionError:
207 self.deleteProfile(name)
208 self.setProfile(name,size,position)
210 def deleteProfile(self,name):
211 self.configparser.remove_section(name)
214 def writeConfig(self):
215 fp = open(self.configfile,"w")
216 self.configparser.write(fp)
221 #############################
222 def main(session, **kwargs):
223 session.open(AntiScrollMain)
224 def Plugins(**kwargs):
225 return [PluginDescriptor(name=myname,description="overlay for scrolling bars",where = PluginDescriptor.WHERE_PLUGINMENU,fnc = main),
226 PluginDescriptor(name=myname,description="overlay for scrolling bars",where = PluginDescriptor.WHERE_EXTENSIONSMENU,fnc = main)]