From ed40f6f85c9c07c3c1224ae20601082c0309a631 Mon Sep 17 00:00:00 2001 From: Andreas Monzner Date: Tue, 19 Dec 2006 02:12:57 +0000 Subject: some python import cleanups lesser swig overhead --- lib/python/Components/AVSwitch.py | 2 +- lib/python/Components/About.py | 2 +- lib/python/Components/ActionMap.py | 7 ++--- lib/python/Components/ChoiceList.py | 16 ++--------- lib/python/Components/Clock.py | 5 +--- lib/python/Components/ConditionalWidget.py | 6 ++-- lib/python/Components/EpgList.py | 15 ++-------- lib/python/Components/FileList.py | 19 ++++--------- lib/python/Components/Harddisk.py | 12 ++++---- lib/python/Components/Language.py | 3 +- lib/python/Components/LanguageList.py | 41 ---------------------------- lib/python/Components/MediaPlayer.py | 17 +++--------- lib/python/Components/MovieList.py | 9 ++---- lib/python/Components/MultiContent.py | 13 +-------- lib/python/Components/Network.py | 2 -- lib/python/Components/ParentalControlList.py | 13 ++------- lib/python/Components/PluginComponent.py | 18 ++++++------ lib/python/Components/PluginList.py | 4 +-- lib/python/Components/RFmod.py | 6 ++-- lib/python/Components/ServiceList.py | 2 +- lib/python/Components/ServicePosition.py | 2 +- lib/python/Components/TimerList.py | 15 ++-------- lib/python/Components/Timezones.py | 5 ++-- lib/python/Components/components.py | 1 - 24 files changed, 56 insertions(+), 179 deletions(-) (limited to 'lib/python/Components') diff --git a/lib/python/Components/AVSwitch.py b/lib/python/Components/AVSwitch.py index 8a7bd8d1..a8e471ba 100644 --- a/lib/python/Components/AVSwitch.py +++ b/lib/python/Components/AVSwitch.py @@ -1,6 +1,6 @@ from config import config, ConfigSelection, ConfigYesNo, ConfigEnableDisable, ConfigSubsection, ConfigBoolean import os -from enigma import * +from enigma import eAVSwitch class AVSwitch: INPUT = { "ENCODER": (0, 4), "SCART": (1, 3), "AUX": (2, 4) } diff --git a/lib/python/Components/About.py b/lib/python/Components/About.py index e5f9543e..2f3fec09 100644 --- a/lib/python/Components/About.py +++ b/lib/python/Components/About.py @@ -1,4 +1,4 @@ -from Tools.Directories import * +from Tools.Directories import resolveFilename, SCOPE_SYSETC class About: def __init__(self): diff --git a/lib/python/Components/ActionMap.py b/lib/python/Components/ActionMap.py index d2e908e6..b65d6ebc 100644 --- a/lib/python/Components/ActionMap.py +++ b/lib/python/Components/ActionMap.py @@ -1,16 +1,15 @@ -from enigma import * +from enigma import eActionMap class ActionMap: def __init__(self, contexts = [ ], actions = { }, prio=0): self.actions = actions self.contexts = contexts self.prio = prio - self.p = eActionMapPtr() + self.p = eActionMap.getInstance() self.bound = False self.exec_active = False self.enabled = True - eActionMap.getInstance(self.p) - + def setEnabled(self, enabled): self.enabled = enabled self.checkBind() diff --git a/lib/python/Components/ChoiceList.py b/lib/python/Components/ChoiceList.py index a0fbde54..a2070c7d 100644 --- a/lib/python/Components/ChoiceList.py +++ b/lib/python/Components/ChoiceList.py @@ -1,20 +1,8 @@ from HTMLComponent import * from GUIComponent import * - from MenuList import MenuList - -from Tools.Directories import * - -from enigma import * - -RT_HALIGN_LEFT = 0 -RT_HALIGN_RIGHT = 1 -RT_HALIGN_CENTER = 2 -RT_HALIGN_BLOCK = 4 - -RT_VALIGN_TOP = 0 -RT_VALIGN_CENTER = 8 -RT_VALIGN_BOTTOM = 16 +from Tools.Directories import SCOPE_SKIN_IMAGE, resolveFilename +from enigma import RT_HALIGN_LEFT, eListboxPythonMultiContent, eListbox, gFont, loadPNG def ChoiceEntryComponent(key, text): res = [ text ] diff --git a/lib/python/Components/Clock.py b/lib/python/Components/Clock.py index 95f29b16..9a6031e6 100644 --- a/lib/python/Components/Clock.py +++ b/lib/python/Components/Clock.py @@ -2,10 +2,7 @@ from HTMLComponent import * from GUIComponent import * from VariableText import * -#from enigma import eTimer -#from enigma import eLabel - -from enigma import * +from enigma import eTimer, eLabel import time # now some "real" components: diff --git a/lib/python/Components/ConditionalWidget.py b/lib/python/Components/ConditionalWidget.py index 391b8871..7d35d956 100644 --- a/lib/python/Components/ConditionalWidget.py +++ b/lib/python/Components/ConditionalWidget.py @@ -1,7 +1,5 @@ -import skin from GUIComponent import * - -from enigma import * +from enigma import eTimer class ConditionalWidget(GUIComponent): def __init__(self, withTimer = True): @@ -61,7 +59,7 @@ class BlinkingWidget(GUIComponent): if self.visible: self.hide() self.timer.stop() - + class BlinkingWidgetConditional(BlinkingWidget, ConditionalWidget): def __init__(self): BlinkingWidget.__init__(self) diff --git a/lib/python/Components/EpgList.py b/lib/python/Components/EpgList.py index 902968d4..ca209bda 100644 --- a/lib/python/Components/EpgList.py +++ b/lib/python/Components/EpgList.py @@ -2,7 +2,9 @@ from HTMLComponent import * from GUIComponent import * -from enigma import * +from enigma import eEPGCache, eListbox, eListboxPythonMultiContent, gFont, loadPNG, \ + RT_HALIGN_LEFT, RT_HALIGN_RIGHT, RT_HALIGN_CENTER, RT_VALIGN_CENTER + from re import * from time import localtime, time from ServiceReference import ServiceReference @@ -12,17 +14,6 @@ EPG_TYPE_SINGLE = 0 EPG_TYPE_MULTI = 1 EPG_TYPE_SIMILAR = 2 -RT_HALIGN_LEFT = 0 -RT_HALIGN_RIGHT = 1 -RT_HALIGN_CENTER = 2 -RT_HALIGN_BLOCK = 4 - -RT_VALIGN_TOP = 0 -RT_VALIGN_CENTER = 8 -RT_VALIGN_BOTTOM = 16 - -RT_WRAP = 32 - class Rect: def __init__(self, x, y, width, height): self.__left = x diff --git a/lib/python/Components/FileList.py b/lib/python/Components/FileList.py index 7621ccb0..b85b8ea3 100644 --- a/lib/python/Components/FileList.py +++ b/lib/python/Components/FileList.py @@ -2,21 +2,14 @@ from HTMLComponent import * from GUIComponent import * import re +from os import path as os_path, listdir from MenuList import MenuList from Components.Harddisk import harddiskmanager -from Tools.Directories import * +from Tools.Directories import SCOPE_SKIN_IMAGE, resolveFilename -from enigma import * - -RT_HALIGN_LEFT = 0 -RT_HALIGN_RIGHT = 1 -RT_HALIGN_CENTER = 2 -RT_HALIGN_BLOCK = 4 - -RT_VALIGN_TOP = 0 -RT_VALIGN_CENTER = 8 -RT_VALIGN_BOTTOM = 16 +from enigma import RT_HALIGN_LEFT, loadPNG, eListbox, eListboxPythonMultiContent, \ + eServiceReference, eServiceCenter, gFont EXTENSIONS = { "mp3": "music", @@ -111,11 +104,11 @@ class FileList(MenuList, HTMLComponent, GUIComponent): directories.sort() files.sort() else: - files = os.listdir(directory) + files = listdir(directory) files.sort() tmpfiles = files[:] for x in tmpfiles: - if os.path.isdir(directory + x): + if os_path.isdir(directory + x): directories.append(directory + x + "/") files.remove(x) diff --git a/lib/python/Components/Harddisk.py b/lib/python/Components/Harddisk.py index f060c37a..fee1ed74 100644 --- a/lib/python/Components/Harddisk.py +++ b/lib/python/Components/Harddisk.py @@ -1,6 +1,6 @@ -import os +from os import system -from Tools.Directories import * +from Tools.Directories import SCOPE_HDD, resolveFilename def tryOpen(filename): try: @@ -105,7 +105,7 @@ class Harddisk: def unmount(self): cmd = "/bin/umount " + self.devidex + "part*" - res = os.system(cmd) + res = system(cmd) return (res >> 8) def createPartition(self): @@ -117,16 +117,16 @@ class Harddisk: def mkfs(self): cmd = "/sbin/mkfs.ext3 -T largefile -m0 " + self.devidex + "part1" - res = os.system(cmd) + res = system(cmd) return (res >> 8) def mount(self): cmd = "/bin/mount -t ext3 " + self.devidex + "part1 /hdd" - res = os.system(cmd) + res = system(cmd) return (res >> 8) def createMovieFolder(self): - res = os.system("mkdir " + resolveFilename(SCOPE_HDD)) + res = system("mkdir " + resolveFilename(SCOPE_HDD)) return (res >> 8) errorList = [ _("Everything is fine"), _("Creating partition failed"), _("Mkfs failed"), _("Mount failed"), _("Create movie folder failed"), _("Unmount failed")] diff --git a/lib/python/Components/Language.py b/lib/python/Components/Language.py index 1bbf0bc0..a27f247e 100644 --- a/lib/python/Components/Language.py +++ b/lib/python/Components/Language.py @@ -1,7 +1,6 @@ import gettext -import os -from Tools.Directories import * +from Tools.Directories import SCOPE_LANGUAGE, resolveFilename class Language: def __init__(self): diff --git a/lib/python/Components/LanguageList.py b/lib/python/Components/LanguageList.py index e625d7c7..e69de29b 100644 --- a/lib/python/Components/LanguageList.py +++ b/lib/python/Components/LanguageList.py @@ -1,41 +0,0 @@ -from HTMLComponent import * -from GUIComponent import * - -from MenuList import MenuList - -from Tools.Directories import * - -from enigma import * - -RT_HALIGN_LEFT = 0 -RT_HALIGN_RIGHT = 1 -RT_HALIGN_CENTER = 2 -RT_HALIGN_BLOCK = 4 - -RT_VALIGN_TOP = 0 -RT_VALIGN_CENTER = 8 -RT_VALIGN_BOTTOM = 16 - -def LanguageEntryComponent(file, name, index): - res = [ index ] - res.append((eListboxPythonMultiContent.TYPE_TEXT, 80, 10, 200, 50, 0, RT_HALIGN_LEFT ,name)) - png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "countries/" + file + ".png")) - if png == None: - png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "countries/missing.png")) - res.append((eListboxPythonMultiContent.TYPE_PIXMAP, 10, 5, 60, 40, png)) - - return res - -class LanguageList(MenuList, HTMLComponent, GUIComponent): - def __init__(self, list): - GUIComponent.__init__(self) - self.l = eListboxPythonMultiContent() - self.list = list - self.l.setList(list) - self.l.setFont(0, gFont("Regular", 20)) - - GUI_WIDGET = eListbox - - def postWidgetCreate(self, instance): - instance.setContent(self.l) - instance.setItemHeight(50) diff --git a/lib/python/Components/MediaPlayer.py b/lib/python/Components/MediaPlayer.py index d88b6280..44937fa3 100644 --- a/lib/python/Components/MediaPlayer.py +++ b/lib/python/Components/MediaPlayer.py @@ -3,19 +3,10 @@ from GUIComponent import * from MenuList import MenuList -from Tools.Directories import * -import os +from Tools.Directories import SCOPE_SKIN_IMAGE, resolveFilename +from os import path -from enigma import * - -RT_HALIGN_LEFT = 0 -RT_HALIGN_RIGHT = 1 -RT_HALIGN_CENTER = 2 -RT_HALIGN_BLOCK = 4 - -RT_VALIGN_TOP = 0 -RT_VALIGN_CENTER = 8 -RT_VALIGN_BOTTOM = 16 +from enigma import eListboxPythonMultiContent, eListbox, RT_VALIGN_CENTER, loadPNG, gFont STATE_PLAY = 0 STATE_PAUSE = 1 @@ -32,7 +23,7 @@ ForwardIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "ico_mp_forward.png")) def PlaylistEntryComponent(serviceref, state): res = [ serviceref ] - res.append((eListboxPythonMultiContent.TYPE_TEXT,25, 0, 470, 32, 0, RT_VALIGN_CENTER, os.path.split(serviceref.getPath().split('/')[-1])[1])) + res.append((eListboxPythonMultiContent.TYPE_TEXT,25, 0, 470, 32, 0, RT_VALIGN_CENTER, path.split(serviceref.getPath().split('/')[-1])[1])) png = None if state == STATE_PLAY: png = PlayIcon diff --git a/lib/python/Components/MovieList.py b/lib/python/Components/MovieList.py index 1da5a519..dcd99fea 100644 --- a/lib/python/Components/MovieList.py +++ b/lib/python/Components/MovieList.py @@ -1,13 +1,10 @@ from GUIComponent import * from Tools.FuzzyDate import FuzzyTime from ServiceReference import ServiceReference -from Components.MultiContent import MultiContentEntryText, RT_HALIGN_LEFT, RT_HALIGN_RIGHT +from Components.MultiContent import MultiContentEntryText -from enigma import eListboxPythonMultiContent, eListbox, gFont, iServiceInformation - -from enigma import eServiceReference, eServiceCenter, \ - eServiceCenterPtr, iListableServicePtr, \ - iStaticServiceInformationPtr +from enigma import eListboxPythonMultiContent, eListbox, gFont, iServiceInformation, \ + RT_HALIGN_LEFT, RT_HALIGN_RIGHT, eServiceReference, eServiceCenter class MovieList(GUIComponent): def __init__(self, root): diff --git a/lib/python/Components/MultiContent.py b/lib/python/Components/MultiContent.py index 06ecde96..3031fb3a 100644 --- a/lib/python/Components/MultiContent.py +++ b/lib/python/Components/MultiContent.py @@ -1,15 +1,4 @@ -RT_HALIGN_LEFT = 0 -RT_HALIGN_RIGHT = 1 -RT_HALIGN_CENTER = 2 -RT_HALIGN_BLOCK = 4 - -RT_VALIGN_TOP = 0 -RT_VALIGN_CENTER = 8 -RT_VALIGN_BOTTOM = 16 - -RT_WRAP = 32 - -from enigma import eListboxPythonMultiContent +from enigma import eListboxPythonMultiContent, RT_HALIGN_LEFT, RT_VALIGN_TOP def MultiContentEntryText(pos = (0, 0), size = (0, 0), font = 0, flags = RT_HALIGN_LEFT | RT_VALIGN_TOP, text = "", color = None): add = () diff --git a/lib/python/Components/Network.py b/lib/python/Components/Network.py index 5add0c01..f65863dc 100644 --- a/lib/python/Components/Network.py +++ b/lib/python/Components/Network.py @@ -81,14 +81,12 @@ class Network: print "[Network.py] parsing network failed" def deactivateNetworkConfig(self): - import os os.system("ip addr flush eth0") os.system("/etc/init.d/networking stop") os.system("killall -9 udhcpc") os.system("rm /var/run/udhcpc*") def activateNetworkConfig(self): - import os os.system("/etc/init.d/networking start") config.network.ip.value = self.getCurrentIP() config.network.ip.save() diff --git a/lib/python/Components/ParentalControlList.py b/lib/python/Components/ParentalControlList.py index 9791e1b0..02e88002 100644 --- a/lib/python/Components/ParentalControlList.py +++ b/lib/python/Components/ParentalControlList.py @@ -3,18 +3,9 @@ from GUIComponent import * from MenuList import MenuList from Components.ParentalControl import parentalControl -from Tools.Directories import * +from Tools.Directories import SCOPE_SKIN_IMAGE, resolveFilename -from enigma import * - -RT_HALIGN_LEFT = 0 -RT_HALIGN_RIGHT = 1 -RT_HALIGN_CENTER = 2 -RT_HALIGN_BLOCK = 4 - -RT_VALIGN_TOP = 0 -RT_VALIGN_CENTER = 8 -RT_VALIGN_BOTTOM = 16 +from enigma import loadPNG, eListbox, eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT lockPicture = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "lock-fs8.png")) diff --git a/lib/python/Components/PluginComponent.py b/lib/python/Components/PluginComponent.py index 120b4636..9425e56d 100644 --- a/lib/python/Components/PluginComponent.py +++ b/lib/python/Components/PluginComponent.py @@ -1,8 +1,8 @@ -import os -import traceback -import sys +from os import path as os_path, listdir as os_listdir +from traceback import print_exc +from sys import stdout -from Tools.Directories import * +from Tools.Directories import fileExists from Tools.Import import my_import from Plugins.Plugin import PluginDescriptor @@ -33,18 +33,18 @@ class PluginComponent: def readPluginList(self, directory): """enumerates plugins""" - categories = os.listdir(directory) + categories = os_listdir(directory) new_plugins = [ ] for c in categories: directory_category = directory + c - if not os.path.isdir(directory_category): + if not os_path.isdir(directory_category): continue open(directory_category + "/__init__.py", "a").close() - for pluginname in os.listdir(directory_category): + for pluginname in os_listdir(directory_category): path = directory_category + "/" + pluginname - if os.path.isdir(path): + if os_path.isdir(path): if fileExists(path + "/plugin.pyc") or fileExists(path + "/plugin.py"): try: plugin = my_import('.'.join(["Plugins", c, pluginname, "plugin"])) @@ -56,7 +56,7 @@ class PluginComponent: plugins = plugin.Plugins(path=path) except Exception, exc: print "Plugin ", c + "/" + pluginname, "failed to load:", exc - traceback.print_exc(file=sys.stdout) + print_exc(file=stdout) print "skipping plugin." self.warnings.append( (c + "/" + pluginname, str(exc)) ) continue diff --git a/lib/python/Components/PluginList.py b/lib/python/Components/PluginList.py index 9b9cfea8..fd988065 100644 --- a/lib/python/Components/PluginList.py +++ b/lib/python/Components/PluginList.py @@ -4,9 +4,9 @@ from GUIComponent import * from MenuList import MenuList from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE -from Components.MultiContent import RT_HALIGN_LEFT, MultiContentEntryText, MultiContentEntryPixmapAlphaTest +from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmapAlphaTest -from enigma import * +from enigma import loadPNG, eListboxPythonMultiContent, RT_HALIGN_LEFT, eListbox, gFont def PluginEntryComponent(plugin): res = [ plugin ] diff --git a/lib/python/Components/RFmod.py b/lib/python/Components/RFmod.py index 234ae4ca..0ab4a815 100644 --- a/lib/python/Components/RFmod.py +++ b/lib/python/Components/RFmod.py @@ -1,5 +1,5 @@ -from config import * -from enigma import * +from config import config, ConfigSelection, ConfigSubsection, ConfigOnOff, ConfigSlider +from enigma import eRFmod # CHECK ME. RFMOD_CHANNEL_MIN = 21 @@ -24,7 +24,7 @@ class RFmod: def InitRFmod(): - config.rfmod = ConfigSubsection(); + config.rfmod = ConfigSubsection() config.rfmod.enable = ConfigOnOff(default=False) config.rfmod.test = ConfigOnOff(default=False) config.rfmod.sound = ConfigOnOff(default=True) diff --git a/lib/python/Components/ServiceList.py b/lib/python/Components/ServiceList.py index 6145adef..c2d58f2f 100644 --- a/lib/python/Components/ServiceList.py +++ b/lib/python/Components/ServiceList.py @@ -1,7 +1,7 @@ from HTMLComponent import * from GUIComponent import * -from enigma import * +from enigma import loadPNG, eListboxServiceContent, eListbox, eServiceCenter, eServiceReference, gFont, eRect from string import upper diff --git a/lib/python/Components/ServicePosition.py b/lib/python/Components/ServicePosition.py index d34d81fb..6f7082d5 100644 --- a/lib/python/Components/ServicePosition.py +++ b/lib/python/Components/ServicePosition.py @@ -1,6 +1,6 @@ from PerServiceDisplay import PerServiceDisplay, PerServiceBase from Components.GUIComponent import GUIComponent -from enigma import eTimer, iPlayableService, iSeekableServicePtr, ePositionGauge +from enigma import eTimer, iPlayableService, ePositionGauge import time class ServicePosition(PerServiceDisplay, object): diff --git a/lib/python/Components/TimerList.py b/lib/python/Components/TimerList.py index 2f60fcfb..d2ccbb9c 100644 --- a/lib/python/Components/TimerList.py +++ b/lib/python/Components/TimerList.py @@ -4,22 +4,11 @@ from GUIComponent import * from Tools.FuzzyDate import FuzzyTime import time -from enigma import eListboxPythonMultiContent, eListbox, gFont, loadPNG +from enigma import eListboxPythonMultiContent, eListbox, gFont, loadPNG, \ + RT_HALIGN_CENTER, RT_HALIGN_LEFT, RT_HALIGN_RIGHT, RT_VALIGN_CENTER from timer import TimerEntry from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE -RT_HALIGN_LEFT = 0 -RT_HALIGN_RIGHT = 1 -RT_HALIGN_CENTER = 2 -RT_HALIGN_BLOCK = 4 - -RT_VALIGN_TOP = 0 -RT_VALIGN_CENTER = 8 -RT_VALIGN_BOTTOM = 16 - -RT_WRAP = 32 - - # # | | # | | diff --git a/lib/python/Components/Timezones.py b/lib/python/Components/Timezones.py index 704b765e..ccc98279 100644 --- a/lib/python/Components/Timezones.py +++ b/lib/python/Components/Timezones.py @@ -4,8 +4,6 @@ from xml.sax.handler import ContentHandler import os import time -from enigma import * - class Timezones: class parseTimezones(ContentHandler): def __init__(self, timezones): @@ -42,7 +40,8 @@ class Timezones: try: time.tzset() except: - etimezone() + from enigma import e_tzset + e_tzset() def getTimezoneList(self): list = [] diff --git a/lib/python/Components/components.py b/lib/python/Components/components.py index 512defb5..87159bf6 100644 --- a/lib/python/Components/components.py +++ b/lib/python/Components/components.py @@ -1,4 +1,3 @@ -from enigma import * import time import sys -- cgit v1.2.3