Beispiel #1
0
class show_trace(HasTraits):

    command = Str
    container = Instance(VPlotContainer)
    pd = Instance(ArrayPlotData)
    plot1 = Instance(Plot)
    key_bindings = KeyBindings(
        KeyBinding(
            binding1='Ctrl-d',  # CTRL-D works, while D doesn't.
            description='Restitution Displacement',
            method_name='action1'), )

    view = View(Item('container', editor=ComponentEditor()),
                Item('command'),
                key_bindings=key_bindings,
                handler=CodeHandler(),
                resizable=True,
                buttons=["OK"],
                width=1024,
                height=768,
                title='DB FrontEnd 2 - Show Trace')

    def __init__(self):
        self.pd = ArrayPlotData()
        x = linspace(0, 100, 101)
        y = random.random_integers(-100, 100, 101)
        self.pd.set_data('index', x)
        self.pd.set_data('value', y)
        p = Plot(self.pd)
        p.plot(('index', 'value'))
        self.plot1 = p
        self.container = VPlotContainer()
        self.container.add(self.plot1)
Beispiel #2
0
class Transform(HasTraits):
    t_step = .005
    
    R = Array(float,(3,))
    reset = Button
    T = Array(float,(3,))    
    
    _key_bindings = []
    

    for (ax,let,key) in zip('012','xyz','qwe'):
        for (sgn,suff) in zip(('1','-1'),('p','n')):
            if sgn == "-1": key = key.upper()
            fname = let+'q'+suff
                
            s = (
"""
def %(fname)s(self,_):
    t = r_[0.,0,0]
    t[%(ax)s] = %(sgn)s*self.t_step
    self.R = self.R + t
_key_bindings.append(KeyBinding(binding1="%(key)s",method_name="%(fname)s"))
"""%locals())
            print s
            exec(s)
            
            
    for (ax,let,key) in zip('012','xyz','asd'):
        for (sgn,suff) in zip(('1','-1'),('p','n')):
            if sgn == "-1": key = key.upper()
            fname = let+'q'+suff            
            fname = let+'t'+suff
            s = (
"""
def %(fname)s(self,_):
    t = r_[0.,0,0]
    t[%(ax)s] = %(sgn)s*self.t_step
    self.T = self.T + t

_key_bindings.append(KeyBinding(binding1="%(key)s",method_name="%(fname)s"))
"""%locals())
            print s
            exec(s)
            
    del ax,let,key,sgn,suff,fname

    def __init__(self,T,R):
        self.T = T
        self.R = R
        HasTraits.__init__(self)

    view = View(
        VGroup(
            Item("reset"),            
            Item("T",style="readonly"),
            Item("R",style="readonly")),
        key_bindings = KeyBindings(*_key_bindings),
        buttons = OKCancelButtons,
        width = 500)        
Beispiel #3
0
class Transform(HasTraits):
    t_step = .005

    R = Array(float, (3, ))
    reset = Button
    T = Array(float, (3, ))

    _key_bindings = []

    for (ax, let, key) in zip('012', 'xyz', 'qwe'):
        for (sgn, suff) in zip(('1', '-1'), ('p', 'n')):
            if sgn == "-1": key = key.upper()
            fname = let + 'q' + suff

            s = ("""
def %(fname)s(self,_):
    t = r_[0.,0,0]
    t[%(ax)s] = %(sgn)s*self.t_step
    self.R = self.R + t
_key_bindings.append(KeyBinding(binding1="%(key)s",method_name="%(fname)s"))
""" % locals())
            print s
            exec(s)

    for (ax, let, key) in zip('012', 'xyz', 'asd'):
        for (sgn, suff) in zip(('1', '-1'), ('p', 'n')):
            if sgn == "-1": key = key.upper()
            fname = let + 'q' + suff
            fname = let + 't' + suff
            s = ("""
def %(fname)s(self,_):
    t = r_[0.,0,0]
    t[%(ax)s] = %(sgn)s*self.t_step
    self.T = self.T + t

_key_bindings.append(KeyBinding(binding1="%(key)s",method_name="%(fname)s"))
""" % locals())
            print s
            exec(s)

    del ax, let, key, sgn, suff, fname

    def __init__(self, T=(0, 0, 0), R=(0, 0, 0)):
        self.T = T
        self.R = R
        HasTraits.__init__(self)

    def _reset_fired(self):
        #pvec =  self.arm.get_pvec(target_frame='wrist_roll_link')
        self.set(T=[0, 0, 0], R=[0, 0, 0], trait_change_notify=False)

    view = View(VGroup(Item("reset"), Item("T"), Item("R")),
                key_bindings=KeyBindings(*_key_bindings),
                buttons=OKCancelButtons,
                width=500)
