Beispiel #1
0
    def _initialize_resize(self, ui: FrameUI):
        mouse = MouseInput.input(self)

        bounds = self.on_drag_start.pipe(
            ops.filter(
                lambda e: self.resizable and e.button == MouseButton.LEFT),
            ops.map(lambda e: ui.resize_handle_at(
                self, e.position).map(lambda v: Frame._ResizeState(
                    v, e.position, self.bounds, self.minimum_size))),
            ops.map(lambda v: v.map(rx.of).value_or(rx.empty())),
            ops.switch_latest(),
            ops.map(lambda s: mouse.on_mouse_move.pipe(
                ops.map(lambda e: self._bounds_for_state(s, e.position)),
                ops.take_until(mouse.on_button_release(MouseButton.LEFT)))),
            ops.switch_latest(), ops.take_until(self.on_dispose))

        def set_bounds(b: Bounds) -> None:
            self.bounds = b

        self._resize_listener = bounds.subscribe(
            set_bounds, on_error=self.context.error_handler)
Beispiel #2
0
def sequentialSocket(channel):
    scheduler = rx.scheduler.timeoutscheduler.TimeoutScheduler()
    stream = rx.interval(SOCKET_LIMIT_SEC-10, scheduler).pipe(
        ops.start_with('start'),
        ops.map(lambda _: temporarySocket(channel)),
        ops.switch_latest(),
        ops.filter(lambda res: res[:2] == '42'),
        ops.map(lambda res: json.loads(res[13:-1])),
        ops.map(Response.from_dict),
        ops.map(lambda res: res.message.data),
    )
    return stream
Beispiel #3
0
    def on_invalidate(self, component: T) -> Observable:
        other_changes = super().on_invalidate(component)
        children_changes = component.observe("children")

        def child_bounds_changes(child: Component):
            return rx.merge(child.observe("bounds"),
                            child.observe("preferred_size"),
                            child.observe("minimum_size"))

        children_bounds_changes = children_changes.pipe(
            ops.map(lambda children: map(child_bounds_changes, children)),
            ops.map(lambda b: rx.merge(*b)), ops.switch_latest(),
            ops.map(lambda _: None))

        return rx.merge(other_changes, children_changes,
                        children_bounds_changes,
                        component.layout.on_constraints_change)
Beispiel #4
0
    def flat_map_latest(source: Observable) -> Observable:
        """Projects each element of an observable sequence into a new
        sequence of observable sequences by incorporating the element's
        index and then transforms an observable sequence of observable
        sequences into an observable sequence producing values only
        from the most recent observable sequence.

        Args:
            source: Source observable to flat map latest.

        Returns:
            An observable sequence whose elements are the result of
            invoking the transform function on each element of source
            producing an observable of Observable sequences and that at
            any point in time produces the elements of the most recent
            inner observable sequence that has been received.
        """

        return source.pipe(ops.map(mapper), ops.switch_latest())
Beispiel #5
0
    def flat_map_latest(source: Observable) -> Observable:
        """Projects each element of an observable sequence into a new
        sequence of observable sequences by incorporating the element's
        index and then transforms an observable sequence of observable
        sequences into an observable sequence producing values only
        from the most recent observable sequence.

        Args:
            source: Source observable to flat map latest.

        Returns:
            An observable sequence whose elements are the result of
            invoking the transform function on each element of source
            producing an observable of Observable sequences and that at
            any point in time produces the elements of the most recent
            inner observable sequence that has been received.
        """

        return source.pipe(
            ops.map(mapper),
            ops.switch_latest()
        )
import rx
import rx.operators as ops
from rx.subject import Subject

obs1 = Subject()
obs2 = Subject()
obs3 = Subject()
higher_order = Subject()

higher_order.pipe(ops.switch_latest()).subscribe(
    on_next=lambda i: print("on_next {}".format(i)),
    on_error=lambda e: print("on_error: {}".format(e)),
    on_completed=lambda: print("on_completed")
)

higher_order.on_next(obs1)
obs1.on_next("1: 1")
obs1.on_next("1: 2")
higher_order.on_next(obs2)
obs1.on_next("1: 3")
obs2.on_next("2: 1")
obs2.on_next("2: 2")
higher_order.on_next(obs3)
obs2.on_next("2: 3")
obs3.on_next("3: 1")
obs3.on_next("3: 2")
Beispiel #7
0
 def create():
     return xs.pipe(ops.switch_latest())