Skip to content

Instantly share code, notes, and snippets.

@an01f01
an01f01 / delphi_python_parsing.pas
Last active March 13, 2025 09:34
Method parses function arguments from Python to Delphi
function TFrmMain.ConsoleModule_Print( pself, args : PPyObject ) : PPyObject; cdecl;
var
pprint: NativeInt;
val1: Integer;
val2: Single;
val3: PAnsiChar;
begin
with GetPythonEngine do
begin
if (PyErr_Occurred() = nil) and
@an01f01
an01f01 / py4delphi_test.py
Last active December 27, 2024 22:36
py4delphi_test.py
from PythonModule1 import printme
def print_data(handle):
print('starting script...')
for i in range(10000):
print(i)
val1 = 2.5 + i
val2 = 'this is the iteration number ' + str(i)
def make_app():
settings = dict(
cookie_secret=str(os.urandom(45)),
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
default_handler_class=ErrorHandler,
default_handler_args=dict(status_code=404)
)
return tornado.web.Application([
(r"/", StatusHandler),
class StatusHandler(BaseHandler):
async def get(self):
self.set_status(200)
self.write({'message': 'File upload REST API working as expected'})
self.finish()
class UploadHandler(BaseHandler):
async def get(self):
return self.render('uploads.html')
class FileUploadHandler(BaseHandler):
"""
File upload handler inbehrits the BaseHandler, obtains file data from a POST call
"""
def post(self):
# Retrieve file from the request
fileinfo = self.request.files['file'][0]
filename = fileinfo['filename']
content_type = fileinfo['content_type']
file_body = fileinfo['body']
{ Screen Scaling for Device }
function GetScreenScale: Single;
var
ScreenService: IFMXScreenService;
begin
Result := 1;
if TPlatformServices.Current.SupportsPlatformService (IFMXScreenService, IInterface(ScreenService)) then
begin
Result := ScreenService.GetScreenScale;
end;
{ Where AVP is the TViewport3D or self on a TForm3D }
var tmpsp: TPoint3D := ScreenHelper.CalculateScreenPosition(AVP.Context,
TPoint3D.Zero, Layer3D1.Scale.Point, Layer3D1.RotationAngle.Point, Layer3D1.Position.Point);
Circle1.Position.X := tmpsp.X - Circle1.Width / 2;
Circle1.Position.Y := tmpsp.Y - Circle1.Width / 2;
{ FIX: TPaintBox offset position }
tmpsp.X := tmpsp.X - PaintBox1.Position.X;
tmpsp.Y := tmpsp.Y - PaintBox1.Position.Y;
tmpr := RectF(tmpsp.X -FSize, tmpsp.Y -FSize, tmpsp.X +FSize, tmpsp.Y +FSize);
{ ABMP is a TBitmap }
{ Obtains device scaling }
function GetScreenScale: Single;
var
ScreenService: IFMXScreenService;
begin
Result := 1;
if TPlatformServices.Current.SupportsPlatformService (IFMXScreenService, IInterface(ScreenService)) then
begin
Result := ScreenService.GetScreenScale;
end;
var tmpsp: TPoint3D := TPoint3D.Zero;
// Obtain the screen coordinate by using the WorldToScreen method
tmpsp := self.Context.WorldToScreen(TProjection.Camera, Layer3D1.Position.Point);
writeln('2D Position: ' + tmpsp.X.ToString + ', ' + tmpsp.Y.ToString);
# A docker-compose must always start by the version tag.
# We use '3' because it's the last version at this time.
version: '3'
# You should know that docker-composes works with services.
# 1 service = 1 container.
# For example, a service maybe, a server, a client, a database...
# We use the keyword 'services' to start to create services.
services:
# As we said at the beginning, we want to create: a server and a client.