Example #1
0
def _test_SetGet():

    frame = wx.GetApp().GetTopWindow()
    btn = bmptoggle.BitmapToggleButton(frame)

    btn.SetValue(True)
    assert btn.GetValue()

    btn.SetValue(False)
    assert not btn.GetValue()
Example #2
0
def _test_Create():

    frame = wx.GetApp().GetTopWindow()


    falseicon = op.join(datadir, 'false.png')
    trueicon  = op.join(datadir, 'true.png')

    falseicon = wx.Bitmap(falseicon, wx.BITMAP_TYPE_PNG)
    trueicon  = wx.Bitmap(trueicon,  wx.BITMAP_TYPE_PNG)

    btn = bmptoggle.BitmapToggleButton(frame)
    btn = bmptoggle.BitmapToggleButton(frame,
                                       trueBmp=trueicon)
    btn = bmptoggle.BitmapToggleButton(frame,
                                       trueBmp=trueicon,
                                       falseBmp=falseicon)

    btn = bmptoggle.BitmapToggleButton(frame)
    btn.SetBitmap(trueicon)
    btn.SetBitmap(trueicon, falseicon)
Example #3
0
def _test_Toggle():
    falseicon = op.join(datadir, 'false.png')
    trueicon  = op.join(datadir, 'true.png')

    falseicon = wx.Bitmap(falseicon, wx.BITMAP_TYPE_PNG)
    trueicon  = wx.Bitmap(trueicon,  wx.BITMAP_TYPE_PNG)

    sim   = wx.UIActionSimulator()
    frame = wx.GetApp().GetTopWindow()
    btn   = bmptoggle.BitmapToggleButton(frame)
    btn.SetBitmap(trueicon, falseicon)

    assert not btn.GetValue()
    simclick(sim, btn)
    assert btn.GetValue()
Example #4
0
def _test_Event():
    trueicon = op.join(datadir, 'true.png')
    trueicon = wx.Bitmap(trueicon,  wx.BITMAP_TYPE_PNG)

    sim   = wx.UIActionSimulator()
    frame = wx.GetApp().GetTopWindow()
    btn   = bmptoggle.BitmapToggleButton(frame)
    btn.SetBitmap(trueicon)

    result = [None]

    def handler(ev):
        result[0] = ev.value

    btn.Bind(bmptoggle.EVT_BITMAP_TOGGLE, handler)

    simclick(sim, btn)
    assert result[0]
    simclick(sim, btn)
    assert not result[0]
def _booleanToggle(parent, icons):
    """Create a :class:`.BitmapToggleButton` to link to the :class:`.Boolean`
    property.
    """
    if len(icons) == 1:
        icons = icons + [None]

    trueBmp  = icons[0]
    falseBmp = icons[1]

    style  = wx.BU_EXACTFIT | wx.ALIGN_CENTRE | wx.BU_NOTEXT
    widget = bmptoggle.BitmapToggleButton(
        parent,
        trueBmp=trueBmp,
        falseBmp=falseBmp,
        style=style)
    event  = bmptoggle.EVT_BITMAP_TOGGLE
    widget.SetMinSize(widget.GetBestSize())

    return widget, event, None, None
Example #6
0
def _createToggle(parent, viewItem, hasProps, propGui):
    """Creates a widget for the given :class:`.Toggle` object. If no icons
    have been set, a ``wx.CheckBox`` is used. Otherwise a
    :class:`.BitmapToggleButton` is used.
    """

    widget = None
    icon   = viewItem.icon

    # If no icons are set, use a CheckBox
    if icon is None:
        widget = wx.CheckBox(parent)
        event  = wx.EVT_CHECKBOX

    # Otherwise, use a BitmapToggleButton
    else:

        if isinstance(icon, six.string_types):
            icon = [icon]

        for i in range(len(icon)):

            icon[i] = wx.Bitmap(icon[i], wx.BITMAP_TYPE_PNG)

        if len(icon) == 1:
            icon = icon + [None]

        style = wx.BU_EXACTFIT | wx.ALIGN_CENTRE | wx.BU_NOTEXT
        widget = bmptoggle.BitmapToggleButton(parent,
                                              trueBmp=icon[0],
                                              falseBmp=icon[1],
                                              style=style)
        event  = bmptoggle.EVT_BITMAP_TOGGLE

    widget.Bind(event, lambda e: viewItem.callback(hasProps, widget))
    return widget
