Delphi VCL for Python
Project description
DelphiVCL for Python ![DelphiVCL4Python](https://pypi-camo.freetls.fastly.net/2f1c843b31d67ec2bca115952c4dcc7494ff41ed/68747470733a2f2f6769746875622e636f6d2f456d62617263616465726f2f44656c70686956434c34507974686f6e2f7261772f6d61696e2f696d616765732f44656c70686956434c34507974686f6e283235367078292e706e67)
Delphi's VCL library as a Python module for building native Windows GUI Applications
Installation:
pip install delphivcl
Supports:
- Win32 & Win64 x86 architectures
- Python cp3.6, cp3.7, cp3.8, cp3.9 and cp3.10
Conda support:
- Win x86 and x64 from Python cp3.6 to cp3.10
Quickstart Guide:
Let us create a TODO Task Application to understand some components of GUI Applications.
Let's take a look at the code to achieve that:
from delphivcl import *
class TodoApp(Form):
def __init__(self, Owner):
self.Caption = "A TODO GUI Application"
self.SetBounds(100, 100, 700, 500)
self.task_lbl = Label(self)
self.task_lbl.SetProps(Parent=self, Caption="Enter your TODO task")
self.task_lbl.SetBounds(10, 10, 125, 25)
self.task_text_box = Edit(self)
self.task_text_box.SetProps(Parent=self)
self.task_text_box.SetBounds(10, 30, 250, 20)
self.add_task_btn = Button(self)
self.add_task_btn.Parent = self
self.add_task_btn.SetBounds(150, 75, 100, 30)
self.add_task_btn.Caption = "Add Task"
self.add_task_btn.OnClick = self.__add_task_on_click
self.del_task_btn = Button(self)
self.del_task_btn.SetProps(Parent = self, Caption = "Delete Task")
self.del_task_btn.SetBounds(150, 120, 100, 30)
self.del_task_btn.OnClick = self.__del_task_on_click
self.list_of_tasks = ListBox(self)
self.list_of_tasks.Parent = self
self.list_of_tasks.SetBounds(300, 50, 300, 350)
self.OnClose = self.__on_form_close
def __on_form_close(self, Sender, Action):
Action.Value = caFree
def __add_task_on_click(self, Sender):
self.list_of_tasks.Items.Add(self.task_text_box.Text)
self.task_text_box.Text = ""
def __del_task_on_click(self, Sender):
self.list_of_tasks.Items.Delete(0)
def main():
Application.Initialize()
Application.Title = "TODO App"
app = TodoApp(Application)
app.Show()
FreeConsole()
Application.Run()
app.Destroy()
main()
As you save and run the above code, you should get the following GUI as a result:
Let's get to the details of what our code does behind the scenes. First, take a look at the main()
function:
def main():
Application.Initialize()
Application.Title = "TODO App"
In the above, Application
instance is part of the delphivcl
library that takes control of the GUI applications that we create. First line initializes the application, and the second line sets a title to the application.
Let's look at other lines of code of the main()
function;
app = TodoApp(Application)
app.Show()
FreeConsole()
Application.Run()
app.Destroy()
Above, We instantiated the TodoApp
class with Application
as the Owner
. We can show the GUI application on the screen using the app.show()
method. GUI applications run in interaction with the command window (console). To make the GUI perform better without lags, we use FreeConsole()
to give primary control to the GUI interface. Application.Run()
starts the GUI interaction loop between the GUI and the user of the GUI application. When we close the GUI application, app.Destroy()
takes care of not crashing it.
As we instantiated the GUI using app = TodoApp(Application)
, the following code runs;
class TodoApp(Form):
def __init__(self, Owner):
self.Caption = "A TODO GUI Application"
self.SetBounds(100, 100, 700, 500)
We inherit the Form
class from the delphivcl
library to create our GUI. In Delphi VCL, all the GUIs are treated as forms. The name of the GUI pop-up window is set using the Caption
property/attribute. The line self.SetBounds(100, 100, 700, 500)
is used to set;
- GUI window's origin position comparable to screen's origin position =
(100, 100)
- length of the GUI window =
700
pixels - width of the GUI window =
500
pixels.
The upper left corner of the screen is treated as the (0, 0)
coordinate with the left side as positive width and down as positive height. We can visualize it as shown below;
Let's look at the following few lines of code;
self.task_lbl = Label(self)
self.task_lbl.SetProps(Parent=self, Caption="Enter your TODO task")
self.task_lbl.SetBounds(10, 10, 125, 25)
self.task_text_box = Edit(self)
self.task_text_box.Parent = self
self.task_text_box.SetBounds(10, 30, 250, 20)
Above the first 3 lines of code will create the text - Enter your TODO task that you see on the GUI app. It does so by instantiating the Label
class of the delphivcl
library. Every component (Label
here) has a SetProps()
method to set its properties. Every component will have a scope that is set using its Parent
property/attribute, which is set to self
here. The Caption
property sets the string of the text label. Similar to GUI app/Form, every component needs to be placed inside the GUI/Form using the SetBounds()
method. For components, the top left corner of their parent (GUI window here) is considered as the origin - (0, 0)
.
The next 3 lines of code create the edit box using the Edit
class. We can also set the properties/attributes directly without using the SetProps()
method like we did here using the code self.task_text_box.Parent = self
. With the Form/GUI window as the parent of the Edit box, we can visualize its position and size as shown in the below figure. The width of the Edit box is automatically set to the default value.
Let's look at next few lines of code;
self.add_task_btn = Button(self)
self.add_task_btn.Parent = self
self.add_task_btn.SetBounds(150, 75,100,30)
self.add_task_btn.Caption = "Add Task"
self.add_task_btn.OnClick = self.__add_task_on_click
self.del_task_btn = Button(self)
self.del_task_btn.SetProps(Parent = self, Caption = "Delete Task")
self.del_task_btn.SetBounds(150,120,100,30)
self.del_task_btn.OnClick = self.__del_task_on_click
Above lines of code create 2 Buttons - Add Task
and Delete Task
using the Button
instance of the delphivcl
package. For the buttons, one extra thing you'll find is an event handling using self.add_task_btn.OnClick = self.__add_task_on_click
and self.del_task_btn.OnClick = self.__del_task_on_click
for Add Task
and Delete Task
buttons respectively. We shall look after this in just a while.
Let's look at the next few lines of code;
self.list_of_tasks = ListBox(self)
self.list_of_tasks.Parent = self
self.list_of_tasks.SetBounds(300,50,300,350)
self.OnClose = self.__on_form_close
In the above lines of code, we created a list box using the ListBox
instance. At the last line of code; self.OnClose = self.__on_form_close
, we're handling the event of closing the GUI window using the following __on_form_close()
method, which is mentioned below;
def __on_form_close(self, Sender, Action):
Action.Value = caFree
When we trigger the OnClose
event, the Form automatically sends two arguments - Sender
and Action
to the event-handling method. This Sender
and Action
can be different names. The line Action.Value = caFree
releases the created instance (app
here) using the caFree
constant.
Let's now look at the event handling methods to Add Task
and Delete Task
buttons;
def __add_task_on_click(self, Sender):
self.list_of_tasks.Items.Add(self.task_text_box.Text)
self.task_text_box.Text = ""
def __del_task_on_click(self, Sender):
self.list_of_tasks.Items.Delete(0)
For all the events other than OnClick
, the Form automatically sends a single argument (Sender
here - this can be any name). We can add a task to the list box by typing anything into the text box and pressing on Add Task
button. Delphi VCL library based GUIs support tab controls too, where you can also navigate from one component to another using the tab. So, you can press the Tab
key on the keyboard, and as Add Task
button gets highlighted, you can press Enter/Return
key to fire its event. We add text from the text box to the list box using Add()
method under Items
under ListBox
instance. We delete the earlier added events on a first-come, first-serve basis by pressing the Delete Task
button.
For other platforms, check out DelphiFMX4Python.
Powered by the Best Windows IDE Embarcadero Delphi and the Python4Delphi library.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for delphivcl-0.1.34-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11edfaefa513e65b5e092ee39ceaefeaa9ce4e6f7bea1f934cbf8f4af02f0419 |
|
MD5 | f2669a8c14e3b8f2e637adfc7936f078 |
|
BLAKE2b-256 | ab34aafc58d85c381418a0452a4c64bb37665788a5ff68f47a4199df2dcdc42c |
Hashes for delphivcl-0.1.34-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df530f67fe8eb5253df10616943d18cd38d5ddc010f4ff169cfffcfebdfd745e |
|
MD5 | 8d6e30e57ac92e5b143874c9aa918c2f |
|
BLAKE2b-256 | 34821abaed539b11f55f7689316597e3eee78bfa456e4b4bf73d52dcbbc7ae68 |
Hashes for delphivcl-0.1.34-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a484b340e58ba65ab3e52cdd1942ba639533f4d2e6c6b558cd7ed4b71373ecf3 |
|
MD5 | ffc259229eed3b15c7355f2d1a96bba1 |
|
BLAKE2b-256 | a995048ecc2cb949d74c90af4a3247e3ac3a749a9f4f2ad647c02a3f6b0ce317 |
Hashes for delphivcl-0.1.34-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97acd832ddc89f615a71032196626de98bbc3a52136a3207dcbee0ae4c5fd443 |
|
MD5 | 4a4a9f590650dc32eafffed5e2de3ff2 |
|
BLAKE2b-256 | 7cbde8efc09d758ab4d71ba64881d9b2d4a8778519ff35c5cad7828cc9ec709f |
Hashes for delphivcl-0.1.34-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eda14f89aa93aa58ed1d52d178dd9a8c5cddeaca8259c65f9952ae2d507b0f39 |
|
MD5 | 982ced5a5729dda587fb00184190fa20 |
|
BLAKE2b-256 | 0794ed7cce9f079149efc0f6fc85479876aa0034e5d264f1c1d1306d7e363a73 |
Hashes for delphivcl-0.1.34-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e22ff26085d32336d495520465c19b0aacd476ea1702b0c5ed79e4fc36f4036 |
|
MD5 | 61af590b5a5a83481a39c75a8e33518a |
|
BLAKE2b-256 | 6c49ce434d940d1346e463f4d1c457dfecfdb86936399bc40010618395120c7f |
Hashes for delphivcl-0.1.34-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9ece01239c624a91194082e669bf25f6796f994789e901b35dd25259d66b5b2 |
|
MD5 | ab3ca13faa09a5e620efc6d09588795a |
|
BLAKE2b-256 | e6dc39b33ce91dd44bb7bbec286fa64702ebe1bc4dba99fe822a30b2612df8f7 |
Hashes for delphivcl-0.1.34-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d120f7b2ddb810aeaeb8dffb1ad58cfb656e3df2c6405c097c9c574f7b257ee0 |
|
MD5 | d92ca76a3167156cc5b95136da3cc006 |
|
BLAKE2b-256 | 36912e71c9eef84f09780839c7cb9efb7af848a0c921d262e9be8f76bfb85648 |
Hashes for delphivcl-0.1.34-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 436e495fb72c35ac407cc7b6e7984c0f9f7e6f85804b6e95fce6ca9dd09f0123 |
|
MD5 | 8b3cabcb8453eefcb8290b901b80a6ed |
|
BLAKE2b-256 | 201c51a105824d1388fae80629014cda2551b525feec96118289058bef60364c |
Hashes for delphivcl-0.1.34-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35f065373887da802aaceed923b5a19fdcb350f220a07be53bd628dffd46c682 |
|
MD5 | 1d363e502102d5960e09cba832ab447d |
|
BLAKE2b-256 | 6112cb2650f3be9406be94daec8f99064bc687c3a93022437a93560e7205fe53 |