Recent

Author Topic: How to show TForm from Qt by calling it from BESEN scripting?  (Read 626 times)

AFFRIZA 亜風実

  • Full Member
  • ***
  • Posts: 136
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][+][-]
  1. uses
  2.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  3.   ComCtrls, SynEdit, SynHighlighterJScript, Besen, BESENValue, BESENObject,
  4.   BESENErrors, BESENObjectPrototype, BESENNativeObject, BESENConstants, template_form;
  5.  
  6. type
  7.   { TForm1 }
  8.   TForm1 = class(TForm)
  9.     btnExec: TButton;
  10.     codeEditor: TSynEdit;
  11.     lbMessages: TListBox;
  12.     SynJScriptSyn1: TSynJScriptSyn;
  13.     procedure btnExecClick(Sender: TObject);
  14.     procedure FormCreate(Sender: TObject);
  15.   private
  16.     myForm: TTemplateForm;
  17.     BesenInst: TBesen;
  18.   public
  19.     procedure Info(const ThisArgument:TBESENValue;Arguments:PPBESENValues;CountArguments:integer;var AResult:TBESENValue);
  20.     procedure RunScript(const Lines: String);
  21.   end
  22.  
  23. procedure TForm1.btnExecClick(Sender: TObject);
  24. begin
  25.   RunScript(codeEditor.Text);
  26. end;
  27.  
  28. procedure TForm1.Info(const ThisArgument: TBESENValue; Arguments: PPBESENValues;
  29.   CountArguments:integer;var AResult:TBESENValue);
  30. begin
  31.   myForm := TTemplateForm.Create(nil);
  32.   myForm.Show;
  33. end;
  34.  
  35. procedure TForm1.RunScript(const Lines: String);
  36. begin
  37.    try
  38.       BesenInst.Execute(Lines);
  39.    except
  40.       on e: EBESENError do
  41.         lbMessages.Items.Add(Format('(%s) Syntax error on line %d: %s', [e.Name,
  42.           TBESEN(BesenInst).LineNumber, e.Message]));
  43.  
  44.       on e: exception do
  45.         lbMessages.Items.Add(Format('(%s) Exception error on line %d: %s', ['Exception',
  46.           TBESEN(BesenInst).LineNumber, e.Message]));
  47.    end;
  48. end
  49.  
  50. procedure TForm1.FormCreate(Sender: TObject);
  51. begin
  52.   BesenInst := TBesen.Create;
  53.   TBESEN(BesenInst).ObjectGlobal.RegisterNativeFunction('info', @Info, 0, []);
  54. end;
  55.  

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][+][-]
  1. TForm1 = class(TForm)
  2.     btnExec: TButton;
  3.     codeEditor: TSynEdit;
  4.     lbMessages: TListBox;
  5.     SynJScriptSyn1: TSynJScriptSyn;
  6.     procedure btnExecClick(Sender: TObject);
  7.     procedure FormCreate(Sender: TObject);
  8.   private
  9.     myForm: TTemplateForm;
  10.     BesenInst: TBesen;
  11.   public
  12.     procedure Info(const ThisArgument:TBESENValue;Arguments:PPBESENValues;CountArguments:integer;var AResult:TBESENValue);
  13.     procedure RunScript(const Lines: String);
  14.     procedure ShowFormASync(Data: ptrInt);
  15.   end
  16.  
  17. procedure TForm1.btnExecClick(Sender: TObject);
  18. begin
  19.   RunScript(codeEditor.Text);
  20. end;
  21.  
  22. procedure TForm1.ShowFormASync(Data: ptrInt);
  23. begin
  24.   myForm := TTemplateForm.Create(nil);
  25.   myForm.Show;
  26. end;
  27.  
  28. procedure TForm1.Info(const ThisArgument: TBESENValue; Arguments: PPBESENValues;
  29.   CountArguments:integer;var AResult:TBESENValue);
  30. begin
  31.   // I have no idea why but this is work with GTK2 and GTK3
  32.   Application.QueueAsyncCall(@ShowFormASync, 0);  
  33. end;
  34.  
  35. procedure TForm1.RunScript(const Lines: String);
  36. begin
  37.    try
  38.       BesenInst.Execute(Lines);
  39.    except
  40.       on e: EBESENError do
  41.         lbMessages.Items.Add(Format('(%s) Syntax error on line %d: %s', [e.Name,
  42.           TBESEN(BesenInst).LineNumber, e.Message]));
  43.  
  44.       on e: exception do
  45.         lbMessages.Items.Add(Format('(%s) Exception error on line %d: %s', ['Exception',
  46.           TBESEN(BesenInst).LineNumber, e.Message]));
  47.    end;
  48. end
  49.  
  50. procedure TForm1.FormCreate(Sender: TObject);
  51. begin
  52.   BesenInst := TBesen.Create;
  53.   TBESEN(BesenInst).ObjectGlobal.RegisterNativeFunction('info', @Info, 0, []);
  54. end;
  55.  

