Skip to content

Commit 8a8a770

Browse files
committed
Merge remote-tracking branch 'refs/remotes/20tab/master'
# Conflicts: # Source/UnrealEnginePython/Private/UEPyModule.cpp # Source/UnrealEnginePython/Public/UnrealEnginePython.h # UnrealEnginePython.uplugin
2 parents 9f56b61 + 360f2e2 commit 8a8a770

File tree

137 files changed

+14185
-1693
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+14185
-1693
lines changed

Source/PythonEditor/Private/PythonEditorStyle.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ void FPythonEditorStyle::Initialize()
6060
StyleSet->Set("PythonEditor.Execute.Small", new IMAGE_BRUSH("UI/Excute_x40", Icon16x16));
6161
StyleSet->Set("PythonEditor.ExecuteInSandbox", new IMAGE_BRUSH("UI/Excute_x40", Icon40x40));
6262
StyleSet->Set("PythonEditor.ExecuteInSandbox.Small", new IMAGE_BRUSH("UI/Excute_x40", Icon16x16));
63+
StyleSet->Set("PythonEditor.PEP8ize", new IMAGE_BRUSH("UI/Excute_x40", Icon40x40));
64+
StyleSet->Set("PythonEditor.PEP8ize.Small", new IMAGE_BRUSH("UI/Excute_x40", Icon16x16));
6365
}
6466

6567
const FSlateFontInfo Consolas10 = TTF_FONT("Font/DroidSansMono", 9);

Source/PythonEditor/Private/PythonProjectEditor.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@ void FPythonProjectEditor::BindCommands()
273273
FCanExecuteAction::CreateSP(this, &FPythonProjectEditor::CanExecute)
274274
);
275275

276+
ToolkitCommands->MapAction(FPythonProjectEditorCommands::Get().PEP8ize,
277+
FExecuteAction::CreateSP(this, &FPythonProjectEditor::PEP8ize_Internal),
278+
FCanExecuteAction::CreateSP(this, &FPythonProjectEditor::CanExecute)
279+
);
280+
276281
}
277282

278283
void FPythonProjectEditor::CloseFileForEditing(UPythonProjectItem* Item)
@@ -493,6 +498,11 @@ void FPythonProjectEditor::Execute_Internal()
493498
Execute();
494499
}
495500

501+
void FPythonProjectEditor::PEP8ize_Internal()
502+
{
503+
PEP8ize();
504+
}
505+
496506
void FPythonProjectEditor::ExecuteInSandbox_Internal()
497507
{
498508
Execute();
@@ -521,6 +531,16 @@ bool FPythonProjectEditor::ExecuteInSandbox()
521531
return true;
522532
}
523533

534+
bool FPythonProjectEditor::PEP8ize()
535+
{
536+
if (DocumentManager.IsValid() && DocumentManager->GetActiveTab().IsValid())
537+
{
538+
TSharedRef<SPythonEditor> PythonEditorRef = StaticCastSharedRef<SPythonEditor>(DocumentManager->GetActiveTab()->GetContent());
539+
PythonEditorRef->PEP8ize();
540+
}
541+
542+
return true;
543+
}
524544

525545
bool FPythonProjectEditor::CanSaveAll() const
526546
{

Source/PythonEditor/Private/PythonProjectEditor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class FPythonProjectEditor : public FWorkflowCentricApplication, public FGCObjec
6363

6464
bool ExecuteInSandbox();
6565

66+
bool PEP8ize();
67+
6668
FString GetSafeName(bool IsDirectory);
6769

6870
private:
@@ -82,6 +84,8 @@ class FPythonProjectEditor : public FWorkflowCentricApplication, public FGCObjec
8284

8385
void ExecuteInSandbox_Internal();
8486

87+
void PEP8ize_Internal();
88+
8589
bool CanNew() const;
8690

8791
bool CanSave() const;

Source/PythonEditor/Private/PythonProjectEditorCommands.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void FPythonProjectEditorCommands::RegisterCommands()
2222
UI_COMMAND(SaveAll, "Save All", "Save all open documents.", EUserInterfaceActionType::Button, FInputGesture(EModifierKey::Control | EModifierKey::Shift, EKeys::S));
2323
UI_COMMAND(Execute, "Execute", "Execute Current Python File.", EUserInterfaceActionType::Button, FInputGesture(EModifierKey::Control, EKeys::Enter));
2424
UI_COMMAND(ExecuteInSandbox, "Execute In Sandbox", "Execute Current Python File in a Sandbox.", EUserInterfaceActionType::Button, FInputGesture(EModifierKey::Control | EModifierKey::Shift, EKeys::Enter));
25+
UI_COMMAND(PEP8ize, "PEP8-ize", "Enforce PEP8 to the current code.", EUserInterfaceActionType::Button, FInputGesture(EModifierKey::Control | EModifierKey::Shift, EKeys::P));
2526

2627
}
2728

Source/PythonEditor/Private/PythonProjectEditorCommands.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class FPythonProjectEditorCommands : public TCommands<FPythonProjectEditorComman
1616
TSharedPtr<FUICommandInfo> SaveAll;
1717
TSharedPtr<FUICommandInfo> Execute;
1818
TSharedPtr<FUICommandInfo> ExecuteInSandbox;
19+
TSharedPtr<FUICommandInfo> PEP8ize;
1920
/** Initialize commands */
2021
virtual void RegisterCommands() override;
2122
};

