Skip to content

Commit

Permalink
Merge pull request #511 from platinops/apply-black-code-formatting
Browse files Browse the repository at this point in the history
Apply default black code style
  • Loading branch information
WolfgangFahl authored Sep 8, 2022
2 parents 8a02e87 + 2227f81 commit 87ced8a
Show file tree
Hide file tree
Showing 17 changed files with 320 additions and 192 deletions.
27 changes: 19 additions & 8 deletions examples/issues/issue_279_key_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,44 @@
import justpy as jp
import time


def button_click(self, _msg):
"""
on button click delete the components of the button
"""
self.num_clicked += 1
self.message.text = f'{self.text} clicked. Number of clicks: {self.num_clicked}'
self.set_class('bg-red-500')
self.set_class('bg-red-700', 'hover')
self.message.text = f"{self.text} clicked. Number of clicks: {self.num_clicked}"
self.set_class("bg-red-500")
self.set_class("bg-red-700", "hover")
self.button_div.delete_components()
# wait a bit so that another button may be clicked
time.sleep(3)


def issue_279():
"""
show misbehavior of handle_events when a message for a non existing component arrives
"""
number_of_buttons = 25
wp = jp.WebPage()
button_div = jp.Div(classes='flex m-4 flex-wrap', a=wp)
button_classes = 'w-32 mr-2 mb-2 bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full'
message = jp.Div(text='No button clicked yet', classes='text-2xl border m-4 p-2', a=wp)
button_div = jp.Div(classes="flex m-4 flex-wrap", a=wp)
button_classes = "w-32 mr-2 mb-2 bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full"
message = jp.Div(
text="No button clicked yet", classes="text-2xl border m-4 p-2", a=wp
)
for i in range(1, number_of_buttons + 1):
b = jp.Button(text=f'Button {i}', a=button_div, classes=button_classes, click=button_click, button_div=button_div)
b = jp.Button(
text=f"Button {i}",
a=button_div,
classes=button_classes,
click=button_click,
button_div=button_div,
)
b.message = message
b.num_clicked = 0
return wp


from examples.basedemo import Demo
Demo("Issue 279 KeyError", issue_279)

Demo("Issue 279 KeyError", issue_279)
84 changes: 69 additions & 15 deletions examples/quasar_tutorial/QRating/rating_test1.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,76 @@
# Justpy Tutorial demo rating_test1 from docs/quasar_tutorial/QRating.md
import justpy as jp


def rating_test1():
wp = jp.QuasarPage(data={'rating': 2})
d = jp.Div(classes='q-pa-md', a=wp)
rating_div = jp.Div(classes='q-gutter-y-md column', a=d)
jp.QRating(size='1.5em', icon='thumb_up', a=rating_div, model=[wp, 'rating'])
jp.QRating(size='2em', icon='favorite_border',color='red-7', a=rating_div, model=[wp, 'rating'])
jp.QRating(size='2.5em', icon='create',color='purple-4', a=rating_div, model=[wp, 'rating'])
jp.QRating(size='3em', icon='pets',color='brown-5', a=rating_div, model=[wp, 'rating'])
jp.QRating(size='4.5em', icon='star_border',color='green-5', a=rating_div, model=[wp, 'rating'])
jp.QRating(size='5em', icon='star_border',icon_selected='star',color='grey', a=rating_div, model=[wp, 'rating'],
color_selected=['light-green-3', 'light-green-6', 'green', 'green-9', 'green-10'])
jp.QRating(size='5em', icon='star_border',icon_selected='star',color='green-5', a=rating_div, model=[wp, 'rating'])
jp.QRating(size='3.5em', max=4,color='red-5', a=rating_div, model=[wp, 'rating'],
icon=['sentiment_very_dissatisfied', 'sentiment_dissatisfied', 'sentiment_satisfied', 'sentiment_very_satisfied'])
wp = jp.QuasarPage(data={"rating": 2})
d = jp.Div(classes="q-pa-md", a=wp)
rating_div = jp.Div(classes="q-gutter-y-md column", a=d)
jp.QRating(size="1.5em", icon="thumb_up", a=rating_div, model=[wp, "rating"])
jp.QRating(
size="2em",
icon="favorite_border",
color="red-7",
a=rating_div,
model=[wp, "rating"],
)
jp.QRating(
size="2.5em",
icon="create",
color="purple-4",
a=rating_div,
model=[wp, "rating"],
)
jp.QRating(
size="3em", icon="pets", color="brown-5", a=rating_div, model=[wp, "rating"]
)
jp.QRating(
size="4.5em",
icon="star_border",
color="green-5",
a=rating_div,
model=[wp, "rating"],
)
jp.QRating(
size="5em",
icon="star_border",
icon_selected="star",
color="grey",
a=rating_div,
model=[wp, "rating"],
color_selected=[
"light-green-3",
"light-green-6",
"green",
"green-9",
"green-10",
],
)
jp.QRating(
size="5em",
icon="star_border",
icon_selected="star",
color="green-5",
a=rating_div,
model=[wp, "rating"],
)
jp.QRating(
size="3.5em",
max=4,
color="red-5",
a=rating_div,
model=[wp, "rating"],
icon=[
"sentiment_very_dissatisfied",
"sentiment_dissatisfied",
"sentiment_satisfied",
"sentiment_very_satisfied",
],
)
return wp


