Example #1
0
def main():
    def listener(obj, traitname, old, new):
        print obj, traitname, old, new

    fred  = Person(name='Fred', age=42)
    fred.on_trait_change(listener)
    def update_fred():
        fred.name = "Wilma"
        fred.age = 4

    args = parse_command_line_args(description=__doc__)
    if args.web:
        import time
        from threading import Thread
        t = Thread(target=lambda:time.sleep(2) or update_fred())
        t.daemon = True
        t.start()
        person_view.serve(model=fred)
    else:
        from pyface.qt import QtGui
        from pyface.timer.api import do_after
        app = QtGui.QApplication.instance() or QtGui.QApplication([])
        person_view.show(model=fred)
        do_after(2000, update_fred)
        app.exec_()
    print fred.name
    print fred.age
Example #2
0
    def set_graph(self):
        from src.graph.regression_graph import StackedRegressionGraph

        g = StackedRegressionGraph(
                         window_title='Peak Regression {}'.format('foo'),
                         window_height=800,
                         window_y=25,
                         show_regression_editor=False
                         )


        cups = ['H2', 'H1', 'AX', 'L1', 'L2']
        cups.reverse()
        for i, cup in enumerate(cups):
            g.new_plot(bounds=(50, 125),
                       show_legend=True)
            g.new_series(plotid=i,
                         fit_type='parabolic',

                         type='scatter', marker='circle', marker_size=1.0)
            g.set_series_label(cup, plotid=i)
        g.set_x_limits(min=0, max=60)
        g.set_x_title('Time (sec)')

        do_after(5, g.edit_traits)
        self.graph = g
 def _left_down(self, event):
     """ Handles the left mouse being pressed.
     """
     self._x, self._y = event.GetX(), event.GetY()
     self._pending = True
     self.control.CaptureMouse()
     do_after(150, self._delayed_click)
Example #4
0
def main():
    def listener(obj, traitname, old, new):
        print obj, traitname, old, new

    fred  = Person(name='Fred', age=42)
    fred.on_trait_change(listener)
    fred.friend = Person(name='Wilma', age=34)

    def update_friend():
        fred.friend.name = "Barney"
        fred.friend.age = 41

    def set_friend():
        print "Setting friend to Dino"
        fred.friend = Person(name="Dino", age=10)

    args = parse_command_line_args(description=__doc__)
    if args.web:
        person_view.serve(model=fred)
    else:
        app = QtGui.QApplication.instance() or QtGui.QApplication([])
        do_after(3000, update_friend)
        do_after(4000, set_friend)

        person_view.show(model=fred)
        app.exec_()

    print fred.name
    print fred.age
    print fred.friend.name, fred.friend.age
Example #5
0
def main():
    app = QtGui.QApplication.instance() or QtGui.QApplication([])
    
    fred = Person(name='Fred', age=42)
    person_view.show(model1=fred)
    do_after(2000, add_model)

    app.exec_()
Example #6
0
 def _source_changed ( self, source ):
     """ Handles the 'source' trait being changed.
     """
     if self.can_save:
         if not self._dont_update:
             self.needs_save = True
             do_after( 750, self._syntax_check )
         else:
             self._syntax_check()
 def show(self, parent=None, title="", width=200, height=80):
     view = View(
         spring,
         HGroup(spring, Item("message", show_label=False, style="readonly"), spring),
         spring,
         width=width,
         height=height,
         title=title,
     )
     do_after(int(1000.0 * self.time), self.edit_traits(parent=parent, view=view).dispose)
Example #8
0
def main():
    app = QtGui.QApplication.instance() or QtGui.QApplication([])
    
    fred  = Person(name='Fred', age=42)
    def on_trait_change(obj, trait, old, new):
        print trait, old, new
    fred.on_trait_change(on_trait_change)
    person_view.show(model=fred)
    do_after(2000, fred.update_name, "Freddie")

    app.exec_()
Example #9
0
    def _update_hud(self):
        if self._maximum_delta > self.threshold and not self._timed_out:
            beep()  # TODO: Requires patched version of pyface
            # See github:enthought/pyface pull request #35

            # Don't beep more than once per second
            self._timed_out = True
            do_after(1000, self._switch_on_timeout)

        self.screen.hud('delta',
            'Current average delta: {0._average_delta:.3f}\n'
            'Current maximum delta: {0._maximum_delta:.3f}'.format(self))
Example #10
0
    def _left_down ( self, event ):
        """ Handles the left mouse being pressed.
        """
        self._x, self._y = event.GetX(), event.GetY()
        self._pending    = True

        self._init_value()

        self.control.CaptureMouse()

        if self.factory.active_color_ != self.factory.hover_color_:
            self.control.Refresh()

        do_after( 200, self._delayed_click )