Source/PythonEditor/Private/PythonProjectEditorToolbar.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void FPythonProjectEditorToolbar::FillEditorToolbar(FToolBarBuilder& ToolbarBuil
3737
{
3838
ToolbarBuilder.AddToolBarButton(FPythonProjectEditorCommands::Get().Execute);
3939
ToolbarBuilder.AddToolBarButton(FPythonProjectEditorCommands::Get().ExecuteInSandbox);
40+
ToolbarBuilder.AddToolBarButton(FPythonProjectEditorCommands::Get().PEP8ize);
4041
}
4142
ToolbarBuilder.EndSection();
4243

Source/PythonEditor/Private/SPythonEditableText.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
void SPythonEditableText::Construct(const FArguments& InArgs)
88
{
9-
109
SMultiLineEditableText::Construct(
1110
SMultiLineEditableText::FArguments()
1211
.Font(FPythonEditorStyle::Get().GetWidgetStyle<FTextBlockStyle>("TextEditor.NormalText").Font)
@@ -18,7 +17,8 @@ void SPythonEditableText::Construct(const FArguments& InArgs)
1817
.HScrollBar(InArgs._HScrollBar)
1918
.VScrollBar(InArgs._VScrollBar)
2019
.OnTextChanged(InArgs._OnTextChanged)
21-
);
20+
.OnCursorMoved(this, &SPythonEditableText::OnCursorMoved)
21+
);
2222
OnExecuted = InArgs._OnExecuted;
2323
}
2424

@@ -92,3 +92,9 @@ FReply SPythonEditableText::OnKeyDown(const FGeometry& MyGeometry, const FKeyEve
9292
return Reply;
9393
}
9494

95+
void SPythonEditableText::GetLineAndColumn(int32 & Line, int32 & Column)
96+
{
97+
Line = CurrentLine;
98+
Column = CurrentColumn;
99+
}
100+

Source/PythonEditor/Private/SPythonEditableText.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,19 @@ class SPythonEditableText : public SMultiLineEditableText
2929

3030
void Construct( const FArguments& InArgs );
3131

32+
void GetLineAndColumn(int32 & Line, int32 & Column);
33+
34+
void OnCursorMoved(const FTextLocation & Location) {
35+
CurrentLine = Location.GetLineIndex();
36+
CurrentColumn = Location.GetOffset();
37+
}
38+
3239
private:
3340
virtual FReply OnKeyChar(const FGeometry& MyGeometry,const FCharacterEvent& InCharacterEvent) override;
3441
virtual FReply OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent) override;
3542

3643
FOnExecuted OnExecuted;
44+
45+
int32 CurrentLine;
46+
int32 CurrentColumn;
3747
};

Source/PythonEditor/Private/SPythonEditor.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void SPythonEditor::Construct(const FArguments& InArgs, UPythonProjectItem* InPy
4040
[
4141
SNew(SGridPanel)
4242
.FillColumn(0, 1.0f)
43-
.FillRow(0, 1.0f)
43+
.FillRow(0, 2.0f)
4444
+SGridPanel::Slot(0, 0)
4545
[
4646
SAssignNew(PythonEditableText, SPythonEditableText)
@@ -59,7 +59,16 @@ void SPythonEditor::Construct(const FArguments& InArgs, UPythonProjectItem* InPy
5959
[
6060
HorizontalScrollbar.ToSharedRef()
6161
]
62+
+ SGridPanel::Slot(0, 2)
63+
[
64+
SNew(SBorder).HAlign(EHorizontalAlignment::HAlign_Right)
65+
[
66+
SNew(STextBlock)
67+
.Text(this, &SPythonEditor::GetLineAndColumn)
68+
]
69+
]
6270
]
71+
6372
];
6473
}
6574

@@ -111,6 +120,16 @@ void SPythonEditor::ExecuteInSandbox() const
111120
PythonModule.RunStringSandboxed(TCHAR_TO_UTF8(*SelectionString));
112121
}
113122

123+
void SPythonEditor::PEP8ize() const
124+
{
125+
Save();
126+
FUnrealEnginePythonModule &PythonModule = FModuleManager::GetModuleChecked<FUnrealEnginePythonModule>("UnrealEnginePython");
127+
128+
FString CleanedCode = PythonModule.Pep8ize(PythonEditableText->GetText().ToString());
129+
130+
PythonEditableText->SetText(FText::FromString(CleanedCode));
131+
}
132+
114133

115134
void SPythonEditor::GotoLineAndColumn(int32 LineNumber, int32 ColumnNumber)
116135
{
@@ -119,4 +138,15 @@ void SPythonEditor::GotoLineAndColumn(int32 LineNumber, int32 ColumnNumber)
119138
PythonEditableText->ScrollTo(Location);
120139
}
121140

141+
FText SPythonEditor::GetLineAndColumn() const
142+
{
143+
int32 Line;
144+
int32 Column;
145+
PythonEditableText->GetLineAndColumn(Line, Column);
146+
147+
FString LineAndColumn = FString::Printf(TEXT("Line: %d Column: %d"), Line, Column);
148+
149+
return FText::FromString(LineAndColumn);
150+
}
151+
122152
#undef LOCTEXT_NAMESPACE

Source/PythonEditor/Private/SPythonEditor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ class SPythonEditor : public SCompoundWidget
2020

2121
void GotoLineAndColumn(int32 LineNumber, int32 ColumnNumber);
2222

23+
void PEP8ize() const;
24+
2325
private:
2426
void OnTextChanged(const FText& NewText);
27+
FText GetLineAndColumn() const;
2528

2629
protected:
2730
class UPythonProjectItem* PythonProjectItem;

0 commit comments

Comments
 (0)