GithubHelp home page GithubHelp logo

how to set a timer about flexx HOT 10 CLOSED

TaucherLoong avatar TaucherLoong commented on August 11, 2024
how to set a timer

from flexx.

Comments (10)

TaucherLoong avatar TaucherLoong commented on August 11, 2024

[I 13:56:06 flexx.app] Starting Flexx event loop.
[I 13:56:08 flexx.app] New session ScrollExample ky0OsXaBn39pI0US7jcJ0ful
JS: C: foo changed:
JS: from 0 to 0
JS: C: foo changed:
JS: from 0 to 5
JS: from 5 to 0
continue
Exception in thread Thread-3:
Traceback (most recent call last):
File "d:\pythonversion38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "d:\pythonversion38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "d:/yolov5_deepsort/Yolov5_DeepSort_Pytorch/taucher_seminar/flexCart/scrollable.py", line 68, in check
event_var.set_foo(n)
File "D:.virtualenvs\smartcart\lib\site-packages\flexx\app_component2.py", line 41, in flx_proxy_action
self._proxy_action(flx_name, *args)
File "D:.virtualenvs\smartcart\lib\site-packages\flexx\app_component2.py", line 499, in _proxy_action
self._session.send_command('INVOKE', self._id, name, args)
File "D:.virtualenvs\smartcart\lib\site-packages\flexx\app_session.py", line 528, in send_command
self._ws.write_command(command)
File "D:.virtualenvs\smartcart\lib\site-packages\flexx\app_tornadoserver.py", line 614, in write_command
self.write_message(bb, binary=True)
File "D:.virtualenvs\smartcart\lib\site-packages\tornado\websocket.py", line 340, in write_message
return self.ws_connection.write_message(message, binary=binary)
File "D:.virtualenvs\smartcart\lib\site-packages\tornado\websocket.py", line 1096, in write_message
fut = self._write_frame(True, opcode, message, flags=flags)
File "D:.virtualenvs\smartcart\lib\site-packages\tornado\websocket.py", line 1073, in _write_frame
return self.stream.write(frame)
File "D:.virtualenvs\smartcart\lib\site-packages\tornado\iostream.py", line 540, in write
future = Future() # type: Future[None]
File "d:\pythonversion38\lib\asyncio\events.py", line 639, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-3'.
JS: C: foo changed:
JS: from 0 to 1

from flexx.

TaucherLoong avatar TaucherLoong commented on August 11, 2024

my code here:

class ScrollExample(flx.Widget):

CSS = """
.flx-ScrollExample {
    overflow-y: scroll;  // scroll or auto
}
"""
foo = event.IntProp(0, settable=True)
def init(self):
    # self.c=Test()
    with flx.Widget():
        with flx.VBox(flex=1) as self.VB:
            for i in range(100):
                flx.Button(text="button " + str(i))

@flx.reaction('VB.pointer_click')
def set_value(self,*e):
    self.set_foo(3)
    print('clicked')

@event.reaction('foo')
def react_to_foo_c(self, *events):
    print('C: foo changed:')
    for ev in events:
        print('    from %i to %i' % (ev.old_value, ev.new_value))
        with self.VB:
            flx.Button(text='button_add')

from threading import Thread
def check(event_var):
n=0
print('Get thread started')
while True:
event_var.set_foo(n)
time.sleep(3)
print('continue')
n+=1

if name == 'main':

m = flx.launch(ScrollExample)
thread=Thread(target=check,args=(m,),daemon=True)
thread.start()
m.set_foo(5)
flx.run()

from flexx.

TaucherLoong avatar TaucherLoong commented on August 11, 2024

I have stranded with the issue for days, I am some new for flexx, hope somebodies can help solve it

from flexx.

Konubinix avatar Konubinix commented on August 11, 2024

I recommend you send a file instead of putting the code in a comment.

In its current form, I think most people won't take the time to try to clean the code and run it.
image

At least I won't :-P

from flexx.

TaucherLoong avatar TaucherLoong commented on August 11, 2024

scrollable.py.txt

from flexx.

TaucherLoong avatar TaucherLoong commented on August 11, 2024

Thank you for your response, I attached the code file above.

from flexx.

TaucherLoong avatar TaucherLoong commented on August 11, 2024

I recommend you send a file instead of putting the code in a comment.

In its current form, I think most people won't take the time to try to clean the code and run it. image

At least I won't :-P

hi, konubinx:
I am just a new one for flexx. I have attached the program above, you may help me solve my issue. I would appreciate for it
Thks a lot

from flexx.

Konubinix avatar Konubinix commented on August 11, 2024

I think you are doing it wrong. I would use threading to do this, but
rather use the asyncio call_later function.

I think you can manage to do something using threads, but it comes with
a lot of issues to deal with concurrency.

Here is what I would do:

  1. have a PyComponent to deal with the server side of stuff
  2. use call_later in the PyComponent to update the UI

There are alternative designs, like

  1. keeping only one Widget and use the async loop of the browser to call later
  2. insist on using threads

But I changed the code to make it more like I feel is the best way to go.

scrollable.py.txt

JS: C: foo changed:
JS:     from 0 to 0
JS: C: foo changed:
JS:     from 0 to 1
JS:     from 1 to 8
JS: C: foo changed:
JS:     from 8 to 9
JS: C: foo changed:
JS:     from 9 to 10
JS: clicked
JS: C: foo changed:
JS:     from 10 to 3
JS: C: foo changed:
JS:     from 3 to 4
JS: C: foo changed:
JS:     from 4 to 5
JS: C: foo changed:
JS:     from 5 to 6

Hope that helps and gets out started.

from flexx.

TaucherLoong avatar TaucherLoong commented on August 11, 2024

konubinix:
Thank you very much. that is so helpful.

from flexx.

almarklein avatar almarklein commented on August 11, 2024

I agree with @Konubinix's answer: asyncio call_later is the way to go on the Python side.

For completeness, if you're only interested in a timer on the JS side, use window.setTimeout or window.setInterval.

from flexx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.