#
# 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 = """
"""
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 ""
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.3
(c) 2013-2016 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)
class ConfigScreen(ConfigListScreen,Screen):
skin = """
"""
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),
]
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)