@@ -659,3 +659,55 @@ window = SWindow(client_size=(512, 32), title='Open Asset', sizing_rule=0)(
659
659
```
660
660
661
661
![ SCheckBox] ( https://github.com/20tab/UnrealEnginePython/raw/master/docs/screenshots/slate_SCheckBox.png )
662
+
663
+ ## OOP refactoring
664
+
665
+ Time to refactor the code to be more elegant, and to allow the reuse of custom/complex widgets:
666
+
667
+ ``` python
668
+ from unreal_engine import SWindow, SEditableTextBox, SHorizontalBox, SButton, SCheckBox, STextBlock, SVerticalBox
669
+ from unreal_engine.classes import Object
670
+ from unreal_engine.enums import EVerticalAlignment
671
+ import unreal_engine as ue
672
+
673
+ class AssetOpener (SHorizontalBox ):
674
+
675
+ def __init__ (self ):
676
+ super ().__init__ (self )
677
+ self .asset_name_picker = SEditableTextBox()
678
+ self .only_validate_path = SCheckBox()
679
+
680
+ self .add_slot(self .asset_name_picker)
681
+ self .add_slot(STextBlock(text = ' only validate path' ), auto_width = True , v_align = EVerticalAlignment.VAlign_Center)
682
+ self .add_slot(self .only_validate_path, auto_width = True )
683
+ self .add_slot(SButton(text = ' Ok' , on_clicked = self .open_or_validate), auto_width = True )
684
+
685
+ def open_or_validate (self ):
686
+ try :
687
+ asset = ue.load_object(Object, self .asset_name_picker.get_text())
688
+ print (asset)
689
+ except :
690
+ ue.message_dialog_open(ue.APP_MSG_TYPE_OK , ' invalid path' )
691
+ return
692
+
693
+ if self .only_validate_path.is_checked():
694
+ ue.message_dialog_open(ue.APP_MSG_TYPE_OK , ' path is valid' )
695
+ else :
696
+ ue.open_editor_for_asset(asset)
697
+
698
+
699
+
700
+ window = SWindow(client_size = (512 , 64 ), title = ' Open Asset' , sizing_rule = 0 )(
701
+ SVerticalBox()
702
+ (
703
+ STextBlock(text = ' OOP widget below' )
704
+ )
705
+ (
706
+ AssetOpener()
707
+ )
708
+ )
709
+ ```
710
+
711
+ ![ OOP] ( https://github.com/20tab/UnrealEnginePython/raw/master/docs/screenshots/slate_OOP.png )
712
+
713
+ As you can see, you can inherit from SWidget. Obviously you can mix 'visual' style, with fully procedural one, but the use of classes will simplify 'context' management.
0 commit comments