Exemplo n.º 1
0
def color_pair_coercer(arg):
    """ Coerce to a tuple of colors

    """
    if not isinstance(arg, (tuple, list)):
        c1, c2 = [arg, arg]
    else:
        c1, c2 = arg
    if not isinstance(c1, Color):
        c1 = parse_color(c1)
    if not isinstance(c2, Color):
        c2 = parse_color(c2)
    return (c1, c2)
Exemplo n.º 2
0
def _make_color(color_str):
    """ A function which converts a color string into a QColor.

    """
    color = parse_color(color_str)
    if color is not None:
        return QColor_from_Color(color)
    return QColor()
Exemplo n.º 3
0
def _make_color(color_str):
    """ A function which converts a color string into a QColor.

    """
    color = parse_color(color_str)
    if color is not None:
        return QColor_from_Color(color)
    return QColor()
Exemplo n.º 4
0
    def set_foreground(self, foreground):
        """ Set the foreground color for the list item.

        """
        qcolor = None
        if foreground:
            color = parse_color(foreground)
            if color is not None:
                qcolor = QColor.fromRgbF(*color)
        with self.loopback_guard('changed'):
            self._item.setData(Qt.ForegroundRole, qcolor)
Exemplo n.º 5
0
    def set_foreground(self, foreground):
        """ Set the foreground color for the list item.

        """
        qcolor = None
        if foreground:
            color = parse_color(foreground)
            if color is not None:
                qcolor = QColor.fromRgbF(*color)
        with self.loopback_guard('changed'):
            self._item.setData(Qt.ForegroundRole, qcolor)
Exemplo n.º 6
0
    def test_set_bgcolor(self):
        """ Test the setting of a WidgetComponent's bgcolor attribute
        """
        background_color = "#FFFFFF"
        with self.app.process_events():
            self.server_widget.bgcolor = background_color
        rgba = parse_color(background_color)

        role = self.client_widget.backgroundRole()
        color = self.client_widget.palette().color(role)
        client_color = get_rbga_from_qt_color(color)

        self.assertEquals(rgba, client_color)
Exemplo n.º 7
0
    def test_set_bgcolor(self):
        """ Test the setting of a WidgetComponent's bgcolor attribute
        """
        background_color = "#FFFFFF"
        with self.app.process_events():
            self.server_widget.bgcolor = background_color
        rgba = parse_color(background_color)

        role = self.client_widget.backgroundRole()
        color = self.client_widget.palette().color(role)
        client_color = get_rbga_from_qt_color(color)

        self.assertEquals(rgba, client_color)
Exemplo n.º 8
0
def test_compiling_a_sequence_not_compiling2(workspace, root, monkeypatch,
                                             process_and_sleep, windows):
    """Test compiling a sequence that can be evaluated but not compiled.

    """
    def __raise(*args, **kwargs):
        return False, {}, {'test': False}
    from ecpy_pulses.testing.context import TestContext
    monkeypatch.setattr(TestContext, 'compile_and_transfer_sequence',
                        __raise)
    workbench = workspace.workbench
    ui = workbench.get_plugin('enaml.workbench.ui')
    ui.show_window()
    process_and_sleep()

    root.external_vars = {'a': 1.5}

    pulse1 = Pulse(def_1='1.0', def_2='{a}')
    pulse2 = Pulse(def_1='{a} + 1.0', def_2='3.0')
    pulse3 = Pulse(def_1='{4_start} + 0.5',
                   def_2='{4_start}+{4_duration}-0.5')
    pulse4 = Pulse(def_1='2.0', def_2='0.5', def_mode='Start/Duration')
    pulse5 = Pulse(def_1='3.0', def_2='0.5', def_mode='Start/Duration')

    sequence2 = BaseSequence(time_constrained=True,
                             def_1='{3_stop} + 0.5', def_2='6')
    sequence2.add_child_item(0, pulse3)
    sequence1 = BaseSequence()
    add_children(sequence1, (pulse2, sequence2, pulse4))

    add_children(root, (pulse1, sequence1, pulse5))

    workspace.state.sequence = root

    dial = CompileDialog(workspace=workspace)
    dial.show()
    process_and_sleep()
    comp_widget = dial.central_widget().widgets()[0]

    comp_widget.widgets()[-1].clicked = True
    process_and_sleep()

    assert comp_widget.elapsed_time
    assert comp_widget.errors
    assert comp_widget.widgets()[-2].background == parse_color('red')
