How to use the traitsui.api.Handler function in traitsui

To help you get started, we’ve selected a few traitsui examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github enthought / traitsui / integrationtests / ui / test_ui5.py View on Github external
integer_text = Int(1)
    enumeration = Trait('one', 'two', 'three', 'four', 'five', 'six',
                        cols=3)
    float_range = Range(0.0, 10.0, 10.0)
    int_range = Range(1, 5)
    boolean = Bool(True)

    view = View('integer_text', 'enumeration', 'float_range',
                'int_range', 'boolean')

#-------------------------------------------------------------------------
#  'TraitsTestHandler' class:
#-------------------------------------------------------------------------


class TraitsTestHandler(Handler):

    def object_enabled_changed(self, info):
        enabled = info.object.enabled
        for i in range(1, 63):
            getattr(info, 'f%d' % i).enabled = enabled

#-------------------------------------------------------------------------
#  'TraitsTest' class
#-------------------------------------------------------------------------


class TraitsTest(HasTraits):

    #-------------------------------------------------------------------------
    #  Trait definitions:
    #-------------------------------------------------------------------------
github enthought / traitsui / integrationtests / ui / test_ui2.py View on Github external
info.city.enabled = enabled
        info.state.enabled = enabled
        if obj.zip == 78664:
            obj.street = '901 Morning View Place'
            obj.city = 'Round Rock'
            obj.state = 'Texas'

    def object_call_changed(self, info):
        print 'You called?'

#-------------------------------------------------------------------------
#  'WizardHandler' class:
#-------------------------------------------------------------------------


class WizardHandler(Handler):

    def object_sex_changed(self, info):
        if info.object.sex == 'Female':
            info.p1.next = 'p3'
        else:
            info.p1.next = 'p2'
            info.p2.next = None

    def object_name_changed(self, info):
        info.p2.enabled = info.p3.enabled = (info.object.name != '')
        if not info.p2.enabled:
            info.p2.msg = info.p3.msg = 'You must enter a valid name.'

#-------------------------------------------------------------------------
#  'Employer' class:
#-------------------------------------------------------------------------
github ruoyu0088 / scpy2 / examples / fractal / ifs_demo.py View on Github external
self.ax.set_axis_off()
            self.canvas.draw()
            self.background = self.canvas.copy_from_bbox(self.ax.bbox)
            self.update_lines()

        # 快速绘制所有三角形
        self.canvas.restore_region(self.background)  # 恢复背景
        # 绘制所有三角形
        for line in self.ax.lines:
            self.ax.draw_artist(line)
        self.canvas.blit(self.ax.bbox)

        self.version += 1


class IFSHandler(Handler):
    """
    在界面显示之前需要初始化的内容
    """

    def init(self, info):
        info.object.init_gui_component()
        return True


class IFSDesigner(HasTraits):
    color_maps = List
    current_map = Str("Greens")
    figure = Instance(Figure)  # 控制绘图控件的Figure对象
    ifs_triangle = Instance(IFSTriangles)
    add_button = Button(u"添加三角形")
    del_button = Button(u"删除三角形")
github enthought / chaco / examples / demo / basic / image_from_file.py View on Github external
# Update the plot data. NB we must extract _data from the image
        # for the time being, until ImageData is made more friendly
        self.pd.set_data("imagedata", image._data)

        # Set the title and redraw
        self.plot.title = os.path.basename(self._load_file)
        self.plot.request_redraw()



#-------------------------------------------------------------------------------
# Class 'DemoController'
#-------------------------------------------------------------------------------

