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)
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)
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 __init__(self): super(ProgressIndicatorsExample, self).__init__() self.setSpacing(True) self.addComponent( Label('<strong>Normal mode</strong> ' 'Runs for 20 seconds', Label.CONTENT_XHTML)) hl = HorizontalLayout() hl.setSpacing(True) self.addComponent(hl) # Add a normal progress indicator self._pi1 = ProgressIndicator() self._pi1.setIndeterminate(False) self._pi1.setEnabled(False) hl.addComponent(self._pi1) hl.setComponentAlignment(self._pi1, Alignment.MIDDLE_LEFT) self._startButton1 = Button('Start normal', NormalListener(self)) self._startButton1.setStyleName('small') hl.addComponent(self._startButton1) self.addComponent( Label('<strong>Indeterminate mode</strong> ' 'Runs for 10 seconds', Label.CONTENT_XHTML)) hl = HorizontalLayout() hl.setSpacing(True) self.addComponent(hl) # Add an indeterminate progress indicator self._pi2 = ProgressIndicator() self._pi2.setIndeterminate(True) self._pi2.setPollingInterval(5000) self._pi2.setEnabled(False) hl.addComponent(self._pi2) l = IndeterminateListener(self) self._startButton2 = Button('Start indeterminate', l) self._startButton2.setStyleName('small') hl.addComponent(self._startButton2)
def __init__(self): super(ProgressIndicatorsExample, self).__init__() self.setSpacing(True) self.addComponent(Label('<strong>Normal mode</strong> ' 'Runs for 20 seconds', Label.CONTENT_XHTML)) hl = HorizontalLayout() hl.setSpacing(True) self.addComponent(hl) # Add a normal progress indicator self._pi1 = ProgressIndicator() self._pi1.setIndeterminate(False) self._pi1.setEnabled(False) hl.addComponent(self._pi1) hl.setComponentAlignment(self._pi1, Alignment.MIDDLE_LEFT) self._startButton1 = Button('Start normal', NormalListener(self)) self._startButton1.setStyleName('small') hl.addComponent(self._startButton1) self.addComponent(Label('<strong>Indeterminate mode</strong> ' 'Runs for 10 seconds', Label.CONTENT_XHTML)) hl = HorizontalLayout() hl.setSpacing(True) self.addComponent(hl) # Add an indeterminate progress indicator self._pi2 = ProgressIndicator() self._pi2.setIndeterminate(True) self._pi2.setPollingInterval(5000) self._pi2.setEnabled(False) hl.addComponent(self._pi2) l = IndeterminateListener(self) self._startButton2 = Button('Start indeterminate', l) self._startButton2.setStyleName('small') hl.addComponent(self._startButton2)
def __init__(self): super(ImmediateUploadExample, self).__init__() self.setSpacing(True) self._status = Label('Please select a file to upload') self._pi = ProgressIndicator() self._receiver = MyReceiver() self._progressLayout = HorizontalLayout() self._upload = Upload(None, self._receiver) # Slow down the upload self._receiver.setSlow(True) self.addComponent(self._status) self.addComponent(self._upload) self.addComponent(self._progressLayout) # Make uploading start immediately when file is selected self._upload.setImmediate(True) self._upload.setButtonCaption('Select file') self._progressLayout.setSpacing(True) self._progressLayout.setVisible(False) self._progressLayout.addComponent(self._pi) self._progressLayout.setComponentAlignment(self._pi, Alignment.MIDDLE_LEFT) cancelProcessing = Button('Cancel') cancelProcessing.addListener(CancelListener(self), button.IClickListener) cancelProcessing.setStyleName('small') self._progressLayout.addComponent(cancelProcessing) # =========== Add needed listener for the upload component: start, # progress, finish, success, fail =========== 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)
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)
def create(self, parent): """ Creates the underlying ProgressIndicator. """ self.widget = ProgressIndicator() parent.addComponent(self.widget)
class MuntjacProgressBar(MuntjacControl, AbstractTkProgressBar): """ Muntjac implementation of ProgressBar. """ #-------------------------------------------------------------------------- # Setup Methods #-------------------------------------------------------------------------- def create(self, parent): """ Creates the underlying ProgressIndicator. """ self.widget = ProgressIndicator() parent.addComponent(self.widget) def initialize(self): """ Initialize the attributes of the progress bar. """ super(MuntjacControl, self).initialize() self.widget.setIndeterminate(False) shell = self.shell_obj self._set_minimum(shell.minimum) self._set_maximum(shell.maximum) self._set_value(shell.value) #-------------------------------------------------------------------------- # Abstract Implementation Methods #-------------------------------------------------------------------------- def shell_value_changed(self, value): """ The change handler for the 'value' attribute of the shell object. """ self._set_value(value) def shell_minimum_changed(self, minimum): """ The change handler for the 'minimum' attribute of the shell object. """ self._set_minimum(minimum) def shell_maximum_changed(self, maximum): """ The change handler for the 'maximum' attribute of the shell object """ self._set_maximum(maximum) #-------------------------------------------------------------------------- # Widget Update Methods #-------------------------------------------------------------------------- def _set_value(self, value): """ Sets the value of the progress bar. """ minimum = self.shell_obj.minimum maximum = self.shell_obj.maximum new_val = value / (maximum - minimum) # normalise: 0.0 - 1.0 self.widget.setValue(new_val) def _set_minimum(self, minimum): """ Sets the minimum value of the progress bar. """ pass def _set_maximum(self, maximum): """ Sets the maximum value of the progress bar. """ pass
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)