2024/04/24「多機能ファイラーAs/Rの魅力と活用法」を出版、KView32公開

C++Builder/Delphi のフォームを Python で使用する

C++Builder

エンバカデロ(embarcadero)のHPで、Pythonツールというページを見つけ見ていると、VCL and FMX Libraries for Pythonが公開されていました。VCL, FMXは、RAD Studio(C++Builder/Delphi)のクラスライブラリですね。強力なGUIのライブラリも含まれており、これがなんとPythonから利用できるとの事です。

VCL and FMX Libraries for Python

VCL and FMX Libraries for Python は、PythonからVCL. FMXのフォームを使えるようにするライブラリィです。

以下、エンバカデロ(embarcadero)のHPより。

VCLとFireMonkey(FMX)は成熟したGUIライブラリで、世界各国のDelphi / C++Builderに
よって利用されています。
「DelphiVCL for Python」と「DelphiFMX for Python」は、堅牢で成熟したVCL / FMX
(FireMonkey)GUIライブラリを、Python開発者が利用できるようにしたPythonモジュール
セットです。

DelphiVCL for Pythonは、Windowsネイティブの開発にフォーカスしたライブラリで、
Windows専用のVCLフレームワークを採用しています。
一方、DelphiFMX for Pythonは、クロスプラットフォーム向けのFireMonkeyフレームワークを
採用しており、強力で柔軟なGUIフレームワークをWindows、Linux、macOS、Android向けに
利用できます。

以下のDelphi のフォームを Python から使う方法に詳しい説明がありましたので、参考にしてください。

Delphi のフォームを Python から使う方法 - Qiita
はじめにDelphi を使って Python の GUI を簡単に作成できるようなので、実際に試してみました。以下に Jim McKeeth 氏の LearnDelphi 動画およびスライドの説…

以下のURLも参考にしてください。

Python へのインストール

VCL and FMX Libraries for Python をPython にインストールします。

VCL

pip 経由で delphivcl をインストールします。以下のURLを参照してください。

コマンドプロンプト(DOS窓)から、以下を実行します。

pip install delphivcl
delphivcl
Delphi VCL for Python

FMX

pip 経由で delphifmx をインストールします。以下のURLを参照してください。

コマンドプロンプト(DOS窓)から、以下を実行します。

pip install delphifmx
delphifmx
Delphi FMX for Python

サンプルコードの実行

以下のライブラリ内に、サンプルコードがありますので実行してみてください。

GitHub - Embarcadero/DelphiVCL4Python: Delphi's VCL library as a Python module for building Windows GUI
Delphi's VCL library as a Python module for building Windows GUI - GitHub - Embarcadero/DelphiVCL4Python: Delphi's VCL l...
GitHub - Embarcadero/DelphiFMX4Python: Python GUI module powered by Delphi's FireMonkey framework. Supporting Windows, MacOS, Linux, and Android GUI development.
Python GUI module powered by Delphi's FireMonkey framework. Supporting Windows, MacOS, Linux, and Android GUI developmen...

ドキュメント

以下の、ライブラリ内のtutorials 内にドキュメントがあります。

使用可能なコンポーネント/定義

VCL/FMXの全てのコンポーネントが使用出来るわけではないようです。

使用可能なコンポーネントは、以下のコマンドで確認することが出来ます。

VCL

以下のpythonのコマンドで、一覧を確認できます。