Beispiel #4
0
    def _key_bindings_default(self):
        """ Trait initializer. """

        key_bindings = KeyBindings(
            KeyBinding(binding1='Ctrl-s',
                       description='Save the run',
                       method_name='save_run'),
            KeyBinding(binding1='Ctrl-r',
                       description='Plot the response',
                       method_name='reset_run'))

        return key_bindings
    def _key_bindings_default(self):
        """ Trait initializer. """

        key_bindings = KeyBindings(
            KeyBinding(binding1='Ctrl-s',
                       description='Save the file',
                       method_name='save'),
            KeyBinding(binding1='Ctrl-r',
                       description='Run the file',
                       method_name='run'))

        return key_bindings
Beispiel #6
0
    def _key_bindings_default(self):
        """ Trait initializer. """

        key_bindings = KeyBindings(
            KeyBinding(
                binding1="Ctrl-s",
                description="Save the file",
                method_name="save",
            ),
            KeyBinding(
                binding1="Ctrl-r",
                description="Run the file",
                method_name="run",
            ),
        )

        return key_bindings
Beispiel #7
0
class Visualization(HasTraits):
    seq_num = Int(0, desc='Sequence number', auto_set=False, enter_set=True)
    seq_name = Str('0')
    label_name = Str(
        'gt    standing    sit    left_h_hold    right_h_hold    drink    walk    bending    clapping    phone_call    pointing'
    )
    gt = Str('')
    est = Str('')
    next_seq = Button('Next seq')
    prev_seq = Button('Prev seq')
    scene = Instance(MlabSceneModel, ())

    def __init__(self, data_set):
        # Do not forget to call the parent's __init__
        HasTraits.__init__(self)
        self.data_set = data_set

        self.net = ActionNet(512, 10)
        self.net.load_state_dict(
            torch.load('./models/action-net-300-140.pkl',
                       map_location=torch.device('cpu')))
        self.net.eval()

        out, lbl = self.estimate(0)
        out = np.array_str(out)
        lbl = np.array_str(lbl)
        x, y, z, s = self.render(0)
        self.plot = self.scene.mlab.points3d(x,
                                             y,
                                             z,
                                             s,
                                             colormap='hot',
                                             scale_factor=1,
                                             scale_mode='none')
        self.trait_set(seq_name=self.data_set.get_name(0), gt=lbl, est=out)
        # self.anim(self))
        #mlab.axes(figure=self.scene.mayavi_scene)

    def key_down(self, vtk, event):
        vtk.GetKeyCode()

    def _next_seq_fired(self):
        seq_num = int(getattr(self, 'seq_num'))
        seq_num += 1

        if seq_num > self.data_set.__len__():
            seq_num = self.data_set.__len__()

        out, lbl = self.estimate(seq_num)
        out = np.array_str(out)
        lbl = np.array_str(lbl)
        x, y, z, s = self.render(seq_num)
        self.scene.mlab.clf()
        self.plot = self.scene.mlab.points3d(x,
                                             y,
                                             z,
                                             s,
                                             colormap='hot',
                                             scale_factor=1,
                                             scale_mode='none')

        self.trait_set(seq_num=seq_num,
                       seq_name=self.data_set.get_name(seq_num),
                       gt=lbl,
                       est=out)
        #self.plot.mlab_source.trait_set(seq_num=seq_num)

    def _prev_seq_fired(self):
        seq_num = int(getattr(self, 'seq_num'))
        seq_num -= 1

        if seq_num < 0:
            seq_num = 0

        out, lbl = self.estimate(self.seq_num)
        out = np.array_str(out)
        lbl = np.array_str(lbl)
        x, y, z, s = self.render(self.seq_num)
        self.scene.mlab.clf()
        self.plot = self.scene.mlab.points3d(x,
                                             y,
                                             z,
                                             s,
                                             colormap='hot',
                                             scale_factor=1,
                                             scale_mode='none')
        self.trait_set(seq_num=seq_num,
                       seq_name=self.data_set.get_name(seq_num),
                       gt=lbl,
                       est=out)

    @on_trait_change('seq_num')
    def update_seq_num(self):
        seq_num = int(getattr(self, 'seq_num'))

        out, lbl = self.estimate(seq_num)
        out = np.array_str(out)
        lbl = np.array_str(lbl)
        x, y, z, s = self.render(seq_num)
        self.scene.mlab.clf()
        self.plot = self.scene.mlab.points3d(x,
                                             y,
                                             z,
                                             s,
                                             colormap='hot',
                                             scale_factor=1,
                                             scale_mode='none')
        self.trait_set(seq_name=self.data_set.get_name(seq_num),
                       gt=lbl,
                       est=out)
        # self.anim(self)

    @animate(delay=100)
    def anim(self):
        for i in range(10):
            frame = self.seq[i]
            x, y, z = np.nonzero(frame)
            s = np.linspace(0, 1, num=x.shape[0])

            self.scene.mlab.clf()
            self.plot = self.scene.mlab.points3d(x,
                                                 y,
                                                 z,
                                                 s,
                                                 colormap='hot',
                                                 scale_factor=1,
                                                 scale_mode='none')
            # self.plot.mlab_source.trait_set(x=x, y=y, z=z, s=s)
            # self.plot.mlab_source.scalars = np.asarray(x * 0.1 * (i + 1), 'd')
            yield

    def render(self, index):
        self.seq, val = self.data_set[index]
        self.seq = self.seq.numpy()
        val = val.numpy()
        first_frame = self.seq
        x, y, z = np.nonzero(first_frame)
        s = np.linspace(0, 1, num=x.shape[0])
        return x, y, z, s

    def _LeftKeyPressed(self, event):
        self._prev_seq_fired(self)

    def _RightKeyPressed(self, event):
        self._next_seq_fired(self)

    def estimate(self, index):
        # Set mini-batch dataset
        data, lbls = self.data_set[index]
        data = data.view(1, 61, 61, 85)
        data = Variable(data)
        lbls = Variable(lbls)
        self.net.zero_grad()
        output = self.net(data)

        output = output.detach().numpy()
        lbls = lbls.detach().numpy()

        output = output.reshape(-1)
        output = (output > 0.99).astype(int)

        return output, lbls

    key_bindings = KeyBindings(
        KeyBinding(binding1='Left',
                   description='prev seq',
                   method_name='_LeftKeyPressed'),
        KeyBinding(binding1='Right',
                   description='next seq',
                   method_name='_RightKeyPressed'))

    # class KeyHandler(Handler):
    #
    #     def save_file(self, info):
    #         info.object.status = "save file"
    #
    #     def run_script(self, info):
    #         info.object.status = "run script"
    #
    #     def edit_bindings(self, info):
    #         info.object.status = "edit bindings"
    #         key_bindings.edit_traits()

    # the layout of the dialog created
    view = View(Item('scene',
                     editor=SceneEditor(scene_class=MayaviScene),
                     height=1000,
                     width=1200,
                     show_label=False),
                HGroup(Item('seq_num'), Item('prev_seq'), Item('next_seq')),
                HGroup(Item('seq_name', style='readonly')),
                HGroup(Item('label_name', style='readonly')),
                HGroup(Item('gt', style='readonly')),
                HGroup(Item('est', style='readonly')),
                key_bindings=key_bindings,
                resizable=True)
