123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- #
- # This file is part of GetPicons - enigma2 plugin to download picons from lyngsat.com
- # Copyright (c) 2016 ivars777 (ivars777@gmail.com)
- # Distributed under the GNU GPL v3. For full terms see http://www.gnu.org/licenses/gpl-3.0.en.html
-
- from Screens.Screen import Screen
- from Screens.Console import Console
- from Components.MenuList import MenuList
- from Components.Sources.StaticText import StaticText
- from Components.Button import Button
- from Components.ActionMap import ActionMap
- from Screens.MessageBox import MessageBox
- from Plugins.Plugin import PluginDescriptor
- import os,os.path
-
- ###########################################################################
- class MainScreen(Screen):
- skin = """
- <screen position="center,center" size="560,400" title="GetPicons" >
- <widget name="content" position="10,40" size="540,350" scrollbarMode="showOnDemand" />
-
- <ePixmap name="red" position="0,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
- <ePixmap name="green" position="140,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
- <ePixmap name="yellow" position="280,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
- <ePixmap name="blue" position="420,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
- <widget name="key_red" position="0,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
- <widget name="key_green" position="140,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
- <widget name="key_yellow" position="280,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
- <widget name="key_blue" position="420,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
- </screen>"""
-
- def __init__(self, session, args = 0):
- self.session = session
- menu_list = [("Download picons for all satellites","all")]
- for line in open("/etc/enigma2/settings"):
- if not "config.Nims.0.advanced.sat." in line: continue
- s = line.strip().split(".")
- sat_num = int(s[5])
- if sat_num>1800: sat_num = sat_num - 3600
- sat_pos = "%s.%s%s"%(abs(sat_num)/10,abs(sat_num)%10,"E" if sat_num>0 else "W")
- menu_list.append( ("Download for %s (%s)"%(sat_pos,s[6]), sat_num) )
- menu_list.append(("Exit","exit"))
-
- Screen.__init__(self, session)
- self["content"] = MenuList(menu_list)
- self["key_red"] = Button("Exit")
- self["key_green"] = Button("Select")
- self["key_yellow"] = Button("Options")
- self["key_blue"] = Button("About")
- self["action_map"] = ActionMap(["OkCancelActions", "ColorActions"],
- {
- "ok": self.go,
- "cancel": self.cancel,
- "green":self.go,
- "red":self.cancel,
- "yellow":self.options,
- "blue":self.about
- }, -1)
-
- def go(self):
- item = self["content"].l.getCurrentSelection()[1]
-
- if item == "exit":
- self.close(None)
- else:
- print "picon folder = %s size = %s overwrite=%s"%(config.plugins.getpicons.folder.value,config.plugins.getpicons.folder.value,config.plugins.getpicons.overwrite.value)
- param = ""
- param += " -s %s"%(item) if item <> "all" else ""
- param += " -o" if config.plugins.getpicons.overwrite.value else ""
- param += " -z %s"%config.plugins.getpicons.size.value if config.plugins.getpicons.size.value else ""
- param += " -b %s"%config.plugins.getpicons.background.value if config.plugins.getpicons.background.value else ""
- param += " -l" if config.plugins.getpicons.simple.value else ""
- param += " -d" if config.plugins.getpicons.debug.value else ""
- cur_directory = os.path.dirname(os.path.realpath(__file__))
- name = os.path.join(cur_directory,"get_picons.py")
- cmd = "python -u %s -f %s %s"%(name,config.plugins.getpicons.folder.value,param,)
- #print "[GetPicons] Execute '%s'"%cmd
- #os.chmod(name, 493)
- if config.plugins.getpicons.folder.value:
- self.session.open(Console, "Download picons from lyngsat.com", cmdlist=[cmd])
-
- def cancel(self):
- print "\n[GetPicons] cancel\n"
- self.close(None)
-
- def options(self):
- print "\n[GetPicons] options\n"
- self.session.open(ConfigScreen)
-
- def about(self):
- txt = """
- GetPicons plugin
-
- Download channels picon files from lyngsat.com for all/selected satellites
-
- Could be run from terminal too:
- /usr/script/get_picons.sh -h
-
- Version 0.4
- (c) 2013-2017 ivars777@gmail.com"""
- self.session.open(MessageBox, txt, MessageBox.TYPE_INFO)
- #self.session.openWithCallback(self.callMyMsg, MessageBox, _("Do you want to exit the plugin?"), MessageBox.TYPE_INFO)
- return
-
-
- ##########################################################################
- from Components.config import config, ConfigSubsection, \
- ConfigYesNo, getConfigListEntry, \
- ConfigSelection, ConfigNumber, ConfigDirectory,ConfigText
- from Components.ConfigList import ConfigListScreen
- from Screens.LocationBox import LocationBox
-
- config.plugins.getpicons = ConfigSubsection()
- config.plugins.getpicons.folder = ConfigDirectory(default="/media/hdd")
- config.plugins.getpicons.size = ConfigSelection({"400x240":"400x240","220x132":"220x132","100x60":"100x60"}, default="220x132")
- config.plugins.getpicons.overwrite = ConfigYesNo(default = True)
- config.plugins.getpicons.background = ConfigText(default="FFFFFF20")
- config.plugins.getpicons.simple = ConfigYesNo(default = False)
- config.plugins.getpicons.debug = ConfigYesNo(default = False)
-
- class ConfigScreen(ConfigListScreen,Screen):
- skin = """
- <screen position="center,center" size="560,400" title="Options" >
- <ePixmap name="red" position="0,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
- <ePixmap name="green" position="140,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
- <ePixmap name="yellow" position="280,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
- <ePixmap name="blue" position="420,0" zPosition="2" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
-
- <widget name="key_red" position="0,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
- <widget name="key_green" position="140,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
- <widget name="key_yellow" position="280,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
- <widget name="key_blue" position="420,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
-
- <widget name="config" position="10,40" size="540,340" scrollbarMode="showOnDemand" />
- </screen>"""
-
- def __init__(self, session, args = 0):
- self.session = session
- self.setup_title = "Options"
- Screen.__init__(self, session)
- cfg = config.plugins.getpicons
- self.list = [
- getConfigListEntry(_("Picons folder"), cfg.folder),
- getConfigListEntry(_("Picon size"), cfg.size),
- getConfigListEntry(_("Overwrite existing picon files"), cfg.overwrite),
- getConfigListEntry(_("Background color hex code (HHHHHHHH)"), cfg.background),
- getConfigListEntry(_("Simple picon"), cfg.simple),
- getConfigListEntry(_("Debug info"), cfg.debug),
- ]
- ConfigListScreen.__init__(self, self.list, session = self.session)
- self["key_red"] = Button(_("Cancel"))
- self["key_green"] = Button(_("Save"))
- self["key_yellow"] = Button("")
- self["key_blue"] = Button("")
- self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
- {
- "red": self.cancel,
- "green": self.save,
- "save": self.save,
- "cancel": self.cancel,
- "ok": self.ok,
- }, -2)
-
- def getCurrentEntry(self):
- return self["config"].getCurrent()[0]
-
- def getCurrentValue(self):
- return str(self["config"].getCurrent()[1].getText())
-
- def ok(self):
- if self["config"].getCurrent()[1] == config.plugins.getpicons.folder:
- folder = config.plugins.getpicons.folder.value
- self.session.openWithCallback(self.change_dir, LocationBox,"Select Folder")
- else:
- self.save()
-
- def change_dir(self, folder, select=None):
- if folder:
- #print "change_dir to %s"%folder
- config.plugins.getpicons.folder.value = folder
-
- def save(self):
- print "saving"
- self.saveAll()
- self.close(True,self.session)
-
- def cancel(self):
- #print "cancel"
- self.close(False,self.session)
-
-
- ###########################################################################
- def start(session, **kwargs):
- print "\n[GetPicons] start\n"
- session.open(MainScreen)
- #session.openWithCallback(done_config, Config)
-
- def Plugins(**kwargs):
- return PluginDescriptor(
- name="Get Picons",
- description="Download picons from lyngsat.com",
- where = [PluginDescriptor.WHERE_PLUGINMENU,PluginDescriptor.WHERE_EXTENSIONSMENU],
- icon="plugin.png",
- fnc=start)
|