D:\work3>python
Python 3.11.2 (tags/v3.11.2:878ead1, Feb  7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from delphivcl import *
>>> dir()

以下、出力の一覧です。

一覧
AbortActionActionListActivityIndicator
ApplicationBaseBindScopeComponentBaseImageListBaseLinkingBindSource
BaseObjectBindSourceBasicActionBasicBindComponentBevel
BindComponentDelegateBindingsListBitBtnBitmap
BoundLabelBufferedFileStreamButtonBytesStream
CanvasCheckBoxCollectionColorBox
ComboBoxComponentContainedActionContainedActionList
ContainedBindComponentControlControlBarCreateComponent
CustomActionCustomActionListCustomActivityIndicatorCustomBindingsList
CustomControlCustomDrawGridCustomEditCustomForm
CustomGridCustomImageListCustomLinkControlToFieldCustomLinkLabel
CustomLinkListControlToFieldCustomLinkPropertyToFieldCustomListControlCustomListView
CustomMemoCustomMemoryStreamCustomMultiSelectListControlCustomNumberBox
CustomPrototypeBindSourceCustomStatusBarCustomStyleServicesCustomTabControl
CustomToggleSwitchCustomTreeViewDateTimePickerDelphiDefaultContainer
DelphiDefaultIteratorDelphiDefaultMappingDelphiMethodDragImageList
DrawGridEditFileOpenDialogFileStream
FormFreeConsoleGetProcessDpiAwarenessGraphic
GroupBoxHandleStreamHeaderIDABORT
IDCANCELIDCLOSEIDCONTINUEIDHELP
IDIGNOREIDNOIDOKIDRETRY
IDTRYAGAINIDYESIconImage
ImageListIsDpiAwareLabelLabeledEdit
LinkControlDelegateLinkControlToFieldLinkControlToFieldDelegateLinkLabel
LinkListControlToFieldLinkPropertyToFieldLinkPropertyToFieldDelegateListBox
ListItemListViewMB_ABORTRETRYIGNOREMB_APPLMODAL
MB_DEFBUTTON1MB_DEFBUTTON2MB_DEFBUTTON3MB_DEFBUTTON4
MB_HELPMB_ICONASTERISKMB_ICONERRORMB_ICONEXCLAMATION
MB_ICONHANDMB_ICONINFORMATIONMB_ICONQUESTIONMB_ICONSTOP
MB_ICONWARNINGMB_NOFOCUSMB_OKMB_OKCANCEL
MB_RETRYCANCELMB_SYSTEMMODALMB_TASKMODALMB_YESNO
MB_YESNOCANCELMainMenuMediaPlayerMemo
MemoryStreamMenuMenuItemMetafile
MonitorNotebookNumberBoxObject
OpenDialogPagePageControlPaintBox
PanelPascalInterfacePascalRecordPersistent
PicturePointPopupMenuPrototypeBindSource
RadioButtonRadioGroupRectResourceStream
SaveDialogScreenScrollBarSetHighDpiAware
SetProcessDpiAwarenessShapeShowMessageSize
SpeedButtonSpinButtonSpinEditSplitter
StaticTextStatusBarStreamStringGrid
StringStreamStringsStyleInfoStyleManager
StyleServicesTabControlTabSheetTimer
ToggleSwitchToolBarToolButtonTrackBar
TreeNodeTreeViewVarParameterWinControl
annotationsbuiltinsdocloader
namepackagespecbkAbort
bkAllbkCancelbkClosebkCustom
bkHelpbkIgnorebkNobkOK
bkRetrybkYescaFreecaHide
caMinimizecaNonecl3DDkShadowcl3DLight
clActiveBorderclActiveCaptionclAppWorkSpaceclAqua
clBackgroundclBlackclBlueclBtnFace
clBtnHighlightclBtnShadowclBtnTextclCaptionText
clCreamclDefaultclDkGrayclFuchsia
clGradientActiveCaptionclGradientInactiveCaptionclGrayclGrayText
clGreenclHighlightclHighlightTextclHotLight
clInactiveBorderclInactiveCaptionclInactiveCaptionTextclInfoBk
clInfoTextclLimeclLtGrayclMaroon
clMedGrayclMenuclMenuBarclMenuHighlight
clMenuTextclMoneyGreenclNavyclNone
clOliveclPurpleclRedclScrollBar
clSilverclSkyBlueclTealclWhite
clWindowclWindowFrameclWindowTextclYellow
crAppStartcrArrowcrCrosscrDefault
crDragcrHSplitcrHandPointcrHelp
crHourGlasscrIBeamcrMultiDragcrNo
crNoDropcrNonecrSQLWaitcrSize
crSizeAllcrSizeNESWcrSizeNScrSizeNWSE
crSizeWEcrUpArrowcrVSplitfmCreate
fmOpenReadfmOpenReadWritefmOpenWritefmShareCompat
fmShareDenyNonefmShareDenyReadfmShareDenyWritefmShareExclusive
fsBorderfsSurfacegdFixedgdFocused
gdSelectedmdNearestmdNullmdPrimary
mrAbortmrAllmrCancelmrIgnore
mrNomrNoToAllmrNonemrOk
mrRetrymrYesmrYesToAllssAlt
ssCtrlssDoublessLeftssMiddle
ssRightssShift

FMX

以下のpythonのコマンドで、一覧を確認できます。

D:\work3>python
Python 3.11.2 (tags/v3.11.2:878ead1, Feb  7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from delphifmx import *
>>> dir()

以下、出力の一覧です。

一覧
AbortActionActionListAdapterListView
AniIndicatorAppearanceListViewApplicationArc
ArcDialBaseBindScopeComponentBaseImageListBaseLinkingBindSource
BaseObjectBindSourceBaseValueRangeBasicActionBasicBindComponent
BindComponentDelegateBindingsListBitmapTrackBarBounds
BufferedFileStreamBufferedLayoutButtonBytesStream
CalendarCalloutPanelCalloutRectangleCameraComponent
CaretRectangleCheckBoxCheckColumnCircle
CollectionColorBoxColorButtonColorComboBox
ColorListBoxColorPanelColorPickerColorQuad
ColumnComboBoxComboColorBoxComboEdit
ComboEditBaseCommonCustomFormComponentContainedAction
ContainedActionListContainedBindComponentControlControlSize
CornerButtonCreateComponentCurrencyColumnCustomAction
CustomActionListCustomBindingsListCustomBufferedLayoutCustomButton
CustomCalendarCustomColorComboBoxCustomComboBoxCustomComboEdit
CustomControlActionCustomCornerButtonCustomDateEditCustomDateTimeEdit
CustomEditCustomEditBoxCustomFormCustomGrid
CustomImageListCustomLinkControlToFieldCustomLinkListControlToFieldCustomLinkPropertyToField
CustomListBoxCustomListViewCustomMediaCodecCustomMediaPlayerAction
CustomMemoCustomMemoryStreamCustomMultiViewCustomNumberColumn
CustomPathCustomPopupFormCustomPopupMenuCustomPresentedFramedScrollBox
CustomPresentedFramedVertScrollBoxCustomPresentedHorzScrollBoxCustomPresentedScrollBoxCustomPresentedVertScrollBox
CustomTimeEditCustomTrackCustomValueRangeCustomValueRangeAction
CustomViewActionDateColumnDateEditDateTimeColumn
DateTimeColumnBaseDelphiDefaultContainerDelphiDefaultIteratorDelphiDefaultMapping
DelphiMethodDialogServiceEditEllipse
ExpanderExpanderButtonFMXBindNavigateActionFMXBindNavigateApplyUpdates
FMXBindNavigateCancelFMXBindNavigateCancelUpdatesFMXBindNavigateDeleteFMXBindNavigateEdit
FMXBindNavigateFirstFMXBindNavigateInsertFMXBindNavigateLastFMXBindNavigateNext
FMXBindNavigatePostFMXBindNavigatePriorFMXBindNavigateRefreshFileExit
FileHideAppFileHideAppOthersFileStreamFloatColumn
FlowLayoutFmxObjectFormFrame
FramedScrollBoxFramedVertScrollBoxGetProcessDpiAwarenessGlyphColumn
GradientEditGridGridLayoutGridPanelLayout
GroupBoxHandleStreamHintActionHorzScrollBox
IDABORTIDCANCELIDCLOSEIDCONTINUE
IDHELPIDIGNOREIDNOIDOK
IDRETRYIDTRYAGAINIDYESImage
ImageColumnImageControlImageListIntegerColumn
IsDpiAwareLabelLayoutLine
LinkControlDelegateLinkControlToFieldLinkControlToFieldDelegateLinkListControlToField
LinkPropertyToFieldLinkPropertyToFieldDelegateListBoxListBoxItem
ListViewListViewBaseMB_ABORTRETRYIGNOREMB_APPLMODAL
MB_DEFBUTTON1MB_DEFBUTTON2MB_DEFBUTTON3MB_DEFBUTTON4
MB_HELPMB_ICONASTERISKMB_ICONERRORMB_ICONEXCLAMATION
MB_ICONHANDMB_ICONINFORMATIONMB_ICONQUESTIONMB_ICONSTOP
MB_ICONWARNINGMB_NOFOCUSMB_OKMB_OKCANCEL
MB_RETRYCANCELMB_SYSTEMMODALMB_TASKMODALMB_YESNO
MB_YESNOCANCELMainMenuMediaMediaPlayer
MediaPlayerControlMediaPlayerCurrentTimeMediaPlayerPlayPauseMediaPlayerStart
MediaPlayerStopMediaPlayerValueMediaPlayerVolumeMemo
MemoryStreamMenuBarMenuItemMultiView
NumberBoxObjectObjectViewActionOpenDialog
PaintBoxPanelPascalInterfacePascalRecord
PathPathLabelPersistentPie
PointPointFPopupPopupColumn
PopupMenuPositionPresentedFramedScrollBoxPresentedFramedVertScrollBox
PresentedHorzScrollBoxPresentedListViewPresentedScrollBoxPresentedTextControl
PresentedVertScrollBoxProgressBarProgressColumnPrototypeBindSource
RadioButtonRectRectFRectangle
ResourceStreamRoundRectSaveDialogScaledLayout
ScreenScrollBarScrollBoxSearchBox
SelectionSelectionPointSetHighDpiAwareSetProcessDpiAwareness
ShapeSizeSizeFSizeGrip
SmallScrollBarSpeedButtonSpinBoxSplitter
StatusBarStreamStringColumnStringGrid
StringStreamStringsStyleBookStyleManager
StyleStreamingStyledControlSwitchSysCommonAction
TabControlTabItemTextTextControl
ThumbTimeColumnTimeEditTimer
ToolBarTouchTrackTrackBar
ValueRangeValueRangeActionVarParameterVertScrollBox
ViewActionVirtualKeyboardWindowCloseannotations
builtinsdocloadername
packagespeccrAppStartcrArrow
crCrosscrDefaultcrDragcrHSplit
crHandPointcrHelpcrHourGlasscrIBeam
crMultiDragcrNocrNoDropcrNone
crSQLWaitcrSizecrSizeAllcrSizeNESW
crSizeNScrSizeNWSEcrSizeWEcrUpArrow
crVSplitfmCreatefmOpenReadfmOpenReadWrite
fmOpenWritefmShareCompatfmShareDenyNonefmShareDenyRead
fmShareDenyWritefmShareExclusivessAltssCtrl
ssDoublessLeftssMiddlessRight
ssShift

Delphi4Python Exporter

VCL and FMX Libraries for Python を使用することで、Pythonから、VCK/FMXのフォームを呼び出すことが出来ますが、少しめんどくさいですね。RAD Studio(C++Builder/Delphi)から、Python用のコードを出力できるパッケージが用意されています。

残炎ながらRAD Studio 12 には、まだ対応していないようです。(2023/11/28現在)

インストール

Delphi4Python Exporter のインストール及び使用法につきましては、以下のプログをご覧ください。

タイトルとURLをコピーしました