Exemplo n.º 1
0
def test_wxFlavour():
    with run_without_wx():
        assert fw.wxFlavour() is None
    with mock.patch('wx.PlatformInfo', ['phoenix']):
        assert fw.wxFlavour() == fw.WX_PHOENIX
    with mock.patch('wx.PlatformInfo', ['oldversion']):
        assert fw.wxFlavour() == fw.WX_PYTHON
Exemplo n.º 2
0
    def __init__(self, parent, size=None, colour=None):
        """Create a ``ColourButton``.

        :arg parent: A :mod:`wx` parent window.

        :arg size:   A tuple containing the ``(width, height)`` of the
                     colour bitmap in pixels. Defaults to ``(32, 32)``.

        :arg colour: Initial colour. Defaults to black.
        """

        if size is None: size = (32, 32)
        if colour is None: colour = (0, 0, 0, 255)

        style = wx.BU_EXACTFIT | wx.BU_NOTEXT

        wx.Button.__init__(self, parent, style=style)

        # Under wxPython-phoenix, setting
        # label='' results in "Button".
        if fw.wxFlavour() == fw.WX_PHOENIX:
            self.SetLabel(' ')

        self.__size = size
        self.__bmp = None

        self.Bind(wx.EVT_BUTTON, self.__onClick)

        self.SetValue(colour)
        self.SetMinSize(self.GetBestSize())
Exemplo n.º 3
0
    def __updateBitmap(self, colour):
        """Called when the colour is changed. Updates the bitmap shown
        on the button.
        """

        import numpy as np

        w, h = self.__size
        data = np.zeros((w, h, 4), dtype=np.uint8)

        data[:, :] = colour

        if fw.wxFlavour() == fw.WX_PHOENIX:
            self.__bmp = wx.Bitmap.FromBufferRGBA(w, h, data)
        else:
            self.__bmp = wx.BitmapFromBufferRGBA(w, h, data)

        self.SetBitmap(self.__bmp)
Exemplo n.º 4
0
"""


import time
import logging

import                    wx
import wx.lib.newevent as wxevent

import fsleyes_widgets as fw


log = logging.getLogger(__name__)


if fw.wxFlavour() == fw.WX_PHOENIX: FloatSpinBase = wx.Panel
else:                               FloatSpinBase = wx.PyPanel


class FloatSpinCtrl(FloatSpinBase):
    """A ``FloatSpinCtrl`` is a :class:`wx.Panel` which contains a
    :class:`wx.TextCtrl` and a :class:`wx.SpinButton`, allowing the user to
    modify a floating point (or integer) value.

    The ``FloatSpinCtrl`` is an alternative to :class:`wx.SpinCtrl`,
    :class:`wx.SpinCtrlDouble`, and :class:`wx.lib.agw.floatspin.FloatSpin`.

     - :class:`wx.SpinCtrlDouble`: Under Linux/GTK, this widget does not allow
        the user to enter values that are not a multiple of the increment.

     - :class:`wx.lib.agw.floatspin.FloatSpin`. Differs from the
Exemplo n.º 5
0
import wx.adv

from fsl.utils.platform import platform as fslplatform
import fsl.utils.idle as idle
import fsleyes_widgets as fwidgets
import fsleyes_widgets.utils.status as status

import fsleyes
import fsleyes.strings as strings
import fsleyes.splash as fslsplash
import fsleyes.cliserver as cliserver
import fsleyes.colourmaps as colourmaps

# wx.ModalDialogHook does not exist in wxPython < 4

if fwidgets.wxFlavour() in (fwidgets.WX_PYTHON, fwidgets.WX_UNKNOWN):

    class ModalDialogHook(object):
        def Register(self):
            pass

    wx.ModalDialogHook = ModalDialogHook

log = logging.getLogger(__name__)


class FSLeyesApp(wx.App):
    """FSLeyes-specific sub-class of ``wx.App``. """
    class ModalHook(wx.ModalDialogHook):
        """Keeps track of any modal dialogs/windows that are opened.
Exemplo n.º 6
0
                        '- unless the application is shutting down, '
                        'this is probably a bug!'.format(type(self).__name__))


FSLeyesPanelBase = None
"""Under Python2/wxPython, we need to derive from ``wx.PyPanel``. But
under Python3/wxPython-Phoenix, we need to derive from ``wx.Panel``.
"""

FSLeyesPanelMeta = None
"""Under Python3/wxPython-Phoenix, we need to specify the meta-class as
``wx.siplib.wrappertype``. This is not necessary under Python2/wxPython.
"""

# wxPython/Phoenix
if fwidgets.wxFlavour() == fwidgets.WX_PHOENIX:

    import wx.siplib as sip

    FSLeyesPanelMeta = sip.wrappertype
    FSLeyesPanelBase = wx.Panel

# Old wxPython
else:
    FSLeyesPanelMeta = type
    FSLeyesPanelBase = wx.PyPanel


class FSLeyesPanel(
        six.with_metaclass(FSLeyesPanelMeta, _FSLeyesPanel, FSLeyesPanelBase)):
    """The ``FSLeyesPanel`` is the base class for all view and control panels
