Skip to content

Commit

Permalink
fix #5131
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey-T committed Jul 5, 2023
1 parent 081bafa commit 69c2ecc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
27 changes: 26 additions & 1 deletion app/formconsole.pas
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface

uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StrUtils, Menus, LclType,
StrUtils, Menus, LclType, Math,
PythonEngine,
ATStrings,
ATSynEdit,
Expand Down Expand Up @@ -102,6 +102,7 @@ TfmConsole = class(TFormDummy)
procedure SetFocus; override;
procedure ApplyTheme;
procedure ApplyCaretView;
procedure FlushConsole;
end;

var
Expand Down Expand Up @@ -285,6 +286,8 @@ procedure TfmConsole.DoRunLine(Str: string);
finally
Py_DECREF(Obj);
end;

FlushConsole;
except
end;
end;
Expand Down Expand Up @@ -592,6 +595,28 @@ procedure TfmConsole.ApplyCaretView;
EditorCaretShapeFromString(EdMemo.CaretShapeReadonly, EditorOps.OpCaretViewReadonly);
end;

procedure TfmConsole.FlushConsole;
var
S: UnicodeString;
NCnt, i: integer;
begin
if not AppConsoleQueue.IsEmpty() then
begin
//avoid output of huge items count at once
NCnt:= Min(AppConsoleQueue.Size, 300);
for i:= 1 to NCnt do
begin
S:= AppConsoleQueue.Front();
AppConsoleQueue.Pop();
DoAddLine(S);
if UiOps.LogConsole then
MsgLogToFilename(S, AppFile_LogConsole, false);
end;

DoUpdateMemo;
end;
end;

finalization
if Assigned(fmConsole) then
FreeAndNil(fmConsole);
Expand Down
29 changes: 4 additions & 25 deletions app/formmain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,6 @@ TfmMain = class(TForm)
procedure FindAndMarkAll(var NCounter: integer);
procedure FindAndReplaceInAllFrames(FramePrev: TEditorFrame; var NCounter: integer);
procedure FindAndExtractRegexMatches;
procedure FlushConsole;
function GetFileOpenOptionsString(AFileCount: integer): string;
procedure HandleTimerCommand(Ed: TATSynEdit; CmdCode: integer; CmdInvoke: TATCommandInvoke);
procedure InvalidateMouseoverDependantControls;
Expand Down Expand Up @@ -2275,28 +2274,6 @@ procedure TfmMain.StatusPanelClick(Sender: TObject; AIndex: Integer);
end;
end;

procedure TfmMain.FlushConsole;
var
S: UnicodeString;
NCnt, i: integer;
begin
if Assigned(fmConsole) and not AppConsoleQueue.IsEmpty() then
begin
//avoid output of huge items count at once
NCnt:= Min(AppConsoleQueue.Size, 300);
for i:= 1 to NCnt do
begin
S:= AppConsoleQueue.Front();
AppConsoleQueue.Pop();
fmConsole.DoAddLine(S);
if UiOps.LogConsole then
MsgLogToFilename(S, AppFile_LogConsole, false);
end;

fmConsole.DoUpdateMemo;
end;
end;

procedure TfmMain.TimerAppIdleTimer(Sender: TObject);
var
STemp: string;
Expand Down Expand Up @@ -2336,7 +2313,8 @@ procedure TfmMain.TimerAppIdleTimer(Sender: TObject);
end;

//flush saved Python "print" results to console
FlushConsole;
if Assigned(fmConsole) then
fmConsole.FlushConsole;

AppUpdateWatcherFrames;
if AppCommandHandlerIsBusy then exit;
Expand Down Expand Up @@ -3748,7 +3726,8 @@ procedure TfmMain.FormShow(Sender: TObject);
end;

AppFormShowCompleted:= true;
FlushConsole;
if Assigned(fmConsole) then
fmConsole.FlushConsole;
end;

procedure TfmMain.FormWindowStateChange(Sender: TObject);
Expand Down

0 comments on commit 69c2ecc

Please sign in to comment.