| |
- __builtin__.object
-
- MPlayer
- asynchat.async_chat(asyncore.dispatcher)
-
- Client
- asyncore.dispatcher
-
- Server
class Client(asynchat.async_chat) |
|
Client()
The PyMPlayer Client |
|
- Method resolution order:
- Client
- asynchat.async_chat
- asyncore.dispatcher
Methods defined here:
- __init__(self)
- collect_incoming_data(self, data)
- connect(self, host, port=50001)
- Connect to a pymplayer.Server
@param host: host to connect to
@param port: port to use
pymplayer.loop should be called (if not called previously)
after calling this method.
- found_terminator(self)
- handle_data(self, data)
- handle_error(self)
- send_command(self, cmd)
- Send an MPlayer command to the server
@param cmd: valid MPlayer command
Valid MPlayer commands are documented in:
http://www.mplayerhq.hu/DOCS/tech/slave.txt
Static methods defined here:
- handle_connect()
Data and other attributes defined here:
- ac_in_buffer_size = 512
- ac_out_buffer_size = 256
Methods inherited from asynchat.async_chat:
- close_when_done(self)
- automatically close this channel once the outgoing queue is empty
- discard_buffers(self)
- get_terminator(self)
- handle_close(self)
- handle_read(self)
- handle_write(self)
- initiate_send(self)
- push(self, data)
- push_with_producer(self, producer)
- readable(self)
- predicate for inclusion in the readable for select()
- refill_buffer(self)
- # refill the outgoing buffer by calling the more() method
# of the first producer in the queue
- set_terminator(self, term)
- Set the input delimiter. Can be a fixed string of any length, an integer, or None
- writable(self)
- predicate for inclusion in the writable for select()
Methods inherited from asyncore.dispatcher:
- __getattr__(self, attr)
- # cheap inheritance, used to pass all other attribute
# references to the underlying socket object.
- __repr__(self)
- accept(self)
- add_channel(self, map=None)
- bind(self, addr)
- close(self)
- create_socket(self, family, type)
- del_channel(self, map=None)
- handle_accept(self)
- handle_expt(self)
- handle_expt_event(self)
- handle_read_event(self)
- handle_write_event(self)
- listen(self, num)
- log(self, message)
- log_info(self, message, type='info')
- recv(self, buffer_size)
- send(self, data)
- set_reuse_addr(self)
- set_socket(self, sock, map=None)
Data and other attributes inherited from asyncore.dispatcher:
- accepting = False
- addr = None
- closing = False
- connected = False
- debug = False
|
class MPlayer(__builtin__.object) |
|
MPlayer(args=())
An out-of-process wrapper for MPlayer. It provides the basic interface
for sending commands and receiving responses to and from MPlayer. Take
note that MPlayer is always started in 'slave', 'idle', and 'quiet' modes.
The MPlayer process would eventually "freeze" if the poll_output method
is not called because the stdout/stderr PIPE buffers would get full.
Also, the handle_data and handle_error methods would only get called,
given an I/O event, after the poll_output method is called.
A different 'I/O watcher' can be used by overriding the create_handler
and remove_handler methods.
@class attribute bin: path to or filename of the MPlayer executable
@property args: MPlayer arguments |
|
Methods defined here:
- __del__(self)
- __init__(self, args=())
- command(self, cmd, timeout=0.10000000000000001)
- Send a command to MPlayer.
@param cmd: command string
@param timeout: time to wait before returning command output
Returns the output if command is a valid get_* command.
Else, None is returned.
Valid MPlayer commands are documented in:
http://www.mplayerhq.hu/DOCS/tech/slave.txt
- create_handler(self, file, callback)
- Create a handler for file.
@param file: file-like object
@param callback: function to be called when data can be read from file
This method may be overridden like so:
PyGTK/PyGObject:
self.handles[file] = gobject.io_add_watch(file, gobject.IO_IN|gobject.IO_PRI, callback)
Tkinter:
tkinter.createfilehandler(file, tkinter.READABLE, callback)
- isalive(self)
- Check if MPlayer process is alive.
Returns True if alive, else, returns False.
- poll_output(self, timeout=30.0, use_poll=False)
- Start polling MPlayer's stdout and stderr.
@param timeout=30.0: timeout parameter for select() or poll()
@param use_poll=False: use poll() instead of select()
This method will block unless it is called before MPlayer is
started or if the MPlayer process is currently not running.
This method need not be called when the create_handler and/or
remove_handler methods are overridden for use with a certain
GUI toolkit (e.g. PyGTK, Tkinter).
In a multithreaded app, you may want to spawn a new Thread
for running this method after calling the start method:
mplayer = MPlayer()
mplayer.start()
thread = threading.Thread(target=mplayer.poll_output)
thread.setDaemon(True)
thread.start()
- remove_handler(self, file)
- Remove a handler for file.
@param file: file-like object
This method may be overridden like so:
PyGTK/PyGObject:
gobject.source_remove(self.handles.pop(file))
Tkinter:
tkinter.deletefilehandler(file)
- restart(self)
- Convenience method for restarting the MPlayer process.
Restarting MPlayer means stopping the current process and
starting a new one which means that the poll_output method
will finish and return and will need to be called again.
Returns the return values of the stop and start methods as a 2-tuple.
- start(self)
- Start the MPlayer process.
Returns True on success, False on failure,
and None if MPlayer is already running.
- stop(self)
- Stop the MPlayer process.
Returns the exit status of MPlayer or None if not running.
Static methods defined here:
- handle_data(data)
- Handle the data read from stdout.
This method is meant to be overridden.
It will be called for each readline() from stdout.
@param data: the line read from stdout
- handle_error(data)
- Handle the data read from stderr.
This method is meant to be overridden.
It will be called for each readline() from stderr.
@param data: the line read from stderr
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- args
- MPlayer arguments
Data and other attributes defined here:
- bin = 'mplayer'
|
class Server(asyncore.dispatcher) |
|
Server(host='', port=pymplayer.PORT, max_conn=1)
Although this class isn't a subclass of MPlayer, all of MPlayer's
methods (except poll_output) and properties are exposed via
the __getattr__ method. The MPlayer properties function and
behave properly via some __getattr__ and __setattr__ magic.
The log method can be overridden to provide more sophisticated
logging and warning methods. |
|
Methods defined here:
- __del__(self)
- __getattr__(self, attr)
- __init__(self, host='', port=50001, max_conn=1)
- __setattr__(self, attr, value)
- handle_accept(self)
- handle_close(self)
- start(self, timeout=30.0, use_poll=False)
- Start the server.
@param timeout=30.0: timeout parameter for select() or poll()
@param use_poll=False: use poll() instead of select()
Starts the MPlayer process, then calls asyncore.loop (blocking)
- stop(self)
- Stop the server.
Closes all the channels found in self._map (including itself)
Static methods defined here:
- writable()
Methods inherited from asyncore.dispatcher:
- __repr__(self)
- accept(self)
- add_channel(self, map=None)
- bind(self, addr)
- close(self)
- connect(self, address)
- create_socket(self, family, type)
- del_channel(self, map=None)
- handle_connect(self)
- handle_error(self)
- handle_expt(self)
- handle_expt_event(self)
- handle_read(self)
- handle_read_event(self)
- handle_write(self)
- handle_write_event(self)
- listen(self, num)
- log(self, message)
- log_info(self, message, type='info')
- readable(self)
- recv(self, buffer_size)
- send(self, data)
- set_reuse_addr(self)
- set_socket(self, sock, map=None)
Data and other attributes inherited from asyncore.dispatcher:
- accepting = False
- addr = None
- closing = False
- connected = False
- debug = False
| |