How to show TForm from Qt by calling it from BESEN scripting? lazarus / 32-Linux ---------------------------------------------------------------------- AFFRIZA 亜風実 · 2022-05-16 03:14 I have a boring project to call Form with script, here's I am using BESEN to do that. But, I have a trouble to run that on Linux, in Windows just fine. So, here's the code for Windows: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,  ComCtrls, SynEdit, SynHighlighterJScript, Besen, BESENValue, BESENObject,  BESENErrors, BESENObjectPrototype, BESENNativeObject, BESENConstants, template_form; type  { TForm1 }   TForm1 = class(TForm)    btnExec: TButton;    codeEditor: TSynEdit;  lbMessages: TListBox;    SynJScriptSyn1: TSynJScriptSyn;    procedure btnExecClick(Sender: TObject);    procedure FormCreate(Sender: TObject);  private    myForm: TTemplateForm;    BesenInst: TBesen;  public    procedure Info(const ThisArgument:TBESENValue;Arguments:PPBE SENValues;CountArguments:integer;var AResult:TBESENValue);    procedure RunScript(const Lines: String);  end procedure TForm1.btnExecClick(Sender: TObject);begin  RunScript(codeEditor.Text);end; procedure TForm1.Info(const ThisArgument: TBESENValue; Arguments: PPBESENValues;  CountArguments:integer;var AResult:TBESENValue);begin  myForm := TTemplateForm.Create(nil);  myForm.Show;end; procedure TForm1.RunScript(const Lines: String);begin   try      BesenInst.Execute(Lines);   except      on e: EBESENError do        lbMessages.Items.Add(Format('(%s) Syntax error on line %d: %s', [e.Name,          TBESEN(BesenInst).LineNumber, e.Message]));       on e: exception do        lbMessages.Items.Add(Format('(%s) Exception error on line %d: %s', ['Exception',          TBESEN(BesenInst).LineNumber, e.Message]));   end;end procedure TForm1.FormCreate(Sender: TObject);begin  BesenInst := TBesen.Create;  TBESEN(BesenInst).ObjectGlobal.RegisterNativeFunction('info', @Info, 0, []);end;   So, when I execute "info()" in the RunScript, it will show the TTemplateForm. Then I made this for Linux, I need to change slightly to make it work on GTK2 and GTK3 by adding Application.QueueAsyncCall. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TForm1 = class(TForm)    btnExec: TButton;    codeEditor: TSynEdit;    lbMessages: TListBox;    SynJScriptSyn1: TSynJScriptSyn;    procedure btnExecClick(Sender: TObject);    procedure FormCreate(Sender: TObject);  private    myForm: TTemplateForm;    BesenInst: TBesen;  public    procedure Info(const ThisArgument:TBESENValue;Arguments:PPBE SENValues;CountArguments:integer;var AResult:TBESENValue);    procedure RunScript(const Lines: String);    procedure ShowFormASync(Data: ptrInt);  end procedure TForm1.btnExecClick(Sender: TObject);begin  RunScript(codeEditor.Text);end; procedure TForm1.ShowFormASync(Data: ptrInt);begin  myForm := TTemplateForm.Create(nil);  myForm.Show;end; procedure TForm1.Info(const ThisArgument: TBESENValue; Arguments: PPBESENValues;  CountArguments:integer;var AResult:TBESENValue);begin  // I have no idea why but this is work with GTK2 and GTK3  Application.QueueAsyncCall(@ShowFormASync, 0);  end; procedure TForm1.RunScript(const Lines: String);begin   try    BesenInst.Execute(Lines);   except      on e: EBESENError do        lbMessages.Items.Add(Format('(%s) Syntax error on line %d: %s', [e.Name,          TBESEN(BesenInst).LineNumber, e.Message]));       on e: exception do        lbMessages.Items.Add(Format('(%s) Exception error on line %d: %s', ['Exception',          TBESEN(BesenInst).LineNumber, e.Message]));   end;end procedure TForm1.FormCreate(Sender: TObject);begin  BesenInst := TBesen.Create;  TBESEN(BesenInst).ObjectGlobal.RegisterNativeFunction('info', @Info, 0, []);end;   But it doesn't work in Qt. I always got a Run Error message from debugger. I'll attach the picture here. ---------------------------------------------------------------------- AFFRIZA 亜風実 · 2022-05-17 16:58 I just moved to KDE Neon and I found this in the Call Stack, previously it didn't show in CutefishOS: ---------------------------------------------------------------------- zeljko · 2022-05-24 08:25 Seem that QApplication does not exist ? ---------------------------------------------------------------------- dbannon · 2022-05-24 11:58 Quote from: Dio Affriza on May 17, 2022, 06:58:03 pmI just moved to KDE Neon and I found this in the Call Stack, previously it didn't show in CutefishOS: I have had two separate users complain my app, running under Qt5 on KDE Neon has problems. Both have moved to my GTK2 version and don't want to pursue it so I intend, time permitting, to do some testing in a VM. Neon claims to be the 'newest' KDE around, that may well be the "least tested". Davo ---------------------------------------------------------------------- zeljko · 2022-05-24 13:50 @dbannon, what problems exactly ? ---------------------------------------------------------------------- dbannon · 2022-05-25 00:49 https://github.com/tomboy-notes/tomboy-ng/issues/121 - look at the last couple of posts, were added long after the original issue was closed. I think the problem may relate rapidly moving a window around .... The other issue was posted privately and apparently related to showing the SysTray icon. Again, end user was happy to switch to GTK and did not want to get involved in debugging. Sigh ... I have also seen issues with Wayland, apparently Neon is first (or early) KDE to use wayland. Its not surprising that causes problems ! https://github.com/tomboy-notes/tomboy-ng/issues/243 https://github.com/tomboy-notes/tomboy-ng/issues/216 I have downloaded a Neon ISO but just have not managed to find the time to build a VM. Davo ---------------------------------------------------------------------- AFFRIZA 亜風実 · 2022-05-25 09:41 Quote from: dbannon on May 24, 2022, 01:58:30 pmI have had two separate users complain my app, running under Qt5 on KDE Neon has problems. Both have moved to my GTK2 version and don't want to pursue it so I intend, time permitting, to do some testing in a VM. Neon claims to be the 'newest' KDE around, that may well be the "least tested". Davo I just give up using BESEN anyway and made some my own weird script And, it works really well. This is the result (image in attachment): https://github.com/afuriza/samarinda-ui Quite fun project to play when I don't know what to do, this project is to make a form dynamically from file.  Quote from: dbannon on May 25, 2022, 02:49:46 amhttps://github.com/tomboy-notes/tomboy-ng/issues/121 - look at the last couple of posts, were added long after the original issue was closed. I think the problem may relate rapidly moving a window around .... The other issue was posted privately and apparently related to showing the SysTray icon. Again, end user was happy to switch to GTK and did not want to get involved in debugging. Sigh ... I have also seen issues with Wayland, apparently Neon is first (or early) KDE to use wayland. Its not surprising that causes problems ! https://github.com/tomboy-notes/tomboy-ng/issues/243 https://github.com/tomboy-notes/tomboy-ng/issues/216 I have downloaded a Neon ISO but just have not managed to find the time to build a VM. Davo Yeah, I have the similar issue with Wayland so I don't use Wayland anymore and still quite happy with X, because when I am using Wayland the mouse hint and the code completion sometimes flying somewhere far from the cursor. Sometimes, even on the corner of the screen. ---------------------------------------------------------------------- zeljko · 2022-05-25 12:42 Quote from: dbannon on May 25, 2022, 02:49:46 amhttps://github.com/tomboy-notes/tomboy-ng/issues/121 - look at the last couple of posts, were added long after the original issue was closed. I think the problem may relate rapidly moving a window around .... The other issue was posted privately and apparently related to showing the SysTray icon. Again, end user was happy to switch to GTK and did not want to get involved in debugging. Sigh ... I have also seen issues with Wayland, apparently Neon is first (or early) KDE to use wayland. Its not surprising that causes problems ! https://github.com/tomboy-notes/tomboy-ng/issues/243 https://github.com/tomboy-notes/tomboy-ng/issues/216 I have downloaded a Neon ISO but just have not managed to find the time to build a VM. Davo If it's about Wayland - do not use Wayland. Wayland is far from finished as X, many things in Wayland DOES NOT work eg BringToFront (Window.Activate). LCL is not ready for wayland, Qt6 have some updates about it, but it's still far from being useable as we want. ---------------------------------------------------------------------- dbannon · 2022-05-25 23:42 Quote from: zeljko on May 25, 2022, 02:42:45 pmIf it's about Wayland - do not use Wayland. Wayland is far from finished as X, many things in Wayland DOES NOT work eg BringToFront (Window.Activate). LCL is not ready for wayland, Qt6 have some updates about it, but it's still far from being useable as we want. While I agree, I advise my Qt users not to use Wayland, but few are happy with that. Its new so it "must" be better. Further, the option of running your whole desktop under X (from startup) and the option of running a particular app bypassing Wayland will not remain in the distributions forever. They will, I am afraid, sooner or later, make them optional and then unavailable. One of the reasons for the move away from X is its old code, very convoluted and very difficult to maintain. So, as soon as someone decides its not needed, it will stop getting the love it needs. It will happen slowly but it will happen ! Davo ---------------------------------------------------------------------- zeljko · 2022-10-29 00:07 Sorry for posting to old topicz but currently I'm coding.qt6 support for lazarus and testing under x11 and wayland. Fyi, eg activate() (TCustomForm.BringToFront) does not work because waland do not support window activation programatically), so wayland is probably good for tetris game, but not for lcl. ---------------------------------------------------------------------- dbannon · 2022-10-29 10:51 Quote from: zeljko on October 29, 2022, 02:07:34 amSorry for posting to old topicz but currently I'm coding.qt6 support for lazarus .... Brilliant ! Quote from: zeljko on October 29, 2022, 02:07:34 am....and testing under x11 and wayland. Fyi, eg activate() (TCustomForm.BringToFront) does not work because waland do not support window activation programatically), so wayland is probably good for tetris game, but not for lcl. Not so brilliant. Is that because Qt6 is still incomplete (unlikely) or they expect you do things differently ?  Thats not going to work ... So, target x11 and rely on Xwayland to keep things working ?  I wonder what XWayland does when your activate() arrives, all it can do is pass it on to Wayland. That must be whats happening now, many of our Qt5 apps are working (via XWayland) on Wayland systems. Anyway, very glad to hear you are working on Qt6 ! Davo