Exemplo n.º 9
0
def test_compiling_a_sequence_not_compiling2(workspace, root, monkeypatch,
                                             process_and_sleep, windows):
    """Test compiling a sequence that can be evaluated but not compiled.

    """
    def __raise(*args, **kwargs):
        return False, {}, {'test': False}

    from ecpy_pulses.testing.context import TestContext
    monkeypatch.setattr(TestContext, 'compile_and_transfer_sequence', __raise)
    workbench = workspace.workbench
    ui = workbench.get_plugin('enaml.workbench.ui')
    ui.show_window()
    process_and_sleep()

    root.external_vars = OrderedDict({'a': 1.5})

    pulse1 = Pulse(def_1='1.0', def_2='{a}')
    pulse2 = Pulse(def_1='{a} + 1.0', def_2='3.0')
    pulse3 = Pulse(def_1='{4_start} + 0.5', def_2='{4_start}+{4_duration}-0.5')
    pulse4 = Pulse(def_1='2.0', def_2='0.5', def_mode='Start/Duration')
    pulse5 = Pulse(def_1='3.0', def_2='0.5', def_mode='Start/Duration')

    sequence2 = BaseSequence(time_constrained=True,
                             def_1='{3_stop} + 0.5',
                             def_2='6')
    sequence2.add_child_item(0, pulse3)
    sequence1 = BaseSequence()
    add_children(sequence1, (pulse2, sequence2, pulse4))

    add_children(root, (pulse1, sequence1, pulse5))

    workspace.state.sequence = root

    dial = CompileDialog(workspace=workspace)
    dial.show()
    process_and_sleep()
    comp_widget = dial.central_widget().widgets()[0]

    comp_widget.widgets()[-1].clicked = True
    process_and_sleep()

    assert comp_widget.elapsed_time
    assert comp_widget.errors
    assert comp_widget.widgets()[-2].background == parse_color('red')
Exemplo n.º 10
0
def test_compiling_a_sequence_not_compiling(workspace, process_and_sleep, root,
                                            windows):
    """Test compiling that cannot compile as the sequence does not evaluate.

    """
    workbench = workspace.workbench
    ui = workbench.get_plugin('enaml.workbench.ui')
    ui.show_window()
    process_and_sleep()

    root.external_vars = {'a': 1.5}

    pulse1 = Pulse(def_1='1.0', def_2='{a}')
    pulse2 = Pulse(def_1='{a + {b} + 1.0', def_2='3.0')
    pulse3 = Pulse(def_1='{4_start} - 0.5',
                   def_2='{4_start}+{4_duration}-0.5')
    pulse4 = Pulse(def_1='2.0', def_2='0.5', def_mode='Start/Duration')
    pulse5 = Pulse(def_1='3.0', def_2='0.5', def_mode='Start/Duration')

    sequence2 = BaseSequence(time_constrained=True,
                             def_1='{3_stop} + 0.5', def_2='6',
                             name='test')
    sequence2.add_child_item(0, pulse3)
    sequence1 = BaseSequence()
    add_children(sequence1, (pulse2, sequence2, pulse4))

    add_children(root, (pulse1, sequence1, pulse5))

    workspace.state.sequence = root

    dial = CompileDialog(workspace=workspace)
    dial.show()
    process_and_sleep()
    comp_widget = dial.central_widget().widgets()[0]

    comp_widget.widgets()[-1].clicked = True
    process_and_sleep()

    assert comp_widget.elapsed_time
    assert comp_widget.errors
    assert comp_widget.widgets()[-2].background == parse_color('red')
Exemplo n.º 11
0
def test_compiling_a_sequence_not_compiling(workspace, process_and_sleep, root,
                                            windows):
    """Test compiling that cannot compile as the sequence does not evaluate.

    """
    workbench = workspace.workbench
    ui = workbench.get_plugin('enaml.workbench.ui')
    ui.show_window()
    process_and_sleep()

    root.external_vars = OrderedDict({'a': 1.5})

    pulse1 = Pulse(def_1='1.0', def_2='{a}')
    pulse2 = Pulse(def_1='{a + {b} + 1.0', def_2='3.0')
    pulse3 = Pulse(def_1='{4_start} - 0.5', def_2='{4_start}+{4_duration}-0.5')
    pulse4 = Pulse(def_1='2.0', def_2='0.5', def_mode='Start/Duration')
    pulse5 = Pulse(def_1='3.0', def_2='0.5', def_mode='Start/Duration')

    sequence2 = BaseSequence(time_constrained=True,
                             def_1='{3_stop} + 0.5',
                             def_2='6',
                             name='test')
    sequence2.add_child_item(0, pulse3)
    sequence1 = BaseSequence()
    add_children(sequence1, (pulse2, sequence2, pulse4))

    add_children(root, (pulse1, sequence1, pulse5))

    workspace.state.sequence = root

    dial = CompileDialog(workspace=workspace)
    dial.show()
    process_and_sleep()
    comp_widget = dial.central_widget().widgets()[0]

    comp_widget.widgets()[-1].clicked = True
    process_and_sleep()

    assert comp_widget.elapsed_time
    assert comp_widget.errors
    assert comp_widget.widgets()[-2].background == parse_color('red')