Beispiel #8
0
    'Universal Inspector':
    'etsdevtools.developer.tools.universal_inspector.UniversalInspector',
    'View Tester': 'etsdevtools.developer.tools.view_tester.ViewTester',
    'Wiretap': 'etsdevtools.developer.tools.wiretap.Wiretap',
    'Template View': 'apptools.template.test.template_view.TemplateView'
}

#-------------------------------------------------------------------------------
#  Key bindings tables:
#-------------------------------------------------------------------------------

tools_key_bindings = KeyBindings(
    KeyBinding(binding1='Alt-t',
               method_name='_select_next_tool',
               description='Selects the next tab on the current tools '
               'page.'),
    KeyBinding(binding1='Alt-Shift-t',
               method_name='_select_previous_tool',
               description='Selects the previous tab on the current tools '
               'page.'))

pages_key_bindings = KeyBindings(
    KeyBinding(binding1='Alt-p',
               method_name='_select_next_page',
               description='Selects the next page tab.'),
    KeyBinding(binding1='Alt-Shift-p',
               method_name='_select_previous_page',
               description='Selects the previous page tab.'),
    KeyBinding(binding1='Alt-Shift-f',
               method_name='_enable_fbi',
               description='Enables the FBI debugger.'))
Beispiel #9
0
 def trait_view(self, name=None, view_elements=None):
     if name is None or name=='full':
         return View(
           VGroup( 
             HSplit(
                   VSplit(
                     Item('function_search',
                          editor = InstanceEditor(view=function_search_view),
                          label      = 'Search',
                          id         = 'search',
                          style      = 'custom',
                          dock       = 'horizontal',
                          show_label = False,                      
                     ),
                     Item('html_window',
                          style='custom',
                          show_label=False,
                          springy= True,
                          resizable=True,
                     ),
                     id='search_help_view'
                   ),      
                 VSplit(
                     Item( 'object.project.active_experiment.canvas',
                           label      = 'Canvas',
                           id         = 'canvas',
                           # FIXME:  need a new way to control the canvas
                           # not using BlockEditor
                           editor     = BlockEditor(),
                           dock       = 'horizontal',
                           show_label = False
                     ),
                     Item( 'object.project.active_experiment.exec_model.code',
                           label      = 'Code',
                           id         = 'code',
                           editor     = CodeEditor(dim_lines = 'dim_lines',
                                                   dim_color = 'dim_color',
                                                   squiggle_lines = 'squiggle_lines'),
                           dock       = 'horizontal',
                           show_label = False
                     ),
                 ),
                 Item( 'context_viewer',
                       label = 'Context',
                       id = 'context_table',
                       editor = InstanceEditor(),
                       style = 'custom',
                       dock = 'horizontal',
                       show_label = False,
                 ),
                 id='panel_split',
             ),
             Item( 'status',
                   style      = 'readonly',
                   show_label = False,
                   resizable  = False 
             ),
           ),
           title     = 'Block Canvas',
           menubar   = BlockApplicationMenuBar,
           width     = 1024,
           height    = 768,
           id        = 'blockcanvas.app.application',
           resizable = True,
           handler   = BlockApplicationViewHandler(model=self),
           key_bindings = KeyBindings(
             KeyBinding(binding1='F5', method_name='_on_execute'),
             ),
         )
     elif name == 'simple':
         return View( 
                     HSplit(
                             VSplit(
                                     Item('function_search',
                                          editor = InstanceEditor(view=function_search_view),
                                          label      = 'Search',
                                          id         = 'search',
                                          style      = 'custom',
                                          dock       = 'horizontal',
                                          show_label = False),
                                     Item('html_window',
                                          style='custom',
                                          show_label=False,
                                          springy= True,
                                          resizable=True),
                                     id='search_help_view'
                                     ),      
                               Item( 'object.project.active_experiment.canvas',
                                           label      = 'Canvas',
                                           id         = 'canvas',
                                           # FIXME:  need a new way to control the canvas
                                           # not using BlockEditor
                                           editor     = BlockEditor(),
                                           dock       = 'horizontal',
                                           show_label = False),
                             id='panel_split'),
                   title     = 'Block Canvas - Simple View',
                   menubar   = BlockApplicationMenuBar,
                   width     = 800,
                   height    = 600,
                   id        = 'blockcanvas.app.application.simple',
                   resizable = True,
                   handler   = BlockApplicationViewHandler(model=self),
                   key_bindings = KeyBindings(
                                              KeyBinding(binding1='F5', method_name='_on_execute'),
                                              )
                 )
