Commit 4043a1ce authored by Olivier Aubert's avatar Olivier Aubert

python-ctypes: fix pylint/pyflakes warnings

parent f6cfac86
......@@ -11,5 +11,9 @@ doc: $(MODULE_NAME)
test: $(MODULE_NAME)
python test.py
check: $(MODULE_NAME)
-pyflakes $<
-pylint $<
clean:
-$(RM) $(MODULE_NAME)
......@@ -44,7 +44,6 @@ def debug_callback(event, data):
print "Data", data
if __name__ == '__main__':
import sys
try:
from msvcrt import getch
except ImportError:
......@@ -66,47 +65,44 @@ if __name__ == '__main__':
sys.exit(0)
if sys.argv[1:]:
if sys.platform == 'win32' and plugin_path is not None:
i=Instance('--plugin-path', plugin_path)
else:
i=Instance()
m=i.media_new(sys.argv[1])
p=i.media_player_new()
p.set_media(m)
p.play()
e=p.event_manager()
e.event_attach(EventType.MediaPlayerEndReached, end_callback, None)
instance=Instance()
media=instance.media_new(sys.argv[1])
player=instance.media_player_new()
player.set_media(media)
player.play()
event_manager=player.event_manager()
event_manager.event_attach(EventType.MediaPlayerEndReached, end_callback, None)
def print_info():
"""Print information about the media."""
m=p.get_media()
print "State:", p.get_state()
print "Media:", m.get_mrl()
media=player.get_media()
print "State:", player.get_state()
print "Media:", media.get_mrl()
try:
print "Current time:", p.get_time(), "/", m.get_duration()
print "Position:", p.get_position()
print "FPS:", p.get_fps()
print "Rate:", p.get_rate()
print "Video size: (%d, %d)" % (p.video_get_width(), p.video_get_height())
print "Current time:", player.get_time(), "/", media.get_duration()
print "Position:", player.get_position()
print "FPS:", player.get_fps()
print "Rate:", player.get_rate()
print "Video size: (%d, %d)" % (player.video_get_width(), player.video_get_height())
except Exception:
pass
def forward():
"""Go forward 1s"""
p.set_time(p.get_time() + 1000)
player.set_time(player.get_time() + 1000)
def one_frame_forward():
"""Go forward one frame"""
p.set_time(p.get_time() + long(1000 / (p.get_fps() or 25)))
player.set_time(player.get_time() + long(1000 / (player.get_fps() or 25)))
def one_frame_backward():
"""Go backward one frame"""
p.set_time(p.get_time() - long(1000 / (p.get_fps() or 25)))
player.set_time(player.get_time() - long(1000 / (player.get_fps() or 25)))
def backward():
"""Go backward 1s"""
p.set_time(p.get_time() - 1000)
player.set_time(player.get_time() - 1000)
def print_help():
"""Print help
......@@ -116,20 +112,20 @@ if __name__ == '__main__':
print " %s: %s" % (k, (m.__doc__ or m.__name__).splitlines()[0])
print " 1-9: go to the given fraction of the movie"
def quit():
def quit_app():
"""Exit."""
sys.exit(0)
keybindings={
'f': p.toggle_fullscreen,
' ': p.pause,
'f': player.toggle_fullscreen,
' ': player.pause,
'+': forward,
'-': backward,
'.': one_frame_forward,
',': one_frame_backward,
'?': print_help,
'i': print_info,
'q': quit,
'q': quit_app,
}
print "Press q to quit, ? to get help."
......@@ -142,6 +138,6 @@ if __name__ == '__main__':
elif o >= 49 and o <= 57:
# Numeric value. Jump to a fraction of the movie.
v=0.1*(o-48)
p.set_position(v)
player.set_position(v)
......@@ -604,7 +604,8 @@ class PythonGenerator(object):
if classname in docstring:
self.output(' """%s\n """' % docstring[classname])
self.output("""
if not 'def __new__' in overrides.get(classname, ''):
self.output("""
def __new__(cls, pointer=None):
'''Internal method used for instanciating wrappers from ctypes.
'''
......@@ -616,13 +617,15 @@ class PythonGenerator(object):
o=object.__new__(cls)
o._as_parameter_=ctypes.c_void_p(pointer)
return o
""")
self.output("""
@staticmethod
def from_param(arg):
'''(INTERNAL) ctypes parameter conversion method.
'''
return arg._as_parameter_
""" % {'name': classname})
""")
if classname in overrides:
self.output(overrides[classname])
......
......@@ -103,7 +103,7 @@ class ListPOINTER(object):
self.etype = etype
def from_param(self, param):
if isinstance(param, (list,tuple)):
if isinstance(param, (list, tuple)):
return (self.etype * len(param))(*param)
class LibVLCException(Exception):
......@@ -170,6 +170,7 @@ class LogMessage(ctypes.Structure):
]
def __init__(self):
super(LogMessage, self).__init__()
self.size=ctypes.sizeof(self)
def __str__(self):
......@@ -187,6 +188,7 @@ class MediaControlPosition(ctypes.Structure):
# class with an int as parameter will create the appropriate
# default position (absolute position, media time, with the
# int as value).
super(MediaControlPosition, self).__init__()
self.value=value
if origin is None:
origin=PositionOrigin.AbsolutePosition
......@@ -205,8 +207,7 @@ class MediaControlPosition(ctypes.Structure):
@staticmethod
def from_param(arg):
if isinstance(arg, (int, long)):
p=MediaControlPosition(arg)
return p
return MediaControlPosition(arg)
else:
return arg
......
......@@ -144,7 +144,7 @@ class MediaControl:
@param end: the end position
"""
if not isinstance(begin, MediaControlPosition):
begin=self.value2position(pos)
begin=self.value2position(begin)
if not isinstance(end, MediaControlPosition):
end=self.value2position(end)
e=MediaControlException()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment