changed imports to import from

This commit is contained in:
Fredrick W. Warren 2024-09-10 12:00:47 -06:00
parent 26de7e1d61
commit 03ca9b0a48

View File

@ -2,14 +2,20 @@
"""pywmnop.py
WindowMaker dockapp doing nothing
WindowMaker dockapp internet radio player
Copyright (C) 2006 Mario Frasca
Licensed under the GNU General Public License.
"""
import sys, time
from codecs import open
from fcntl import fcntl, F_GETFL, F_SETFL
from os import environ, sep, O_NONBLOCK
from re import compile
from select import select
from signal import signal, SIGCHLD
from subprocess import Popen, DEVNULL, PIPE
from wmdocklib import wmoo as wmoo
class Application(wmoo.Application):
@ -33,14 +39,11 @@ class Application(wmoo.Application):
self.reset()
self._buffered = ''
import re
self._feedback = re.compile(r'.+A:.*?% ([0-9\.]+)%')
self._feedback = compile(r'.+A:.*?% ([0-9\.]+)%')
import fileinput, os
configfile = os.sep.join([os.environ['HOME'], '.pyradiorc'])
configfile = sep.join([environ['HOME'], '.pyradiorc'])
import codecs
f = codecs.open(configfile, 'r', 'utf-8')
f = open(configfile, 'r', 'utf-8')
t = f.read()
f.close()
for i in t.split(u'\n'):
@ -57,7 +60,6 @@ class Application(wmoo.Application):
def handler(self, num, frame):
if self._expectdying:
print(self._expectdying)
self._expectdying -= 1
else:
self.reset()
@ -65,37 +67,41 @@ class Application(wmoo.Application):
self._colour = 1
def startPlayer(self):
import os, subprocess, signal
commandline = [mplayer,
'-cache', self.radioList[self.currentRadio][2],
'-cache',
str(abs(int(self.radioList[self.currentRadio][2]))),
self.radioList[self.currentRadio][1]
]
self.child = subprocess.Popen(commandline,
stdin =subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
signal.signal(signal.SIGCHLD, self.handler)
# if cache is negative then this is a playlist
if int(self.radioList[self.currentRadio][2]) < 0:
commandline.insert(2, '-playlist')
self.child = Popen(commandline,
stdin =PIPE,
stdout=PIPE,
stderr=DEVNULL)
signal(SIGCHLD, self.handler)
self._flash = 0
self._paused = False
self._buffered = ''
self._buffering = 1
self._cacheLevel = 0
import fcntl
flags = fcntl.fcntl(self.child.stdout, fcntl.F_GETFL)
fcntl.fcntl(self.child.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
flags = fcntl.fcntl(self.child.stdin, fcntl.F_GETFL)
fcntl.fcntl(self.child.stdin, fcntl.F_SETFL, flags | os.O_NONBLOCK)
flags = fcntl(self.child.stdout, F_GETFL)
fcntl(self.child.stdout, F_SETFL, flags | O_NONBLOCK)
flags = fcntl(self.child.stdin, F_GETFL)
fcntl(self.child.stdin, F_SETFL, flags | O_NONBLOCK)
def stopPlayer(self):
if self.child:
print(self._expectdying)
# print(self._expectdying)
self.child.stdin.write(b'q')
self.child.stdin.flush()
self._expectdying += 1
self.child = None
def muteStream(self, event):
if self.child and self._buffering == 0:
self.child.stdin.write(b'm')
self.child.stdin.flush()
self.putPattern(9*self._muting, 0, 9, 11, 30, 29)
self._muting = 1 - self._muting
@ -128,6 +134,7 @@ class Application(wmoo.Application):
def pauseStream(self, event):
if self.child and not self._buffering:
self.child.stdin.write(b' ')
self.child.stdin.flush()
self._paused = not self._paused
if self._paused:
self._colour = 1
@ -163,8 +170,7 @@ class Application(wmoo.Application):
return
self._count = 0
if self.child:
import select
[i, o, e] = select.select([self.child.stdout], [], [], 0)
[i, o, e] = select([self.child.stdout], [], [], 0)
if i:
line = self.child.stdout.read(102400).decode("utf-8")
self._buffered += line