Beispiel #10
0
    def trait_view(self, name='default'):
        file_menu = Menu(
            ActionGroup(Action(name='New \t Ctrl+N', action='new'),
                        Action(name='Open \t Ctrl+O', action='open'),
                        Action(name='Close \t Ctrl+W', action='close_tab')),
            ActionGroup(Action(name='Save \t Ctrl+S', action='save'),
                        Action(name='Save As', action='saveAs')),
            ActionGroup(Action(name='Exit \t Ctrl+Q', action='exit')),
            name='File')
        edit_menu = Menu(
            ActionGroup(Action(name='Undo \t Ctrl+Z', action='undo'),
                        Action(name='Redo \t Ctrl+Y', action='redo')),
            ActionGroup(Action(name='Cut \t Ctrl+X', action='cut'),
                        Action(name='Copy \t Ctrl+C', action='copy'),
                        Action(name='Paste \t Ctrl+V', action='paste')),
            ActionGroup(
                Action(name='Select All \t Ctrl+A', action='select_all')),
            name='Edit')

        search_menu = Menu(ActionGroup(
            Action(name='Find \t Ctrl+F', action='enable_find'),
            Action(name='Replace \t Ctrl+R', action='enable_replace')),
                           name='Search')

        view_menu = Menu(ActionGroup(
            Action(name='Toggle File Browser', action='toggle_file_browser')),
                         name='View')
        prefs_menu = Menu(Action(name='Sync view on change',
                                 action='toggle_sync_on_change',
                                 checked=self.sync_on_change,
                                 style='toggle'),
                          Action(name='Auto fix table',
                                 action='toggle_auto_table_fix',
                                 checked=self.auto_table_fix,
                                 style='toggle'),
                          Action(name='Use Sphinx',
                                 action='toggle_sphinx',
                                 checked=self.use_sphinx,
                                 style='toggle'),
                          Action(name='Set Sphinx resources path...',
                                 action='change_sphinx_static_path'),
                          Action(name='Change font', action='change_font'),
                          name='Preferences')
        help_menu = Menu(Action(name='About', action='about'), name='Help')
        convert_menu = Menu(Action(name='Docutils - HTML',
                                   action='docutils_rst2html'),
                            Action(name='Docutils - LaTeX',
                                   action='docutils_rst2latex'),
                            Action(name='Sphinx - HTML',
                                   action='sphinx_rst2html'),
                            Action(name='rst2pdf', action='rst2pdf'),
                            name='Convert')
        menu_bar = MenuBar(file_menu, edit_menu, search_menu, view_menu,
                           prefs_menu, convert_menu, help_menu)

        ########################################################################

        file_group = ActionGroup(
            Action(tooltip='New', action='new', image=ImageResource('new')),
            Action(tooltip='Open', action='open', image=ImageResource('open')),
            Action(tooltip='Save', action='save', image=ImageResource('save')),
            Action(tooltip='Save As',
                   action='saveAs',
                   image=ImageResource('save-as')),
            Action(tooltip='Close',
                   action='close_tab',
                   image=ImageResource('close')))

        edit_group = ActionGroup(
            Action(tooltip='Cut', action='cut', image=ImageResource('cut')),
            Action(tooltip='Copy', action='copy', image=ImageResource('copy')),
            Action(tooltip='Paste',
                   action='paste',
                   image=ImageResource('paste')))

        undo_group = ActionGroup(
            Action(tooltip='Undo', action='undo', image=ImageResource('undo')),
            Action(tooltip='Redo', action='redo', image=ImageResource('redo')))

        search_group = ActionGroup(
            Action(tooltip='Find',
                   action='enable_find',
                   image=ImageResource('find')),
            Action(tooltip='Replace',
                   action='enable_replace',
                   image=ImageResource('replace')))

        markup_group = ActionGroup(
            Action(tooltip='Bold', action='bold', image=ImageResource('bold')),
            Action(tooltip='Italic',
                   action='italic',
                   image=ImageResource('italic')),
            Action(tooltip='Inline Literal',
                   action='inline_literal',
                   image=ImageResource('literal')),
            Action(tooltip='Fix underline (Ctrl+D)',
                   action='fix_underline',
                   image=ImageResource('underline')),
            Action(tooltip='Fix underline and overline (Ctrl+Shift+D)',
                   action='fix_under_overline',
                   image=ImageResource('under-over')))

        sync_group = ActionGroup(
            Action(tooltip='Sync rst2html',
                   action='sync_scrollbar_rst2html',
                   image=ImageResource('sync_rst2html')),
            Action(tooltip='Sync html2rst',
                   action='sync_scrollbar_html2rst',
                   image=ImageResource('sync_html2rst')))

        tool_bar = ToolBar(file_group, edit_group, undo_group, search_group,
                           markup_group, sync_group)

        ##################################

        key_bindings = KeyBindings(
            KeyBinding(binding1='Ctrl-n', method_name='new'),
            KeyBinding(binding1='Ctrl-o', method_name='open'),
            KeyBinding(binding1='Ctrl-s', method_name='save'),
            KeyBinding(binding1='Ctrl-w', method_name='close_tab'),
            KeyBinding(binding1='Ctrl-q', method_name='exit'),
            KeyBinding(binding1='Ctrl-d', method_name='fix_underline'),
            KeyBinding(binding1='Ctrl-Shift-d',
                       method_name='fix_under_overline'),
            # The following are identical to the already set hotkeys in
            # the source editor. We just want them to work regardless of
            # whether the editor has focus.
            KeyBinding(binding1='Ctrl-z', method_name='undo'),
            KeyBinding(binding1='Ctrl-y', method_name='redo'),
            KeyBinding(binding1='Ctrl-x', method_name='cut'),
            KeyBinding(binding1='Ctrl-c', method_name='copy'),
            KeyBinding(binding1='Ctrl-v', method_name='paste'),
            KeyBinding(binding1='Ctrl-a', method_name='select_all'),
            KeyBinding(binding1='Ctrl-f', method_name='enable_find'),
            KeyBinding(binding1='Ctrl-r', method_name='enable_replace'))

        return View(Group(Item('_tree',
                               style='custom',
                               width=0.25,
                               editor=InstanceEditor()),
                          Item('open_views',
                               style='custom',
                               editor=ListEditor(use_notebook=True,
                                                 deletable=True,
                                                 dock_style='tab',
                                                 ui_kind='panel',
                                                 selected='selected_view',
                                                 page_name='.title')),
                          id='rest_editor_view.EditorSplit',
                          orientation='horizontal',
                          layout='split',
                          show_labels=False),
                    id='rest_editor_view.EditorView',
                    handler=ReSTHTMLEditorHandler(),
                    width=1024,
                    height=786,
                    resizable=True,
                    menubar=menu_bar,
                    toolbar=tool_bar,
                    key_bindings=key_bindings,
                    title="reStructured Text Editor",
                    icon=self.icon)
