Does anyone have example code of tw.jquery.FlotWidget working with the
versions listed? I only seem to be getting blank pieces of canvas
being rendered on my pages.
I have this in my controller:
...
from tw.jquery import FlotWidget
fw = FlotWidget()
tmpl_context.graphic = fw
...
In my template:
tmpl_context.graphic(data=data)
Here is a paste of the output from the rendered webpage sans a pretty chart.
http://paste.turbogears.org/paste/39329
Using ToscaWidgets-0.9.4 too.
Thanks, Andrew
>
> http://paste.turbogears.org/paste/39329
>
With further investigation and editing the output of the rendered
template as a static page and trying to get that to work...
It seems that tw.core.js is escaping the id of the widget and this is
breaking tw.jquery.FlotWidget
Here is a snippet from tw.core.js that shows the escaping behaviour of
the id selector as per the paste above.
class TWEncoder(simplejson.encoder.JSONEncoder):
"""A JSON encoder that can encode Widgets, js_calls, js_symbols and
js_callbacks.
Example::
>>> encode = TWEncoder().encode
>>> print encode({'onLoad':
js_function("do_something")(js_symbol("this"))})
{"onLoad": do_something(this)}
>>> from tw.api import Widget
>>> w = Widget("foo")
>>> args = {'onLoad':
js_callback(js_function('jQuery')(w).click(js_symbol('onClick')))}
>>> print encode(args)
{"onLoad": function(){jQuery(\\"foo\\").click(onClick)}}
>>> print encode({'args':args})
{"args": {"onLoad": function(){jQuery(\\"foo\\").click(onClick)}}}
Although I now know what the problem is, I haven't a clue where to
begin to fix it...
Ok, I hacked and got a chart...
2009/3/21 Andrew Basson <andrew...@gmail.com>:
> Hi,
>
>>
>> http://paste.turbogears.org/paste/39329
>>
> With further investigation and editing the output of the rendered
> template as a static page and trying to get that to work...
>
> It seems that tw.core.js is escaping the id of the widget and this is
> breaking tw.jquery.FlotWidget
>
> Here is a snippet from tw.core.js that shows the escaping behaviour of
> the id selector as per the paste above.
>
Ok, so I hacked __get_js_repr on _js_call and put in a replace as per below.
class _js_call(object):
__slots__ = ('__name', '__call_list', '__args', '__called')
def __init__(self, name, call_list, args=None, called=False):
self.__name = name
self.__args = args
call_list.append(self)
self.__call_list = call_list
self.__called = called
def __getattr__(self, name):
return self.__class__(name, self.__call_list)
def __call__(self, *args):
self.__args = args
self.__called = True
return self
def __get_js_repr(self):
if self.__called:
args = self.__args
return '%s(%s)' % (self.__name, ', '.join(imap(encode,
args)).replace('\\',''))
else:
return self.__name
Don't know what else will break, but for now I'm happy to fall into
bed knowing I can finally produce a chart.
Cheers, Andrew.