Example #11
0
    def show ( self, parent = None, title = '' ):
        """ Display the wait message for a limited duration.
        """
        view = View(
            HGroup(
                spring,
                Item( 'message',
                      show_label = False,
                      style      = 'readonly'
                ),
                spring
            ),
            title = title
        )

        do_after( int( 1000.0 * self.time ),
                  self.edit_traits( parent = parent, view = view ).dispose )
Example #12
0
    def _context_is_modified ( self, event ):
        """ Handles the context modified event.
        """
        if self.context_notification_delay <= 0:
            self._process_context_modified_event( event )
        else:
            if event.reset:
                self._context_reset    = True
                self._context_modified = {}
            elif not self._context_reset:
                self._context_modified.update( dict.fromkeys( event.modified ) )

            self._context_added_removed( self._context_removed,
                                         self._context_added, event.removed )

            self._context_added_removed( self._context_added,
                                         self._context_removed, event.added )

            do_after( self.context_notification_delay,
                      self._propagate_context_modified )

        super( TraitsContext, self )._context_is_modified( event )
Example #13
0
    def update_editor ( self ):
        """ Updates the editor when the object trait changes externally to the
            editor.
        """
        control = self.control
        if self.playing:
            control.Stop()

        control.LoadFile( self.value )
        self._file_loaded = True

        # Note: It seems to be necessary to Play/Stop the control to avoid a
        # hard wx crash when 'PlayNextFrame' is called the first time (must be
        # some kind of internal initialization issue):
        control.Play()
        control.Stop()

        if self.playing or self._not_first:
            self._playing_changed()
        else:
            do_after( 300, self._frame_changed )

        self._not_first = True
Example #14
0
def main():
    def listener(obj, traitname, old, new):
        print obj, traitname, old, new

    fred = Person(name='Fred', age=42)
    fred.on_trait_change(listener)
    wilma = Person(name="Wilma", age=42, fruits=['pineapple', 'litchi'])
    barney = Person(name="Barney", age=40)

    fred.fruits = ['peach', 'pear']

    def set_list():
        fred.fruits = ["banana", "kiwi"]
        fred.friends = [wilma]

    def update_list():
        fred.fruits.append("apple")
        fred.friends.append(barney)
        fred.fruits[0] = 'mango'
        wilma.fruits.append('guava')
        wilma.fruits[0] = 'strawberry'

    args = parse_command_line_args(description=__doc__)
    if args.web:
        set_list()
        update_list()
        person_view.serve(model=fred)
    else:
        app = QtGui.QApplication.instance() or QtGui.QApplication([])
        do_after(3000, set_list)
        do_after(4000, update_list)
        person_view.show(model=fred)
        app.exec_()
    print fred.fruits
    print wilma.fruits
    print [x.name for x in fred.friends]
Example #15
0
    def record(self):
        t = self.time_generator.next()
        # d = pseudo_peak_regressions.next()
        d = 0
        # come
        d.reverse()

        datum = [t] + d
        self.info('get data {},{}'.format(*datum))
        self.data_manager.write_to_frame(datum)

        data = [(t, di) for di in d]
        if self.signals is None:
            self.signals = array(datum)
        else:
            self.signals = vstack((self.signals, datum))

        do_after(1, self.graph.add_data, data)

        '''
            if we have enough datapoints calculate an age
            
        '''
        '''
    def _context_is_modified ( self, event ):
        """ Handles the context modified event.
        """
        if self.context_propagation_delay <= 0:
            super( DeferredContext, self )._context_is_modified( event )
        else:
            if event.reset:
                self._context_reset    = True
                self._context_modified = {}
            elif not self._context_reset:
                self._context_modified.update( dict.fromkeys( event.modified ) )

            self._context_changed.update( dict.fromkeys( event.changed ) )

            self._move_dict_items( self._context_removed,
                                   self._context_added, event.removed )

            self._move_dict_items( self._context_added,
                                   self._context_removed, event.added )

            # (Is this correct? cf. 'event.merge_context_modified_events'...)

            do_after( self.context_propagation_delay,
                      self._propagate_context_modified )
Example #17
0
 def read_input_continuously(self):
     """ Polling function. This polls for any new data once every 
     READ_INTERVAL_MS milliseconds. If there's an error, it stops polling.
     """
     if self.read_input_buffer():
         do_after(READ_INTERVAL_MS, self.read_input_continuously)
Example #18
0
 def stream_statement(self):
     self.info('stream')
     self.measurement_timer = Timer(250, self.stream)
     do_after(1, self.measurement_timer.Start)