Exemplo n.º 12
0
def q_parse_color(color):
    """ Convert a color string into a QColor.

    Parameters
    ----------
    color : string
        A CSS3 color string to convert to a QColor.

    Returns
    -------
    result : QColor
        The QColor for the given color string

    """
    rgba = parse_color(color)
    if rgba is None:
        qcolor = QColor()
    else:
        r, g, b, a = rgba
        qcolor = QColor.fromRgbF(r, g, b, a)
    return qcolor
Exemplo n.º 13
0
def wx_parse_color(color):
    """ Convert a color string into a wxColour.

    Parameters
    ----------
    color : string
        A CSS3 color string to convert to a wxColour.

    Returns
    -------
    result : wxColour
        The wxColour for the given color string

    """
    rgba = parse_color(color)
    if rgba is None:
        wx_color = wx.NullColour
    else:
        r, g, b, a = rgba
        i = int
        wx_color = wx.Colour(i(r * 255), i(g * 255), i(b * 255), i(a * 255))
    return wx_color
Exemplo n.º 14
0
def wx_parse_color(color):
    """ Convert a color string into a wxColour.

    Parameters
    ----------
    color : string
        A CSS3 color string to convert to a wxColour.

    Returns
    -------
    result : wxColour
        The wxColour for the given color string

    """
    rgba = parse_color(color)
    if rgba is None:
        wx_color = wx.NullColour
    else:
        r, g, b, a = rgba
        i = int
        wx_color = wx.Colour(i(r * 255), i(g * 255), i(b * 255), i(a * 255))
    return wx_color
Exemplo n.º 15
0
 def _default_grid_colors(self):
     return (parse_color('#888'), parse_color('#444'))
Exemplo n.º 16
0
 def _default_background_gradient(self):
     return (parse_color('white'), parse_color('silver'))
Exemplo n.º 17
0
from atom.api import Atom, Int, Float, Str

from enaml.colors import parse_color
from enaml.itemmodels.api import (Editor, Group, Item, IntItem, StrItem,
                                  FloatItem, EditorTable)

#------------------------------------------------------------------------------
# Custom Items
#------------------------------------------------------------------------------
lightskyblue = parse_color('lightskyblue')
steelblue = parse_color('steelblue')


class AltBlue(Item):
    def get_background(self, model):
        if getattr(model, self.name) % 7 != 0:
            return lightskyblue
        return steelblue


#------------------------------------------------------------------------------
# Data Models
#------------------------------------------------------------------------------
class Foo(Atom):
    name = Str()
    a = Int()
    b = Int()
    c = Int()

    groups = [
        Group('Ints',
Exemplo n.º 18
0
 def assert_exec():
     assert comp_widget.elapsed_time
     assert not comp_widget.errors
     assert comp_widget.widgets()[-2].background == parse_color('green')
Exemplo n.º 19
0
from atom.api import Atom, Int, Float, Str

from enaml.colors import parse_color
from enaml.itemmodels.api import (
    Editor, Group, Item, IntItem, StrItem, FloatItem, EditorTable
)

#------------------------------------------------------------------------------
# Custom Items
#------------------------------------------------------------------------------
lightskyblue = parse_color('lightskyblue')
steelblue = parse_color('steelblue')

class AltBlue(Item):

    def get_background(self, model):
        if getattr(model, self.name) % 7 != 0:
            return lightskyblue
        return steelblue


#------------------------------------------------------------------------------
# Data Models
#------------------------------------------------------------------------------
class Foo(Atom):
    name = Str()
    a = Int()
    b = Int()
    c = Int()

    groups = [