I'am updating old code and this part does not work :
IFrameElement iframe = query('#myframe iframe');
Window iframeW = iframe.contentWindow;// cast error
var myframeDoc = iframeW.document;
I changed Window to 'WindowBase` :
IFrameElement iframe = query('#myframe iframe');
WindowBase iframeW = iframe.contentWindow;
var myframeDoc = iframeW.document;
But document is not a member of WindowBase.
I want to access it to query like this:
myframeDoc.query("#myId");
With javascript, the solution works :
var myframeDoc = document.querySelector('#myframe iframe').contentWindow.document;
iFrame's and Windows have slightly different APIs, so you have to use WindowBase rather than Window.
You can see that the type of IFrameElement.contentWindow is WindowBase in the API docs and you should also see it in the pop-up docs in the Editor.
Related
I am playing around with Vala and GTK4.
FileChooserDialog is not working for me
using Gtk;
int main (string[] argv) {
// Create a new application
var app = new Gtk.Application ("com.example.GtkApplication",
GLib.ApplicationFlags.FLAGS_NONE);
app.activate.connect (() => {
// Create a new window
var window = new Gtk.ApplicationWindow (app);
window.title = "File chooser";
window.set_default_size (350, 70);
window.resizable = false;
// Create a new button
var file_choose_button = new Gtk.Button.with_label ("...");
file_choose_button.clicked.connect (() => {
var fileChooser = new FileChooserDialog(
"Select File",
window,
FileChooserAction.OPEN,
"Cancel",
ResponseType.CANCEL,
"Open",
ResponseType.ACCEPT,
null);
fileChooser.response.connect(()=> {
stdout.printf("File selectd!");
});
// WHAT TO DO IN ORDER TO SHOW FILE CHOOSER?
});
window.set_child (file_choose_button);
// Show
window.present ();
});
return app.run (argv);
}
I am missing some important piece of code, that will cause the FileChooserDialog to "appear".
In previous Versions of GTK there is "dialog.run" - which is missing in GTK4.
The C-Example on https://docs.gtk.org/gtk4/class.FileChooserDialog.html uses makro(?) "gtk_widget_show(xxx)" for which I was not able to find an representation in Vala.
Any help appreciated!
Best Regards
Emil
After some struggle the solution was found (and is pretty simple).
As stated in the Vala Documentaion Site - File Chooser Dialog
It inherits from couple of classes one of which is GTK.Window.
So it is as simple as calling the present() method.
Thus the missing command above is:
fileChooser.present();
One should not forget to use the close() method once file was selected or selection was canceled.
Important note:
"gtk_widget_show()" representation in Vala is GTK.Widget.show() BUT
I was not clever enough to find out how to prepare the parameter.
It expects pointer (GtkWidget*) and simply passing the "fileChooser" causes all kinds of compiler exceptions.
May be someone can throw more light on this (as I am using Vala to avoid the use of C - I am clearly not the expert in this area)
Good afternoon. I have reports with parameters, before forming reports, I would like to make a preview. How to use "webReport.Report.ShowPrepared ()"?
item = reportDB.SelectFirst(Convert.ToInt64(showID));
reportDB.SelectBinaryFile(ref item);
var r = new FastReport.Report();
r.LoadFromString(Encoding.UTF8.GetString(item.ReportBody));
WebReport webReport = new WebReport();
webReport.Width = Unit.Percentage(100);
webReport.Height = Unit.Percentage(100);
if (1==1)//проверка на рус язык
webReport.LocalizationFile = "~\\Translation\\Russian.frl";
SetUserInfo(ref r);
webReport.AutoWidth = true;
webReport.AutoHeight = true;
webReport.Report =r;
webReport.PrevPage();
ViewBag.WebReport = webReport.GetHtml();
As per the official documentation if Fast reports you can use like below.
First you needs to check whether the report is prepared, if prepared returns true boolean value simply you can call the showprepared() method.
webReport.Load("report1.frl");
webReport.Prepare(true);
webReport.ShowPrepared();
if you wants to use some modal window and needs to return to the privious pages then you can use it like below.
void ShowPrepared(bool modal,Form owner)
The same as the previous method. The ow ner parameter determines a
window that owns the preview window.
Please read more from here to implement it in better way.
Official Documentation Fast Reports
I have a code that is working with a canvas and I'd like to convert it into a layer.
The problem is that I do not want to use the build mechanism of OL3, I just want to use plain javascript.
At the moment, the problem I have is that my handleRender_ function is never called.
Here is my JS code :
ol.layer.MyLayerProperty = {
};
ol.layer.My = function (opt_options) {
var options = opt_options || {};
ol.layer.Layer.call(this, options);
this.on('render', this.handleRender_.bind(this)); //I suspect this is not working
};
ol.inherits(ol.layer.My, ol.layer.Layer);
ol.layer.My.prototype.handleRender_ = function (event) {
console.log('render process'); //never called
};
In fact, to display a canvas "above" openlayers, you simply have to use ImageCanvas.
see http://www.acuriousanimal.com/thebookofopenlayers3/chapter03_04_imagecanvas.html for example
I am developing an app which uses WKWebView to show an html document. I want to inject content from my Swift code to this document. This is what I tried:
var myString: String
// ... Code which assigns some value to myString
targetView.evaluateJavaScript("injector.injectSnippet(\(myString);", completionHandler: nil)
This works exactly as I expect so long as the argument in the JavaScript function call is hardcoded:
targetView.evaluateJavaScript("injector.injectSnippet(\"Hello World\");", completionHandler: nil)
The injector object is in a JavaScript file which I have already added to the web view's user controller:
var injector = (function () {
"use strict"
var msgBox;
var injectSnippet = function (test) {
msgBox.innerHTML = "Received value: " + test;
}
var init = function () {
// Create msgBox div element and insert it into the document
}
return {
init: init,
injectSnippet: injectSnippet
};
} ());
injector.init();
How do I get content into the WKWebView?
I went through the Apple docs WebKit Objective-C Programming Guide and WebKit DOM Programming Topics but I don't understand what sort of WebView class they are using there. Both WKWebView and UIWebView don't have all the API they use in these documents.
Is there some way to manipulate the DOM directly in Swift? I get the sense that WebScriptObject might be what I'm looking for but can I use this with WKWebView?
If you want to continue using evaluateJavaScript, you need to inject the value into the javascript string.
Something like
var jsTemplate = "injector.injectSnippet(\"%#\");"
var js = String(format:jsTemplate , myString)
I'm learning F#, and decided to try making simple XNA games for windows using F# (pure enthusiasm) , and got a window with some images showing up.
Here's the code:
(*Methods*)
member self.DrawSprites() =
_spriteBatch.Begin()
for i = 0 to _list.Length-1 do
let spentity = _list.List.ElementAt(i)
_spriteBatch.Draw(spentity.ImageTexture,new Rectangle(100,100,(int)spentity.Width,(int)spentity.Height),Color.White)
_spriteBatch.End()
(*Overriding*)
override self.Initialize() =
ChangeGraphicsProfile()
_graphicsDevice <- _graphics.GraphicsDevice
_list.AddSprite(0,"NagatoYuki",992.0,990.0)
base.Initialize()
override self.LoadContent() =
_spriteBatch <- new SpriteBatch(_graphicsDevice)
base.LoadContent()
override self.Draw(gameTime : GameTime) =
base.Draw(gameTime)
_graphics.GraphicsDevice.Clear(Color.CornflowerBlue)
self.DrawSprites()
And the AddSprite Method:
member self.AddSprite(ID : int,imageTexture : string , width : float, height : float) =
let texture = content.Load<Texture2D>(imageTexture)
list <- list # [new SpriteEntity(ID,list.Length, texture,Vector2.Zero,width,height)]
The _list object has a ContentManager, here's the constructor:
type SpriteList(_content : ContentManager byref) =
let mutable content = _content
let mutable list = []
But I can't minimize the window, since when it regains its focus, i get this error:
ObjectDisposedException
Cannot access a disposed object.
Object name: 'GraphicsDevice'.
What is happening?
Well after struggling for some time I got it to work. But it doesn't seem "right"
(thinking that way, using XNA and F# doesn't seem right either, but it's fun.)
(*Methods*)
member self.DrawSprites() =
_spriteBatch.Begin()
for i = 0 to _list.Length-1 do
let spentity = _list.List.ElementAt(i)
if spentity.ImageTexture.IsDisposed then
spentity.ImageTexture <- _list.Content.Load<Texture2D>(spentity.Name)
_spriteBatch.Draw(spentity.ImageTexture,new Rectangle(100,100,(int)spentity.Width,(int)spentity.Height),Color.White)
_spriteBatch.End()
(*Overriding*)
override self.Initialize() =
ChangeGraphicsProfile()
_list.AddSprite(0,"NagatoYuki",992.0,990.0)
base.Initialize()
override self.LoadContent() =
ChangeGraphicsProfile()
_graphicsDevice <- _graphics.GraphicsDevice
_spriteBatch <- new SpriteBatch(_graphicsDevice)
base.LoadContent()
I adjust the graphicsDevice whenever my game needs to LoadContent, and in the DrawSprites() method I check if the texture is disposed, if it is, load it up again.
But this thing bugs me. I didn't know I had to Load all Content again everytime the window is minimized.
(And the code makes it look like Initialize() loads Content, and LoadContent() initializes, but oh well)
What you are observing is normal behaviour, it's by the way not specific to F#. See http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.loadcontent.aspx
This method is called by Initialize. Also, it is called any time the game content needs to be reloaded, such as when the DeviceReset event occurs.
Are you loading all of your content in Game.LoadContent? If you do, you should not be getting these errors.