| |
- threading.Thread(threading._Verbose)
-
- AutoAdvance
- ImageDisplay
- SaveState
- UserInput
class AutoAdvance(threading.Thread) |
|
Automatically advances the slideshow.
Has a default waiting time, on top of which the score will be used to determine display time.
Has two functions, __init__, and run. |
|
- Method resolution order:
- AutoAdvance
- threading.Thread
- threading._Verbose
- __builtin__.object
Methods defined here:
- run(self)
- Advances the slideshow.
Displays the next image, then sleeps for n seconds (user specified, default 10).
Then sleeps for between 0 and 10 seconds depending on the score of the image.
Checks ten times a second to see whether we're done here.
Data and other attributes defined here:
- begin = False
- imageDisplay = None
- quit = False
- scroll = True
- time = 10.0
Methods inherited from threading.Thread:
- __init__(self, group=None, target=None, name=None, args=(), kwargs=None, verbose=None)
- This constructor should always be called with keyword arguments. Arguments are:
*group* should be None; reserved for future extension when a ThreadGroup
class is implemented.
*target* is the callable object to be invoked by the run()
method. Defaults to None, meaning nothing is called.
*name* is the thread name. By default, a unique name is constructed of
the form "Thread-N" where N is a small decimal number.
*args* is the argument tuple for the target invocation. Defaults to ().
*kwargs* is a dictionary of keyword arguments for the target
invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke
the base class constructor (Thread.__init__()) before doing anything
else to the thread.
- __repr__(self)
- getName(self)
- isAlive(self)
- Return whether the thread is alive.
This method returns True just before the run() method starts until just
after the run() method terminates. The module function enumerate()
returns a list of all alive threads.
- isDaemon(self)
- is_alive = isAlive(self)
- Return whether the thread is alive.
This method returns True just before the run() method starts until just
after the run() method terminates. The module function enumerate()
returns a list of all alive threads.
- join(self, timeout=None)
- Wait until the thread terminates.
This blocks the calling thread until the thread whose join() method is
called terminates -- either normally or through an unhandled exception
or until the optional timeout occurs.
When the timeout argument is present and not None, it should be a
floating point number specifying a timeout for the operation in seconds
(or fractions thereof). As join() always returns None, you must call
isAlive() after join() to decide whether a timeout happened -- if the
thread is still alive, the join() call timed out.
When the timeout argument is not present or None, the operation will
block until the thread terminates.
A thread can be join()ed many times.
join() raises a RuntimeError if an attempt is made to join the current
thread as that would cause a deadlock. It is also an error to join() a
thread before it has been started and attempts to do so raises the same
exception.
- setDaemon(self, daemonic)
- setName(self, name)
- start(self)
- Start the thread's activity.
It must be called at most once per thread object. It arranges for the
object's run() method to be invoked in a separate thread of control.
This method will raise a RuntimeError if called more than once on the
same thread object.
Data descriptors inherited from threading.Thread:
- daemon
- A boolean value indicating whether this thread is a daemon thread (True) or not (False).
This must be set before start() is called, otherwise RuntimeError is
raised. Its initial value is inherited from the creating thread; the
main thread is not a daemon thread and therefore all threads created in
the main thread default to daemon = False.
The entire Python program exits when no alive non-daemon threads are
left.
- ident
- Thread identifier of this thread or None if it has not been started.
This is a nonzero integer. See the thread.get_ident() function. Thread
identifiers may be recycled when a thread exits and another thread is
created. The identifier is available even after the thread has exited.
- name
- A string used for identification purposes only.
It has no semantics. Multiple threads may be given the same name. The
initial name is set by the constructor.
Data descriptors inherited from threading._Verbose:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class ImageDisplay(threading.Thread) |
|
For all your image displaying needs.
Has 6 functions, __init__, display, next, previous, putscore and score.
Defines the server location. |
|
- Method resolution order:
- ImageDisplay
- threading.Thread
- threading._Verbose
- __builtin__.object
Methods defined here:
- __init__(self)
- Called once on thread creation.
Extends Thread.__init__.
Finds the maximum image stored on the server and puts it in a variable for safe keeping.
The readline will be of the form 'xx\n', so we split it (to remove the newline) and convert to integer.
- display(self, imageNo)
- Display the image in the browser.
Lets the user know which image we're displaying.
Sets the image number for future reference.
Asks the webbrowser to display the image thank you very much.
No way to interact with the webbrowser, alas.
- next(self)
- Next image.
If we have never seen an image before, starts at number 1.
If we have got to the end of the images, goes back to number 1 (and tell the user).
Otherwise, goes to the next image.
Asks itself to display the image it has thus selected.
- previous(self)
- Previous image.
If we have never seen an image before, starts at the end.
If we have got to the beginning of the images, goes back to number the end (and tell the user).
Otherwise, goes to the previous image.
Asks itself to display the image it has thus selected.
- putScore(self, score)
- Tell the server about the score.
Nice and simple - assembles the string, then opens the url.
Doesn't care about the return - already knows what it's up to.
Tells the user so that they know that we did it.
- score(self)
- Ask the server about the score.
Assembles the string, then opens the url.
Splits the return to get rid of the newline, then converts it to a float.
Tells the user what we've just found out.
Data and other attributes defined here:
- imageNo = None
- saveState = None
- server = 'http://ajhurst.org/~ajh/cgi-bin/imageServer.py'
Methods inherited from threading.Thread:
- __repr__(self)
- getName(self)
- isAlive(self)
- Return whether the thread is alive.
This method returns True just before the run() method starts until just
after the run() method terminates. The module function enumerate()
returns a list of all alive threads.
- isDaemon(self)
- is_alive = isAlive(self)
- Return whether the thread is alive.
This method returns True just before the run() method starts until just
after the run() method terminates. The module function enumerate()
returns a list of all alive threads.
- join(self, timeout=None)
- Wait until the thread terminates.
This blocks the calling thread until the thread whose join() method is
called terminates -- either normally or through an unhandled exception
or until the optional timeout occurs.
When the timeout argument is present and not None, it should be a
floating point number specifying a timeout for the operation in seconds
(or fractions thereof). As join() always returns None, you must call
isAlive() after join() to decide whether a timeout happened -- if the
thread is still alive, the join() call timed out.
When the timeout argument is not present or None, the operation will
block until the thread terminates.
A thread can be join()ed many times.
join() raises a RuntimeError if an attempt is made to join the current
thread as that would cause a deadlock. It is also an error to join() a
thread before it has been started and attempts to do so raises the same
exception.
- run(self)
- Method representing the thread's activity.
You may override this method in a subclass. The standard run() method
invokes the callable object passed to the object's constructor as the
target argument, if any, with sequential and keyword arguments taken
from the args and kwargs arguments, respectively.
- setDaemon(self, daemonic)
- setName(self, name)
- start(self)
- Start the thread's activity.
It must be called at most once per thread object. It arranges for the
object's run() method to be invoked in a separate thread of control.
This method will raise a RuntimeError if called more than once on the
same thread object.
Data descriptors inherited from threading.Thread:
- daemon
- A boolean value indicating whether this thread is a daemon thread (True) or not (False).
This must be set before start() is called, otherwise RuntimeError is
raised. Its initial value is inherited from the creating thread; the
main thread is not a daemon thread and therefore all threads created in
the main thread default to daemon = False.
The entire Python program exits when no alive non-daemon threads are
left.
- ident
- Thread identifier of this thread or None if it has not been started.
This is a nonzero integer. See the thread.get_ident() function. Thread
identifiers may be recycled when a thread exits and another thread is
created. The identifier is available even after the thread has exited.
- name
- A string used for identification purposes only.
It has no semantics. Multiple threads may be given the same name. The
initial name is set by the constructor.
Data descriptors inherited from threading._Verbose:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class SaveState(threading.Thread) |
|
Loads and saves the state.
Has three functions, load, save and output. |
|
- Method resolution order:
- SaveState
- threading.Thread
- threading._Verbose
- __builtin__.object
Methods defined here:
- load(self)
- Read the history file.
First tries to open and read in the history file (history.txt).
Splits the history file on newlines and adds it to the array of commands.
The final element of the file will be the last image viewed carried from the previous session.
Remove stray newlines.
Remove this final element and tell the image display thread.
Remove the new final element and tell the auto advance thread.
If the file doesn't exist or is blank then we will get an exception and proceed with a blank history.
- output(self, text, *strings)
- Includes some output in the history.
Strips off newlines for the history, and then outputs to stdout.
- save(self)
- Save the history file.
Adds the last image viewed from the image display thread to the list of commands.
Opens history.txt in overwrite mode.
Converts each historical command to a string (mainly for the last image, but just in case).
Write the elements separated by newlines to the history file.
Close the history file.
Data and other attributes defined here:
- autoAdvance = None
- commands = []
- imageDisplay = None
Methods inherited from threading.Thread:
- __init__(self, group=None, target=None, name=None, args=(), kwargs=None, verbose=None)
- This constructor should always be called with keyword arguments. Arguments are:
*group* should be None; reserved for future extension when a ThreadGroup
class is implemented.
*target* is the callable object to be invoked by the run()
method. Defaults to None, meaning nothing is called.
*name* is the thread name. By default, a unique name is constructed of
the form "Thread-N" where N is a small decimal number.
*args* is the argument tuple for the target invocation. Defaults to ().
*kwargs* is a dictionary of keyword arguments for the target
invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke
the base class constructor (Thread.__init__()) before doing anything
else to the thread.
- __repr__(self)
- getName(self)
- isAlive(self)
- Return whether the thread is alive.
This method returns True just before the run() method starts until just
after the run() method terminates. The module function enumerate()
returns a list of all alive threads.
- isDaemon(self)
- is_alive = isAlive(self)
- Return whether the thread is alive.
This method returns True just before the run() method starts until just
after the run() method terminates. The module function enumerate()
returns a list of all alive threads.
- join(self, timeout=None)
- Wait until the thread terminates.
This blocks the calling thread until the thread whose join() method is
called terminates -- either normally or through an unhandled exception
or until the optional timeout occurs.
When the timeout argument is present and not None, it should be a
floating point number specifying a timeout for the operation in seconds
(or fractions thereof). As join() always returns None, you must call
isAlive() after join() to decide whether a timeout happened -- if the
thread is still alive, the join() call timed out.
When the timeout argument is not present or None, the operation will
block until the thread terminates.
A thread can be join()ed many times.
join() raises a RuntimeError if an attempt is made to join the current
thread as that would cause a deadlock. It is also an error to join() a
thread before it has been started and attempts to do so raises the same
exception.
- run(self)
- Method representing the thread's activity.
You may override this method in a subclass. The standard run() method
invokes the callable object passed to the object's constructor as the
target argument, if any, with sequential and keyword arguments taken
from the args and kwargs arguments, respectively.
- setDaemon(self, daemonic)
- setName(self, name)
- start(self)
- Start the thread's activity.
It must be called at most once per thread object. It arranges for the
object's run() method to be invoked in a separate thread of control.
This method will raise a RuntimeError if called more than once on the
same thread object.
Data descriptors inherited from threading.Thread:
- daemon
- A boolean value indicating whether this thread is a daemon thread (True) or not (False).
This must be set before start() is called, otherwise RuntimeError is
raised. Its initial value is inherited from the creating thread; the
main thread is not a daemon thread and therefore all threads created in
the main thread default to daemon = False.
The entire Python program exits when no alive non-daemon threads are
left.
- ident
- Thread identifier of this thread or None if it has not been started.
This is a nonzero integer. See the thread.get_ident() function. Thread
identifiers may be recycled when a thread exits and another thread is
created. The identifier is available even after the thread has exited.
- name
- A string used for identification purposes only.
It has no semantics. Multiple threads may be given the same name. The
initial name is set by the constructor.
Data descriptors inherited from threading._Verbose:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class UserInput(threading.Thread) |
|
For the user to interact with the program.
Has two main functions, __init__ and run.
Also has subsidiary functions for dealing with the commands (command_h/s/d/p/n/man/help/q). |
|
- Method resolution order:
- UserInput
- threading.Thread
- threading._Verbose
- __builtin__.object
Methods defined here:
- command_d(self, command)
- Display command.
With no arguments, checks whether the image display thread is aware of a previous image.
If not, we are running without a history file, so go to 1.
If it is, ask the image display thread to redisplay that image.
With 2+ arguments, complains and sulks (does nothing).
If the argument doesn't boil down to an integer, complains and sulks.
If the argument is not within 1 and the max image (from the image display thread), complains and sulks.
Ask the image display thread to display the image specified by the argument.
- command_h(self, command)
- History command.
With no arguments, defaults to 10, otherwise n.
If there are 2+ arguments, complains and defaults to 10.
If the argument doesn't boil down to an integer, complains and defaults to 10.
Trims off the last n elements of the commands array, and iterates through printing them.
- command_help(self, command)
- Help command.
With no arguments, prints off the list of commands below.
With 1+ arguments, complains and then pretends it has no arguments.
- command_man(self, command)
- Manual command.
With no arguments, asks the operating system to display the user manual (UserManual.html).
With 1+ arguments, complains and then pretends it has no arguments.
- command_n(self, command)
- Next command.
With no arguments, asks the image display thread to display the next image.
With 1+ arguments, complains and then pretends it has no arguments.
- command_p(self, command)
- Previous command.
With no arguments, asks the image display thread to display the previous image.
With 1+ arguments, complains and then pretends it has no arguments.
- command_q(self, command)
- Quit command.
Can only complain.
With 1+ arguments, complains.
- command_s(self, command)
- Score command.
With no arguments, asks the image display thread to get the score for the current image.
With 2+ arguments, complains and sulks (does nothing).
If the argument doesn't boil down to a float between 0 and 10 inclusive, complains and sulks.
Asks the image display thread to tell the server about the score.
- command_t(self, command)
- Time command.
With no arguments, tells the auto advance thread to stop displaying images.
With one argument, tells the auto advance thread how long to wait before displaying the next image.
With 2+ arguments, complains and then sulks.
- run(self)
- Run the program.
Loads the state.
Then prompts the user to enter a command:
First adds the command to the history of commands.
h -> UserInput.command_h
s -> UserInput.command_s
d -> UserInput.command_d
p -> UserInput.command_p
n -> UserInput.command_n
t -> UserInput.command_t
man -> UserInput.command_man
help -> UserInput.command_help
q -> breaks the loop, continue execution
Then prompts the user to enter another command (back to start of loop), as long as we didn't q.
Saves the state.
Data and other attributes defined here:
- autoAdvance = None
- imageDisplay = None
- saveState = None
Methods inherited from threading.Thread:
- __init__(self, group=None, target=None, name=None, args=(), kwargs=None, verbose=None)
- This constructor should always be called with keyword arguments. Arguments are:
*group* should be None; reserved for future extension when a ThreadGroup
class is implemented.
*target* is the callable object to be invoked by the run()
method. Defaults to None, meaning nothing is called.
*name* is the thread name. By default, a unique name is constructed of
the form "Thread-N" where N is a small decimal number.
*args* is the argument tuple for the target invocation. Defaults to ().
*kwargs* is a dictionary of keyword arguments for the target
invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke
the base class constructor (Thread.__init__()) before doing anything
else to the thread.
- __repr__(self)
- getName(self)
- isAlive(self)
- Return whether the thread is alive.
This method returns True just before the run() method starts until just
after the run() method terminates. The module function enumerate()
returns a list of all alive threads.
- isDaemon(self)
- is_alive = isAlive(self)
- Return whether the thread is alive.
This method returns True just before the run() method starts until just
after the run() method terminates. The module function enumerate()
returns a list of all alive threads.
- join(self, timeout=None)
- Wait until the thread terminates.
This blocks the calling thread until the thread whose join() method is
called terminates -- either normally or through an unhandled exception
or until the optional timeout occurs.
When the timeout argument is present and not None, it should be a
floating point number specifying a timeout for the operation in seconds
(or fractions thereof). As join() always returns None, you must call
isAlive() after join() to decide whether a timeout happened -- if the
thread is still alive, the join() call timed out.
When the timeout argument is not present or None, the operation will
block until the thread terminates.
A thread can be join()ed many times.
join() raises a RuntimeError if an attempt is made to join the current
thread as that would cause a deadlock. It is also an error to join() a
thread before it has been started and attempts to do so raises the same
exception.
- setDaemon(self, daemonic)
- setName(self, name)
- start(self)
- Start the thread's activity.
It must be called at most once per thread object. It arranges for the
object's run() method to be invoked in a separate thread of control.
This method will raise a RuntimeError if called more than once on the
same thread object.
Data descriptors inherited from threading.Thread:
- daemon
- A boolean value indicating whether this thread is a daemon thread (True) or not (False).
This must be set before start() is called, otherwise RuntimeError is
raised. Its initial value is inherited from the creating thread; the
main thread is not a daemon thread and therefore all threads created in
the main thread default to daemon = False.
The entire Python program exits when no alive non-daemon threads are
left.
- ident
- Thread identifier of this thread or None if it has not been started.
This is a nonzero integer. See the thread.get_ident() function. Thread
identifiers may be recycled when a thread exits and another thread is
created. The identifier is available even after the thread has exited.
- name
- A string used for identification purposes only.
It has no semantics. Multiple threads may be given the same name. The
initial name is set by the constructor.
Data descriptors inherited from threading._Verbose:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
| |