freelanceprogrammers.org Forum Index » Delphi

How can do this?


View user's profile Post To page top
coolbrother@... Posted: Thu Aug 18, 2005 5:33 pm


Joined: 18 Aug 2005

Posts: 1
How can do this?
Hello, to understand PythonForDelphi, I would like do these tasks:
"manipulating a python script file trough C++Builder).

Code:
// file MyScript.py
import fmod02 # to use our fmod`s module written in C

class FmodLibrary:
"""
A class to use the fmod library to play sound.
Une classe qui utilise la librairie Fmod pour jouer le son
"""
def __init__(self):
self.loop =0

# to initialize Fmod Mixer
def Fmod_InitLoad_It(self, dir_file_name, loop):
#global dir_file_name
fmod02.InitLoad(dir_file_name, loop)

def Fmod_Play_It(self): # to play the song
fmod02.Play()

def Fmod_Stop_It(self): # to stop the song
fmod02.Stop()
#---------------------------------------
test = FmodLibrary()

// end of file MyScript.py

// file Unit1.cpp
// Here`s what I would like to do ?
void __fastcall TForm1::FormShow(TObject *Sender)
{
test.Fmod_InitLoad_It("tada.wav", 0);
// or something like this

}
//---------------------------------------------------------------------

void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
switch (Key)
{
case VK_SPACE :
test.Fmod_Play_It();
// or something like this?

break;
case `s`:
test.Fmod_Stop_It();
// or something like this?
}
}
//---------------------------------------------------------------------

If you can tell me how to do that, or if it`s possible or not to do that,
I would be very happy !!!
Big thanks !!!
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Mon Aug 29, 2005 7:23 am


Joined: 29 Apr 2005

Posts: 103
How can do this?
Hi everybody!
 
I`m happy to announce a new release of
P4D. You can download it from http://mmm-experts.com/Downloads.aspx?ProductId=3
 
The biggest change is the new component
TPyDelphiWrapper that was initially developed by Kiriakos Vlahos. It will let
you create or access VCL objects from Python, and it will also make it easier
to expose your regular Delphi classes to
Python, if you’re using Delphi7 or later.
Of course, this is beta code that has not
been extensively tested, but I release it now to help you embedding Python into
your applications, and to have some feedback about this…
You will find 2 demos that try to show
what you can do with that (because we still lack some good documentation, but
you can have a look at the WrapDelphi.pas unit which contains embedded
documentation at the beginning), and there is a new module named Delphi.dpr
that generates a Python pyd module allowing you to use the VCL from the regular
Python console. See the very simple TestApp.py script in the Modules folder.
But as you’re all experienced Delphi developers, it should be pretty obvious for you to
invoke VCL objects from Python…
All published properties are accessible
and some public properties/methods are also available. We still need to wrap
more classes, but I think that you already have a good basis.
Note that each XXX Delphi unit should be
wrapped in a specific WrapDelphiXXX unit, to minimize the dependencies. To make
it simpler, you can add the WrapDelphiVCL unit to your uses clause, to link all
wrapped units to your project.
 
Here’s a sample of what you can
write:
from Delphi
import *
class MyForm(Form):
  def __init__(self, Owner):
    self.Caption =
`Subclassed form`
    self.btnClose =
Button(self)
    self.btnClose.Parent =
self
    self.btnClose.Caption =
`Close`
   
self.btnClose.SetBounds(10, 10, 120, 30)
    self.btnClose.OnClick =
self.btnCloseClick
 
    self.chkCanClose =
CheckBox(self)
    self.chkCanClose.SetProps(Parent
= self, Caption = `Can close?`)
   
self.chkCanClose.SetBounds(10, 50, 120, 30)
 
    self.OnCloseQuery =
self.MyFormCloseQuery
    self.OnClose =
self.MyFormClose
 
  def btnCloseClick(self, Sender):
    print
"Close!"
    self.Close()
 
  def MyFormCloseQuery(self, Sender,
CanClose):
    CanClose.Value =
