Package muntjac :: Package ui :: Module upload :: Class Upload
[hide private]
[frames] | no frames]

Class Upload

source code

                          object --+                
                                   |                
                 util.IEventListener --+            
                                       |            
           terminal.paintable.IPaintable --+        
                                           |        
                              object --+   |        
                                       |   |        
  terminal.variable_owner.IVariableOwner --+        
                                           |        
                              object --+   |        
                                       |   |        
             terminal.sizeable.ISizeable --+        
                                           |        
                        component.IComponent --+    
                                               |    
                                  object --+   |    
                                           |   |    
event.method_event_source.IMethodEventSource --+    
                                               |    
            abstract_component.AbstractComponent --+
                                                   |
                          object --+               |
                                   |               |
                 util.IEventListener --+           |
                                       |           |
           terminal.paintable.IPaintable --+       |
                                           |       |
                              object --+   |       |
                                       |   |       |
  terminal.variable_owner.IVariableOwner --+       |
                                           |       |
                              object --+   |       |
                                       |   |       |
             terminal.sizeable.ISizeable --+       |
                                           |       |
                        component.IComponent --+   |
                                               |   |
                            component.IFocusable --+
                                                   |
                                                  Upload

IComponent for uploading files from client to server.

The visible component consists of a file name input box and a browse button and an upload submit button to start uploading.

The Upload component needs a StringIO to write the uploaded data. You need to implement the upload.IReceiver interface and return the output stream in the receiveUpload() method.

You can get an event regarding starting (StartedEvent), progress (ProgressEvent), and finishing (FinishedEvent) of upload by implementing IStartedListener, IProgressListener, and IFinishedListener, respectively. The IFinishedListener is called for both failed and succeeded uploads. If you wish to separate between these two cases, you can use ISucceededListener (SucceededEvenet) and IFailedListener (FailedEvent).

The upload component does not itself show upload progress, but you can use the ProgressIndicator for providing progress feedback by implementing IProgressListener and updating the indicator in updateProgress().

Setting upload component immediate initiates the upload as soon as a file is selected, instead of the common pattern of file selection field and upload button.

Note! Because of browser dependent implementations of <input type="file"> element, setting size for Upload component is not supported. For some browsers setting size may work to some extent.


Authors:
Vaadin Ltd., Richard Lincoln

Version: 1.1.2

Instance Methods [hide private]
 
__init__(self, caption=None, uploadReceiver=None)
Creates a new instance of Upload.
source code
 
changeVariables(self, source, variables)
Invoked when the value of a variable has changed.
source code
 
paintContent(self, target)
Paints the content of this component.
source code
 
addListener(self, listener, iface=None)
Adds an event listener.
source code
 
addCallback(self, callback, eventType=None, *args) source code
 
removeListener(self, listener, iface=None)
Removes an event listener.
source code
 
removeCallback(self, callback, eventType=None) source code
 
fireStarted(self, filename, MIMEType)
Emit upload received event.
source code
 
fireUploadInterrupted(self, filename, MIMEType, length, e=None)
Emits the upload failed event.
source code
 
fireNoInputStream(self, filename, MIMEType, length) source code
 
fireNoOutputStream(self, filename, MIMEType, length) source code
 
fireUploadSuccess(self, filename, MIMEType, length)
Emits the upload success event.
source code
 
fireUpdateProgress(self, totalBytes, contentLength)
Emits the progress event.
source code
 
getReceiver(self)
Returns the current receiver.
source code
 
setReceiver(self, receiver)
Sets the receiver.
source code
 
focus(self)
Sets the focus for this component if the component is IFocusable.
source code
 
getTabIndex(self)
Gets the Tabulator index of this IFocusable component.
source code
 
setTabIndex(self, tabIndex)
Sets the Tabulator index of this IFocusable component.
source code
 
startUpload(self)
Go into upload state.
source code
 
interruptUpload(self)
Interrupts the upload currently being received.
source code
 
endUpload(self)
Go into state where new uploading can begin.
source code
 
isUploading(self) source code
 
getBytesRead(self)
Gets read bytes of the file currently being uploaded.
source code
 
getUploadSize(self)
Returns size of file currently being uploaded.
source code
 
setProgressListener(self, progressListener)
This method is deprecated, use addListener(IProgressListener) instead.
source code
 
getProgressListener(self)
This method is deprecated.
source code
 
getButtonCaption(self)
Returns: String to be rendered into button that fires uploading
source code
 
setButtonCaption(self, buttonCaption)
In addition to the actual file chooser, upload components have button that starts actual upload progress.
source code
 
submitUpload(self)
Forces the upload the send selected file to the server.
source code
 
requestRepaint(self)
Requests that the paintable should be repainted as soon as possible.
source code
 
getStreamVariable(self) source code
 
getListeners(self, eventType)
Returns all listeners that are registered for the given event type or one of its subclasses.
source code
 
getCallbacks(self, eventType) source code

Inherited from abstract_component.AbstractComponent: __getstate__, __setstate__, addStyleName, attach, childRequestedRepaint, detach, fireComponentErrorEvent, fireComponentEvent, fireEvent, fireRequestRepaintEvent, getApplication, getCSSHeight, getCSSWidth, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorHandler, getErrorMessage, getHeight, getHeightUnits, getIcon, getLocale, getParent, getStyle, getStyleName, getWidth, getWidthUnits, getWindow, handleError, hasListeners, isEnabled, isImmediate, isReadOnly, isVisible, paint, parseStringSize, registerCallback, registerListener, removeStyleName, requestRepaintRequests, setCaption, setComponentError, setData, setDebugId, setDescription, setEnabled, setErrorHandler, setHeight, setHeightUnits, setIcon, setImmediate, setLocale, setParent, setReadOnly, setSizeFull, setSizeUndefined, setStyle, setStyleName, setVisible, setWidth, setWidthUnits, withdrawCallback, withdrawListener

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  CLIENT_WIDGET = None
hash(x)

