예제 #1
0
    def draw (self):
        """I.draw () -> None

        Draws the ImageButton surface and places its picture and Label on it.
        """
        ButtonBase.draw (self)

        spacing = StyleInformation.get ("IMAGEBUTTON_SPACING")
        rect_img = None
        rect_child = None
        rect = self.image.get_rect ()
        
        if self.picture:
            rect_img = self.picture.get_rect ()
            rect_img.center = rect.center
            if self.child:
                rect_img.right -= (self.child.width / 2 + spacing)
            rect_img.centery = rect.centery
            self.image.blit (self.picture, rect_img)
        
        if self.child:
            self.child.center = rect.center
            if self.picture:
                self.child.left = rect_img.right + spacing
            rect_child = self.child.rect
            self.image.blit (self.child.image, rect_child)
예제 #2
0
 def onAttach(self):
     """
     Overridden on attach to ensure that a button face has been chosen before
     the button is displayed.
     """
     self.finishSetup()
     ButtonBase.onAttach(self)
예제 #3
0
파일: CustomButton.py 프로젝트: Afey/pyjs
 def onAttach(self):
     """
     Overridden on attach to ensure that a button face has been chosen before
     the button is displayed.
     """
     self.finishSetup()
     ButtonBase.onAttach(self)
예제 #4
0
    def draw (self):
        """B.draw () -> None

        Draws the Button surface and places its Label on it.
        """
        ButtonBase.draw (self)
        if self.child:
            self.child.center = self.image.get_rect ().center
            self.image.blit (self.child.image, self.child.rect)
예제 #5
0
    def draw(self):
        """R.draw () -> None

        Draws the ToggleButton surface and places its Label on it.
        """
        ButtonBase.draw(self)
        if self.child:
            self.child.center = self.image.get_rect().center
            self.image.blit(self.child.image, self.child.rect)
예제 #6
0
 def setEnabled(self, enabled):
     """Sets whether this button is enabled."""
     if self.getEnabled() == enabled:
         return
     self.toggleDisabled()
     ButtonBase.setEnabled(self, enabled)
     if enabled:
         self.setAriaPressed(self.getCurrentFace())
     else:
         self.cleanupCaptureState()
예제 #7
0
파일: CustomButton.py 프로젝트: Afey/pyjs
 def setEnabled(self, enabled):
     """Sets whether this button is enabled."""
     if self.isEnabled() == enabled:
         return
     self.toggleDisabled()
     ButtonBase.setEnabled(self, enabled)
     if enabled:
         self.setAriaPressed(self.getCurrentFace())
     else:
         self.cleanupCaptureState()
예제 #8
0
 def setEnabled(self, enabled):
     """Sets whether this button is enabled."""
     if self.isEnabled() != enabled:
         self.toggleDisabled()
         ButtonBase.setEnabled(self, enabled)
         if not enabled:
             self.cleanupCaptureState()
             # XXX - TODO: Accessibility
         else:
             self.setAriaPressed(self.getCurrentFace())
예제 #9
0
 def setEnabled(self, enabled):
     """Sets whether this button is enabled."""
     if self.isEnabled() != enabled:
         self.toggleDisabled()
         ButtonBase.setEnabled(self, enabled)
         if not enabled:
             self.cleanupCaptureState()
             # XXX - TODO: Accessibility
         else:
             self.setAriaPressed(self.getCurrentFace())
예제 #10
0
    def __init__ (self, text=None):
        ButtonBase.__init__ (self)
        self._border = BORDER_RAISED

        # Internal click handler
        self.__click = False
        self._active = False
        
        # The ToggleButton emits a 'toggled' event.
        self._signals[SIG_TOGGLED] = []

        self.set_text (text)
예제 #11
0
    def __init__(self, text=None):
        ButtonBase.__init__(self)
        self._border = BORDER_RAISED

        # Internal click handler
        self.__click = False
        self._active = False

        # The ToggleButton emits a 'toggled' event.
        self._signals[SIG_TOGGLED] = []

        self.set_text(text)
예제 #12
0
    def set_state (self, state):
        """T.set_state (...) -> None

        Sets the state of the ToggleButton.

        Sets the state of the ToggleButton and causes its child to set
        its state to the same value.
        """
        if (self.active and (state != STATE_ACTIVE)) or (self.state == state):
            return

        self.lock ()
        if self.child:
            self.child.state = state
        ButtonBase.set_state (self, state)
        self.unlock ()
