class ProgressIndicatorsExample(VerticalLayout): 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 prosessed(self): i = self._worker1.getCurrent() if i == Worker1.MAX: self._pi1.setEnabled(False) self._startButton1.setEnabled(True) self._pi1.setValue(1.0) else: self._pi1.setValue(i / self.Worker1.MAX) def prosessed2(self): self._pi2.setEnabled(False) self._startButton2.setEnabled(True)
class ProgressIndicatorsExample(VerticalLayout): 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 prosessed(self): i = self._worker1.getCurrent() if i == Worker1.MAX: self._pi1.setEnabled(False) self._startButton1.setEnabled(True) self._pi1.setValue(1.0) else: self._pi1.setValue(i / self.Worker1.MAX) def prosessed2(self): self._pi2.setEnabled(False) self._startButton2.setEnabled(True)
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