Jump to content

pyscripter

Members
  • Content Count

    1111
  • Joined

  • Last visited

  • Days Won

    75

Everything posted by pyscripter

  1. @Kas Ob. There are many ways to skin a cat. The approach adopted in pascal-process uses asynchronous (overlapped) IO with alertable wait. So there are no tight loops with Sleep, or additional threads for reading. I think it is as efficient as it can get. I compared your code to pascal-process by using: 'cmd /v:on /c "set start=!time! && dir C:\Windows /s && set end=!time! && echo Start time: !start! && echo End time: !end!"'#13#10 Your code: Start time: 14:31:08.09 End time: 14:31:22.64 about 14 secs pascal-process Start time: 14:35:54.74 End time: 14:36:04.58 about 9 secs. To make sure disk caching did not play a role, I run your code again, with similar results: Start time: 15:01:58.56 End time: 15:02:14.17 About 15 secs. Of course one should not read much in a single benchmark. But, I do not see any reason your code is faster or otherwise better than the one used in pascal-process. Regarding AttachConsole do you happen to know, in which Delphi version it was first declared?
  2. @Kas Ob. This is an open-source project. You are welcome to create PRs, open issues, make suggestions etc.
  3. I have installed the Linux platform support and I am able to run simple Linux console applications targeting WSL. However, I cannot find the Posix source files, such as Posix.Base, Posix.SysTypes etc. What am I missing? I am using Delphi 12.3. I can see the files in my Delphi 11 installation.
  4. pyscripter

    Posix source files missing

    For some reason, I do not see the May Patch.
  5. @Dave Nottage Thanks for testing. I have updated the Readme with the corrected parameter list for OnRead. Regarding the conversion to string, the whole point of the library is that you get bytes. It is up to the user to use the bytes whichever way is appropriate. The console encoding may be not be Delphi's default encoding. In Linux it is most likely UTF8. On Windows one might use the GetConsoleOutputCP API to get the code page for the output. However even that is not reliable, For instance, on Windows, the scp command expects input and produces output in UTF8 encoding irrespective of the console encoding. The use of ANSI encoding on the project page was just an example. I agree thought that for the example TEncoding.Default is a better choice. So I have updated that as well.
  6. pascal-process is now multi-platform! So now there is a Delphi library to match fpc's TProcess. Desktop POSIX platforms (LINUX and MACOS) are now supported in addition to Windows. I have tested with LINUX. Since, I do not have a MACOS system available, I would appreciate some help in testing with MACOS.
  7. pyscripter

    Posix source files missing

    As mentioned I can compile code. Just the sources in the above path are missing.
  8. pyscripter

    Turbopower Visual Planit??

    For the record, TurboPower was a good company, but their components were commercial. They were open-sourced their products when the company shut-down their component business. However, they are products of the previous century and they show it. And incidentally, TurboPower was owned by a gambling business (a Casino or something).
  9. pyscripter

    Is it possible to implement floating/fully custom Dropdown Menus?

    Following on @Anders Melander suggestion you can find here a free implementation of his idea. The library also supports controls on menus and toolbars, is Vcl styles compatible and High-DPI aware. See some of the images here.
  10. pyscripter

    Python Output

    For now, there are very serious limitations you need to consider when using emNewInterpreterOwnGIL to achieve true parallelism. See for instance the limitations in What’s new in Python 3.14 — Python 3.14.0b3 documentation. Even the innocent looking print command is not thread-safe. And almost nothing can be share between the interpreters. Also there are limitations about what you can import, and P4D modules are not yet considered safe for use with emNewInterpreterOwnGIL. This is changing with the forthcoming python 3.14. It will include a new module concurrent.interpreters that exposes the interpreters with their own GIL to pure python code. There will also be an addition of ways to communicate between the interpreters using queues. See PEP 734. So for example you could store your output to such a queue and print it when everything is finished. But all the above is cutting edge and unless you really need it you should avoid it, If you decide to use it then make sure you fully understand the limitations and implications. I will try to make P4D modules compatible with emNewInterpreterOwnGIL and that would at least give you the option to say add output to a Delphi string list (or something similar) protected with a global lock on the Delphi side. Note that all the above are not related to the free-threading version of Python, which in itself is another story altogether.
  11. pyscripter

    Getting exitcode (%errorlevel%) of python script

    It should. Please update to the latest version of P4D and try again. Then report here whether it works.
  12. TOML is a "config file format for humans", that has gained a lot of traction in the python and rust communities among others. It is basically the INI file format on steroids. It compares quite well to alternative formats such as JSON, YAML and XML. Compared to JSON is way more readable and compact. Since I could not find any Delphi library for processing TOML, I have created my own: toml-delphi. Features: TOML v1.0.0 compliant. Passes all 734 (valid/invalid) official validation tests. Fast. Single stream tokenizer and lexer that doesn't use regex. Converts TOML documents to Delphi's RTL's TJSONObject, thus allowing for easy traversal, manipulation and query of the generated documents. Includes TTOMLWriter for converting TJSONObjects back to TOML. Provides for easy (de)serialization of Delphi objects and records from/to TOML. This is the interface of the main unit: TJSONObjectHelper = class helper for TJSONObject function ToTOML(MultilineStrings: Boolean = False; Indent: Integer = 4): string; procedure StreamTOML(Stream: TStream; MultilineStrings: Boolean = False; Indent: Integer = 4); procedure SaveTOMLtoFile(const FileName: string; MultilineStrings: Boolean = False; Indent: Integer = 4); class function FromTOML(const Contents: string): TJSONObject; overload; class function FromTOML(Contents: TBytes): TJSONObject; overload; class function FromTOML(Stream: TStream): TJSONObject; overload; class function FromTOMLFile(const FileName: string): TJSONObject; end; ETOMLSerializer = class(Exception); TTOMLSerializer = class class function Serialize<T>(const AValue: T): string; overload; class function Deserialize<T>(const ATOML: string): T; overload; end; Example usage: You can convert TOML source to TJSONObject using one of the FromTOML functions. For example to parse a TOML file you use: var JsonObject := TJSONObject.FromTOMLFile(FileName); //or for parsing a TOML string: var JsonObject := TJSONObject.FromTOML(TOMLstring); To convert a TJSONObject to TOML you use one of the methods ToTOML, StreamTOML or SaveTOMLToFile. For example: TOMLString := JsonObject.ToTOML; // or JsonObject.SaveTOMLToFile(FileName); Example serialization: type TTestRec = record IntValue: Integer; FloatValue: double; StringValue: string; DateValue: TDateTime; ArrayValue: TArray<string>; end; procedure TestSerializer; var Rec: TTestRec; TOMLString: string; begin Rec.IntValue := 123; Rec.FloatValue := 3.14; Rec.StringValue := 'abc'; Rec.DateValue := Now; Rec.ArrayValue := ['A', 'B', 'C']; Writeln('Serialized record:'); WriteLn('=================='); TOMLString := TTOMLSerializer.Serialize(Rec); Writeln(TOMLString); Writeln('Record deserialized and serialized again:'); Writeln('========================================='); Rec := TTOMLSerializer.Deserialize<TTestRec>(TOMLString); TOMLString := TTOMLSerializer.Serialize(Rec); Writeln(TOMLString); end; Output: Serialized record: ================== IntValue = 123 FloatValue = 3.14 StringValue = "abc" DateValue = "2025-06-18T05:37:02.110+03:00" ArrayValue = [ "A", "B", "C" ] Record deserialized and serialized again: ========================================= IntValue = 123 FloatValue = 3.14 StringValue = "abc" DateValue = "2025-06-18T05:37:02.110+03:00" ArrayValue = [ "A", "B", "C" ] I hope you find it useful.
  13. pyscripter

    TOML delphi parser, writer and serializer

    These two tests appear to be identical. Parsing them leads to a call result := TJSONNumber.Create(str); where str = '0.1.2' Apparently this succeeds in Delphi 10.4 but correctly fails in later versions. This is easily fixed by using TryStrToFloat before creating the TJSONNumber. @dummzeuch I have committed a potential fix for the above10.4 failed invalid tests. Could you please try again.
  14. pyscripter

    TOML delphi parser, writer and serializer

    I have now replaced that call to Contains. Tested with Delphi 11. ✖ comment\after-literal-no-ws.toml: 'inf' is not a valid floating point value ✖ float\inf-and-nan.toml: 'nan' is not a valid floating point value ✖ spec-1.0.0\float-2.toml: 'inf' is not a valid floating point value Completed: 205, Succeeded: 202, Failed: 3 Completed: 529, Succeeded: 529, Failed: 0 ✓ All tests passed! I think I can live with that. Apparently StrToFloat was extended to cope with inf, nan, and -inf in Delphi 12. In Delphi 12 you can serialize such special floating point values. Could you please test again with Delphi 10.4 The parsing might work, but the serializer had many bugs in 10.4.
  15. pyscripter

    TOML delphi parser, writer and serializer

    Backward compatibility is going to be an issue at least for the serializer part. Right now I am trying to fix Delphi 11 compatibility. It should be possible to make the parsing staff made compatible with earlier versions of Delphi, as long as TJSONObject exists.
  16. pyscripter

    TOML delphi parser, writer and serializer

    TOML 1.1 is not yet official. 1.0 is the latest TOML standard. So they are correctly rejected for now.
  17. pyscripter

    TOML delphi parser, writer and serializer

    @dummzeuch Fixed (I think). Could you please try again.
  18. pyscripter

    TOML delphi parser, writer and serializer

    There is no need for that, if you clone the project. You just update the submodule.
  19. pyscripter

    TOML delphi parser, writer and serializer

    Here: Completed: 205, Succeeded: 205, Failed: 0 ✓ All tests passed! Completed: 529, Succeeded: 529, Failed: 0 ✓ All tests passed! I can guess the issue is with the TFormatSettings in the conversion to float. I wlll fix it.
  20. pyscripter

    TOML delphi parser, writer and serializer

    @dummzeuch With the permission of the original author the license has now been changed to the MIT one.
  21. pyscripter

    TOML delphi parser, writer and serializer

    See https://github.com/genericptr/fpTOML/issues/5#issuecomment-2983448165
  22. pyscripter

    Getting exitcode (%errorlevel%) of python script

    You can do something similar in python. You can use sys.exit(n) which raises the SystemExit exception. n can be a number or a string or anything else. But if you call sys.exit(n) with different integer values then you can do the following: try PythonEngine.ExecString(...); except on E: EPySystemExit do begin case IntToStr(e.EValue): 1: 2: end; end; end;
  23. pyscripter

    Getting exitcode (%errorlevel%) of python script

    PythonEngine1.ExecStrings(lines) will raise in exception (a subclass of EPyException) if an error occurs. If you redirecting the python output using for instance TPythonGUIInputOutput then error information is printed and you will be able to see where the error occurred including a traceback. You can also use the Traceback object to extract information about the error. If you want to handle the Exception you can use try PythonEngine1.ExecStrings(lines); except on E: EPyException // Do whatever you want. You can use the PythonEngine1.Traceback to get information about what went wrong end
×