예제 #13
0
    def set_state (self, state):
        """I.set_state (...) -> None

        Sets the state of the ImageButton.

        Sets the state of the ImageButton and causes its child to set
        its state to the same value.
        """
        if self.state == state:
            return

        self.lock ()
        if self.child:
            self.child.state = state
        ButtonBase.set_state (self, state)
        self.unlock ()
예제 #14
0
    def set_state(self, state):
        """T.set_state (...) -> None

        Sets the state of the ToggleButton.

        Sets the state of the ToggleButton and causes its child to set
        its state to the same value.
        """
        if (self.active and (state != STATE_ACTIVE)) or (self.state == state):
            return

        self.lock()
        if self.child:
            self.child.state = state
        ButtonBase.set_state(self, state)
        self.unlock()
예제 #15
0
    def notify (self, event):
        """T.notify (event) -> None

        Notifies the ToggleButton about an event.
        """
        if not self.sensitive:
            return

        if event.signal in SIGNALS_MOUSE:
            eventarea = self.rect_to_client ()

            if event.signal == SIG_MOUSEDOWN:
                if eventarea.collidepoint (event.data.pos):
                    self.focus = True
                    # The button only acts upon left clicks.
                    if event.data.button == 1:
                        self.__click = True
                        self.state = STATE_ACTIVE
                    self.run_signal_handlers (SIG_MOUSEDOWN, event.data)
                    event.handled = True

            elif event.signal == SIG_MOUSEUP:
                if eventarea.collidepoint (event.data.pos):
                    self.run_signal_handlers (SIG_MOUSEUP, event.data)
                    if event.data.button == 1:
                        if self.__click:
                            # The usual order for a ToggleButton: get a
                            # click and toggle state upon it.
                            self.run_signal_handlers (SIG_CLICKED)
                            self.set_active (not self.active)
                            self.run_signal_handlers (SIG_TOGGLED)
                            if not self.active:
                                self.state = STATE_ENTERED
                    event.handled = True
                elif (event.data.button == 1) and self.__click and \
                         not self.active:
                    # Only a half click was made, reset the state of the
                    # ToggleButton.
                    self.state = STATE_NORMAL

            elif event.signal == SIG_MOUSEMOVE:
                ButtonBase.notify (self, event)
        else:
            # Any other event will be escalated to the parent(s).
            ButtonBase.notify (self, event)
예제 #16
0
    def notify(self, event):
        """T.notify (event) -> None

        Notifies the ToggleButton about an event.
        """
        if not self.sensitive:
            return

        if event.signal in SIGNALS_MOUSE:
            eventarea = self.rect_to_client()

            if event.signal == SIG_MOUSEDOWN:
                if eventarea.collidepoint(event.data.pos):
                    self.focus = True
                    # The button only acts upon left clicks.
                    if event.data.button == 1:
                        self.__click = True
                        self.state = STATE_ACTIVE
                    self.run_signal_handlers(SIG_MOUSEDOWN, event.data)
                    event.handled = True

            elif event.signal == SIG_MOUSEUP:
                if eventarea.collidepoint(event.data.pos):
                    self.run_signal_handlers(SIG_MOUSEUP, event.data)
                    if event.data.button == 1:
                        if self.__click:
                            # The usual order for a ToggleButton: get a
                            # click and toggle state upon it.
                            self.run_signal_handlers(SIG_CLICKED)
                            self.set_active(not self.active)
                            self.run_signal_handlers(SIG_TOGGLED)
                            if not self.active:
                                self.state = STATE_ENTERED
                    event.handled = True
                elif (event.data.button == 1) and self.__click and \
                         not self.active:
                    # Only a half click was made, reset the state of the
                    # ToggleButton.
                    self.state = STATE_NORMAL

            elif event.signal == SIG_MOUSEMOVE:
                ButtonBase.notify(self, event)
        else:
            # Any other event will be escalated to the parent(s).
            ButtonBase.notify(self, event)