Exemplo n.º 7
0
    def __init__(self,
                 parent,
                 title=None,
                 message=None,
                 cbMessages=None,
                 cbStates=None,
                 yesText=None,
                 noText=None,
                 cancelText=None,
                 hintText=None,
                 focus=None,
                 icon=None,
                 style=None):
        """Create a ``CheckBoxMessageDialog``.

        :arg parent:        A ``wx`` parent object.

        :arg title:         The dialog frame title.

        :arg message:       Message to show on the dialog.

        :arg cbMessages:    A list of labels, one for each ``wx.CheckBox``.

        :arg cbStates:      A list of initial states (boolean values) for
                            each ``wx.CheckBox``.

        :arg yesText:       Text to show on the *yes*/confirm button. Defaults
                            to *OK*.

        :arg noText:        Text to show on the *no* button. If not provided,
                            there will be no *no* button.

        :arg cancelText:    Text to show on the *cancel* button. If not
                            provided, there will be no cancel button.

        :arg hintText:      If provided, shown as a "hint", in a slightly
                            faded font, between the checkboxes and the buttons.

        :arg focus:         One of ``'yes'``, ``'no'```, or ``'cancel'``,
                            specifying which button should be given initial
                            focus.

        :arg icon:          A ``wx`` icon identifier (e.g.
                            ``wx.ICON_EXCLAMATION``).

        :arg style:         Passed through to the ``wx.Dialog.__init__``
                            method. Defaults to ``wx.DEFAULT_DIALOG_STYLE``.
        """

        if style is None: style = wx.DEFAULT_DIALOG_STYLE
        if title is None: title = ''
        if message is None: message = ''
        if cbMessages is None: cbMessages = ['']
        if cbStates is None: cbStates = [False] * len(cbMessages)
        if yesText is None: yesText = 'OK'

        wx.Dialog.__init__(self, parent, title=title, style=style)

        if icon is not None:
            icon = wx.ArtProvider.GetMessageBoxIcon(icon)
            self.__icon = wx.StaticBitmap(self)

            if fw.wxFlavour() == fw.WX_PHOENIX:
                bmp = wx.Bitmap()
            else:
                bmp = wx.EmptyBitmap(icon.GetWidth(), icon.GetHeight())

            bmp.CopyFromIcon(icon)
            self.__icon.SetBitmap(bmp)
        else:
            self.__icon = (1, 1)

        self.__checkboxes = []
        for msg, state in zip(cbMessages, cbStates):
            cb = wx.CheckBox(self, label=msg)
            cb.SetValue(state)
            self.__checkboxes.append(cb)

        self.__message = wx.StaticText(self, label=message)
        self.__yesButton = wx.Button(self, label=yesText, id=wx.ID_YES)

        self.__yesButton.Bind(wx.EVT_BUTTON, self.__onYesButton)

        if noText is not None:
            self.__noButton = wx.Button(self, label=noText, id=wx.ID_NO)
            self.__noButton.Bind(wx.EVT_BUTTON, self.__onNoButton)

        else:
            self.__noButton = None

        if cancelText is not None:
            self.__cancelButton = wx.Button(self,
                                            label=cancelText,
                                            id=wx.ID_CANCEL)
            self.__cancelButton.Bind(wx.EVT_BUTTON, self.__onCancelButton)
        else:
            self.__cancelButton = None

        if hintText is not None:
            self.__hint = wx.StaticText(self, label=hintText)
            self.__hint.SetForegroundColour(
                wx.SystemSettings.GetColour(
                    wx.SYS_COLOUR_WINDOWTEXT).ChangeLightness(75))
        else:
            self.__hint = None

        self.__mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        self.__contentSizer = wx.BoxSizer(wx.VERTICAL)
        self.__btnSizer = wx.BoxSizer(wx.HORIZONTAL)

        self.__contentSizer.Add(self.__message, flag=wx.EXPAND, proportion=1)
        self.__contentSizer.Add((1, 20), flag=wx.EXPAND)
        for cb in self.__checkboxes:
            self.__contentSizer.Add(cb, flag=wx.EXPAND)

        if self.__hint is not None:
            self.__contentSizer.Add((1, 20), flag=wx.EXPAND)
            self.__contentSizer.Add(self.__hint, flag=wx.EXPAND)

        self.__contentSizer.Add((1, 20), flag=wx.EXPAND)
        self.__btnSizer.Add((1, 1), flag=wx.EXPAND, proportion=1)

        buttons = [self.__yesButton, self.__noButton, self.__cancelButton]
        buttons = [b for b in buttons if b is not None]

        for i, b in enumerate(buttons):
            self.__btnSizer.Add(b)
            if i != len(buttons) - 1:
                self.__btnSizer.Add((5, 1), flag=wx.EXPAND)

        self.__contentSizer.Add(self.__btnSizer, flag=wx.EXPAND)

        self.__mainSizer.Add(self.__icon, flag=wx.ALL | wx.CENTRE, border=20)
        self.__mainSizer.Add(self.__contentSizer,
                             flag=wx.EXPAND | wx.ALL,
                             proportion=1,
                             border=20)

        self.__message.Wrap(self.GetSize().GetWidth())

        yes = self.__yesButton
        no = self.__noButton
        cncl = self.__cancelButton

        if focus == 'yes': yes.SetDefault()
        elif focus == 'no' and no is not None: no.SetDefault()
        elif focus == 'cancel' and cncl is not None: cncl.SetDefault()

        self.SetSizer(self.__mainSizer)
        self.Layout()
        self.Fit()
        self.CentreOnParent()