Example #7
0
    def __init__(self,
                 parent,
                 overlay,
                 display,
                 displayCtx,
                 listBox,
                 showVis=True,
                 showGroup=True,
                 showSave=True,
                 propagateSelect=True):
        """Create a ``ListItemWidget``.

        :arg parent:          The :mod:`wx` parent object.
        :arg overlay:         The overlay associated with this
                              ``ListItemWidget``.
        :arg display:         The :class:`.Display` associated with the
                              overlay.
        :arg displayCtx:      The :class:`.DisplayContext` instance.
        :arg listBox:         The :class:`.EditableListBox` that contains this
                              ``ListItemWidget``.
        :arg showVis:         If ``True`` (the default), a button will be shown
                              allowing the user to toggle the overlay
                              visibility.
        :arg showGroup:       If ``True`` (the default), a button will be shown
                              allowing the user to toggle overlay grouping.
        :arg showSave:        If ``True`` (the default), a button will be shown
                              allowing the user to save the overlay (if it is
                              not saved).
        :arg propagateSelect: If ``True`` (the default), when an overlay is
                              selected in the list, the
                              :attr:`.DisplayContext.selectedOverlay` is
                              updated accordingly.
        """
        wx.Panel.__init__(self, parent)

        self.__overlay         = overlay
        self.__display         = display
        self.__displayCtx      = displayCtx
        self.__listBox         = listBox
        self.__propagateSelect = propagateSelect
        self.__name            = '{}_{}'.format(self.__class__.__name__,
                                                id(self))
        self.__sizer           = wx.BoxSizer(wx.HORIZONTAL)

        self.SetSizer(self.__sizer)
        self.Bind(wx.EVT_WINDOW_DESTROY, self.__onDestroy)

        btnStyle = wx.BU_EXACTFIT | wx.BU_NOTEXT

        if showSave:
            self.__saveButton = wx.Button(self, style=btnStyle)
            self.__saveButton.SetBitmapLabel(icons.loadBitmap('floppydisk16'))
            self.__saveButton.SetToolTip(
                wx.ToolTip(fsltooltips.actions[self, 'save']))

            self.__sizer.Add(self.__saveButton, flag=wx.EXPAND, proportion=1)

            if isinstance(overlay, fslimage.Image):
                overlay.register(self.__name,
                                 self.__saveStateChanged,
                                 'saveState')
                self.__saveButton.Bind(wx.EVT_BUTTON, self.__onSaveButton)
            else:
                self.__saveButton.Enable(False)

            self.__saveStateChanged()

        if showGroup:
            self.__lockButton = bmptoggle.BitmapToggleButton(
                self, style=btnStyle)

            self.__lockButton.SetBitmap(
                icons.loadBitmap('chainlinkHighlight16'),
                icons.loadBitmap('chainlink16'))

            self.__lockButton.SetToolTip(
                wx.ToolTip(fsltooltips.actions[self, 'group']))

            self.__sizer.Add(self.__lockButton, flag=wx.EXPAND, proportion=1)

            # There is currently only one overlay
            # group in the application. In the
            # future there may be multiple groups.
            group = displayCtx.overlayGroups[0]

            group  .addListener('overlays',
                                self.__name,
                                self.__overlayGroupChanged)

            self.__lockButton.Bind(wx.EVT_TOGGLEBUTTON, self.__onLockButton)
            self.__overlayGroupChanged()

        # Set up the show/hide button if needed
        if showVis:
            self.__visibility = bmptoggle.BitmapToggleButton(
                self,
                trueBmp=icons.loadBitmap('eyeHighlight16'),
                falseBmp=icons.loadBitmap('eye16'),
                style=btnStyle)

            self.__visibility.SetToolTip(
                wx.ToolTip(fsltooltips.properties[display, 'enabled']))

            self.__sizer.Add(self.__visibility, flag=wx.EXPAND, proportion=1)

            display.addListener('enabled',
                                self.__name,
                                self.__displayVisChanged)

            self.__visibility.Bind(bmptoggle.EVT_BITMAP_TOGGLE,
                                   self.__onVisButton)

            self.__displayVisChanged()