예제 #17
0
파일: CheckBox.py 프로젝트: certik/pyjamas
    def initElement(self, element, **kwargs):
        self.inputElem = element
        self.labelElem = DOM.createLabel()
        if kwargs.has_key('Element'):
            element = kwargs.pop('Element')
        else:
            element = DOM.createSpan()
        ButtonBase.__init__(self, element, **kwargs)

        self.unsinkEvents(Event.FOCUSEVENTS| Event.ONCLICK)
        DOM.sinkEvents(self.inputElem, Event.FOCUSEVENTS | Event.ONCLICK | DOM.getEventsSunk(self.inputElem))

        DOM.appendChild(self.getElement(), self.inputElem)
        DOM.appendChild(self.getElement(), self.labelElem)

        uid = "check%d" % self.getUniqueID()
        DOM.setAttribute(self.inputElem, "id", uid)
        DOM.setAttribute(self.labelElem, "htmlFor", uid)
예제 #18
0
    def __init__(self, html=None, listener=None, **kwargs):
        """
        Create a new button widget.

        @param html: Html content (e.g. the button label); see setHTML()
        @param listener: A new click listener; see addClickListener()

        """
        if not kwargs.has_key('StyleName'): kwargs['StyleName'] = "gwt-Button"
        if html: kwargs['HTML'] = html
        if kwargs.has_key('Element'):
            element = kwargs.pop('Element')
        else:
            element = DOM.createButton()
        ButtonBase.__init__(self, element, **kwargs)
        self.adjustType(self.getElement())
        if listener:
            self.addClickListener(listener)
예제 #19
0
    def draw (self):
        """C.draw () -> None

        Draws the RadioButton surface.

        Creates the visible surface of the RadioButton and places a
        radio check and its Label on it.
        """
        border_active = base.GlobalStyle.get_border_size \
                        (self.__class__, self.style,
                         StyleInformation.get ("ACTIVE_BORDER"))
        ButtonBase.draw (self)
        if self.child:
            self.child.centery = self.image.get_rect ().centery
            self.child.x = self.padding + border_active + \
                           StyleInformation.get ("RADIO_SPACING") + \
                           StyleInformation.get ("RADIO_SIZE")
            self.image.blit (self.child.image, self.child.rect)
예제 #20
0
    def draw(self):
        """C.draw () -> None

        Draws the RadioButton surface.

        Creates the visible surface of the RadioButton and places a
        radio check and its Label on it.
        """
        border_active = base.GlobalStyle.get_border_size \
                        (self.__class__, self.style,
                         StyleInformation.get ("ACTIVE_BORDER"))
        ButtonBase.draw(self)
        if self.child:
            self.child.centery = self.image.get_rect().centery
            self.child.x = self.padding + border_active + \
                           StyleInformation.get ("RADIO_SPACING") + \
                           StyleInformation.get ("RADIO_SIZE")
            self.image.blit(self.child.image, self.child.rect)
예제 #21
0
    def __init__(self, html=None, listener=None, **kwargs):
        """
        Create a new button widget.

        @param html: Html content (e.g. the button label); see setHTML()
        @param listener: A new click listener; see addClickListener()

        """
        if not kwargs.has_key('StyleName'): kwargs['StyleName']="gwt-Button"
        if html: kwargs['HTML'] = html
        if kwargs.has_key('Element'):
            element = kwargs.pop('Element')
        else:
            element = DOM.createButton()
        ButtonBase.__init__(self, element, **kwargs)
        self.adjustType(self.getElement())
        if listener:
            self.addClickListener(listener)
예제 #22
0
    def initElement(self, element, **kwargs):
        self.inputElem = element
        self.labelElem = DOM.createLabel()
        if kwargs.has_key('Element'):
            element = kwargs.pop('Element')
        else:
            element = DOM.createSpan()
        ButtonBase.__init__(self, element, **kwargs)

        self.unsinkEvents(Event.FOCUSEVENTS | Event.ONCLICK)
        DOM.sinkEvents(
            self.inputElem, Event.FOCUSEVENTS | Event.ONCLICK
            | DOM.getEventsSunk(self.inputElem))

        DOM.appendChild(self.getElement(), self.inputElem)
        DOM.appendChild(self.getElement(), self.labelElem)

        uid = "check%d" % self.getUniqueID()
        DOM.setAttribute(self.inputElem, "id", uid)
        DOM.setAttribute(self.labelElem, "htmlFor", uid)
