Skip to content

Commit 70219d8

Browse files
committed
checks for config; might work with python 2.6; stops audio on back button
1 parent 3ddd653 commit 70219d8

File tree

3 files changed

+56
-23
lines changed

3 files changed

+56
-23
lines changed

TO_DO_s.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,26 @@
77
List of bugs/features to be implemented
88
'''
99

10+
11+
#TODO: stop function when clicking "back"
12+
1013
'''general'''
1114

12-
# text to speech?
1315

14-
# avbin support?
15-
#from pyglet.media import avbin
16+
# VLC as standard - but windows media player as backup?
17+
# remove unnecessary VLC stuff to keep size down
18+
19+
1620

1721

1822
'''features '''
1923
# change system volume instead of program volume only
2024

21-
# play mp3 and other sound files
22-
2325
# play videos?
2426

27+
28+
# text to speech?
29+
2530
# make config file changeable by the program, with default config file to "reset" config file.
2631
# default config file to be included in the exe, the other to live outside.
2732

talkshow.py

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
11
import os
22
import math
33
import glob
4-
import subprocess
4+
import sys
55

66
from talkshowLogger import logger
7+
# function alias
8+
debug = logger.debug
9+
info = logger.info
10+
warn = logger.warn
11+
error = logger.error
12+
info("Initialising talkshow. Version of Python: %s" % str(sys.version))
13+
14+
try:
15+
import pyglet
16+
info("pyglet seems installed and working fine.")
17+
except:
18+
logger.error("Pyglet (a python library) is not installed. Talkshow cannot work. Please install pyglet")
19+
20+
try:
21+
import tinycss
22+
info("tinyCSS seems installed and working fine.")
23+
except:
24+
logger.error("TinyCSS (a python library) is not installed. Talkshow cannot work. Please install tinyCSS")
25+
26+
try:
27+
import vlc
28+
vlc_test_instance = vlc.Instance()
29+
info("VLC seems available and working fine. Audio playback should work.")
30+
except:
31+
logger.error("There is a problem with VLC. Either you are using the wrong version of talkshow (32/64 bit), or there is a bug in the code, or you can try and install VLC.")
32+
733
try:
834
import CommandBar
935
from wrappers import *
@@ -16,14 +42,10 @@
1642
from vlcPlayer import vlcPlayer
1743

1844
except Exception as e:
19-
logger.exception("exception! Details: {}".format(e))
45+
logger.exception("exception! Details: {0}".format(e))
2046
raise
2147

22-
# function alias
23-
debug = logger.debug
24-
info = logger.info
25-
warn = logger.warn
26-
error = logger.error
48+
2749

2850

2951

@@ -305,13 +327,13 @@ def initializeConfig(self):
305327
CONTENT_DIRECTORY = self.config.CONTENT_DIRECTORY
306328
return
307329
possible_content_paths = ["Content", "content", "Inhalt", "inhalt"]
308-
warn("{} is not a valid content directory.".format(os.path.abspath(self.config.CONTENT_DIRECTORY)))
330+
warn("{0} is not a valid content directory.".format(os.path.abspath(self.config.CONTENT_DIRECTORY)))
309331
for path in possible_content_paths:
310332
if os.path.isdir(path):
311-
info("setting content Path to : {}".format(os.path.abspath(path)))
333+
info("setting content Path to : {0}".format(os.path.abspath(path)))
312334
self.config.CONTENT_DIRECTORY = os.path.abspath(path)
313335
return
314-
error("{} is not a valid content directory.".format(os.path.abspath(self.config.CONTENT_DIRECTORY)))
336+
error("{0} is not a valid content directory.".format(os.path.abspath(self.config.CONTENT_DIRECTORY)))
315337

316338

317339
def onResize(self, width, height):
@@ -453,7 +475,7 @@ def quit(self):
453475
try:
454476
self.PlaybakcProc.terminate()
455477
except Exception as e:
456-
logger.exception("Could not kill media player process... {}".format(e))
478+
logger.exception("Could not kill media player process... {0}".format(e))
457479
warn( "some process might not have exited! Use your task manager to kill the wmplayer.exe process if needed. ")
458480
sys.exit(0)
459481

@@ -484,7 +506,7 @@ def onFieldClicked(self, f):
484506
#self.playPath_AudioRecorder(self.pathPrefix + self.pathForField(f.index))
485507

486508
def iconForPath(self, path):
487-
images = glob.globl(path, "*.png")
509+
images = glob.glob(str(path)+os.sep+ "*.png")
488510
if images:
489511
path = normalizePath(images[0])
490512
i = wrappers.Image(None, path, path)
@@ -515,12 +537,12 @@ def playPath(self, path):
515537
mediaFiles += glob.glob1(path, pattern)
516538

517539
debug(path)
518-
debug("audio files under {}: {}. Playing the first one if there is one...".format(path, mediaFiles))
540+
debug("audio files under {0}: {1}. Playing the first one if there is one...".format(path, mediaFiles))
519541

520542
if mediaFiles:
521543
self.player.play(os.path.join(path, mediaFiles[0]))
522544
else:
523-
info("no media file found under {}".format(path))
545+
info("no media file found under {0}".format(path))
524546

525547

526548

@@ -546,6 +568,8 @@ def volumeUp(self):
546568
self.setVolume(self.volume + self.volumeIncrease)
547569

548570
def back(self):
571+
572+
self.player.stop()
549573
l = self.path.split("/")
550574

551575
if l:
@@ -597,7 +621,7 @@ def gridFromPath(self, color_and_path = None):
597621
self.PlaybackCommand(path[path.rfind('/')+1:],self.PlaybakcProc)
598622

599623

600-
debug("prefix=[{}] path =[{}]".format(self.pathPrefix, self.path))
624+
debug("prefix=[{0}] path =[{1}]".format(self.pathPrefix, self.path))
601625
debug(self.pathPrefix + path)
602626

603627
self.items = self.subdirs(self.pathPrefix, self.path)
@@ -830,5 +854,5 @@ def main():
830854
main()
831855
except Exception as e:
832856
#log all and any exceptions to file
833-
logger.exception("exception! {}".format(e))
857+
logger.exception("exception! {0}".format(e))
834858
raise

vlcPlayer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ def __init__(self):
2323
self.player = self.instance.media_player_new()
2424

2525

26+
def stop(self):
27+
self.player.stop()
28+
29+
2630
def play(self, path_to_media_file):
2731
if not os.path.isfile(path_to_media_file):
28-
warn("This file: {} does not exist. Full path: {}".format(path_to_media_file, os.path.abspath(path_to_media_file)))
32+
warn("This file: {0} does not exist. Full path: {1}".format(path_to_media_file, os.path.abspath(path_to_media_file)))
2933
return
3034
try:
3135
media = self.instance.media_new(path_to_media_file)
3236
except Exception as e:
33-
logger.exception("exception! {}".format(e))
37+
logger.exception("exception! {0}".format(e))
3438
warn('NameError: %s (LibVLC %s)' % (sys.exc_info()[1],vlc.libvlc_get_version()))
3539
self.player.set_media(media)
3640
self.player.play()

0 commit comments

Comments
 (0)