Skip to content

Commit

Permalink
0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
elimintz committed Feb 23, 2020
1 parent 0198f90 commit 96ee3ee
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 22 deletions.
20 changes: 18 additions & 2 deletions docs/reference/webpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,33 @@ Url to favicon. If `None`, `False` or the empty string, the default favicon is u
CSS to inject into the page. The string is inserted in style tag in the head of the document.


### head_html
### head_html and body_html

* Type: `string` or `'''`
* Default: `'''`

A string of any extra HTML to put in the head section of the template. Can be additional JavaScript for example.
From version 0.0.7

A string of any extra HTML to put in the head section or body section of the template. Can be additional JavaScript for example.
```python
wp.head_html ="""
<script src="/my_scripts.js"></script>
"""
```

Simple example:
```python
import justpy as jp

def test_head():
wp = jp.WebPage()
wp.head_html = '<script>console.log("Hello there from head");</script>'
wp.body_html = '<script>console.log("Hello there from body");</script>'
jp.Div(text='Testing...', a=wp)
return wp

jp.justpy(test_head)
```

### html

Expand Down
2 changes: 1 addition & 1 deletion justpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .justpy import *
__version__ = '0.0.6'
__version__ = '0.0.7'
2 changes: 1 addition & 1 deletion justpy/chartcomponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, **kwargs):
self.tooltip_debounce = 100 # Default is 100 ms
self.update_animation = True # Whether to animate changes when chart is updated
self.update_create = False # Whether to create new chart on update, if false current chart is updated
kwargs['temp'] = False
kwargs['temp'] = False # Force an id to be assigned to chart
super().__init__(**kwargs)
for k, v in kwargs.items():
self.__setattr__(k,v)
Expand Down
2 changes: 2 additions & 0 deletions justpy/gridcomponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self, **kwargs):
self.pages = {}
self.auto_size = True # If True, automatically resize columns after load to optimal fit
self.theme = 'ag-theme-balham' # one of ag-theme-balham, ag-theme-balham-dark, ag-theme-material
self.html_columns = []
kwargs['temp'] = False
super().__init__(**kwargs)
for k, v in kwargs.items():
Expand Down Expand Up @@ -105,4 +106,5 @@ def convert_object_to_dict(self):
d['def'] = self.options
d['auto_size'] = self.auto_size
d['events'] = self.events
d['html_columns'] = self.html_columns
return d
6 changes: 4 additions & 2 deletions justpy/htmlcomponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(self, **kwargs):
self.components = [] # list of direct children components on page
self.css = ''
self.head_html = ''
self.body_html = ''
# If html attribute is not empty, sets html of page directly
self.html = ''
self.body_style = ''
Expand Down Expand Up @@ -601,8 +602,9 @@ class Input(Div):
html_tag = 'input'
attributes = ['accept', 'alt', 'autocomplete', 'autofocus', 'checked', 'dirname', 'disabled', 'form',
'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'height', 'list',
'max', 'maxlength', 'min', 'multiple', 'name', 'pattern', 'placeholder', 'readonly',
'max', 'maxlength', 'min', 'minlength', 'multiple', 'name', 'pattern', 'placeholder', 'readonly',
'required', 'size', 'src', 'step', 'type', 'value', 'width']


def __init__(self, **kwargs):

Expand Down Expand Up @@ -954,7 +956,7 @@ def convert_object_to_dict(self):
'width'],
'input': ['accept', 'alt', 'autocomplete', 'autofocus', 'checked', 'dirname', 'disabled', 'form',
'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'height', 'list',
'max', 'maxlength', 'min', 'multiple', 'name', 'pattern', 'placeholder', 'readonly',
'max', 'maxlength', 'min', 'minlength','multiple', 'name', 'pattern', 'placeholder', 'readonly',
'required', 'size', 'src', 'step', 'type', 'value', 'width'], 'ins': ['cite', 'datetime'],
'label': ['for', 'form'], 'li': ['value'],
'link': ['crossorigin', 'href', 'hreflang', 'media', 'rel', 'sizes', 'type'], 'map': ['name'],
Expand Down
6 changes: 3 additions & 3 deletions justpy/justpy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from starlette.applications import Starlette
# from starlette.responses import Response
from starlette.responses import JSONResponse
from starlette.responses import PlainTextResponse
from starlette.endpoints import WebSocketEndpoint
Expand Down Expand Up @@ -54,8 +53,9 @@
QUASAR = config('QUASAR', cast=bool, default=False)
HIGHCHARTS = config('HIGHCHARTS', cast=bool, default=True)
AGGRID = config('AGGRID', cast=bool, default=True)
AGGRID_ENTERPRISE = config('AGGRID_ENTERPRISE', cast=bool, default=False)