예제 #23
0
    def set_child (self, child=None):
        """B.set_child (...) -> None

        Sets the Label to display on the Button.

        Creates a parent-child relationship from the Button to a Label
        and causes the Label to set its mnemonic widget to the Button.

        Raises a TypeError, if the passed argument does not inherit
        from the Label class.
        """
        self.lock ()
        if child and not isinstance (child, Label):
            raise TypeError ("child must inherit from Label")
        ButtonBase.set_child (self, child)
        if child:
            child.set_widget (self)
            if not child.style:
                child.style = self.style or \
                              base.GlobalStyle.get_style (self.__class__)
        self.unlock ()
예제 #24
0
    def set_child(self, child=None):
        """B.set_child (...) -> None

        Sets the Label to display on the Button.

        Creates a parent-child relationship from the Button to a Label
        and causes the Label to set its mnemonic widget to the Button.

        Raises a TypeError, if the passed argument does not inherit
        from the Label class.
        """
        self.lock()
        if child and not isinstance(child, Label):
            raise TypeError("child must inherit from Label")
        ButtonBase.set_child(self, child)
        if child:
            child.set_widget(self)
            if not child.style:
                child.style = self.style or \
                              base.GlobalStyle.get_style (self.__class__)
        self.unlock()
예제 #25
0
 def onDetach(self):
     self.setChecked(self.isChecked())
     ButtonBase.onDetach(self)
예제 #26
0
파일: CustomButton.py 프로젝트: Afey/pyjs
 def onDetach(self):
     ButtonBase.onDetach(self)
     self.cleanupCaptureState()
예제 #27
0
 def __init__ (self, text=None):
     ButtonBase.__init__ (self)
     self._border = BORDER_RAISED
     self.set_text (text)
예제 #28
0
파일: CustomButton.py 프로젝트: Afey/pyjs
    def onBrowserEvent(self, event):
        # Should not act on button if disabled.
        if not self.isEnabled():
            # This can happen when events are bubbled up from
            # non-disabled children
            return

        event_type = DOM.eventGetType(event)

        if event_type == "click":
            # If clicks are currently disallowed, keep it from bubbling or
            # being passed to the superclass.
            if not self.allowClick:
                DOM.eventStopPropagation(event)
                return

        elif event_type == "mousedown":
            if DOM.eventGetButton(event) == Event.BUTTON_LEFT:
                self.setFocus(True)
                self.onClickStart()
                DOM.setCapture(self.getElement())
                self.isCapturing = True
                # Prevent dragging (on some browsers)
                DOM.eventPreventDefault(event)

        elif event_type == "mouseup":
            if self.isCapturing:
                self.isCapturing = False
                DOM.releaseCapture(self.getElement())
                if self.isHovering()  and  \
                   DOM.eventGetButton(event) == Event.BUTTON_LEFT:
                    self.onClick()

        elif event_type == "mousemove":
            if self.isCapturing:
                # Prevent dragging (on other browsers)
                DOM.eventPreventDefault(event)

        elif event_type == "mouseout":
            to = DOM.eventGetToElement(event)
            if (DOM.isOrHasChild(self.getElement(), DOM.eventGetTarget(event))
               and (to is None or not DOM.isOrHasChild(self.getElement(), to))):
                if self.isCapturing:
                    self.onClickCancel()
                self.setHovering(False)

        elif event_type == "mouseover":
            if DOM.isOrHasChild(self.getElement(), DOM.eventGetTarget(event)):
                self.setHovering(True)
                if self.isCapturing:
                    self.onClickStart()

        elif event_type == "blur":
            if self.isFocusing:
                self.isFocusing = False
                self.onClickCancel()

        elif event_type == "losecapture":
            if self.isCapturing:
                self.isCapturing = False
                self.onClickCancel()

        ButtonBase.onBrowserEvent(self, event)

        # Synthesize clicks based on keyboard events AFTER the normal
        # key handling.
        if (DOM.eventGetTypeInt(event) & Event.KEYEVENTS) == 0:
            return

        keyCode = DOM.eventGetKeyCode(event)
        if event_type == "keydown":
            if keyCode == ' ':
                self.isFocusing = True
                self.onClickStart()

        elif event_type == "keyup":
            if self.isFocusing  and  keyCode == ' ':
                self.isFocusing = False
                self.onClick()

        elif event_type == "keypress":
            if keyCode == '\n'  or  keyCode == '\r':
                self.onClickStart()
                self.onClick()
