FIX: RabbitVCS context menu under Qt5

This commit is contained in:
Alexander Koblov 2020-01-19 11:56:39 +00:00
commit b47c8bbcd2
2 changed files with 28 additions and 24 deletions

View file

@ -83,6 +83,7 @@ function PyStringToString(S: PPyObject): String;
procedure PythonAddModulePath(const Path: String);
function PythonLoadModule(const ModuleName: String): PPyObject;
function PythonRunFunction(Module: PPyObject; const FunctionName: String): PPyObject; overload;
function PythonRunFunction(Module: PPyObject; const FunctionName, FunctionArg: String): PPyObject; overload;
function PythonRunFunction(Module: PPyObject; const FunctionName: String; FileList: TStrings): PPyObject; overload;
@ -168,7 +169,11 @@ begin
pyFunc:= PyObject_GetAttrString(Module, PAnsiChar(FunctionName));
if (Assigned(pyFunc) and (PyCallable_Check(pyFunc) <> 0)) then
begin
pyArgs:= PyObjectsToPyTuple([FunctionArg]);
if (FunctionArg = nil) then
pyArgs:= nil
else begin
pyArgs:= PyObjectsToPyTuple([FunctionArg]);
end;
Result:= PyObject_CallObject(pyFunc, pyArgs);
Py_XDECREF(pyArgs);
if (Result = nil) then begin
@ -179,6 +184,11 @@ begin
end;
end;
function PythonRunFunction(Module: PPyObject; const FunctionName: String): PPyObject;
begin
Result:= PythonCallFunction(Module, FunctionName, nil);
end;
function PythonRunFunction(Module: PPyObject; const FunctionName, FunctionArg: String): PPyObject;
var
pyArgs: PPyObject;

View file

@ -318,7 +318,6 @@ end;
function CheckVersion: Boolean;
var
ATemp: AnsiString;
pyFunc: PPyObject;
RabbitGTK3: Boolean;
pyModule: PPyObject;
pyVersion: PPyObject;
@ -329,36 +328,31 @@ begin
pyModule:= PythonLoadModule('rabbitvcs');
if Assigned(pyModule) then
begin
pyFunc:= PyObject_GetAttrString(pyModule, 'package_version');
if (Assigned(pyFunc) and (PyCallable_Check(pyFunc) <> 0)) then
pyVersion:= PythonRunFunction(pyModule, 'package_version');
if Assigned(pyVersion) then
begin
pyVersion:= PyObject_CallObject(pyFunc, nil);
if Assigned(pyVersion) then
ATemp:= PyStringToString(pyVersion);
AVersion:= ATemp.Split(['.']);
Print('Version ' + ATemp);
if (Length(AVersion) > 2) then
begin
ATemp:= PyStringToString(pyVersion);
AVersion:= ATemp.Split(['.']);
Print('Version ' + ATemp);
if (Length(AVersion) > 2) then
begin
Major:= StrToIntDef(AVersion[0], 0);
Minor:= StrToIntDef(AVersion[1], 0);
Micro:= StrToIntDef(AVersion[2], 0);
// RabbitVCS migrated to GTK3 from version 0.17.1
RabbitGTK3:= (Major > 0) or (Minor > 17) or ((Minor = 17) and (Micro > 0));
Major:= StrToIntDef(AVersion[0], 0);
Minor:= StrToIntDef(AVersion[1], 0);
Micro:= StrToIntDef(AVersion[2], 0);
// RabbitVCS migrated to GTK3 from version 0.17.1
RabbitGTK3:= (Major > 0) or (Minor > 17) or ((Minor = 17) and (Micro > 0));
{$IF DEFINED(LCLQT5)}
// Qt5 can work with RabbitVCS GTK2 when no GTK3 platform theme plugin
if not RabbitGTK3 then Result:= (g_type_from_name('GtkWidget') = 0);
Result:= RabbitGTK3;
// Qt5 can work with RabbitVCS GTK2 when no GTK3 platform theme plugin
if not Result then Result:= (g_type_from_name('GtkWidget') = 0);
{$ELSEIF DEFINED(LCLGTK2)}
Result:= not RabbitGTK3;
Result:= not RabbitGTK3;
{$ELSEIF DEFINED(LCLGTK3)}
Result:= RabbitGTK3;
Result:= RabbitGTK3;
{$ELSE}
Result:= True
Result:= True
{$ENDIF}
end;
Py_DECREF(pyVersion);
end;
Py_DECREF(pyFunc);
end;
end;
end;