Jump to content

matrix1233

Members
  • Content Count

    15
  • Joined

  • Last visited

Community Reputation

0 Neutral

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Hi, I installed the last version of python on my Mac With python 3.9.i have the same error => I installed a second time python4lazarus to test with python3.9 and it's work ==> Now i added another test : 1 - Installed Python4lazarus (with working demo1) 2 - using Demo1 with library of lazarus and changing the file PythonEngine.pas (lazarus) with the PythonEngine.pas (python4Delphi) and i have the same error ( Error: could not map symbol "Py_DebugFlag" ) so the problem is on this file . At this time i do not have access to access to Delphi for MacOS. i will test when i will have access as soon possible.
  2. The strange think is if i install python4lazarus( https://github.com/Alexey-T/Python-for-Lazarus/) it's work. i will install now python3.9 and i will test
  3. Hi if i comment from Import('Py_DebugFlag') to Import('Py_IgnoreEnvironmentFlag') i have : and if you means that i have to comment from Import('Py_DebugFlag') to Import('PyGILState_Release') i have this error :
  4. Now i have Error on Py_VerboseFlag (please see the screenshot below)
  5. Yes it's the latest version installed on Lazarus Windows and Lazarus MacOs (just for info When i change the target (to compile on windows) of lazarus installed on Windows it's work )
  6. Hi, Am trying to execute a simple application (Demo1) with Python4Delphi on MacOs Catalina so i tried two Method: Method 1: - Compiling Demo1 on Windows to - Target OS : Darwin - Target CPU i86_64 => Demo1 app is generated correctly and when i move it to Mac and i execute it i have a Error ( Error: could not map symbol "Py_DebugFlag" ) Method 2: - Installing Lazarus on MacOs with Python4Delphi and executing the Demo1 (of corse i added the correct path to the lib ) : => Demo1 when start it generate the same Error (See the screenshot below) How can i correct this ? Thanks
  7. matrix1233

    Problem with FPC

    Hi, i stored MainModule.screenshot() to a variable _im like you asked and it doesn't work (See the first code below) but when i change the line where pResult are affected with presult := PyEval_CallObjectWithKeywords(ExtractPythonObjectFrom(MainModule.screenshot()), nil, nil), it work on lazarus . (See the second code below) . i think that ExtractPythonObjectFrom are only needed to do the job and adding PyEval_CallObjectWithKeywords is not needed in this case but lazarus have some bugs .. we can perhaps correct this ? var _im : Variant; _dib : Variant; i:integer; pargs: PPyObject; pResult :PPyObject; P : PAnsiChar; _stream:TmemoryStream; Len : NativeInt; SPython:TstringList; begin SPython:=TstringList.Create; SPython.Add('from io import BytesIO'); SPython.Add('from PIL import ImageGrab'); SPython.Add('def screenshot():'); SPython.Add(' im = ImageGrab.grab()'); SPython.Add(' stream = BytesIO()'); SPython.Add(' im.save(stream, "BMP")'); SPython.Add(' return stream.getvalue()'); SPython.Add('screenshot()'); PythonEngine1.ExecStrings(SPython); _im:=MainModule.screenshot(); with GetPythonEngine do begin try pResult := ExtractPythonObjectFrom(_im); if (PyBytes_AsStringAndSize(pResult, P, Len) < 0) then begin ShowMessage('This does not work and needs fixing'); Abort; end; finally _stream := TMemoryStream.Create(); try _stream.Write(P^, Len); _stream.Position := 0; Memo2.Lines.add(_stream.Size.ToString); Image1.Picture.LoadFromStream(_stream); application.ProcessMessages; finally _stream.Free; end; end; end; var _im : Variant; _dib : Variant; i:integer; pargs: PPyObject; pResult :PPyObject; P : PAnsiChar; _stream:TmemoryStream; Len : NativeInt; SPython:TstringList; begin SPython:=TstringList.Create; SPython.Add('from io import BytesIO'); SPython.Add('from PIL import ImageGrab'); SPython.Add('def screenshot():'); SPython.Add(' im = ImageGrab.grab()'); SPython.Add(' stream = BytesIO()'); SPython.Add(' im.save(stream, "BMP")'); SPython.Add(' return stream.getvalue()'); SPython.Add('screenshot()'); PythonEngine1.ExecStrings(SPython); with GetPythonEngine do begin try presult := PyEval_CallObjectWithKeywords(ExtractPythonObjectFrom(MainModule.screenshot()), nil, nil); if (PyBytes_AsStringAndSize(pResult, P, Len) < 0) then begin ShowMessage('This does not work and needs fixing'); Abort; end; finally _stream := TMemoryStream.Create(); try _stream.Write(P^, Len); _stream.Position := 0; Memo2.Lines.add(_stream.Size.ToString); Image1.Picture.LoadFromStream(_stream); application.ProcessMessages; finally _stream.Free; end; end; end;
  8. matrix1233

    Problem with FPC

    yes i see! .. between Delphi and Lazarus the result of execution are different for example this code below With Delphi work perfectly and with lazarus it doesn't work and it say that ( 'This does not work and needs fixing' ) generated by the test on PyBytes_AsStringAndSize. Any idea for this example why it's different ? var _im : Variant; _dib : Variant; i:integer; pargs: PPyObject; pResult :PPyObject; P : PAnsiChar; _stream:TmemoryStream; Len : NativeInt; SPython:TstringList; begin SPython:=TstringList.Create; SPython.Add('from io import BytesIO'); SPython.Add('from PIL import ImageGrab'); SPython.Add('def screenshot():'); SPython.Add(' im = ImageGrab.grab()'); SPython.Add(' stream = BytesIO()'); SPython.Add(' im.save(stream, "BMP")'); SPython.Add(' return stream.getvalue()'); SPython.Add('screenshot()'); PythonEngine1.ExecStrings(SPython); with GetPythonEngine do begin try pResult := ExtractPythonObjectFrom(MainModule.screenshot()); if (PyBytes_AsStringAndSize(pResult, P, Len) < 0) then begin ShowMessage('This does not work and needs fixing'); Abort; end; finally _stream := TMemoryStream.Create(); try _stream.Write(P^, Len); _stream.Position := 0; Memo2.Lines.add(_stream.Size.ToString); Image1.Picture.LoadFromStream(_stream); application.ProcessMessages; finally _stream.Free; end; end; end;
  9. matrix1233

    Problem with FPC

    Thanks, it's work!
  10. matrix1233

    Problem with FPC

    any solution ?
  11. matrix1233

    Problem with FPC

    the problem is not P, i think that is just MainModule.ImageToBytes like i explained above .. any idea ?
  12. matrix1233

    Problem with FPC

    i think that the problem is on MainModule.ImageToBytes because on Delphi when i try to display it to a memo (Memo3.Lines.Add(MainModule.ImageToBytes); ) i have <function ImageToBytes at 0x00000000068DDCA0> but when i try the same code on Lazarus i have nothing . any idea how can i resolve on lazarus ?
  13. matrix1233

    Problem with FPC

    if p := nil then i have the msg 'This does not work and needs fixing' if (Image1.Picture.Graphic = nil) or Image1.Picture.Graphic.Empty then raise Exception.Create('You must first select an image'); PythonEngine1.ExecStrings(Memo1.Lines); _im := MainModule.ProcessImage(ImageToPyBytes(Image1.Picture.Graphic)); if not chkUseDC.Checked then begin P := nil; // We have to call PyString_AsStringAndSize because the image may contain zeros with GetPythonEngine do begin pargs := MakePyTuple([ExtractPythonObjectFrom(_im)]); try presult := PyEval_CallObjectWithKeywords( ExtractPythonObjectFrom(MainModule.ImageToBytes), pargs, nil); try if (P = nil) or (PyBytes_AsStringAndSize(presult, P, Len) < 0) then begin ShowMessage('This does not work and needs fixing'); Abort; end; finally Py_XDECREF(pResult); end; finally Py_DECREF(pargs); end; end; _stream := TMemoryStream.Create(); try _stream.Write(P^, Len); _stream.Position := 0; _stream.SaveToFile('test.jpeg'); // Image1.Picture.Graphic.LoadFromStream(_stream); finally _stream.Free; end; end else begin Image1.Picture.Bitmap.SetSize(Image1.Width, Image1.Height); _dib := Import('PIL.ImageWin').Dib(_im); Image1.Picture.Bitmap.SetSize(Image1.Height, Image1.Width); _dib.expose(NativeInt(Image1.Picture.Bitmap.Canvas.Handle)); end;
  14. matrix1233

    Problem with FPC

    Hi the file is saved and his size is 197k and the content is "þîþîþîþîþî.." (from the begin to end)
  15. matrix1233

    Problem with FPC

    Hi, Am using Lazarus(FPC) and am trying to execute the Demo29 (work perfectly on delphi). the problem when i open Image and i Execute (Use Device Context Unchecked) the program go to the end and Image1.Picture.Graphic.LoadFromStream(_stream); raise an exception Wrong Image Format if (Image1.Picture.Graphic = nil) or Image1.Picture.Graphic.Empty then raise Exception.Create('You must first select an image'); PythonEngine1.ExecStrings(Memo1.Lines); _im := MainModule.ProcessImage(ImageToPyBytes(Image1.Picture.Graphic)); if not chkUseDC.Checked then begin // We have to call PyString_AsStringAndSize because the image may contain zeros with GetPythonEngine do begin pargs := MakePyTuple([ExtractPythonObjectFrom(_im)]); try presult := PyEval_CallObjectWithKeywords( ExtractPythonObjectFrom(MainModule.ImageToBytes), pargs, nil); try if (P = nil) or (PyBytes_AsStringAndSize(presult, P, Len) < 0) then begin ShowMessage('This does not work and needs fixing'); Abort; end; finally Py_XDECREF(pResult); end; finally Py_DECREF(pargs); end; end; _stream := TMemoryStream.Create(); try _stream.Write(P^, Len); _stream.Position := 0; Image1.Picture.Graphic.LoadFromStream(_stream); finally _stream.Free; end; end else begin Image1.Picture.Bitmap.SetSize(Image1.Width, Image1.Height); _dib := Import('PIL.ImageWin').Dib(_im); Image1.Picture.Bitmap.SetSize(Image1.Height, Image1.Width); _dib.expose(NativeInt(Image1.Picture.Bitmap.Canvas.Handle)); end; How can i correct that ? Thanks .
×