예제 #29
0
파일: CustomButton.py 프로젝트: Afey/pyjs
    def __init__(self, upImageText=None, downImageText=None, listener=None,
                       **kwargs):
        """Constructor for CustomButton."""

        if not kwargs.has_key('StyleName'):
            kwargs['StyleName']=self.STYLENAME_DEFAULT
        if kwargs.has_key('Element'):
            # XXX FIXME: createFocusable is used for a reason...
            element = kwargs.pop('Element')
        else:
            element = Focus.createFocusable()
        ButtonBase.__init__(self, element, **kwargs)

        self.curFace      = None # The button's current face.
        self.curFaceElement = None # No "undefined" anymore
        self.up           = None # Face for up.
        self.down         = None # Face for down.
        self.downHovering = None # Face for downHover.
        self.upHovering   = None # Face for upHover.
        self.upDisabled   = None # Face for upDisabled.
        self.downDisabled = None # Face for downDisabled.
        self.isCapturing = False # If True, this widget is capturing with
                                 # the mouse held down.
        self.isFocusing  = False # If True, widget has focus with space down.
        self.allowClick  = False # Used to decide whether to allow clicks to
                                 # propagate up to the superclass or container
                                 # elements.

        self.setUpFace(self.createFace(None, "up", self.UP))
        #self.getUpFace().setText("Not initialized yet:)")
        #self.setCurrentFace(self.getUpFace())

        # Add a11y role "button"
        # XXX: TODO Accessibility

        # TODO: pyjslib.isinstance
        if downImageText is None and listener is None:
            listener = upImageText
            upImageText = None

        if upImageText and isinstance(upImageText, basestring):
           upText = upImageText
           upImage = None
        else:
           upImage = upImageText
           upText = None

        if downImageText and isinstance(downImageText, basestring):
           downText = downImageText
           downImage = None
        else:
           downImage = downImageText
           downText = None

        #self.getUpFace().setText("Just a test")
        if upImage is not None:
            self.getUpFace().setImage(upImage)
        if upText is not None:
            self.getUpFace().setText(upText)
        if downImage is not None:
            self.getDownFace().setImage(downImage)
        if downText is not None:
            self.getDownFace().setText(downText)

        # set the face DOWN
        #self.setCurrentFace(self.getDownFace())

        # set the face UP
        #self.setCurrentFace(self.getUpFace())

        self.sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.FOCUSEVENTS
                        | Event.KEYEVENTS)
        if listener is not None:
            self.addClickListener(listener)
예제 #30
0
 def onDetach(self):
     ButtonBase.onDetach(self)
     self.cleanupCaptureState()
예제 #31
0
 def __init__ (self, image=None):
     ButtonBase.__init__ (self)
     self._border = BORDER_RAISED
     self._picture = None
     self._path = None
     self.set_picture (image)
