class DragDropHtml5FromDesktopExample(VerticalLayout): def __init__(self): super(DragDropHtml5FromDesktopExample, self).__init__() self.addComponent( Label('Drag text from desktop application or ' 'image files from the ' + 'file system to the drop box ' 'below (dragging files requires HTML5 capable browser ' 'like FF 3.6, Safari or Chrome)')) dropPane = CssLayout() dropPane.setWidth('200px') dropPane.setHeight('200px') dropPane.addStyleName('image-drop-pane') dropBox = ImageDropBox(dropPane, self) dropBox.setSizeUndefined() panel = Panel(dropBox) panel.setSizeUndefined() panel.addStyleName('no-vertical-drag-hints') panel.addStyleName('no-horizontal-drag-hints') self.addComponent(panel) self._progress = ProgressIndicator() self._progress.setIndeterminate(True) self._progress.setVisible(False) self.addComponent(self._progress) def attach(self): super(DragDropHtml5FromDesktopExample, self).attach() # warn the user if the browser does not support file drop context = self.getApplication().getContext() if isinstance(context, AbstractWebApplicationContext): webBrowser = context.getBrowser() # FF supportsHtml5FileDrop = ( webBrowser.isFirefox() and (webBrowser.getBrowserMajorVersion() >= 4) or (webBrowser.getBrowserMajorVersion() == 3 and webBrowser.getBrowserMinorVersion() >= 6)) if not supportsHtml5FileDrop: # pretty much all chromes and safaris are new enough supportsHtml5FileDrop = ( webBrowser.isChrome() or (webBrowser.isSafari() and webBrowser.getBrowserMajorVersion() > 4)) if not supportsHtml5FileDrop: self.getWindow().showNotification( 'Image file drop is ' 'only supported on Firefox 3.6 and later. ' 'Text can be dropped into the box on other browsers.', Notification.TYPE_WARNING_MESSAGE)
class DragDropHtml5FromDesktopExample(VerticalLayout): def __init__(self): super(DragDropHtml5FromDesktopExample, self).__init__() self.addComponent(Label('Drag text from desktop application or ' 'image files from the ' + 'file system to the drop box ' 'below (dragging files requires HTML5 capable browser ' 'like FF 3.6, Safari or Chrome)')) dropPane = CssLayout() dropPane.setWidth('200px') dropPane.setHeight('200px') dropPane.addStyleName('image-drop-pane') dropBox = ImageDropBox(dropPane, self) dropBox.setSizeUndefined() panel = Panel(dropBox) panel.setSizeUndefined() panel.addStyleName('no-vertical-drag-hints') panel.addStyleName('no-horizontal-drag-hints') self.addComponent(panel) self._progress = ProgressIndicator() self._progress.setIndeterminate(True) self._progress.setVisible(False) self.addComponent(self._progress) def attach(self): super(DragDropHtml5FromDesktopExample, self).attach() # warn the user if the browser does not support file drop context = self.getApplication().getContext() if isinstance(context, AbstractWebApplicationContext): webBrowser = context.getBrowser() # FF supportsHtml5FileDrop = (webBrowser.isFirefox() and (webBrowser.getBrowserMajorVersion() >= 4) or (webBrowser.getBrowserMajorVersion() == 3 and webBrowser.getBrowserMinorVersion() >= 6)) if not supportsHtml5FileDrop: # pretty much all chromes and safaris are new enough supportsHtml5FileDrop = (webBrowser.isChrome() or (webBrowser.isSafari() and webBrowser.getBrowserMajorVersion() > 4)) if not supportsHtml5FileDrop: self.getWindow().showNotification('Image file drop is ' 'only supported on Firefox 3.6 and later. ' 'Text can be dropped into the box on other browsers.', Notification.TYPE_WARNING_MESSAGE)
class UploadWithProgressMonitoringExample(VerticalLayout): def __init__(self): super(UploadWithProgressMonitoringExample, self).__init__() self.setSpacing(True) self._state = Label() self._result = Label() self._fileName = Label() self._textualProgress = Label() self._pi = ProgressIndicator() self._counter = LineBreakCounter() self._upload = Upload(None, self._counter) self.addComponent(Label('Upload a file and we\'ll count the number ' 'of line break characters (\\n) found in it.')) # make analyzing start immediatedly when file is selected self._upload.setImmediate(True) self._upload.setButtonCaption('Upload File') self.addComponent(self._upload) handBrake = CheckBox('Simulate slow server') handBrake.setValue(True) self._counter.setSlow(True) handBrake.setDescription('Sleep for 100ms after each kilobyte to ' 'simulate slower processing/bandwidth. This is to show ' 'progress indicator even with rather small files.') handBrake.addListener(HandBrakeListener(self), button.IClickListener) cancelProcessing = Button('Cancel') cancelProcessing.addListener(CancelListener(self), button.IClickListener) cancelProcessing.setVisible(False) cancelProcessing.setStyleName('small') handBrake.setImmediate(True) self.addComponent(handBrake) p = Panel('Status') p.setSizeUndefined() l = FormLayout() l.setMargin(True) p.setContent(l) stateLayout = HorizontalLayout() stateLayout.setSpacing(True) stateLayout.addComponent(self._state) stateLayout.addComponent(cancelProcessing) stateLayout.setCaption('Current state') self._state.setValue('Idle') l.addComponent(stateLayout) self._fileName.setCaption('File name') l.addComponent(self._fileName) self._result.setCaption('Line breaks counted') l.addComponent(self._result) self._pi.setCaption('Progress') self._pi.setVisible(False) l.addComponent(self._pi) self._textualProgress.setVisible(False) l.addComponent(self._textualProgress) self.addComponent(p) self._upload.addListener(StartedListener(self), upload.IStartedListener) self._upload.addListener(ProgressListener(self), upload.IProgressListener) self._upload.addListener(SucceededListener(self), upload.ISucceededListener) self._upload.addListener(FailedListener(self), upload.IFailedListener) self._upload.addListener(FinishedListener(self), upload.IFinishedListener)
class UploadWithProgressMonitoringExample(VerticalLayout): def __init__(self): super(UploadWithProgressMonitoringExample, self).__init__() self.setSpacing(True) self._state = Label() self._result = Label() self._fileName = Label() self._textualProgress = Label() self._pi = ProgressIndicator() self._counter = LineBreakCounter() self._upload = Upload(None, self._counter) self.addComponent( Label('Upload a file and we\'ll count the number ' 'of line break characters (\\n) found in it.')) # make analyzing start immediatedly when file is selected self._upload.setImmediate(True) self._upload.setButtonCaption('Upload File') self.addComponent(self._upload) handBrake = CheckBox('Simulate slow server') handBrake.setValue(True) self._counter.setSlow(True) handBrake.setDescription( 'Sleep for 100ms after each kilobyte to ' 'simulate slower processing/bandwidth. This is to show ' 'progress indicator even with rather small files.') handBrake.addListener(HandBrakeListener(self), button.IClickListener) cancelProcessing = Button('Cancel') cancelProcessing.addListener(CancelListener(self), button.IClickListener) cancelProcessing.setVisible(False) cancelProcessing.setStyleName('small') handBrake.setImmediate(True) self.addComponent(handBrake) p = Panel('Status') p.setSizeUndefined() l = FormLayout() l.setMargin(True) p.setContent(l) stateLayout = HorizontalLayout() stateLayout.setSpacing(True) stateLayout.addComponent(self._state) stateLayout.addComponent(cancelProcessing) stateLayout.setCaption('Current state') self._state.setValue('Idle') l.addComponent(stateLayout) self._fileName.setCaption('File name') l.addComponent(self._fileName) self._result.setCaption('Line breaks counted') l.addComponent(self._result) self._pi.setCaption('Progress') self._pi.setVisible(False) l.addComponent(self._pi) self._textualProgress.setVisible(False) l.addComponent(self._textualProgress) self.addComponent(p) self._upload.addListener(StartedListener(self), upload.IStartedListener) self._upload.addListener(ProgressListener(self), upload.IProgressListener) self._upload.addListener(SucceededListener(self), upload.ISucceededListener) self._upload.addListener(FailedListener(self), upload.IFailedListener) self._upload.addListener(FinishedListener(self), upload.IFinishedListener)