Exemplo n.º 8
0
    def __init__(self, parent, toolName, osxHint):
        """Create a ``FSLDirDialog``.

        :arg parent:   The :mod:`wx` parent object.

        :arg toolName: The name of the tool which is running.

        :arg osxHint:  If ``True``, an OSX-specific hint is added to the
                       dialog.
        """

        wx.Dialog.__init__(self, parent, title='$FSLDIR is not set')

        self.__fsldir = None
        self.__icon = wx.StaticBitmap(self)
        self.__message = wx.StaticText(self)
        self.__locate = wx.Button(self, id=wx.ID_OK)
        self.__skip = wx.Button(self, id=wx.ID_CANCEL)

        icon = wx.ArtProvider.GetMessageBoxIcon(wx.ICON_EXCLAMATION)

        if fw.wxFlavour() == fw.WX_PHOENIX:
            bmp = wx.Bitmap()
        else:
            bmp = wx.EmptyBitmap(icon.GetWidth(), icon.GetHeight())

        bmp.CopyFromIcon(icon)

        self.__icon.SetBitmap(bmp)
        self.__message.SetLabel(
            'The $FSLDIR environment variable is not set - {} '
            'may not behave correctly.'.format(toolName))
        self.__locate.SetLabel('Locate $FSLDIR')
        self.__skip.SetLabel('Skip')

        self.__skip.Bind(wx.EVT_BUTTON, self.__onSkip)
        self.__locate.Bind(wx.EVT_BUTTON, self.__onLocate)

        self.__mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        self.__contentSizer = wx.BoxSizer(wx.VERTICAL)
        self.__buttonSizer = wx.BoxSizer(wx.HORIZONTAL)

        self.__buttonSizer.Add((1, 1), flag=wx.EXPAND, proportion=1)
        self.__buttonSizer.Add(self.__locate)
        self.__buttonSizer.Add((20, 1))
        self.__buttonSizer.Add(self.__skip)

        self.__contentSizer.Add(self.__message, flag=wx.EXPAND, proportion=1)
        self.__contentSizer.Add((1, 20))
        self.__contentSizer.Add(self.__buttonSizer, flag=wx.EXPAND)

        # If running on OSX, add a message
        # telling the user about the
        # cmd+shift+g shortcut
        if osxHint:

            self.__hint = wx.StaticText(
                self,
                label='Hint: Press \u2318+\u21e7+G in the file '
                'dialog to manually type in a location.')

            self.__hint.SetForegroundColour(
                wx.SystemSettings.GetColour(
                    wx.SYS_COLOUR_WINDOWTEXT).ChangeLightness(75))

            self.__contentSizer.Insert(2, self.__hint, flag=wx.EXPAND)
            self.__contentSizer.Insert(3, (1, 20))

        else:
            self.__hint = None

        self.__mainSizer.Add(self.__icon, flag=wx.ALL | wx.CENTRE, border=20)
        self.__mainSizer.Add(self.__contentSizer,
                             flag=wx.EXPAND | wx.ALL,
                             proportion=1,
                             border=20)

        self.__message.Wrap(self.GetSize().GetWidth())

        self.SetSizer(self.__mainSizer)
        self.__mainSizer.Layout()
        self.__mainSizer.Fit(self)

        self.CentreOnParent()
