meadows - what is it and what is it good for? #522
Unanswered
WolfgangFahl
asked this question in
Q&A
Replies: 1 comment
-
Meadows is experimental code I developed that allows components in python that include templates. Below is an example of how the code for the dogs example looks and how it can be reused in another component. Basically, justpy components now look much more similar to Vue components. I am fine with taking it out of justpy as I am not convinced it is the a good way to go. I think the nicegui direction is better. I think we should aim for less html than more html and getting rid of templates. @jp.Register('dog')
class Dog(jp.BaseTemplate):
template = """<div class="q-pa-md">
<div class="q-pa-md">
<q-img @click="change_pic" class="m-4" src="{{ src }}"
style="height: 300px; max-width: 300px; cursor: pointer;"/>
<div class="q-ma-md">
<q-btn @click="change_pic" class="">Change Picture</q-btn>
<q-btn-dropdown label="{{ breed }}" disable_events="True" icon="fas fa-dog" auto-close class="m-2">
<q-list dense>
{% for b in breeds %}
<q-item clickable v-ripple breed="{{ b }}" @click="change_breed">
<q-item-section>
<q-item-label>{{ b }}</q-item-label>
</q-item-section>
</q-item>
{% endfor %}
</q-list>
</q-btn-dropdown>
</div>
</div>
</div>
"""
def __init__(self, **kwargs):
self.breed = kwargs.get('breed', 'papillon')
self.src = ''
self.breeds = breeds
super().__init__(**kwargs)
async def async_init(self, **kwargs):
await self.change_pic(None)
async def change_pic(self, msg):
# https://dog.ceo/dog-api/
if '-' in self.breed:
b = self.breed.split('-')
r = await jp.get(f'https://dog.ceo/api/breed/{b[0]}/{b[1]}/images/random')
else:
r = await jp.get(f'https://dog.ceo/api/breed/{self.breed}/images/random')
self.src = r['message']
async def change_breed(self, msg):
self.breed = msg.target.breed
return await self.change_pic(msg)
class ManyDogs(jp.BaseTemplate):
template = """
<div class="flex">
<div class="flex">
{% for i in range(num) %}
<div>{{ i }}</div>
<dog breed.initial="akita"></dog>
{% endfor %}
</div>
</div>
"""
def __init__(self, **kwargs):
self.num = 5
super().__init__(**kwargs) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There is some 614 lines of code in meadows.py which i don't understand. The code introduces a cyclic dependency in webpage.py which I'd like to get rid of.
Beta Was this translation helpful? Give feedback.
All reactions