Inherited from abstract_component.AbstractComponent: SIZE_PATTERN

Inherited from terminal.sizeable.ISizeable: SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS, UNIT_SYMBOLS

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, caption=None, uploadReceiver=None)
(Constructor)

source code 

Creates a new instance of Upload.

The receiver must be set before performing an upload.

Overrides: object.__init__

changeVariables(self, source, variables)

source code 

Invoked when the value of a variable has changed.

Parameters:
  • source - the Source of the variable change. This is the origin of the event. For example in Web Adapter this is the request.
  • variables - the Mapping from variable names to new variable values.
Overrides: terminal.variable_owner.IVariableOwner.changeVariables

See Also: AbstractComponent.changeVariables

paintContent(self, target)

source code 

Paints the content of this component.

Parameters:
  • target - Target to paint the content on.
Raises:
Overrides: abstract_component.AbstractComponent.paintContent

addListener(self, listener, iface=None)

source code 

Adds an event listener.

Parameters:
  • listener - the listener to be added.
Raises:
  • ValueError - unless method has a match in object
Overrides: event.method_event_source.IMethodEventSource.addListener

addCallback(self, callback, eventType=None, *args)

source code 
Overrides: terminal.paintable.IPaintable.addCallback

removeListener(self, listener, iface=None)

source code 

Removes an event listener.

Parameters:
  • listener - the listener to be removed.
Overrides: event.method_event_source.IMethodEventSource.removeListener

removeCallback(self, callback, eventType=None)

source code 
Overrides: terminal.paintable.IPaintable.removeCallback

fireUpdateProgress(self, totalBytes, contentLength)

source code 

Emits the progress event.

Parameters:
  • totalBytes - bytes received so far
  • contentLength - actual size of the file being uploaded, if known

getReceiver(self)

source code 

Returns the current receiver.

Returns:
the IStreamVariable.

setReceiver(self, receiver)

source code 

Sets the receiver.

Parameters:
  • receiver - the receiver to set.

focus(self)

source code 

Sets the focus for this component if the component is IFocusable.

Overrides: component.IFocusable.focus
(inherited documentation)

getTabIndex(self)

source code 

Gets the Tabulator index of this IFocusable component.

Returns:
tab index set for the IFocusable component
Overrides: component.IFocusable.getTabIndex

setTabIndex(self, tabIndex)

source code 

Sets the Tabulator index of this IFocusable component.

Parameters:
  • tabIndex - the tab order of this component. Indexes usually start from 1. Zero means that default tab order should be used. A negative value means that the field should not be included in the tabbing sequence.
Overrides: component.IFocusable.setTabIndex

startUpload(self)

source code 

Go into upload state. This is to prevent double uploading on same component.

Warning: this is an internal method used by the framework and should not be used by user of the Upload component. Using it results in the Upload component going in wrong state and not working. It is currently public because it is used by another class.

interruptUpload(self)

source code 

Interrupts the upload currently being received. The interruption will be done by the receiving tread so this method will return immediately and the actual interrupt will happen a bit later.

endUpload(self)

source code 

Go into state where new uploading can begin.

Warning: this is an internal method used by the framework and should not be used by user of the Upload component.

getBytesRead(self)

source code 

Gets read bytes of the file currently being uploaded.

Returns:
bytes

getUploadSize(self)

source code 

Returns size of file currently being uploaded. Value sane only during upload.

Returns:
size in bytes

setProgressListener(self, progressListener)

source code 

This method is deprecated, use addListener(IProgressListener) instead.

Deprecated: Use addListener(IProgressListener) instead.

getProgressListener(self)

source code 

This method is deprecated.

Returns:
listener

Deprecated: Replaced with addListener/removeListener

getButtonCaption(self)

source code 
Returns:
String to be rendered into button that fires uploading

setButtonCaption(self, buttonCaption)

source code 

In addition to the actual file chooser, upload components have button that starts actual upload progress. This method is used to set text in that button.

In case the button text is set to null, the button is hidden. In this case developer must explicitly initiate the upload process with submitUpload.

In case the Upload is used in immediate mode using setImmediate, the file choose (html input with type "file") is hidden and only the button with this text is shown.

Note the string given is set as is to the button. HTML formatting is not stripped. Be sure to properly validate your value according to your needs.

Parameters:
  • buttonCaption - text for upload components button.

submitUpload(self)

source code 

Forces the upload the send selected file to the server.

In case developer wants to use this feature, he/she will most probably want to hide the uploads internal submit button by setting its caption to null with setButtonCaption method.

Note, that the upload runs asynchronous. Developer should use normal upload listeners to trac the process of upload. If the field is empty uploaded the file name will be empty string and file length 0 in the upload finished event.

Also note, that the developer should not remove or modify the upload in the same user transaction where the upload submit is requested. The upload may safely be hidden or removed once the upload started event is fired.

requestRepaint(self)

source code 

Requests that the paintable should be repainted as soon as possible.

Overrides: terminal.paintable.IPaintable.requestRepaint
(inherited documentation)

getListeners(self, eventType)

source code 

Returns all listeners that are registered for the given event type or one of its subclasses.

Parameters:
  • eventType - The type of event to return listeners for.
Returns:
A collection with all registered listeners. Empty if no listeners are found.
Overrides: abstract_component.AbstractComponent.getListeners
(inherited documentation)