Beispiel #11
0
class ParticipantIDPane(CustomDockPane):
    # ------------------------------------------------------------------------
    # TaskPane interface.
    # ------------------------------------------------------------------------

    #: The dock pane's identifier.
    id = 's4l.participant_id_pane'

    #: The dock pane's user-visible name.
    name = 'Participant ID'

    # ------------------------------------------------------------------------
    # LineAttributes interface.
    # ------------------------------------------------------------------------

    #: Current participant ID.
    participant_id = Str()

    #: ID trait for user input.
    part_box = Str()

    #: Button to set current participant ID to value in box.
    set_id_button = Button(label='Set ID', style='button')

    #: Key bindings for the pane - 'Enter' = clicking set_id_button
    key_bindings = KeyBindings(
        KeyBinding(
            binding1='Enter',
            description='Set ID',
            method_name='set_current_id',
        ), )

    @observe('set_id_button', post_init=True)
    def set_current_id(self, event):
        self.participant_id = self.part_box
        self.task.update_participant_id()

    def default_traits_view(self):
        """
        """
        return View(
            Group(Spring(),
                  Item(label="Current Participant ID",
                       style='custom',
                       emphasized=True),
                  Spring(),
                  orientation='horizontal'),
            Group(Spring(),
                  Item('participant_id',
                       show_label=False,
                       style='readonly',
                       visible_when='participant_id != ""'),
                  Item(label="N/A",
                       style='readonly',
                       visible_when='participant_id == ""'),
                  Spring(),
                  orientation='horizontal'),
            Item('_'),
            Group(
                Item('part_box', label='Participant ID'),
                Item(
                    'set_id_button',
                    show_label=False,
                    tooltip=
                    'Sets the current participant ID and resets values to default'
                ),
                orientation='horizontal'),
            key_bindings=self.key_bindings)
