Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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 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 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)
Exemplo n.º 5
0
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