Jump to content

pyscripter

Members
  • Content Count

    920
  • Joined

  • Last visited

  • Days Won

    56

Everything posted by pyscripter

  1. Use for key in spam.myPoint.ColumnA.Keys.ToArray(): print(key) It is possible to allow for a more natural iteration, but it would require to hand craft the TDictionary wrapper. See for instance how it is done in TPyDelphiStrings in WrapDelphiClasses.
  2. You could allow for both Point() and Point(x, y) by modifying CreateWith if PyArg_ParseTupleAndKeywords(args, kwds, '|ICreatePoint') then // no arguements else if PyArg_ParseTupleAndKeywords(args, kwds, 'ii|:CreatePoint', @fx, @fy) then // two integer arguements begin ... end;
  3. To be able to create columns you need to also to customize the TColumn wrapper: TColumnWrapper = class(TPyClassWrapper<TColumn>) constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override; end; constructor TColumnWrapper.CreateWith(APythonType: TPythonType; args, kwds: PPyObject); var W: integer; P: PPyObject; begin Create(APythonType); GetPythonEngine.PyArg_ParseTuple(args, 'iO:CreateColumn', @W, @P); DelphiObject := TColumn.Create; DelphiObject.Width := W; DelphiObject.Visible := GetPythonEngine.PyObject_IsTrue(P) = 1; end; then register it in Form.Create PyDelphiWrapper.RegisterDelphiWrapper(TColumnWrapper).Initialize; PyDelphiWrapper.RegisterDelphiWrapper(TPyClassWrapper<TDictionary<string, TColumn>>).Initialize; Then the following code works: from spam import myPoint, Column print(myPoint.ColumnA['Note'].Width) print(myPoint.ColumnA['Note'].Visible) new_column = Column(100, False) myPoint.ColumnA.Add('Note1', new_column) print(myPoint.ColumnA['Note1'].Width) print(myPoint.ColumnA['Note1'].Visible)
  4. Assuming your register the dictionary as shown above the following works. from spam import myPoint print(myPoint.ColumnA['Note'].Width) print(myPoint.ColumnA['Note'].Visible)
  5. Please use the latest version from https://github.com/pyscripter/python4delphi/. Not the Getit version. Here PyDelphiWrapper.RegisterDelphiWrapper(TPyClassWrapper<TDictionary<string, TColumn>>).Initialize; works. You could also subclass TDictionary<string, TColumn>. type TColumnDict = class( TDictionary<string, TColumn>) end; and in Form.Create PyDelphiWrapper.RegisterDelphiWrapper(TPyClassWrapper<TColumnDict>).Initialize;
  6. You need to register the TDictionary<String,TColumn> in Form.Create, PyDelphiWrapper.RegisterDelphiWrapper(TPyClassWrapper<TDictionary<String,TColumn>>).Initialize; Have not tested, Does it work?
  7. pyscripter

    RegExpressions and preUnGreedy

    See the record helpers in https://github.com/pyscripter/Pcre-Jit-Delphi/blob/master/Demos/benchmark.dpr and the methods SetAdditionalPCREOptions
  8. XML used to be considered the universal data format. Now is a bit passé with JSON, YAML etc being "in". I got involved in XML parsing, since SVG files are in XML format. XML Delphi support At the surface the XML support in Delphi is very good: You have TXMLDocument/IXMLDocument offering high-level support (Xml.xmldoc) Support for the standard DOM interfaces (Xml.XmlDom) Multiple implementations including (MSXML, OmniXML, OpenXML and more) Ability to plug in your own implementation Multiple platform support. The most common way of accessing XML is through TXMLDocument/IXMLDocument. However there is a big catch: PERFORMANCE. Say you want to use MSXML and you specify 'MSXML' as your DefaultDomVendor. (or you simply include the implementation unit Xml.Win.msxmldom in your uses clause). Your create an XML document and you access the top node: var Doc: IXMLDocument = TXMLDocument.Create(nil); var Node: IXMLNode := Doc.DocumentElement; Node is an IXMLInterface implemented by TXMLNode (TInterfacedObject defined in Xml.XmlDoc). TXMLNode wraps an IDOMNode stored in a private field FDOMNode. IDOMNode is defined in Xml.Xmldom. The IDOMNode is implemented by the used vendor in this case Xml.Win.msxmldom by a class TMSDOMNode TMSDOMNode (also a TInterfacedObject) wraps IXMLDOMNode stored in a private field FMSNode. IXMLDOMNode is defined in Winapi.msxml. As a result when you create any IXMLNode, a TXMLNode is created and this creates a TMSDOMNode which points to an IXMLDOMNode. Any call/property access to IXMLNode translates in a call of IDOMNode which then calls IXMLDOMNode. The created TInterfaced objects also need to be destroyed when you release your XML Node. The same two-level indirection applies to all XML objects (attributes, Children) and cause a huge degradation of performance. Conclusion If you care about speed forget about TXMLDocument. You can access the Vendor implementation or even better in the case of MSXML the Microsoft ActiveX objects directly: uses WinAPI.msxml var XML: IXMLDOMDocument3 := CoDOMDocument60.Create; XML.loadXML(XMLString); var DocNode: IXMLDOMNode := XML.documentElement; In SVG parsing and processing accessing directly the ActiveX objects reduced processing time by more than 50%. Additional tip A common performance pitfall with MSXML is explained in http://www.gerixsoft.com/blog/delphi/msxml. The fastest way to iterate through ChildNodes is via getFirstChild/nextSibling and Attributes via nextNode.
  9. pyscripter

    Multi Istance problem

    I think this has to do with the default encoding of the pipe stdout. Python uses utf8, however since the script is run from a Delphi program it may inherit the encoding from the parent process. Just a guess.
  10. uses VarPyth; ... var Res, S: string; PythonEngine1.ExecStrings(sl); Res := MainModule.Parser(S); It would help to watch the tutorial videos and play with the Demos.
  11. A single TPythonModule and TPyDelphiWrapper should do. Running python code in threads is quite complex. See PythonThreads · pyscripter/python4delphi Wiki (github.com) for details.
  12. Why create/destroy/recreate the PythonModule and PythonWrapper instead of reusing them? To avoid the finalization of the PythonEngine keep at least one client alive.
  13. pyscripter

    P4D FMX requirements

    Do you have the appropriate python lib in your system? eg. See also the replies in Getting started with Ubuntu 18.04. Error Could not open DLL - Python4Delphi - Delphi-PRAXiS [en] (delphipraxis.net) I would try first to run a console app and when this works then try an FMX app.
  14. pyscripter

    Howto use P4D Demo29 with PIL and OpenCV

    I meant call CheckError before that.
  15. pyscripter

    Howto use P4D Demo29 with PIL and OpenCV

    Also have a look at Demo 35 to see how you transfer arrays and array-like objects from Python to Delphi using the buffer protocol.
  16. pyscripter

    Howto use P4D Demo29 with PIL and OpenCV

    Add some error checking after the call. GetPythonEngine.CheckError; What is the error you are getting? It might help to post a minimal project.
  17. pyscripter

    Is there any edit/memo which allows multiselect?

    It is explained in the link to CudaText I gave above.
  18. pyscripter

    Is there any edit/memo which allows multiselect?

    All modern code editors have multi-select and multi-caret functionality (Visual Studio, VS-Code, Scintilla, Atom etc.). Also the freepascal CudaText. See CudaText - Free Pascal wiki for how it works. Very useful. I am currently working to add this to SynEdit.
  19. The sample code above uses VarPyth for high level access to python objects. MainModule is custom variant wrapping the __main__ python module. Unless you provide optional parameters to ExecStrings, the code is executed in the context of the __main__ module.
  20. How about? var SL := TStringList.Crete; try SL.LoadFromFile('example.py'); PyEngine.ExecStrings(SL); var Res := MainModule.DoExample('input'); finally SL.Free; end;
  21. pyscripter

    Problems while importing libraries with conda

    Are you calling SetPythonHome, as suggested in that page? Have you tried MaskFPUExceptions(True) instead? Is the Conda Library\bin subdirectory in the system path? If not try adding it.
  22. pyscripter

    Problems while importing libraries with conda

    Have you read FindingPython · pyscripter/python4delphi Wiki (github.com) regarding Conda? Is the DLLs subdirectory in the environment path?
  23. Please open an issue and describe the problem. Using SearchBuf should be OK.
  24. pyscripter

    D4P_export_demo

    Have seen https://github.com/Embarcadero/DelphiVCL4Python/issues/12?
×