But it doesn't work in Qt. I always got a Run Error message from debugger. I'll attach the picture here.
« Last Edit: May 16, 2022, 05:31:56 am by Dio Affriza »
Kyoukai Framework: https://github.com/afuriza/kyoukai_framework

Dukung kemerdekaan Donetsk dan Lugansk! Tidak membalas profil berbendera biru-kuning apalagi ber-Bandera.

AFFRIZA 亜風実

  • Full Member
  • ***
  • Posts: 136
Re: How to show TForm from Qt by calling it from BESEN scripting?
« Reply #1 on: May 17, 2022, 06:58:03 pm »
I just moved to KDE Neon and I found this in the Call Stack, previously it didn't show in CutefishOS:
Kyoukai Framework: https://github.com/afuriza/kyoukai_framework

Dukung kemerdekaan Donetsk dan Lugansk! Tidak membalas profil berbendera biru-kuning apalagi ber-Bandera.

zeljko

  • Hero Member
  • *****
  • Posts: 1262
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: How to show TForm from Qt by calling it from BESEN scripting?
« Reply #2 on: May 24, 2022, 10:25:52 am »
Seem that QApplication does not exist ?

dbannon

  • Hero Member
  • *****
  • Posts: 2045
    • tomboy-ng, a rewrite of the classic Tomboy
Re: How to show TForm from Qt by calling it from BESEN scripting?
« Reply #3 on: May 24, 2022, 01:58:30 pm »
I 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
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

zeljko

  • Hero Member
  • *****
  • Posts: 1262
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: How to show TForm from Qt by calling it from BESEN scripting?
« Reply #4 on: May 24, 2022, 03:50:24 pm »
@dbannon, what problems exactly ?

dbannon

  • Hero Member
  • *****
  • Posts: 2045
    • tomboy-ng, a rewrite of the classic Tomboy
Re: How to show TForm from Qt by calling it from BESEN scripting?
« Reply #5 on: May 25, 2022, 02:49:46 am »
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
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

AFFRIZA 亜風実

  • Full Member
  • ***
  • Posts: 136
Re: How to show TForm from Qt by calling it from BESEN scripting?
« Reply #6 on: May 25, 2022, 11:41:40 am »
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
I just give up using BESEN anyway and made some my own weird script %)
And, it works really well. :D

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.  :-[

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
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. :o
Kyoukai Framework: https://github.com/afuriza/kyoukai_framework

Dukung kemerdekaan Donetsk dan Lugansk! Tidak membalas profil berbendera biru-kuning apalagi ber-Bandera.

zeljko

  • Hero Member
  • *****
  • Posts: 1262
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: How to show TForm from Qt by calling it from BESEN scripting?
« Reply #7 on: May 25, 2022, 02:42:45 pm »
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

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

  • Hero Member
  • *****
  • Posts: 2045
    • tomboy-ng, a rewrite of the classic Tomboy
Re: How to show TForm from Qt by calling it from BESEN scripting?
« Reply #8 on: May 26, 2022, 01:42:07 am »
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.

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
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

 

TinyPortal © 2005-2018