class DemoController(Handler):

    # The HasTraits object we are a controller for
    view = Instance(DemoView)

    #---------------------------------------------------------------------------
    # Public 'DemoController' interface
    #---------------------------------------------------------------------------

    def init(self, info):
        """ Initializes the controls of a user interface.
        Overridden here to assign the 'view' trait.
        """
        self.view = info.object

    def save(self, ui_info):
        """
github LTS5 / connectomeviewer / cviewer / plugins / text_editor / editor / text_editor_handler.py View on Github external
""" The traits UI handler for the text editor. """


# Enthought library imports.
from traitsui.api import Handler


class TextEditorHandler(Handler):
    """ The traits UI handler for the text editor. """

    ###########################################################################
    # 'TextEditorHandler' interface.
    ###########################################################################

    # fixme: We need to work out how to create these 'dispatch' methods
    # dynamically! Plugins will want to add bindings to the editor to bind
    # a key to an action.
    def run(self, info):
        """ Run the text as Python code. """

        info.object.run()

        return
github LTS5 / connectomeviewer / cviewer / visualization / matrix / cmatrix_viewer.py View on Github external
from enable.api import BaseTool

# Enthought library imports
from enable.api import Component, ComponentEditor, Window
from traits.api import HasTraits, Instance, Str, Enum, Float, Int, Any
from traitsui.api import Item, Group, View, HGroup, Handler

# Chaco imports
from chaco.api import ArrayPlotData, ColorBar, HPlotContainer, jet, LinearMapper, Plot
from chaco.tools.api import PanTool, RangeSelection, RangeSelectionOverlay, ZoomTool

# ConnectomeViewer imports
from cviewer.plugins.cff.ui.edge_parameters_view import EdgeParameters
from cviewer.visualization.matrix.matrix_viewer import MatrixViewer

class CustomHandler(Handler):
    """ Handler used to set NetworkName in TraitsTitle """
    
    def object_network_reference_changed(self, info):
        if not info.initialized:
            info.ui.title = info.object.network_reference.networkname + ' - Matrix Viewer'
            
class CustomTool(BaseTool):
    
    #event_state = Enum("normal", "mousedown")
    xval = Float
    yval = Float
    
    def normal_mouse_move(self, event):
        xval, yval = self.component.map_data((event.x, event.y))
        
        self.xval = xval
github mne-tools / mne-python / mne / gui / _fiducials_gui.py View on Github external
# find fiducials file
        fid_files = _find_fiducials_files(subject, subjects_dir)
        if len(fid_files) == 0:
            self.fid.reset_traits(['file'])
            self.lock_fiducials = False
        else:
            self.fid_file = fid_files[0].format(subjects_dir=subjects_dir,
                                                subject=subject)
            self.lock_fiducials = True

        # does not seem to happen by itself ... so hard code it:
        self.reset_fiducials()


class SetHandler(Handler):
    """Handler to change style when setting MRI fiducials."""

    def object_set_changed(self, info):  # noqa: D102
        return self.object_locked_changed(info)

    def object_locked_changed(self, info):  # noqa: D102
        if info.object.locked:
            ss = ''
        else:
            ss = 'border-style: solid; border-color: red; border-width: 2px;'
        # This will only work for Qt, but hopefully that's most users!
        try:
            _color_children(info.ui.info.ui.control, ss)
        except AttributeError:  # safeguard for wxpython
            pass
github hyperspy / hyperspyUI / hyperspyui / widgets / dataviewwidget.py View on Github external
from functools import partial
import traits.api as t
import traitsui.api as tu

from hyperspyui.util import create_add_component_actions, win2sig


def tr(text):
    return QtCore.QCoreApplication.translate("DataViewWidget", text)


NameCol = 1
VisibilityCol = 0


class ComponentEditorHandler(tu.Handler):

    def setattr(self, info, object, name, value):
        # Set the value etc.
        tu.Handler.setattr(self, info, object, name, value)
        if name in ('value', 'std'):
            try:
                # Make sure the value is actually stored in array
                object.store_current_value_in_array()
            except AttributeError:
                pass


class VisbilityDelegate(QtWidgets.QStyledItemDelegate):

    def __init__(self, parent=None, icons=None):
        if icons is None or len(icons) < 1:
github enthought / traitsui / examples / demo / Advanced / Dynamic_views_demo.py View on Github external
name='foo',
            id='traitsui.demos.dynamic_views',
            keywords={
                'buttons': ['OK'],
                'dock': 'tab',
                'height': 0.4,
                'width': 0.4,
                'resizable': True,
                'scrollable': True,
            },
            use_as_default=True,
        )
        self.declare_dynamic_view(declaration)


class MyInfoHandler(Handler):

    def object_first_changed(self, info):
        info.object.derived = info.object.first


class BaseFoo(HasFooView):
    """ A base class that puts some content in the 'foo' dynamic view.
    """

    first = Str('My first name')
    last = Str('My last name')

    # A derived trait set by the handler associated with out dynamic view
    # contribution:
    derived = Str