Closed dominiced closed 2 years ago
#support input() in plugins
def _input(s):
return dlg_input(s, '') or ''
import builtins
builtins.input = _input
use script like this.
#support input() in plugins def _input(s): return dlg_input(s, '') or '' import builtins builtins.input = _input
use script like this.
Apologies Alexey-T but I get a NameError with the code provided because 'dlg_input' is not define, where is that meant to come from? Is it meant to be included as part of P4D?
No, dlg_input is CudaText (app with Python4Lazarus) python function, you must write Delphi function and then export it via Py module.
function api_dlg_input(Self, Args : PPyObject): PPyObject; cdecl;
var
P1, P2: PChar;
StrCaption, StrVal: string;
begin
with AppPython.Engine do
if Bool(PyArg_ParseTuple(Args, 'ss:dlg_input', @P1, @P2)) then
begin
StrCaption:= string(P1);
StrVal:= string(P2);
if InputQuery(msgTitle, StrCaption, StrVal) then
Result:= PyUnicodeFromString(StrVal)
else
Result:= ReturnNone;
end
else
Result:= ReturnNone;
end;
And
procedure TfmMain.PythonModuleInitialization(Sender: TObject);
begin
with Sender as TPythonModule do
begin
AddMethod('app_ver', @api_app_ver, '');
AddMethod('app_path', @api_app_path, '');
AddMethod('app_proc', @api_app_proc, '');
AddMethod('app_log', @api_app_log, '');
AddMethod('app_idle', @api_app_idle, '');
AddMethod('emmet', @api_emmet, '');
AddMethod('msg_status', @api_msg_status, '');
AddMethod('msg_status_alt', @api_msg_status_alt, '');
AddMethod('msg_box', @api_msg_box, '');
AddMethod('msg_box_ex', @api_msg_box_ex, '');
AddMethod('dlg_input', @api_dlg_input, '');
Excellent, thank you Alexey
This is presented when Python fires the input() function
Is there any way to present the input prompt message, rather than just this generic input dialog box with no information present? I would like to include the input argument within the dialog box.