# initialize the demo
from examples.basedemo import Demo
Demo ("rating_test1",rating_test1)
from examples.basedemo import Demo

Demo("rating_test1", rating_test1)
22 changes: 16 additions & 6 deletions examples/quasar_tutorial/QRating/rating_test2.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
# Justpy Tutorial demo rating_test2 from docs/quasar_tutorial/QRating.md
import justpy as jp


def rating_test2():
wp = jp.QuasarPage()
wp.tailwind = True
num_stars = 3
r = jp.QRating(size='2em', max=num_stars, color='primary', classes='m-2 p-2', a=wp, value=2, debounce=0)
for i in range(1,num_stars + 1,1):
t = jp.QTooltip(text=f'{i} rating')
r.add_scoped_slot(f'tip-{i}', t)
r = jp.QRating(
size="2em",
max=num_stars,
color="primary",
classes="m-2 p-2",
a=wp,
value=2,
debounce=0,
)
for i in range(1, num_stars + 1, 1):
t = jp.QTooltip(text=f"{i} rating")
r.add_scoped_slot(f"tip-{i}", t)
return wp


# initialize the demo
from examples.basedemo import Demo
Demo ("rating_test2",rating_test2)
from examples.basedemo import Demo

Demo("rating_test2", rating_test2)
14 changes: 9 additions & 5 deletions examples/tutorial/routes/bye_function1.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# Justpy Tutorial demo bye_function1 from docs/tutorial/routes.md
import justpy as jp


def hello_function2():
wp = jp.WebPage()
wp.add(jp.P(text='Hello there!', classes='text-5xl m-2'))
wp.add(jp.P(text="Hello there!", classes="text-5xl m-2"))
return wp


def bye_function1():
wp = jp.WebPage()
wp.add(jp.P(text='Goodbye!', classes='text-5xl m-2'))
wp.add(jp.P(text="Goodbye!", classes="text-5xl m-2"))
return wp

jp.Route('/hello', hello_function2)

jp.Route("/hello", hello_function2)

# initialize the demo
from examples.basedemo import Demo
Demo ("bye_function1",bye_function1)
from examples.basedemo import Demo

Demo("bye_function1", bye_function1)
11 changes: 7 additions & 4 deletions examples/tutorial/routes/route1.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Justpy Tutorial demo from docs/tutorial/routes.md
import justpy as jp


def hello_function1():
wp = jp.WebPage()
wp.add(jp.P(text='Hello there!', classes='text-5xl m-2'))
wp.add(jp.P(text="Hello there!", classes="text-5xl m-2"))
return wp

jp.Route('/hello', hello_function1)

jp.Route("/hello", hello_function1)

# initialize the demo
from examples.basedemo import Demo
Demo ("route1",None)
from examples.basedemo import Demo

Demo("route1", None)
15 changes: 9 additions & 6 deletions examples/tutorial/routes/route2.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# Justpy Tutorial demo from docs/tutorial/routes.md
import justpy as jp

