I'm using the (2.0)js-interop library in combination with the JS library ImageLoaded and I'm stuck the FunctionProxy class because the code below throw the following error:
Breaking on exception: Closure call with mismatched arguments: function 'call'
js.FunctionProxy loaded = new js.FunctionProxy((){
print("called");
js.Proxy pckry = new js.Proxy(context.Packery, container, options);
});
js.Proxy img = new js.Proxy(context.imagesLoaded, container, loaded);
Which is weird because my js callback is called 5 times before the app crashes.
Looking at the Usage section of imagesLoaded it looks like the callback takes one parameter. So you have to add this parameter to your callback :
js.FunctionProxy loaded = new js.FunctionProxy((instance) {
print("called");
js.Proxy pckry = new js.Proxy(context.Packery, container, options);
});
js.Proxy img = new js.Proxy(context.imagesLoaded, container, loaded);
Additional notes :
You can avoid new js.FunctionProxy. There are only a limited number of cases where it's needed and your case here is not one of them.
imagesLoaded can be use as a function and it simplifies the code.
Thus, you should be able to use :
final img = context.imagesLoaded(container, (instance) {
print("called");
js.Proxy pckry = new js.Proxy(context.Packery, container, options);
});
Related
I'm trying to run some image processing and MLmodel prediction inside isolate for all images in the gallery device. But some packages like FaceDetector(from google_ml_kit), and PhotoGallery, don't let me run inside isolate. The question is, exist any possibility to run everything inside an isolate, like an entire package with these imports?
Without using isolate all the code is working and is kind of fast but the screen freezes when I start to load and process the images.
I also could process one by one image whitout freezing, but takes too much time.
So I m trying to run with isolate for example when a run this code:
void process(String path){
final options = FaceDetectorOptions(
performanceMode: FaceDetectorMode.accurate,
minFaceSize: .4,
);
final faceDetector = FaceDetector(options: options);
var file = File(path);
var image = InputImage.fromFile(file);
var bytes = file.readAsBytesSync();
var faces = (await faceDetector.processImage(image))
.map(
(e) => FaceRect(
e.boundingBox.left,
e.boundingBox.top,
e.boundingBox.width,
e.boundingBox.height,
),
)
.toList();
var faceImage = FacesImage(path, faces, bytes);
}
compute(process, "/storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20221022-WA0006.jpeg");
I get this:
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Binding has not yet been initialized.
E/flutter (32478): The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
E/flutter (32478): Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After calling that method, the "instance" getter will return the binding
But I can't call WidgetsFlutterBinding.ensureInitialized() in isolate and my app already have.
There is any alternative to find all photos and albuns that can be called in isolate? and faceDetector?
Run an entire package in isolate is a possibility?
I'm new to Protractor.
I'm trying to select a button based on the button title. I want to make this into a function, and pass the button title in as a parameter.
This is the hard-coded version which works:
it('I click on a button based on the button title', async function() {
let button = element(by.css('button[title=example_button_title]'));
await button.click();
});
I created a global variable and a function to try and replace this, where 'buttonTitle' is the parameter I'm passing into the function:
Variable:
let dynamicButton = buttonTitle => { return element(by.css("'button[title=" + buttonTitle + "]'")) };
Function:
this.selectDynamicButton = async function(buttonTitle) {
await browser.waitForAngularEnabled(false);
await dynamicButton(buttonTitle).click();
};
When I try this I get the following error:
Failed: invalid selector: An invalid or illegal selector was specified
Apologies if there appear to be basic errors here, I am still learning. I appreciate any help that anyone can give me. Thanks.
You can add a custom locator using protractors addLocator functionality. (this is actually a very similar use case to the example listed in the link)
This would look like the following:
onPrepare: function () {
by.addLocator('buttonTitle', function (titleText, opt_parentElement) {
// This function will be serialized as a string and will execute in the
// browser. The first argument is the text for the button. The second
// argument is the parent element, if any.
const using = opt_parentElement || document;
const matchingButtons = using.querySelectorAll(`button[title="${titleText}"]`);
let result = undefined;
if (matchingButtons.length === 0) {
result = null;
} else if (matchingButtons.length === 1) {
result = matchingButtons[0];
} else {
result = matchingButtons;
}
return result;
});
}
This is called like
const firstMatchingButton = element(by.buttonTitle('example_button_title'));
const allMatchingButtons = element.all(by.buttonTitle('example_button_title'));
I had to edit this code before posting so let me know if this does not work. My work here is largely based off this previous answer
let dynamicButton = buttonTitle => { return element(by.css('button[title=${buttonTitle} ]')) };
Use template literals instead of string concatenation with +.
Protractor already has a built in locator which allows you to get a button using the text. I think you are looking at something like that. See the element(by.buttonText('text of button')) locator.
For more reference see here.
I am writing a program in Vala using GTK+. It has a function that creates a ListBox that contains a lot of EventBox objects. There is one issue: there is one function that downloads the image and it takes a lot of time, so the main window didn't show up unless all downloads are finished. This is not what I wanted, I wanted main window to appear and then images to download and to be shown. So I separated image load to separate function, but main window still doesn't show unless all downloads are finished. What am I doing wrong?
Here is the function I'm using:
foreach (MediaInfo post in feedPosts)
feedList.prepend(post);
foreach (PostBox box in feedList.boxes)
box.loadImage();
("feedList" is a class inherited from Gtk.ListBox and "boxes" is a list containing all of PostBox (which is inherited from Gtk.EventBox) objects)
This is feedList.prepend function:
public void append(MediaInfo post)
{
Gtk.Separator separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
base.prepend(separator);
PostBox box = new PostBox(post);
base.prepend(box);
boxes.append(box);
}
And this is the constructor and loadImage functions of PostBox class:
public PostBox(MediaInfo post)
{
box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
this.add(box);
this.post = post;
userToolbar = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
userNameLabel = new Gtk.Label("#" + post.postedUser.username);
this.userNameLabel.set_markup(
"<span underline='none' font_weight='bold' size='large'>" +
post.postedUser.username + "</span>"
);
userToolbar.add(userNameLabel);
box.pack_start(userToolbar, false, true);
image = new Gtk.Image();
box.add(image);
box.add(new Gtk.Label(post.title));
box.add(new Gtk.Label( post.likesCount.to_string() + " likes."));
print("finished.\n");
return;
}
public void loadImage()
{
var imageFileName = PhotoStream.App.CACHE_URL + getFileName(post.image.url);
downloadFile(post.image.url, imageFileName);
Pixbuf imagePixbuf = new Pixbuf.from_file(imageFileName);
imagePixbuf = imagePixbuf.scale_simple(IMAGE_SIZE, IMAGE_SIZE, Gdk.InterpType.BILINEAR);
image.set_from_pixbuf(imagePixbuf);
}
You have written the download operations in another method, however the operations are still synchronous, i.e. they block the thread. You never want to do computationaly or otherwise expensive things in the GUI thread, because that makes the GUI unresponsive.
You should start your downloads asynchronously, and trigger a callback method when the download is complete. In the callback, then you may for example change the image placeholders to actual images.
I replaced all my async methods with multithreading and now it is working the way I want it to work.
I'm new to SAPUI5
I'm trying to show the master page when a Tile is clicked in a home page. Below is the code that I have used with in event handler.
var context = evt.getSource().getBindingContext();
this.nav.to("Master", context);
The problem here is I am getting following error TypeError: this.nav.to is not a function
Please assist
What is this in your context? That depends on where your tilePressed method is defined. If it's defined in a controller, this will refer to the controller.
If it is defined statically - you often find this for formatter functions - this will refer to the control that triggered the event.
Is the variable this.nav defined and appropriatly initialized? It needs to contain some kind of NavContainer e.g. the outermost sap.m.App resp. sap.m.SplitApp.
Also check out this article on the usage of this in JavaScript and this very handy jQuery function jQuery.proxy
The this.nav.to() and this.nav.back() functions are not
defined in the App.controller.js. You need to write the following code
in App.controller.js so that the compiler identifies the functions
being called.
to : function (pageId, context) {
var app = this.getView().app;
// load page on demand
var master = ("Master" === pageId);
if (app.getPage(pageId, master) === null) {
var page = sap.ui.view({
id : pageId,
viewName : "ProjectPath.view." + pageId,
type : "XML"
});
page.getController().nav = this;
app.addPage(page, master);
jQuery.sap.log.info("app controller > loaded page: " + pageId);
}
// show the page
app.to(pageId);
// set data context on the page
if (context) {
var page = app.getPage(pageId);
page.setBindingContext(context);
}
},
back : function (pageId) {
this.getView().app.backToPage(pageId);
}
Exactly one month ago I encountered this problem Closure call with mismatched arguments: function 'call' with js interop.
Now I have the same problem with the SnapSVG library. I'm using it in combination with JsInterop since a moment. Today i tried to use the mouseover function and I get the same exception.
But when I hover the SVG element my function is fired four times :
hover in
hover in
hover in
hover in
Breaking on exception: Closure call with mismatched arguments: function 'call'
I tried :
var img = s.image("$url", x, y, image.width/2, image.height/2);
js.FunctionProxy hover = new js.FunctionProxy(() {
print("hover in");
});
img.mouseover(hover);
and
var img = s.image("$url", x, y, image.width/2, image.height/2);
img.mouseover(() {
print("hover in");
});
This time I checked twice and there is no extra arguments for the callback function.
Considering the logs you paste, the mouseover handler seems to be called sometimes with parameters sometimes without. To handle that you can use a function with optional parameters :
var img = s.image("$url", x, y, image.width/2, image.height/2);
img.mouseover(([p1, p2, p3, p4]) {
print("hover in");
});
The above callback now handles calls with from 0 to 4 parameters.