brython-dev / brython

Brython (Browser Python) is an implementation of Python 3 running in the browser
BSD 3-Clause "New" or "Revised" License
6.38k stars 511 forks source link

implement extendModule, or is there workaround? #2486

Closed ImageDeeply closed 2 months ago

ImageDeeply commented 2 months ago

is extendModule implemented? If not, is there a workaround

Error:

window.Tabulator.extendModule('filter', 'filters', {
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'TabulatorFull' has no attribute 'extendModule'

Brython:

window.Tabulator.extendModule('filter', 'filters', {
    'foo': foo_filter,
})

this works in js:

Tabulator.extendModule('filter', 'filters', {
    foo: foo_filter,
});
PierreQuentel commented 2 months ago

@ImageDeeply Thanks for the report. I could run the following example:


<!doctype html>
<html>
<head>
<meta charset="utf-8">

<script type="text/javascript" src="/src/brython.js"></script>

<link href="https://unpkg.com/tabulator-tables@6.2.5/dist/css/tabulator.min.css" rel="stylesheet" crossorigin="anonymous">
<script type="text/javascript" src="https://unpkg.com/tabulator-tables@6.2.5/dist/js/tabulator.min.js" crossorigin="anonymous"></script>

</head>
<body>

<div id="example-table-py"></div>

<script type="text/python" debug="3">
from browser import window

def foopy(headerValue, rowValue, *args):
  return rowValue > 20

window.Tabulator.extendModule('filter', 'filters', {'foopy': foopy})

tabledata = [
    {'id':1, 'name':"Billy Bob", 'age':12, 'dob':"14/05/2010"},
    {'id':2, 'name':"Jenny Jane", 'age':42, 'dob':"30/07/1954"},
    {'id':3, 'name':"Steve McAlistaire", 'age':35, 'dob':"04/11/1982"}
]

# define table
table = window.Tabulator.new("#example-table-py", {
    'data': tabledata,
    'autoColumns': True
})

def onbuilt(*args):
  table.setFilter('age', 'foopy')

table.on('tableBuilt', onbuilt)

</script>

</body>
</html>
ImageDeeply commented 2 months ago

Tabulator is a cool library, so thanks for taking the time to create a specific test script to check the fix.

Brython is working very well for us. Your persistence over the years is amazing.