@jp.SetRoute('/hello')

@jp.SetRoute("/hello")
def hello_function3():
wp = jp.WebPage()
wp.add(jp.P(text='Hello there!', classes='text-5xl m-2'))
wp.add(jp.P(text="Hello there!", classes="text-5xl m-2"))
return wp

@jp.SetRoute('/bye')

@jp.SetRoute("/bye")
def bye_function2():
wp = jp.WebPage()
wp.add(jp.P(text='Goodbye!', classes='text-5xl m-2'))
wp.add(jp.P(text="Goodbye!", classes="text-5xl m-2"))
return wp


# initialize the demo
from examples.basedemo import Demo
Demo ("route2",None)
from examples.basedemo import Demo

Demo("route2", None)
15 changes: 10 additions & 5 deletions examples/tutorial/routes/route3.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Justpy Tutorial demo from docs/tutorial/routes.md
import justpy as jp


def greeting_function(request):
wp = jp.WebPage()
name=f"""{request.path_params["name"]}"""
wp.add(jp.P(text=f'Hello there, {name}!', classes='text-5xl m-2'))
name = f"""{request.path_params["name"]}"""
wp.add(jp.P(text=f"Hello there, {name}!", classes="text-5xl m-2"))
return wp
jp.Route('/hello/{name}', greeting_function)


jp.Route("/hello/{name}", greeting_function)

# initialize the demo
from examples.basedemo import Demo
Demo ("route3",None)
from examples.basedemo import Demo

Demo("route3", None)
65 changes: 34 additions & 31 deletions jpcore/template.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
'''
"""
Created on 2022-09-07
@author: wf
'''
"""


class Context:
"""
"""
legacy context handler, encapsulates context
"""
def __init__(self,context_dict:dict):

def __init__(self, context_dict: dict):
"""
constructor
Args:
context_dict(dict): a context dict in legacy format
"""
self.context_dict=context_dict
self.page_options=PageOptions(context_dict.get("page_options",{}))
self.context_dict = context_dict
self.page_options = PageOptions(context_dict.get("page_options", {}))

def as_javascript(self):
"""
generate my initial JavaScript
"""
title=self.page_options.get_title()
debug=str(self.page_options.get_debug()).lower()
page_ready=str(self.page_options.get_page_ready()).lower()
result_ready=str(self.page_options.get_result_ready()).lower()
reload_interval_ms=self.page_options.get_reload_interval_ms()
javascript=f"""let justpy_core=new JustpyCore(
title = self.page_options.get_title()
debug = str(self.page_options.get_debug()).lower()
page_ready = str(self.page_options.get_page_ready()).lower()
result_ready = str(self.page_options.get_result_ready()).lower()
reload_interval_ms = self.page_options.get_reload_interval_ms()
javascript = f"""let justpy_core=new JustpyCore(
this, // window
'{title}', // title
{page_ready}, // page_ready
Expand All @@ -36,32 +38,33 @@ def as_javascript(self):
{debug} // debug
);"""
return javascript



class PageOptions:
"""
legacy page_options handler, encapsulating page_options
"""
def __init__(self,page_options_dict:dict):
self.page_options_dict=page_options_dict
self.events=page_options_dict["events"]

def __init__(self, page_options_dict: dict):
self.page_options_dict = page_options_dict
self.events = page_options_dict["events"]

def get_title(self):
return self.page_options_dict.get("title","JustPy")
return self.page_options_dict.get("title", "JustPy")

def get_debug(self):
return self.page_options_dict.get("debug",False)
return self.page_options_dict.get("debug", False)

def get_page_ready(self):
return "page_ready" in self.events

def get_result_ready(self):
return "result_ready" in self.events
def get_reload_interval_ms(self)->float:
reload_interval=self.page_options_dict.get("reload_interval",0)

def get_reload_interval_ms(self) -> float:
reload_interval = self.page_options_dict.get("reload_interval", 0)
if reload_interval:
ms=round(reload_interval*1000)
ms = round(reload_interval * 1000)
else:
ms=0
return ms
ms = 0
return ms
Loading

0 comments on commit 87ced8a

Please sign in to comment.