Jump to content

Search the Community

Showing results for tags 'python'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Delphi Questions and Answers
    • Algorithms, Data Structures and Class Design
    • VCL
    • FMX
    • RTL and Delphi Object Pascal
    • Databases
    • Network, Cloud and Web
    • Windows API
    • Cross-platform
    • Delphi IDE and APIs
    • General Help
    • Delphi Third-Party
  • C++Builder Questions and Answers
    • General Help
  • General Discussions
    • Embarcadero Lounge
    • Tips / Blogs / Tutorials / Videos
    • Job Opportunities / Coder for Hire
    • I made this
  • Software Development
    • Project Planning and -Management
    • Software Testing and Quality Assurance
  • Community
    • Community Management

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Delphi-Version

Found 13 results

  1. shineworld

    Place image in a TImage

    Hi all. I'm trying to convert a layout from PySimpleGUI to DelphiVCL. All works fine but I was not able to put an image in an Image() component programmatically. 1] I get a frame from OpenCV VideoCamera cap with: self.__cap = cv2.VideoCapture(0, cv2.CAP_DSHOW) ret, frame = self.__cap.read() 2] I convert the frame to a png image with: png_image = cv2.imencode('.png', frame)[1].tobytes() Now with PySimpleGUI I just update it with: view.window['image_1'].update(data=png_image) where image_1 = sg.Image(filename='', key='image_1', size=(640, 480)) With DelphiVCL I've created a image_1 = Image(self) and assigned basic parent and props but I don't find a way to update the img (an array of bytes with a PNG image inner). Thank you very much for suggestions.
  2. There have been a lot of questions in this forum about running python code in threads using Python4Delphi. I have created a comprehensive guide in this Wiki topic.
  3. Johansy

    Delphi4PythonExporter

    Hello, I would like to know if there is a different way to export a user interface for Python than with the Delphi4PythonExporter component, since I need to do it with Delphi 12 and this component does not yet have an update?
  4. In case you have not heard, Python 12 made a breakthrough towards running threads in parallel. For now, the feature is only available through the C-API and there are limitations. But still, the performance boost that comes from the exploitation of multiple cores makes this feature very desirable. P4D makes this feature very easily accessible by adding a new execution mode to TPythonThread. There is also a new demo (Demo 36) that shows how to run threads in parallel. If you are wondering about the performance boost, see the results below: Classic Subinterpreters: prime count 78498 prime count 78498 prime count 78498 prime count 78498 prime count 78498 Elapsed ms: 13695 Subinterpreters with own GIL: prime count 78498 prime count 78498 prime count 78498 prime count 78498 prime count 78498 Elapsed ms: 3482 You can find more details in this P4D announcement.
  5. JonRobertson

    RunntimeError in simple demo

    I just installed Phython4Delphi. The first demo, Demo01, throws an EPyRuntimeError (s_type = 'RuntimeError', s_value = '') when I click Execute Script on the simple print(2+2) example. The fourth line of Run_CommandAsObjectWithDict calls CheckError, which calls PyErr_Occurred, which does not return nil. I am just getting started with Python (for fun), so I am in the dark about why this error would occur or what needs to be done to resolve the issue. I have python 3.12 installed, both 32-bit and 64-bit. I have tested Demo01 as 32-bit and 64-bit and both throw the same exception. I can launch python at a command prompt and execute the script with no error. Any idea why this is occurring? Thanks.
  6. I have the following functionality, currently made with PacalScript, and I want to implement it in Python. I create a script component on the fly and programmatically create some variables of different types inside it. After I load the script proportionated by the user and I execute it. If all goes well, I recover the current values of the firstly proportionated variables and apply them to my Delphi program. Also, the end user can use some methods implemented in the Delphi main program inside the script. Summarizing: 1- I need to create variables on the fly inside a Python Script. 2- I need to recover the current values of some variables inside a Python Script. 3- I need to create some functions inside a Python script that can be called from it but really exists in the host Delphi program. Can anyone help me or knows where I can find examples of these three functionalities?
  7. I gonna run python script in separate thread. My PythonEngine has IO field assigned with TPythonGUIInputOutput component What is the correct way to synchronize output (e.g. print("Hello World!") to Delphi's TMemo component? As far as I know VCL is not thread safe... Thank you.
  8. Hi all. To complete my first Python + DelphiVCL program I need to expose to Python an extra Image Viewer Control. I don't want to create a custom delphivcl.pyd which is a good thing remains original and installable with pip install delphivcl, so I've tried to add the component in a custom package. Well, seems simple to do but does not work fine... The control to expose is TImgView32 which inherits from: TImgView32->TCustomImgView32->TCustomImage32->TCustomPaintBox32->TCustomControl so it is close to TLabel and looking at DelphiVCL code I've made same steps: library cnc_vision_ext; uses osPyCncVisionExt in 'sources\osPyCncVisionExt.pas'; exports PyInit_cnc_vision_ext; {$E pyd} begin end. unit osPyCncVisionExt; interface uses PythonEngine; function PyInit_cnc_vision_ext: PPyObject; cdecl; implementation uses System.Classes, System.SysUtils, System.Variants, Winapi.Windows, Vcl.ExtCtrls, VarPyth, WrapDelphi, WrapVclExtCtrls, WrapVclControls, WrapDelphiClasses, GR32_Image; type TPyDelphiImgView32 = class(TPyDelphiControl) private function GetDelphiObject: TImgView32; procedure SetDelphiObject(const Value: TImgView32); public class function DelphiObjectClass: TClass; override; property DelphiObject: TImgView32 read GetDelphiObject write SetDelphiObject; end; TPyExtensionManager = class private FEngine: TPythonEngine; FModule: TPythonModule; FWrapper: TPyDelphiWrapper; public procedure WrapperInitializationEvent(Sender: TObject); end; var ExtensionManager: TPyExtensionManager; { module import functions } function PyInit_cnc_vision_ext: PPyObject; begin Result := nil; try ExtensionManager.FEngine := TPythonEngine.Create(nil); ExtensionManager.FEngine.AutoFinalize := False; ExtensionManager.FEngine.UseLastKnownVersion := True; ExtensionManager.FEngine.LoadDllInExtensionModule(); ExtensionManager.FModule := TPythonModule.Create(nil); ExtensionManager.FModule.Engine := ExtensionManager.FEngine; ExtensionManager.FModule.ModuleName := 'cnc_vision_ext'; ExtensionManager.FWrapper := TPyDelphiWrapper.Create(nil); ExtensionManager.FWrapper.Engine := ExtensionManager.FEngine; ExtensionManager.FWrapper.Module := ExtensionManager.FModule; ExtensionManager.FModule.Initialize; ExtensionManager.FWrapper.OnInitialization := ExtensionManager.WrapperInitializationEvent; ExtensionManager.FWrapper.Initialize; Result := ExtensionManager.FModule.Module; except end; end; { TPyDelphiImgView32 } class function TPyDelphiImgView32.DelphiObjectClass: TClass; begin Result := TImgView32; end; function TPyDelphiImgView32.GetDelphiObject: TImgView32; begin Result := TImgView32(inherited DelphiObject); end; procedure TPyDelphiImgView32.SetDelphiObject(const Value: TImgView32); begin inherited DelphiObject := Value; end; { TPyExtensionManager } procedure TPyExtensionManager.WrapperInitializationEvent(Sender: TObject); begin FWrapper.RegisterDelphiWrapper(TPyDelphiImgView32); end; initialization ExtensionManager := TPyExtensionManager.Create; finalization ExtensionManager.Free; end. Well, compilation OK and import on Python OK, but when I try to create the object assigning the parent I got that: from delphivcl import * from cnc_vision_ext import * class TestForm(Form): def __init__(self, owner): # print type of self ('__main__.TestForm') print(type(self)) # create a vcl label and assign parent: WORKS self.label = Label(self) self.label.Parent = self self.label.Left = 10 self.label.Top = 10 self.label.Caption = 'Hello World' # create a ext image and assign parent: ERROR self.image = ImgView32(self) # <-- AttributeError: Owner receives only Delphi objects self.image.Parent = self self.image.Left = 10 self.image.Top = 30 self.image.Width = 200 self.image.Height = 100 def main(): Application.Initialize() Application.Title = 'test' MainForm = TestForm(Application) MainForm.Show() FreeConsole() Application.Run() if __name__ == '__main__': main() ù If I check with a Python console the types seem very close: D:\x\develop\qem\cnc_vision_1>python Python 3.9.12 (tags/v3.9.12:b28265d, Mar 23 2022, 23:52:46) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from delphivcl import * >>> from cnc_vision_ext import * >>> frm = Form(None) >>> lbl = Label(frm) >>> lbl.Parent = frm >>> type(lbl) <class 'Label'> >>> lbl.__doc__ 'Wrapper for Delphi TLabel\n' >>> lbl.ClassName 'TLabel' >>> img = ImgView32(frm) # does not work with frm as like as lbl Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: Owner receives only Delphi objects >>> img = ImgView32(None) # try with none to check object type >>> type(img) <class 'ImgView32'> >>> img.__doc__ 'Wrapper for Delphi TImgView32\n' >>> img.ClassName 'TImgView32' Thank you in advance for any suggestion 🙂
  9. Hi, we are doing some image processing and will use OpenCV for it. Doing this from Python is very useful as it disconnects us from the OpenCV libraries which we can now directly use. However, most processing is done with bitmaps. I have used the Demo29 and that works but it has the following limitations from our perspective. It requires image in a TGraphic form which we don't get from a frame grabber and I find no documentation to describe either the structure of or how to convert a bitmap to it. Internally we can convert the Byte stream with cv.imdecode into a opencv image and can convert our result image back to PILLOW Returning the image however does not work unless the image is converted back to a PILLOW format from where demo29 code can display it. I think part of my problem is that I don't have enough information regarding the PILLOW format or the TGraphic format. Also I don't find information about functions such as PyEval_CallObjectWithKeywords and ExtractPythonObjectFrom as the statement in demo29 returns a nil if I return any other format than PILLOW from Python. Any assistance will be appreciated and if anyone can point me to support documentation describing how to use bitmaps in Python and also how to understand the many Python methods. I ahve been mostly a Delphi programmer. An example of how we do it is as follows but this seems unnecessary and also requires input in TGraphic form, not TBitmap. def LoadPicData(data): # Convert data (image converted into Python Bytes) into a ocv image stream = BytesIO(data) ocv_img = cv.imdecode(np.asarray(bytearray(stream.read()), dtype=np.uint8), cv.IMREAD_COLOR) pil_src = Image.open(stream) # cv.imshow('ocv', ocv_img) ocv_img = cv.cvtColor(ocv_img, cv.COLOR_BGR2GRAY) # cv.imshow('gray', ocv_img) # Convert this image to pil image color_converted = cv.cvtColor(ocv_img, cv.COLOR_BGR2RGB) pil_img = Image.fromarray(color_converted) # convert ocv to PIL image pil_img.format = pil_src.format # ImageShow.show(pil_img, 'PIL') return pil_img Some assistance will be much appreciated.
  10. Albion

    Calculation problem

    Good afternoon, I encountered such a problem, when executing a python script, the calculations are not written to the output fields, and therefore cannot go further, since they take values from them. Can anyone tell me what I did wrong?
  11. Albion

    Testing with python

    Good day everyone! I have a question. Perhaps someone has already experienced this. I have a ready-made program on Delphi. And I need to initialize and execute all the functions of this program using a Python script. Is it possible to accomplish this task only with the help of TPytnon components? Without adding memos and other things as shown in the demo programs. Just run the script and get the result. Maybe someone can help with this question. I would be very grateful for any help. Thanks for attention.
  12. shineworld

    OnMouseDown/Up events

    Hi, all I'm trying to use Python extension from Embarcadero: https://github.com/Embarcadero/DelphiVCL4Python installed in Python 3.9 (32 bits) with pip install delphivcl I was able to assign an OnClick event (in a Button): # creates jogs buttons btnXM = Button(self) btnXM.Parent = pgOne btnXM.Caption = 'X-' btnXM.Left = 8 btnXM.Top = 10 btnXP = Button(self) btnXP.Parent = pgOne btnXP.Caption = 'X+' btnXP.Left = btnXM.Left + btnXM.Width + 8 btnXP.Top = 10 def ClickEventHandler(Sender): pass btnXP.OnClick = self.jogClickEvent def MouseDownHandler(Sender, State, Button, X, Y): pass btnXP.OnMouseDown = MouseDownHandler but when reaches the btnXP.OnMouseDown Python notice this error: *** Remote Interpreter Reinitialized *** Traceback (most recent call last): File "D:\x\develop\qem\rosetta_cnc_1\python-scripts\pyipctcpjsonvcl-demo.py", line 249, in <module> main() File "D:\x\develop\qem\rosetta_cnc_1\python-scripts\pyipctcpjsonvcl-demo.py", line 241, in main f = MainForm(Application) File "D:\x\develop\qem\rosetta_cnc_1\python-scripts\pyipctcpjsonvcl-demo.py", line 67, in __init__ btnXP.OnMouseDown = MouseDownHandler AttributeError: Error in setting property OnMouseDown Error: No Registered EventHandler for events of type "TMouseEvent Looking at btnXP dir(): print(btnXP.__dir__()) ['__bound__', '__dir__', '__owned__', 'Action', 'AfterConstruction', 'Align', 'AlignDisabled', 'AlignWithMargins', 'Anchors', 'Assign', 'BeforeDestruction', 'BeginDrag', 'BeginInvoke', 'BiDiMode', 'BindMethodsToEvents', 'BoundsRect', 'BringToFront', 'Broadcast', 'Brush', 'Cancel', 'CanFocus', 'Caption', 'CheckNonMainThreadUsage', 'ClassInfo', 'ClassName', 'ClassNameIs', 'ClassParent', 'ClassType', 'CleanupInstance', 'Click', 'ClientHeight', 'ClientOrigin', 'ClientRect', 'ClientToParent', 'ClientToScreen', 'ClientWidth', 'CommandLinkHint', 'ComObject', 'ComponentCount', 'ComponentIndex', 'Components', 'ComponentState', 'ComponentStyle', 'Constraints', 'ContainsControl', 'ControlAtPos', 'ControlCount', 'Controls', 'ControlState', 'ControlStyle', 'Create', 'CreateParented', 'CreateParentedControl', 'CurrentPPI', 'Cursor', 'CustomHint', 'Default', 'DefaultHandler', 'DesignInfo', 'Destroy', 'DestroyComponents', 'Destroying', 'DisableAlign', 'DisabledImageIndex', 'DisabledImageName', 'DisabledImages', 'Dispatch', 'DisposeOf', 'Dock', 'DockClientCount', 'DockDrop', 'DockManager', 'DockOrientation', 'DockSite', 'DoubleBuffered', 'DragCursor', 'DragDrop', 'Dragging', 'DragKind', 'DragMode', 'DrawTextBiDiModeFlags', 'DrawTextBiDiModeFlagsReadingOnly', 'DropDownMenu', 'ElevationRequired', 'EnableAlign', 'Enabled', 'EndDrag', 'EndFunctionInvoke', 'EndInvoke', 'Equals', 'ExecuteAction', 'ExplicitHeight', 'ExplicitLeft', 'ExplicitTop', 'ExplicitWidth', 'FieldAddress', 'FindChildControl', 'FindComponent', 'FlipChildren', 'Floating', 'FloatingDockSiteClass', 'Focused', 'Font', 'Free', 'FreeInstance', 'FreeNotification', 'FreeOnRelease', 'GetChildren', 'GetControlsAlignment', 'GetEnumerator', 'GetHashCode', 'GetInterface', 'GetInterfaceEntry', 'GetInterfaceTable', 'GetNamePath', 'GetParentComponent', 'GetStyleName', 'GetSystemMetrics', 'GetTabControlList', 'GetTabOrderList', 'GetTextBuf', 'GetTextLen', 'Handle', 'HandleAllocated', 'HandleNeeded', 'HasParent', 'Height', 'HelpContext', 'HelpKeyword', 'HelpType', 'Hide', 'Hint', 'HostDockSite', 'HotImageIndex', 'HotImageName', 'ImageAlignment', 'ImageIndex', 'ImageMargins', 'ImageName', 'Images', 'InheritsFrom', 'InitiateAction', 'InitInstance', 'InsertComponent', 'InsertControl', 'InstanceSize', 'Invalidate', 'IsCustomStyleActive', 'IsDrawingLocked', 'IsImplementorOf', 'IsLightStyleColor', 'IsRightToLeft', 'Left', 'LockDrawing', 'LRDockWidth', 'ManualDock', 'ManualFloat', 'Margins', 'MethodAddress', 'MethodName', 'ModalResult', 'MouseInClient', 'MouseWheelHandler', 'Name', 'NewInstance', 'Observers', 'OnClick', 'OnContextPopup', 'OnDragDrop', 'OnDragOver', 'OnDropDownClick', 'OnEndDock', 'OnEndDrag', 'OnEnter', 'OnExit', 'OnGesture', 'OnKeyDown', 'OnKeyPress', 'OnKeyUp', 'OnMouseActivate', 'OnMouseDown', 'OnMouseEnter', 'OnMouseLeave', 'OnMouseMove', 'OnMouseUp', 'OnStartDock', 'OnStartDrag', 'Owner', 'Padding', 'PaintTo', 'Parent', 'ParentBiDiMode', 'ParentCustomHint', 'ParentDoubleBuffered', 'ParentFont', 'ParentShowHint', 'ParentToClient', 'ParentWindow', 'Perform', 'PixelsPerInch', 'PopupMenu', 'PreProcessMessage', 'PressedImageIndex', 'PressedImageName', 'QualifiedClassName', 'Realign', 'RedrawDisabled', 'ReferenceInterface', 'Refresh', 'RemoveComponent', 'RemoveControl', 'RemoveFreeNotification', 'Repaint', 'ReplaceDockedControl', 'SafeCallException', 'ScaleBy', 'ScaleFactor', 'ScaleForPPI', 'ScaleRectSize', 'ScaleValue', 'ScreenToClient', 'ScrollBy', 'SelectedImageIndex', 'SelectedImageName', 'SendToBack', 'SetBounds', 'SetDesignVisible', 'SetFocus', 'SetParentComponent', 'SetProps', 'SetSubComponent', 'SetTextBuf', 'Show', 'ShowHint', 'Showing', 'Style', 'StyleElements', 'StyleName', 'StylusHotImageIndex', 'StylusHotImageName', 'TabOrder', 'TabStop', 'Tag', 'TBDockHeight', 'ToList', 'Top', 'ToString', 'ToTuple', 'Touch', 'UndockHeight', 'UndockWidth', 'UnitName', 'UnitScope', 'UnlockDrawing', 'Update', 'UpdateAction', 'UpdateControlState', 'UseDockManager', 'UseRightToLeftAlignment', 'UseRightToLeftReading', 'UseRightToLeftScrollBar', 'VCLComObject', 'Visible', 'VisibleDockClientCount', 'Width', 'WindowProc', 'WordWrap'] OnMouseDown/Up are exposed.... I'm not able to understand what I've missed... Thank you in advance for suggestions
  13. shineworld

    python delphivcl development

    I'm converting a complex Python PySimpleGUI based program to Python using delphivcl module. In my initial test, the gained speed on UI things sees delphivcl as a very winner. But I need to add some missing features in delphivcl controls as well as the possibility to modify an Image (TImage) content sending it as an array of bitmap (NumPy arrays) instead to have to create a file.bmp and then load it with Image.Picture.LoadFromFile. Also, I need to add OnMouseDown/OnMouseUp in buttons. Gitting delphivcl, or delphifmx, I was not able to find the delphi building project, only the final files. Where I can find sources and projects to make delphivcl module and so to add new features?
×