Exemplo n.º 9
0
    def __init__(self,
                 parent,
                 title='',
                 message='',
                 text='',
                 icon=None,
                 style=None):
        """Create a ``TextEditDialog``.

        :arg parent:  The :mod:`wx` parent object.

        :arg title:   Dialog title.

        :arg message: Dialog message.

        :arg text:    String  to display in the text field.

        :arg icon:    A :mod:`wx` icon identifier, such as
                      :data:`wx.ICON_INFORMATION` or :data:`wx.ICON_WARNING`.

        :arg style:   A combination of :data:`TED_READONLY`,
                      :data:`TED_MULTILINE`, :data:`TED_OK`,
                      :data:`TED_CANCEL`, :data:`TED_OK_CANCEL`,
                      :data:`TED_COPY` and :data:`TED_COPY_MESSAGE` . Defaults
                      to :data:`TED_OK`.
        """

        if style is None:
            style = TED_OK

        wx.Dialog.__init__(self,
                           parent,
                           title=title,
                           style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)

        textStyle = 0
        if style & TED_READONLY: textStyle |= wx.TE_READONLY
        if style & TED_MULTILINE: textStyle |= wx.TE_MULTILINE

        self.__message = wx.StaticText(self)
        self.__textEdit = wx.TextCtrl(self, style=textStyle)

        self.__message.SetLabel(message)
        self.__textEdit.SetValue(text)

        self.__showCopyMessage = style & TED_COPY_MESSAGE

        # set the min size of the text
        # ctrl so it can fit a few lines
        self.__textEdit.SetMinSize((-1, 120))
        self.__textEdit.SetMaxSize((600, -1))

        self.__ok = (-1, -1)
        self.__copy = (-1, -1)
        self.__cancel = (-1, -1)
        self.__icon = (-1, -1)
        self.__buttons = []

        if icon is not None:

            icon = wx.ArtProvider.GetMessageBoxIcon(icon)

            if fw.wxFlavour() == fw.WX_PHOENIX:
                bmp = wx.Bitmap()
            else:
                bmp = wx.EmptyBitmap(icon.GetWidth(), icon.GetHeight())

            bmp.CopyFromIcon(icon)
            self.__icon = wx.StaticBitmap(self)
            self.__icon.SetBitmap(bmp)

        if style & TED_OK:
            self.__ok = wx.Button(self, id=wx.ID_OK)
            self.__ok.Bind(wx.EVT_BUTTON, self.onOk)
            self.__buttons.append(self.__ok)

        if style & TED_CANCEL:
            self.__cancel = wx.Button(self, id=wx.ID_CANCEL)
            self.__cancel.Bind(wx.EVT_BUTTON, self.onCancel)
            self.__buttons.append(self.__cancel)

        if style & TED_COPY:
            self.__copy = wx.Button(self, label='Copy to clipboard')
            self.__copy.Bind(wx.EVT_BUTTON, self.__onCopy)
            self.__buttons.append(self.__copy)

        self.__textEdit.Bind(wx.EVT_CHAR_HOOK, self.__onCharHook)

        textSizer = wx.BoxSizer(wx.VERTICAL)
        iconSizer = wx.BoxSizer(wx.HORIZONTAL)
        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
        mainSizer = wx.BoxSizer(wx.VERTICAL)

        textSizer.Add(self.__message, flag=wx.ALL | wx.CENTRE, border=20)
        textSizer.Add(self.__textEdit,
                      flag=wx.ALL | wx.EXPAND,
                      border=20,
                      proportion=1)

        iconSizer.Add(self.__icon, flag=wx.ALL | wx.CENTRE, border=20)
        iconSizer.Add(textSizer, flag=wx.EXPAND, proportion=1)

        btnSizer.AddStretchSpacer()
        btnSizer.Add(self.__ok, flag=wx.ALL | wx.CENTRE, border=10)
        btnSizer.Add(self.__copy, flag=wx.ALL | wx.CENTRE, border=10)
        btnSizer.Add(self.__cancel, flag=wx.ALL | wx.CENTRE, border=10)
        btnSizer.Add((-1, 20))

        mainSizer.Add(iconSizer, flag=wx.EXPAND, proportion=1)
        mainSizer.Add(btnSizer, flag=wx.EXPAND)

        self.SetSizer(mainSizer)
        self.Fit()