template_options = {'tailwind': TAILWIND, 'quasar': QUASAR, 'highcharts': HIGHCHARTS, 'aggrid': AGGRID,
template_options = {'tailwind': TAILWIND, 'quasar': QUASAR, 'highcharts': HIGHCHARTS, 'aggrid': AGGRID, 'aggrid_enterprise': AGGRID_ENTERPRISE,
'static_name': STATIC_NAME}
logging.basicConfig(level=LOGGING_LEVEL, format='%(levelname)s %(module)s: %(message)s')

Expand Down Expand Up @@ -132,7 +132,7 @@ async def get(self, request):
assert issubclass(type(load_page), WebPage), 'Function did not return a web page'
assert len(load_page) > 0 or load_page.html, '\u001b[47;1m\033[93mWeb page is empty, add components\033[0m'
page_options = {'reload_interval': load_page.reload_interval, 'body_style': load_page.body_style,
'body_classes': load_page.body_classes, 'css': load_page.css, 'scripts': load_page.head_html,
'body_classes': load_page.body_classes, 'css': load_page.css, 'head_html': load_page.head_html, 'body_html': load_page.body_html,
'display_url': load_page.display_url, 'dark': load_page.dark, 'title': load_page.title,
'highcharts_theme': load_page.highcharts_theme, 'debug': load_page.debug,
'favicon': load_page.favicon if load_page.favicon else FAVICON}
Expand Down
37 changes: 36 additions & 1 deletion justpy/quasarcomponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ class QBtn(QDiv):
html_tag = 'q-btn'

def __init__(self, **kwargs):
self.loading = False
super().__init__(**kwargs)
self.prop_list = ['ripple', 'type', 'to', 'replace', 'label', 'icon', 'icon-right', 'round', 'outline', 'flat',
'unelevated', 'rounded', 'push', 'glossy', 'size', 'fab', 'fab-mini', 'color', 'text-color',
Expand Down Expand Up @@ -1698,14 +1699,19 @@ class QInputDateTime(QInput):

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.mask = '####-##-## ##:##'
self.fill_mask = True
self.proxy = {}

date_slot = QIcon(name='event', classes='cursor-pointer')
c2 = QPopupProxy(transition_show='scale', transition_hide='scale', a=date_slot)
self.date = QDate(mask='YYYY-MM-DD HH:mm', name='date', a=c2)
self.proxy['QDate'] = c2

time_slot = QIcon(name='access_time', classes='cursor-pointer')
c2 = QPopupProxy(transition_show='scale', transition_hide='scale', a=time_slot)
self.time = QTime(mask='YYYY-MM-DD HH:mm', format24h=True, name='time', a=c2)
self.proxy['QTime'] = c2

self.date.parent = self
self.time.parent = self
Expand All @@ -1718,12 +1724,41 @@ def __init__(self, **kwargs):
self.on('input', self.input_change)

@staticmethod
def date_time_change(self, msg):
async def date_time_change(self, msg):
print(self.value)
self.parent.value = self.value
self.parent.date.value = self.value
self.parent.time.value = self.value
await self.parent.proxy[msg.class_name].run_method('hide()', msg.websocket)

@staticmethod
def input_change(self, msg):
self.date.value = self.value
self.time.value = self.value


class QInputDate(QInput):

def __init__(self, **kwargs):
super().__init__(**kwargs)

date_slot = QIcon(name='event', classes='cursor-pointer')
c2 = QPopupProxy(transition_show='scale', transition_hide='scale', a=date_slot)
self.date = QDate(mask='YYYY-MM-DD', name='date', a=c2)

self.date.parent = self
self.date.value = self.value
self.append_slot = date_slot
self.date.on('input', self.date_time_change)
self.on('input', self.input_change)
self.proxy = c2

@staticmethod
async def date_time_change(self, msg):
self.parent.value = self.value
self.parent.date.value = self.value
await self.parent.proxy.run_method('hide()', msg.websocket)

@staticmethod
def input_change(self, msg):
self.date.value = self.value
5 changes: 5 additions & 0 deletions justpy/templates/js/aggrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Vue.component('grid', {
grid_change() {
var j = JSON.stringify(this.$props.jp_props.def);
var grid_def = JSON.parse(j); // Deep copy the grid definition
for (let i=0; i < this.$props.jp_props.html_columns.length; i++) {
grid_def.columnDefs[this.$props.jp_props.html_columns[i]].cellRenderer = function(params) {
return params.value ? params.value : '';
}
}
cached_grid_def[this.$props.jp_props.id] = j;
grid_def.onGridReady = grid_ready;
new agGrid.Grid(document.getElementById(this.$props.jp_props.id.toString()), grid_def); // the api calls are added to grid_def
Expand Down
2 changes: 0 additions & 2 deletions justpy/templates/js/event_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var files_chosen = {};
function eventHandler(props, event, form_data, aux) {

if (props.jp_props.debug) {
// if (true) {
console.log('-------------------------');
console.log('In eventHandler: ' + event.type + ' ' + props.jp_props.vue_type + ' ' + props.jp_props.class_name);
console.log(event);
Expand Down Expand Up @@ -55,7 +54,6 @@ function eventHandler(props, event, form_data, aux) {
}
if (aux) e['aux'] = aux;
if (event instanceof KeyboardEvent) {
// it is a keyboard event!
// https://developer.mozilla.org/en-US/docs/Web/Events/keydown keyup, keypress
e['key_data'] = {
altKey: event.altKey,
Expand Down
13 changes: 9 additions & 4 deletions justpy/templates/quasar.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

{% if options.tailwind %}
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<style>
{% include 'css/form.css' %}
</style>
<style>
{% include 'css/form.css' %}
</style>

{% endif %}

Expand Down Expand Up @@ -37,13 +37,18 @@
<script src="https://unpkg.com/ag-grid-community/dist/ag-grid-community.min.js"></script>
{% endif %}

{% if options.aggrid_enterprise %}
<script src="https://unpkg.com/ag-grid-enterprise/dist/ag-grid-enterprise.min.js"></script>
{% endif %}

</head>


<body class="" style="{{ page_options.body_style }}" class="{{ page_options.body_classes }}">
{% if html %}
{{ html | safe }}
{% else %}
{{ page_options.body_html | safe }}
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://cdn.jsdelivr.net/npm/quasar@^1.8.5/dist/quasar.umd.min.js"></script>
Expand All @@ -55,7 +60,7 @@
<script>
console.log('Quasar Version ' + Quasar.version);
{% if page_options.dark %}
Quasar.Dark.set(true);
Quasar.Dark.set(true);
{% endif %}
</script>

Expand Down
16 changes: 11 additions & 5 deletions justpy/templates/tailwind.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
</style>
{% endif %}

<style>
{{ page_options.css }}
</style>


<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.0/animate.min.css"/>
Expand All @@ -23,7 +21,11 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css"/>
<script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>

{{ page_options.head_html }}
<style>
{{ page_options.css }}
</style>

{{ page_options.head_html | safe }}

{% if not html %}
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
Expand All @@ -37,11 +39,15 @@
{% if options.aggrid %}
<script src="https://unpkg.com/ag-grid-community/dist/ag-grid-community.min.js"></script>
{% endif %}

{% if options.aggrid_enterprise %}
<script src="https://unpkg.com/ag-grid-enterprise/dist/ag-grid-enterprise.min.js"></script>
{% endif %}
</head>


<body style="{{ page_options.body_style }}" class="{{ page_options.body_classes }}">

{{ page_options.body_html | safe }}
<div id="components">

</div>
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def get_long_description():
setuptools.setup(
name="justpy",
python_requires=">=3.6",
version="0.0.6",
version="0.0.7",
license="Apache",
author="Eliezer Mintz",
author_email="[email protected]",
Expand Down

0 comments on commit 96ee3ee

Please sign in to comment.