self.chkCanClose.Checked
 
  def MyFormClose(self, Sender,
Action):
    Action.Value = caFree
 
f = MyForm(Application)
try:
  f.ShowModal()
finally:
  f.Free()
 
Note also that you can subclass an
existing Delphi form simply by using the same class name in Python as in Delphi:
class TTestForm(Form):
  def __init__(self, Owner):
    self.Caption =
self.Caption + ` - changed by Python subclass`
   
self.BindMethodsToEvents()
 
  def handle_btnAdd_OnClick(self,
Sender):
   
self.ListBox1.Items.Add(self.Edit1.Text)
 
This will allow you to extend an existing
form with Python, or just hook Python code to some of the events of your form. BindMethodsToEvents
is a helper method introduced in the TComponent wrapper, that will try connect
component events with your Python methods, if you respect a specific pattern of
naming: handle_ComponentName_EventName
 
If you want to access your main form, you
can simply do:
Application.MainForm.Caption = ‘my
new caption’
Or lookup any form from the Screen.Forms
collection.
 
Here are the whole changes of version
3.29:

Fixed bug in TPythonType, reported by Roar
Larsen [roar@...], where a Access Violation would occur when
exceeding 10 methods/getsets/members in a new base type (tpfBaseType
option).
Fixed bug found by daydaysy [ildg@...]
where VarIsPythonClass would return False when checking a new style Python
class inheriting from object (class Foo(object): pass).
Used exported API for function PyImport_ExecCodeModule instead of
duplicating code
Added APIs PyObject_GetIter, PyIter_Next and
PyIter_Check to TPythonEngine
Added changes sent by Chris Nicolai :
added PyThreadState_SetAsyncExc -- throw an exception into _another_
thread!!
added new PyThreadState members from Python2.3
Addew new virtual class procedure SetupType to TPyObject, allowing the
class to setup its associated Python type. This is very useful when
building a hierarchy of classes, and thus avoiding copy&paste of the
type services for each TPythonType. Instead, setup the type in the base
class, and introduce in the subclasses the new services when they`re
implemented.
Added methods AddMethodWithKeywords/AddDelphiMethodWithKeywords
to TPythonModule and TPythonType, allowing you to create functions
receiving keyword parameters: foo(param1=val1, param2=val2...)
Added function VarPythonIsIterator to VarPyth.pas (and rewrote functions
len and iter)
Added new component TPyDelphiWrapper originally written and donated by
Kiriakos Vlahos [kvlahos@...] It allows you to interact with Delphi
VCL objects from Python. It works with Delphi5 or above. It also helps
expose your own Delphi classes to Python more easily with Delphi 7 or later.
Look at the documentation embedded at the beginning of the WrapDelphi.pas
unit.
Added Demos 31 and 32 that show how you can
benefit from WrapDelphi.
Added support for Free Pascal Compiler (http://www.freepascal.org/) and
Lazarus Project (http://www.lazarus.freepascal.org/)
Thanks to Michiel du Toit (micdutoit@...)
Added new folder "Modules" containing
the folder "Delphi" which
contains a Dll project for building a Python .pyd module in order to
expose the VCL to a regular Python interpreter. Modules also constains a
very simple Python script relying on Delphi.pyd for displaying a simple
form.
Note that you must ensure that Delphi.pyd is accessible from the Python
path, before trying to run TestApp.py
Updated source code of PythonIDE (PyScripter) to
reflect latest 1.2 version.

 
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Mon Aug 29, 2005 7:34 am


Joined: 29 Apr 2005

Posts: 103
How can do this?
Hi again,
 
I’m very pleased to announce another update: Kiriakos Vlahos worked
a lot to extend the last version of PyScripter and make it a top notch Python
IDE!
You can have a look by downloading it from http://mmm-experts.com/Downloads.aspx?ProductId=4
 
You will enjoy the Ctrl+Click on any symbol, as in Delphi,
to lookup its declaration.
If you’re addicted to GExperts like me, you’ll benefit from
the Function List (Ctrl+G) that provides an incremental search on any function
declared in the module. And you’ll appreciate the Grep search too.
The IDE is also easily extensible thanks to the external Tools feature
which lets you invoke any external command, using a lot of custom parameters.
You’ll also like to see a true help file, accessible from
anywhere.
You can now run a Python script in an external process to avoid any
side effect with the hosting IDE.
 
Here are the new features of version 1.2:

Extended code editor:

Context sensitive help on
Python keywords
Parameterized Code Templates
(Ctrl-J)
Accept files dropped from
Explorer
File change notification
Detecting loading/saving
UTF-8 encoded files
Converting line breaks
(Windows, Unix, Mac)

Editor Views

Disassembly
HTML Documentation (pydoc)

To Do List
Find and Replace in Files
Parameterized Code Templates
Choice of Python version to run via command
line parameters
Run Python Script externally (highly
configurable)
External Tools (External run and capture
output)

Integration with Python tools
such as PyLint, TabNanny, Profile etc.
Powerful parameter
functionality for external tool integration

Find Procedure
Find Definition/Find references using BicycleRepairMan
Find definition by clicking and browsing
history
Modern GUI with docked forms and configurable
look&feel (themes)

 
Reply with quote
Send private message
View user's profile Post To page top
daydaysy Posted: Sat Sep 03, 2005 4:27 pm


Joined: 21 May 2005

Posts: 13
How can do this?
Good~
I`m really happy to see so many features enhanced.
--- In pythonfordelphi@yahoogroups.com, "Morgan Martinet" <yahoo@m...>
wrote:
> Hi everybody!
>
>
>
> I`m happy to announce a new release of P4D. You can download it from
> http://mmm-experts.com/Downloads.aspx?ProductId=3
>
>
>
> The biggest change is the new component TPyDelphiWrapper that was
initially
> developed by Kiriakos Vlahos. It will let you create or access VCL
objects
> from Python, and it will also make it easier to expose your regular
Delphi
> classes to Python, if you`re using Delphi7 or later.
>
> Of course, this is beta code that has not been extensively tested, but I
> release it now to help you embedding Python into your applications,
and to
> have some feedback about this.
>
> You will find 2 demos that try to show what you can do with that
(because we
> still lack some good documentation, but you can have a look at the
> WrapDelphi.pas unit which contains embedded documentation at the
beginning),
> and there is a new module named Delphi.dpr that generates a Python pyd
> module allowing you to use the VCL from the regular Python console.
See the
> very simple TestApp.py script in the Modules folder.
>
> But as you`re all experienced Delphi developers, it should be pretty
obvious
> for you to invoke VCL objects from Python.
>
> All published properties are accessible and some public
properties/methods
> are also available. We still need to wrap more classes, but I think
that you
> already have a good basis.
>
> Note that each XXX Delphi unit should be wrapped in a specific
WrapDelphiXXX
> unit, to minimize the dependencies. To make it simpler, you can add the
> WrapDelphiVCL unit to your uses clause, to link all wrapped units to
your
> project.
>
>
>
> Here`s a sample of what you can write:
>
> from Delphi import *
>
> class MyForm(Form):
>
> def __init__(self, Owner):
>
> self.Caption = `Subclassed form`
>
> self.btnClose = Button(self)
>
> self.btnClose.Parent = self
>
> self.btnClose.Caption = `Close`
>
> self.btnClose.SetBounds(10, 10, 120, 30)
>
> self.btnClose.OnClick = self.btnCloseClick
>
>
>
> self.chkCanClose = CheckBox(self)
>
> self.chkCanClose.SetProps(Parent = self, Caption = `Can close?`)
>
> self.chkCanClose.SetBounds(10, 50, 120, 30)
>
>
>
> self.OnCloseQuery = self.MyFormCloseQuery
>
> self.OnClose = self.MyFormClose
>
>
>
> def btnCloseClick(self, Sender):
>
> print "Close!"
>
> self.Close()
>
>
>
> def MyFormCloseQuery(self, Sender, CanClose):
>
> CanClose.Value = self.chkCanClose.Checked
>
>
>
> def MyFormClose(self, Sender, Action):
>
> Action.Value = caFree
>
>
>
> f = MyForm(Application)
>
> try:
>
> f.ShowModal()
>
> finally:
>
> f.Free()
>
>
>
> Note also that you can subclass an existing Delphi form simply by
using the
> same class name in Python as in Delphi:
>
> class TTestForm(Form):
>
> def __init__(self, Owner):
>
> self.Caption = self.Caption + ` - changed by Python subclass`
>
> self.BindMethodsToEvents()
>
>
>
> def handle_btnAdd_OnClick(self, Sender):
>
> self.ListBox1.Items.Add(self.Edit1.Text)
>
>
>
> This will allow you to extend an existing form with Python, or just hook
> Python code to some of the events of your form. BindMethodsToEvents is a
> helper method introduced in the TComponent wrapper, that will try
connect
> component events with your Python methods, if you respect a specific
pattern
> of naming: handle_ComponentName_EventName
>
>
>
> If you want to access your main form, you can simply do:
>
> Application.MainForm.Caption = `my new caption`
>
> Or lookup any form from the Screen.Forms collection.
>
>
>
> Here are the whole changes of version 3.29:
>
> * Fixed bug in TPythonType, reported by Roar Larsen
> [roar@t...], where a Access Violation would occur when exceeding 10
> methods/getsets/members in a new base type (tpfBaseType option).
> * Fixed bug found by daydaysy [ildg@1...] where VarIsPythonClass
> would return False when checking a new style Python class inheriting
from
> object (class Foo(object): pass).
> * Used exported API for function PyImport_ExecCodeModule instead of
> duplicating code
> * Added APIs PyObject_GetIter, PyIter_Next and PyIter_Check to
> TPythonEngine
> * Added changes sent by Chris Nicolai :
> added PyThreadState_SetAsyncExc -- throw an exception into _another_
> thread!!
> added new PyThreadState members from Python2.3
> * Addew new virtual class procedure SetupType to TPyObject, allowing
> the class to setup its associated Python type. This is very useful when
> building a hierarchy of classes, and thus avoiding copy&paste of the
type
> services for each TPythonType. Instead, setup the type in the base
class,
> and introduce in the subclasses the new services when they`re
implemented.
> * Added methods AddMethodWithKeywords/AddDelphiMethodWithKeywords to
> TPythonModule and TPythonType, allowing you to create functions
receiving
> keyword parameters: foo(param1=val1, param2=val2...)
> * Added function VarPythonIsIterator to VarPyth.pas (and rewrote
> functions len and iter)
> * Added new component TPyDelphiWrapper originally written and donated
> by Kiriakos Vlahos [kvlahos@l...] It allows you to interact with
> Delphi VCL objects from Python. It works with Delphi5 or above. It also
> helps expose your own Delphi classes to Python more easily with
Delphi 7 or
> later.
> Look at the documentation embedded at the beginning of the
WrapDelphi.pas
> unit.
> * Added Demos 31 and 32 that show how you can benefit from WrapDelphi.
> * Added support for Free Pascal Compiler (http://www.freepascal.org/)
> and Lazarus Project (http://www.lazarus.freepascal.org/)
> Thanks to Michiel du Toit (micdutoit@h...)
> * Added new folder "Modules" containing the folder "Delphi" which
> contains a Dll project for building a Python .pyd module in order to
expose
> the VCL to a regular Python interpreter. Modules also constains a very
> simple Python script relying on Delphi.pyd for displaying a simple form.
> Note that you must ensure that Delphi.pyd is accessible from the Python
> path, before trying to run TestApp.py
> * Updated source code of PythonIDE (PyScripter
> <http://mmm-experts.com/Products.aspx?ProductId=4> ) to reflect
latest 1.2
> version.
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help