When I attach a Python callback to a widget I usually get the old and new values but for a js callback I only get the object and its current value, not the old value. Is this true?
For example, for a slider:
def print_values(attr, old, new):
print(attr, old, new)
slider = Slider(start=0, end=100, value=0, step=1)
slider.on_change('value', print_values)
code = "console.log(cb_obj);"
log_values = CustomJS(args={}, code=code)
slider.js_on_change('value', log_values)
How can I get the old value from cb_obj?
Is this true?
Yes, as of Bokeh 1.2 CustomJS callbacks are not provided with the old property values. It could potentially be considered for new development, so it would be reasonable to make a feature request issue.
Related
We are using Watson Conversation from Python. Our dialog has responses with variation texts, but we always receive the first one variation -that is the problem. The dialog does work well when you run it from Bluemix Converation Tooling.
def wd_conv_send_message(sTexto):
# Replace with the context obtained from the initial request
context = {}
workspace_id = conv_workspaceid
response = conversation.message(
workspace_id=workspace_id,
message_input={'text': sTexto},
context=context
)
# print(json.dumps(response, indent=2))
print(response['output']['text'][0])
Change:
response = conversation.message(
workspace_id=workspace_id,
message_input={'text': sTexto},
context=context
)
to:
response = conversation.message(
workspace_id=workspace_id,
message_input={'text': sTexto},
context=context
)
context = response['context']
Conversation is stateless. So you need to send back the context you received or it won't know where to continue on from.
It turned out to be a somewhat erratic behaviour from Watson Conversation side, combined with debugging: if you run/debug from Pycharm -either setting Sequential or Random- you get only the very first Variation several times (five or more). But if you run from Python interpreter command line, it seems to work fine. So, I guess -just speculative- it has to do with some timing issue when running from Pycharm.
I have a Meteor template that renders the documents of a collection. The subscription is set up in the template's autorun:
Template.userSearch.rendered = ->
Session.set "userSearchLimit", 5
#autorun ->
Meteor.subscribe "userSearch", "something to find", Session.get "userSearchLimit"
When the user pressed a "Load more" button I increment the userSearchLimit session variable, which causes the autorun to rerun. The subscription changes since I ask for more data, so the old subscription will be torn down and a new one created, however the first part of the actual data will be the same.
The problem is that the entire list is being redrawn, causing a horrible flicker. When I put debug logging into the find() method as suggested here, then I see that the documents are first being removed, then added back again.
I would have expected the server to avoid resending data that already exists on the client.
How can I solve this?
To further confuse the issue I also tried using ddp-analyzer to see what data was being sent. As soon as I use that then only the new data gets sent and the flicker is eliminated. As soon as I stop using it the problem comes back.
I've solved this by manually waiting for the new subscription to be ready before taking down the previous one:
currentMatchingSub = null
prevMatchingSub = null
subscribeToUserSearch = (limit) ->
prevMatchingSub = currentMatchingSub
currentMatchingSub = Meteor.subscribe "userSearch", "john baker", limit, ->
# Only once the new subscription is ready should be take down the previous one. This ensure's
# that there's no flicker...
prevMatchingSub.stop() if prevMatchingSub?
prevMatchingSub = null
Template.userSearch.rendered = ->
limit = 5
Session.set "userSearchLimit", limit
subscribeToUserSearch limit
Template.userSearch.destroyed = ->
prevMatchingSub.stop() if prevMatchingSub?
currentMatchingSub.stop() if currentMatchingSub?
I have a project will load a HTTP page, parse it, and then open other pages based on the data it received from the first page.
Since Qt's QNetworkAccessManager works asyncronusly, it seems I should be able to load more than one page at a time by continuing to make HTTP requests, and then taking care of the response would happen in the order the replies come back and would be handled by the even loop.
I'm a having a few problems figuring out how to do this though:
First, I read somewhere on stackoverflow that you should use only one QNetworkAccess manager. I do not know if that is true.
The problem is that I'm connecting to the finished slot on the single QNetworkAccess manager. If I do more than one request at a time, I don't know what request the finished signal is in response to. I don't know if there is a way to inspect the QNetworkReply object that is passed from the signal to know what reply it is in response to? Or should I actually be using a different QNetworkAccessManager for each request?
Here is an example of how I'm chaining stuff together right now. But I know this won't work when I'm doing more than one request at at time:
from PyQt4 import QtCore,QtGui,QtNetwork
class Example(QtCore.QObject):
def __init__(self):
super().__init__()
self.QNetworkAccessManager_1 = QtNetwork.QNetworkAccessManager()
self.QNetworkCookieJar_1 = QtNetwork.QNetworkCookieJar()
self.QNetworkAccessManager_1.setCookieJar(self.QNetworkCookieJar_1)
self.app = QtGui.QApplication([])
def start_request(self):
QUrl_1 = QtCore.QUrl('https://erikbandersen.com/')
QNetworkRequest_1 = QtNetwork.QNetworkRequest(QUrl_1)
#
self.QNetworkAccessManager_1.finished.connect(self.someurl_finshed)
self.QNetworkAccessManager_1.get(QNetworkRequest_1)
def someurl_finshed(self, NetworkReply):
# I do this so that this function won't get called for a diffent request
# But it will only work if I'm doing one request at a time
self.QNetworkAccessManager_1.finished.disconnect(self.someurl_finshed)
page = bytes(NetworkReply.readAll())
# Do something with it
print(page)
QUrl_1 = QtCore.QUrl('https://erikbandersen.com/ipv6/')
QNetworkRequest_1 = QtNetwork.QNetworkRequest(QUrl_1)
#
self.QNetworkAccessManager_1.finished.connect(self.someurl2_finshed)
self.QNetworkAccessManager_1.get(QNetworkRequest_1)
def someurl2_finshed(self, NetworkReply):
page = bytes(NetworkReply.readAll())
# Do something with it
print(page)
kls = Example()
kls.start_request()
I am not familiar to PyQt but from general Qt programming point of view
Using only one QNetworkAccessManager is right design choice
finished signal provides QNetworkReply*, with that we can identify corresponding request using request().
I hope this will solve your problem with one manager and multiple requests.
This is a C++ example doing the same.
I am having an issue with call Drupal node.save using MooTool's JSONP. Here is an example.
Here is my request:
callback Request.JSONP.request_map.request_1
method node.save
sessid 123123123123123
node {"type":"blog","title":"New Title","body":"This is the blog body"}
Here is my result
HTTP/1.0 500 Internal Server Error
I got this working before, but i used AMFPHP and was able to send objects to drupal. I am assuming that this has to do with Drupal expecting an object, but since it is a GET it gets transformed as a string. Is there any way of getting around this with out hacking the code?
Here is my code:
$('newBlogSubmit').addEvent('click', function()
{
var node = {
type : "blog",
title:"New Title",
body :"This is the blog body"
}
var string = JSON.encode(node);
string.escapeRegExp()
var sessID = _sessID;
DrupalService.getInstance().node_save(string, sessID, drupal_handleBlogSubmit);
});
My Drupal Service JS Code:
//NODE
DrupalService.prototype.node_save = function(node, sessid, callback){
var dataObj = {
method : "node.save",
sessid : sessid,
node : node
}
DrupalService.getInstance().request(dataObj, callback);
}
//SEND REQUEST AND CALLBACK FUNCTION
DrupalService.prototype.request = function(dataObject, callback){
new JsonP('http://myDrupalSite.com/services/json', {data: dataObject,onComplete: callback}).request();
}
I am trying to connect the dots, but not too familiar with Drupal, but i would guess all I need to do is turn the string back into an object. Any ideas where I should be looking, or if there is an existing patch?
A first question could be why you use mootools since Drupal comes with jQuery and use it extensively throughout the different modules and Drupal core itself.
Anyways I don't know mootools so can't help you there, but if your request in ending in a internal server error, you have a problem with your drupal code or your js code. So even if I knew exactly what you were doing, I couldn't tell you the problem without looking at the drupal code for your http://myDrupalSite.com/services/json callback.
In general, what you want to make sure is:
You make a POST request, as drupal will cache get's and the semantic of this, is that you are posting data - the node - to the server.
Your data should be sent as post params, this will make them end up in the PHP $_POST variable
Your callback should validate the data and act accordingly, creating a node when the data is intact. You don't need session id's since the script will have the same session the browser has.
I've answered a similar question in detail, which was about altering a field instead of saving a node, but much of the work is still the same. You can take a look on the post, although this is with jQuery and not Mootools.
When i use loader.load(request); for the first time, my flex freeze for 10 secondes before posting the data (i can see the web server result in real time).
However if redo a similar POST with other data but same request.url, it's instantaneous.
// Multi form encoded data
variables = new URLVariables();
variables.user = "aaa";
variables.boardjpg = new URLFileVariable(data.boardBytes, "foo.jpg");
request = new URLRequestBuilder(variables).build();
request.url = "http://localhost:8000/upload/";
loader.load(request);
How can i see what is taking so long ?
Thanks !
Ok, this is an old question, anyway I find it searching for other things so quick adding this
URLFileVariables nor URLRequestBuilder are core classes in AS3, so I guess you're using some custom library to build your request. I don't know which library you use, but it seems that the purpose is to serialize some binary data to build a POST. Serializing usually takes some times the first time (lookup initialization and the like) and goes faster next, a well known example is Remoting in his different flavours