1

I have been trying to implement Quasar Ajax Bar in justPy. The code below will increase the value of Ajax bar by 10 when the increment button is clicked. But the increment is not working properly. Can someone point out what should I change? Thanks.

The code below is modified version of justpy example taken from here. The explanation for quasar component is here

import justpy as jp

async def start_bar(self, msg):
    wp = msg.page
    wp.startValues = 0
    await wp.ajax_bar.run_method('start(0)', msg.websocket)

async def stop_bar(self, msg):
    wp = msg.page
    await wp.ajax_bar.run_method('stop()', msg.websocket)

async def increment_bar(self, msg):
    wp = msg.page
    await wp.ajax_bar.run_method(f'increment({wp.startValues})', msg.websocket)

async def looping(self, msg):
    wp = msg.page
    wp.startValues = wp.startValues + 10
    print(wp.startValues)
    await increment_bar(self, msg)

def ajax_bar_example():
    wp = jp.QuasarPage()
    d = jp.Div(classes='q-pa-md', a=wp)
    # temp=False is important because this generates an id for the element that is required for run_method to work
    wp.ajax_bar = jp.QAjaxBar(position='bottom', color='accent', size='10px', skip_hijack=True, a=d, temp=False)
    btn_start = jp.QBtn(color='primary', label='Start Bar', a=d, click=start_bar, style='margin-right: 20px')
    btn_stop = jp.QBtn(color='primary', label='Stop Bar', a=d, click=stop_bar, style='margin-right: 20px')
    btn_increment = jp.QBtn(color='primary', label='Increment Bar', a=d)
    btn_increment.on('click', looping)
    wp.startValues = 0
    return wp

jp.justpy(ajax_bar_example)
Kanda
  • 67
  • 5
  • What do you mean by "it's not working properly?" What behavior do you see (a video would be great to explain) and what behavior do you expect (a video would be great to explain). See https://user-images.githubusercontent.com/95085996/199009063-9e819072-6646-4efd-bc3d-6ff47ae62240.gif for an example video – Wolfgang Fahl Nov 05 '22 at 08:40

0 Answers0