Beispiel #12
0
import numpy as np
from random import randint
import time
from threading import Thread
from traits.api import Int, HasTraits, Array,Str, Instance, List, Tuple, \
Enum, Bool

from traitsui.key_bindings import KeyBinding, KeyBindings
from traitsui.tabular_adapter import TabularAdapter
from traitsui.api import View, Item, TabularEditor, Group

key_bindings = KeyBindings(
    KeyBinding(binding1='Up', description='Up', method_name='up'),
    KeyBinding(binding1='Down', method_name='down'),
    KeyBinding(binding1='Left', method_name='left'),
    KeyBinding(binding1='Right', method_name='right'))


class TestArrayAdapter1(TabularAdapter):
    control = Instance(HasTraits)
    columns = List(Tuple)
    width = Int(25)

    def _columns_default(self):
        return [('Col{}'.format(i), i) for i in range(self.control.col)]

    def get_format(self, object, name, row, column):
        return ''

    def get_bg_color(self, object, trait, row, column=0):
        return ["white", "black",
Beispiel #13
0
heap_browser_key_bindings = KeyBindings(
    KeyBinding( binding1    = 'Ctrl-b', method_name = '_baseline_changed',
                description = 'Creates a new baseline set.' ),
    KeyBinding( binding1    = 'Ctrl-d', method_name = '_show_details_changed',
                description = 'Shows the instances of the selected heap '
                              'classes.' ),
    KeyBinding( binding1    = 'Ctrl-k', method_name = 'edit_bindings',
                description = 'Edits the keyboard bindings.' ),
    KeyBinding( binding1    = 'Ctrl-r', method_name = '_refresh_changed',
                description = 'Refreshes the heap statistics.' ),
    KeyBinding( binding1    = 'Ctrl-c', method_name = '_set_filter_change_1',
                description = 'Sets the filter change value to 1.' ),
    KeyBinding( binding1    = 'Ctrl-f', method_name = '_clear_filter',
                description = 'Resets all filter values back to their '
                              'defaults.' ),
    KeyBinding( binding1    = 'Ctrl-a', method_name = '_select_all',
                description = 'Selects all currently displayed count '
                              'entries.' ),
    KeyBinding( binding1    = 'Ctrl-Shift-a', method_name = '_unselect_all',
                description = 'Unselects all currently selected count '
                              'entries.' ),
    KeyBinding( binding1    = 'Ctrl-h', method_name = '_hide_selected_changed',
                description = 'Hides all currently selected count entries.' ),
    KeyBinding( binding1    = 'Ctrl-s', method_name = '_show_selected_changed',
                description = 'Shows only the currently selected count '
                              'entries.' ),
    KeyBinding( binding1    = 'Ctrl-Shift-s', method_name = '_show_all_changed',
                description = 'Shows all count entries.' )
)
Beispiel #14
0
'''
menu_tools_report_tex = Action(name='Report as LaTeX source',
                               action='menu_tools_report_tex')
'''Menubar action for generation of report in LaTeX format 
'''

menu_tools_report_pdf = Action(name='Report as PDF document',
                               action='menu_tools_report_pdf')
'''Menubar action for generation of report in LaTeX format 
'''

key_bindings = KeyBindings(
    KeyBinding(binding1='Ctrl-r',
               description='Run simulation',
               method_name='run_action'),
    KeyBinding(binding1='Ctrl-p',
               description='Pause calculation',
               method_name='pause_action'),
    KeyBinding(binding1='Ctrl-s',
               description='Stop calculation',
               method_name='stop_action'))


class BMCSTreeViewHandler(Handler):
    '''Handler for BMCSTreeView class
    '''
    # The UIInfo object associated with the view:
    info = Instance(UIInfo)
    node = WeakRef

    ok = Button('OK')
    cancel = Button('Cancel')
    filtered_indices    = 'filtered_indices',
    selection_bg_color  = 0xFBD391,
    selection_color     = 'black',
    selection_mode      = 'rows',
    selected            = 'selected_images'
)

#-------------------------------------------------------------------------------
#  Image library viewer key bindings:
#-------------------------------------------------------------------------------

image_viewer_key_bindings = KeyBindings(
    KeyBinding( binding1    = 'Ctrl-a', method_name = '_select_all',
                description = 'Select all images.' ),
    KeyBinding( binding1    = 'Ctrl-Shift-a', method_name = '_unselect_all',
                description = 'Unselect all images.' ),
    KeyBinding( binding1    = 'Ctrl-c', method_name = '_copy_to_clipboard',
                description = 'Copy selected image names to the clipboard.' ),
    KeyBinding( binding1    = 'Ctrl-k', method_name = 'edit_bindings',
                description = 'Edits the keyboard bindings.' ),
)

#-------------------------------------------------------------------------------
#  'ImageFilter' class:
#-------------------------------------------------------------------------------

class ImageFilter ( TableFilter ):
    """ Filter for ImageInfo objects.
    """

    # The volume name:
    volume = Str
Beispiel #16
0
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
from enthought.etsconfig.api import ETSConfig
ETSConfig.toolkit = "qt4"

from traits.api import *
from traitsui.api import *
from tvtk.pyface.scene_editor import SceneEditor
from mayavi.tools.mlab_scene_model import MlabSceneModel
from mayavi.core.ui.mayavi_scene import MayaviScene

from traitsui.key_bindings import KeyBinding, KeyBindings

bindings = KeyBindings(*[
        KeyBinding(
            binding1 = str(i),
            description = "first binding",
            method_name = "func%i"%i)
        for i in [1,2,3]])


        

class MlabGui(HasTraits):    
    x = Bool
    scene = Instance(MlabSceneModel,  ())
    funcs = []

    def __init__(self,funcs):
        HasTraits.__init__(self)
        self.funcs = funcs        
    
class Visualization(HasTraits):
    seq_num = Int(0, desc='Sequence number', auto_set=False, enter_set=True)
    seq_name = Str('0')
    next_seq = Button('Next seq')
    prev_seq = Button('Prev seq')
    scene = Instance(MlabSceneModel, ())

    def __init__(self, data_set):
        # Do not forget to call the parent's __init__
        HasTraits.__init__(self)
        self.data_set = data_set

        x, y, z, s = self.render(0)
        self.plot = self.scene.mlab.points3d(x,
                                             y,
                                             z,
                                             s,
                                             colormap='hot',
                                             scale_factor=1,
                                             scale_mode='none')
        self.trait_set(seq_name=self.data_set.get_name(0))
        # self.anim(self))
        #mlab.axes(figure=self.scene.mayavi_scene)

    def key_down(self, vtk, event):
        vtk.GetKeyCode()

    def _next_seq_fired(self):
        seq_num = int(getattr(self, 'seq_num'))
        seq_num += 1

        if seq_num > self.data_set.__len__():
            seq_num = self.data_set.__len__()

        x, y, z, s = self.render(seq_num)
        self.scene.mlab.clf()
        self.plot = self.scene.mlab.points3d(x,
                                             y,
                                             z,
                                             s,
                                             colormap='hot',
                                             scale_factor=1,
                                             scale_mode='none')

        self.trait_set(seq_num=seq_num,
                       seq_name=self.data_set.get_name(seq_num))
        #self.plot.mlab_source.trait_set(seq_num=seq_num)

    def _prev_seq_fired(self):
        seq_num = int(getattr(self, 'seq_num'))
        seq_num -= 1

        if seq_num < 0:
            seq_num = 0

        x, y, z, s = self.render(self.seq_num)
        self.scene.mlab.clf()
        self.plot = self.scene.mlab.points3d(x,
                                             y,
                                             z,
                                             s,
                                             colormap='hot',
                                             scale_factor=1,
                                             scale_mode='none')
        self.trait_set(seq_num=seq_num,
                       seq_name=self.data_set.get_name(seq_num))

    @on_trait_change('seq_num')
    def update_seq_num(self):
        seq_num = int(getattr(self, 'seq_num'))

        x, y, z, s = self.render(seq_num)
        self.scene.mlab.clf()
        self.plot = self.scene.mlab.points3d(x,
                                             y,
                                             z,
                                             s,
                                             colormap='hot',
                                             scale_factor=1,
                                             scale_mode='none')
        self.trait_set(seq_name=self.data_set.get_name(seq_num))
        # self.anim(self)

    @animate(delay=100)
    def anim(self):
        for i in range(10):
            frame = self.seq[i]
            x, y, z = np.nonzero(frame)
            s = np.linspace(0, 1, num=x.shape[0])

            self.scene.mlab.clf()
            self.plot = self.scene.mlab.points3d(x,
                                                 y,
                                                 z,
                                                 s,
                                                 colormap='hot',
                                                 scale_factor=1,
                                                 scale_mode='none')
            # self.plot.mlab_source.trait_set(x=x, y=y, z=z, s=s)
            # self.plot.mlab_source.scalars = np.asarray(x * 0.1 * (i + 1), 'd')
            yield

    def render(self, index):
        self.seq, val = self.data_set[index]
        self.seq = self.seq.numpy()
        val = val.numpy()
        first_frame = self.seq
        x, y, z = np.nonzero(first_frame)
        s = np.linspace(0, 1, num=x.shape[0])
        return x, y, z, s

    def _LeftKeyPressed(self, event):
        self._prev_seq_fired(self)

    def _RightKeyPressed(self, event):
        self._next_seq_fired(self)

    key_bindings = KeyBindings(
        KeyBinding(binding1='Left',
                   description='prev seq',
                   method_name='_LeftKeyPressed'),
        KeyBinding(binding1='Right',
                   description='next seq',
                   method_name='_RightKeyPressed'))

    # class KeyHandler(Handler):
    #
    #     def save_file(self, info):
    #         info.object.status = "save file"
    #
    #     def run_script(self, info):
    #         info.object.status = "run script"
    #
    #     def edit_bindings(self, info):
    #         info.object.status = "edit bindings"
    #         key_bindings.edit_traits()

    # the layout of the dialog created
    view = View(Item('scene',
                     editor=SceneEditor(scene_class=MayaviScene),
                     height=1000,
                     width=1200,
                     show_label=False),
                HGroup(Item('seq_num'), Item('prev_seq'), Item('next_seq')),
                HGroup(Item('seq_name', style='readonly')),
                key_bindings=key_bindings,
                resizable=True)
Beispiel #18
0
# key_bindings.py -- Example of a code editor with a key bindings editor

from traits.api import Button, Code, HasPrivateTraits, observe, Str
from traitsui.api import Group, Handler, Item, View
from traitsui.key_bindings import KeyBinding, KeyBindings

key_bindings = KeyBindings(
    KeyBinding(
        binding1='Ctrl-s',
        description='Save to a file',
        method_name='save_file',
    ),
    KeyBinding(
        binding1='Ctrl-r',
        description='Run script',
        method_name='run_script',
    ),
    KeyBinding(
        binding1='Ctrl-k',
        description='Edit key bindings',
        # special method name handled internally
        method_name='edit_bindings',
    ),
)


class CodeHandler(Handler):
    """Handler class for bound methods."""
    def save_file(self, info):
        info.object.status = "save file"
Beispiel #19
0
from traitsui.api \
    import View, Item, Handler, CodeEditor

from traitsui.key_bindings \
    import KeyBinding, KeyBindings

#-------------------------------------------------------------------------
#  Define a KeyBindings object:
#-------------------------------------------------------------------------

key_bindings = KeyBindings(
    KeyBinding(binding1='Ctrl-s',
               description='Save to a file',
               method_name='save_file'),
    KeyBinding(binding1='Ctrl-r',
               description='Run script',
               method_name='run_script'),
    KeyBinding(binding1='Ctrl-q',
               description='Edit key bindings',
               method_name='edit_bindings'))

#-------------------------------------------------------------------------
#  'CodeHandler' class:
#-------------------------------------------------------------------------


class CodeHandler(Handler):
    def save_file(self, info):
        info.object.status = "save file"

    def run_script(self, info):
Beispiel #20
0
        info.object.specleft = True

    def close(self, info, is_ok):
        info.object.lastspec = None
        return True

    def object_editfeatures_changed(self, info):
        #event handler placed here to pass in the correct parent
        info.object.edit_traits(view='features_view', parent=info.ui.control)


spylotkeybindings = KeyBindings(
    KeyBinding(binding1='<',
               binding2='Ctrl-,',
               description='Previous spectrum',
               method_name='prevSpec'),
    KeyBinding(binding1='>',
               binding2='Ctrl-.',
               description='Next spectrum',
               method_name='nextSpec'))


class Spylot(HasTraits):
    """
    This class represents the spylot application state.
    """

    defaultlines = 'galaxy'  #can be 'galaxy' or 'stellar' or None
    """
    This class attribute sets the default line lists to use - 'galaxy' or
    'stellar'