예제 #32
0
    def onBrowserEvent(self, event):
        # Should not act on button if disabled.
        if not self.getEnabled():
            # This can happen when events are bubbled up from
            # non-disabled children
            return

        event_type = DOM.eventGetType(event)

        if event_type == "click":
            # If clicks are currently disallowed, keep it from bubbling or
            # being passed to the superclass.
            if not self.allowClick:
                DOM.eventStopPropagation(event)
                return

        elif event_type == "mousedown":
            if DOM.eventGetButton(event) == Event.BUTTON_LEFT:
                self.setFocus(True)
                self.onClickStart()
                DOM.setCapture(self.getElement())
                self.isCapturing = True
                # Prevent dragging (on some browsers)
                DOM.eventPreventDefault(event)

        elif event_type == "mouseup":
            if self.isCapturing:
                self.isCapturing = False
                DOM.releaseCapture(self.getElement())
                if self.isHovering()  and  \
                   DOM.eventGetButton(event) == Event.BUTTON_LEFT:
                    self.onClick()

        elif event_type == "mousemove":
            if self.isCapturing:
                # Prevent dragging (on other browsers)
                DOM.eventPreventDefault(event)

        elif event_type == "mouseout":
            to = DOM.eventGetToElement(event)
            if (DOM.isOrHasChild(self.getElement(), DOM.eventGetTarget(event))
               and (to is None or not DOM.isOrHasChild(self.getElement(), to))):
                if self.isCapturing:
                    self.onClickCancel()
                self.setHovering(False)

        elif event_type == "mouseover":
            if DOM.isOrHasChild(self.getElement(), DOM.eventGetTarget(event)):
                self.setHovering(True)
                if self.isCapturing:
                    self.onClickStart()

        elif event_type == "blur":
            if self.isFocusing:
                self.isFocusing = False
                self.onClickCancel()

        elif event_type == "losecapture":
            if self.isCapturing:
                self.isCapturing = False
                self.onClickCancel()

        ButtonBase.onBrowserEvent(self, event)

        # Synthesize clicks based on keyboard events AFTER the normal
        # key handling.
        if (DOM.eventGetTypeInt(event) & Event.KEYEVENTS) == 0:
            return

        keyCode = DOM.eventGetKeyCode(event)
        if event_type == "keydown":
            if keyCode == ' ':
                self.isFocusing = True
                self.onClickStart()

        elif event_type == "keyup":
            if self.isFocusing  and  keyCode == ' ':
                self.isFocusing = False
                self.onClick()

        elif event_type == "keypress":
            if keyCode == '\n'  or  keyCode == '\r':
                self.onClickStart()
                self.onClick()
예제 #33
0
파일: CheckBox.py 프로젝트: certik/pyjamas
 def onDetach(self):
     self.setChecked(self.isChecked())
     ButtonBase.onDetach(self)
예제 #34
0
    def __init__(self, upImageText=None, downImageText=None, listener=None,
                       **kwargs):
        """Constructor for CustomButton."""

        if not kwargs.has_key('StyleName'):
            kwargs['StyleName']=self.STYLENAME_DEFAULT
        if kwargs.has_key('Element'):
            # XXX FIXME: createFocusable is used for a reason...
            element = kwargs.pop('Element')
        else:
            element = Focus.createFocusable()
        ButtonBase.__init__(self, element, **kwargs)

        self.curFace      = None # The button's current face.
        self.curFaceElement = None # No "undefined" anymore
        self.up           = None # Face for up.
        self.down         = None # Face for down.
        self.downHovering = None # Face for downHover.
        self.upHovering   = None # Face for upHover.
        self.upDisabled   = None # Face for upDisabled.
        self.downDisabled = None # Face for downDisabled.
        self.isCapturing = False # If True, this widget is capturing with
                                 # the mouse held down.
        self.isFocusing  = False # If True, widget has focus with space down.
        self.allowClick  = False # Used to decide whether to allow clicks to
                                 # propagate up to the superclass or container
                                 # elements.

        self.setUpFace(self.createFace(None, "up", self.UP))
        #self.getUpFace().setText("Not initialized yet:)")
        #self.setCurrentFace(self.getUpFace())

        # Add a11y role "button"
        # XXX: TODO Accessibility

        # TODO: pyjslib.isinstance
        if downImageText is None and listener is None:
            listener = upImageText
            upImageText = None

        if upImageText and isinstance(upImageText, basestring):
           upText = upImageText
           upImage = None
        else:
           upImage = upImageText
           upText = None

        if downImageText and isinstance(downImageText, basestring):
           downText = downImageText
           downImage = None
        else:
           downImage = downImageText
           downText = None

        #self.getUpFace().setText("Just a test")
        if upImage is not None:
            self.getUpFace().setImage(upImage)
        if upText is not None:
            self.getUpFace().setText(upText)
        if downImage is not None:
            self.getDownFace().setImage(downImage)
        if downText is not None:
            self.getDownFace().setText(downText)

        # set the face DOWN
        #self.setCurrentFace(self.getDownFace())

        # set the face UP
        #self.setCurrentFace(self.getUpFace())

        self.sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.FOCUSEVENTS
                        | Event.KEYEVENTS)
        if listener is not None:
            self.addClickListener(listener)
예제 #35
0
 def _getProps(self):
     return ButtonBase._getProps() + self._props
예제 #36
0
파일: Button.py 프로젝트: illume/eyestabs
 def __init__(self, text=None):
     ButtonBase.__init__(self)
     self._border = BORDER_RAISED
     self.set_text(text)