Skip to content

Commit

Permalink
FIX : Migrate static _fired methods with observe decorated methods (#441
Browse files Browse the repository at this point in the history
)

modified:   docs/source/guide/examples/background_processes.py
	modified:   docs/source/guide/examples/pi_iterations.py
	modified:   docs/source/guide/examples/prime_counting.py
	modified:   docs/source/guide/examples/slow_squares.py
	modified:   traits_futures/tests/i_pingee_tests.py
  • Loading branch information
Poruri Sai Rahul committed Jul 19, 2021
1 parent b825c2b commit 9aa148d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
10 changes: 7 additions & 3 deletions docs/source/guide/examples/background_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
HasStrictTraits,
Instance,
List,
observe,
Property,
Range,
Str,
Expand Down Expand Up @@ -127,15 +128,18 @@ class SquaringHelper(HasStrictTraits):
#: Value that we'll square.
input = Range(low=0, high=100)

def _square_fired(self):
@observe("square")
def _do_slow_square(self, event):
future = submit_call(self.traits_executor, slow_square, self.input)
self.current_futures.append(future)

def _cancel_all_fired(self):
@observe("cancel_all")
def _cancel_all_futures(self, event):
for future in self.current_futures:
future.cancel()

def _clear_finished_fired(self):
@observe("clear_finished")
def _clear_finished_futures(self, event):
for future in list(self.current_futures):
if future.done:
self.current_futures.remove(future)
Expand Down
6 changes: 4 additions & 2 deletions docs/source/guide/examples/pi_iterations.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ class PiIterator(HasStrictTraits):
#: The plot.
plot = Instance(Plot)

def _approximate_fired(self):
@observe("approximate")
def _calculate_pi_approximately(self, event):
self.future = submit_iteration(
self.traits_executor, pi_iterations, chunk_size=self.chunk_size
)

def _cancel_fired(self):
@observe("cancel")
def _cancel_future(self, event):
self.future.cancel()

@observe("future")
Expand Down
3 changes: 2 additions & 1 deletion docs/source/guide/examples/prime_counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ class PrimeCounter(HasStrictTraits):
#: Limit used for most recent run.
_last_limit = Int()

def _count_fired(self):
@observe("count")
def _count_primes(self, event):
self._last_limit = self.limit
self.future = submit_progress(
self.traits_executor,
Expand Down
10 changes: 7 additions & 3 deletions docs/source/guide/examples/slow_squares.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
HasStrictTraits,
Instance,
List,
observe,
Property,
Range,
Str,
Expand Down Expand Up @@ -115,15 +116,18 @@ class SquaringHelper(HasStrictTraits):
#: Value that we'll square.
input = Range(low=0, high=100)

def _square_fired(self):
@observe("square")
def _do_slow_square(self, event):
future = submit_call(self.traits_executor, slow_square, self.input)
self.current_futures.append(future)

def _cancel_all_fired(self):
@observe("cancel_all")
def _cancel_all_futures(self, event):
for future in self.current_futures:
future.cancel()

def _clear_finished_fired(self):
@observe("clear_finished")
def _clear_finished_futures(self, event):
for future in list(self.current_futures):
if future.done:
self.current_futures.remove(future)
Expand Down
5 changes: 3 additions & 2 deletions traits_futures/tests/i_pingee_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import threading
import weakref

from traits.api import Event, HasStrictTraits, Int
from traits.api import Event, HasStrictTraits, Int, observe

#: Safety timeout, in seconds, for blocking operations, to prevent
#: the test suite from blocking indefinitely if something goes wrong.
Expand Down Expand Up @@ -90,7 +90,8 @@ class PingListener(HasStrictTraits):
#: Total number of pings received.
ping_count = Int(0)

def _ping_fired(self):
@observe("ping")
def _handle_incoming_ping(self, event):
self.ping_count += 1

def fire_ping(self):
Expand Down

0 comments on commit 9aa148d

Please sign in to comment.