22
22
23
23
from qt_material import apply_stylesheet ,list_themes
24
24
25
+ from maltoolbox .language import LanguageGraph , LanguageClassesFactory
26
+ from maltoolbox .model import Model
27
+
25
28
from .ModelScene import ModelScene
26
29
from .ModelView import ModelView
27
30
from .ObjectExplorer .AssetBase import AssetBase
35
38
from .DockedWindows .AttackStepsWindow import AttackStepsWindow
36
39
from .DockedWindows .AssetRelationsWindow import AssetRelationsWindow
37
40
38
- from maltoolbox .language import LanguageGraph , LanguageClassesFactory
39
- from maltoolbox .model import Model
41
+ from .file_utils import image_path
40
42
41
43
# Used to create absolute paths of assets
42
44
PACKAGE_DIR = Path (__file__ ).resolve ().parent
@@ -64,32 +66,32 @@ def __init__(self,app,malLanguageMarFilePath):
64
66
self .modelFileName = None
65
67
66
68
assetImages = {
67
- "Application" : "images/ application.png" ,
68
- "Credentials" : "images/ credentials.png" ,
69
- "Data" : "images/ datastore.png" ,
70
- "Group" : "images/ group.png" ,
71
- "Hardware" : "images/ hardware.png" ,
72
- "HardwareVulnerability" : "images/ hardwareVulnerability.png" ,
73
- "IDPS" : "images/ idps.png" ,
74
- "Identity" : "images/ identity.png" ,
75
- "Privileges" : "images/ privileges.png" ,
76
- "Information" : "images/ information.png" ,
77
- "Network" : "images/ network.png" ,
78
- "ConnectionRule" : "images/ connectionRule.png" ,
79
- "PhysicalZone" : "images/ physicalZone.png" ,
80
- "RoutingFirewall" : "images/ routingFirewall.png" ,
81
- "SoftwareProduct" : "images/ softwareProduct.png" ,
82
- "SoftwareVulnerability" : "images/ softwareVulnerability.png" ,
83
- "User" : "images/ user.png"
69
+ "Application" : image_path ( " application.png") ,
70
+ "Credentials" : image_path ( " credentials.png") ,
71
+ "Data" : image_path ( " datastore.png") ,
72
+ "Group" : image_path ( " group.png") ,
73
+ "Hardware" : image_path ( " hardware.png") ,
74
+ "HardwareVulnerability" : image_path ( " hardwareVulnerability.png") ,
75
+ "IDPS" : image_path ( " idps.png") ,
76
+ "Identity" : image_path ( " identity.png") ,
77
+ "Privileges" : image_path ( " privileges.png") ,
78
+ "Information" : image_path ( " information.png") ,
79
+ "Network" : image_path ( " network.png") ,
80
+ "ConnectionRule" : image_path ( " connectionRule.png") ,
81
+ "PhysicalZone" : image_path ( " physicalZone.png") ,
82
+ "RoutingFirewall" : image_path ( " routingFirewall.png") ,
83
+ "SoftwareProduct" : image_path ( " softwareProduct.png") ,
84
+ "SoftwareVulnerability" : image_path ( " softwareVulnerability.png") ,
85
+ "User" : image_path ( " user.png")
84
86
}
85
87
86
- self .eyeUnhideIconImage = str ( PACKAGE_DIR / "images" / "eyeUnhide.png" )
87
- self .eyeHideIconImage = str ( PACKAGE_DIR / "images" / "eyeHide.png" )
88
- self .rgbColorIconImage = str ( PACKAGE_DIR / "images" / "rgbColor.png" )
88
+ self .eyeUnhideIconImage = image_path ( "eyeUnhide.png" )
89
+ self .eyeHideIconImage = image_path ( "eyeHide.png" )
90
+ self .rgbColorIconImage = image_path ( "rgbColor.png" )
89
91
90
92
#Create a registry as a dictionary containing name as key and class as value
91
93
self .assetFactory = AssetFactory ()
92
- attacker_icon = str ( PACKAGE_DIR / "images" / "attacker.png" )
94
+ attacker_icon = image_path ( "attacker.png" )
93
95
self .assetFactory .registerAsset ("Attacker" , attacker_icon )
94
96
95
97
# Create the MAL language graph, language classes factory, and
@@ -101,12 +103,11 @@ def __init__(self,app,malLanguageMarFilePath):
101
103
102
104
for asset in self .langGraph .assets :
103
105
if not asset .is_abstract :
104
- asset_image_path = str (PACKAGE_DIR / assetImages [asset .name ])
105
106
self .assetFactory .registerAsset (
106
107
asset .name ,
107
- asset_image_path
108
+ assetImages [ asset . name ]
108
109
)
109
-
110
+
110
111
#assetFactory registration should complete before injecting into ModelScene
111
112
self .scene = ModelScene (self .assetFactory , self .langGraph , self .lcs ,self .model , self )
112
113
self .view = ModelView (self .scene , self )
@@ -287,46 +288,46 @@ def updateAssetRelationsWindow(self, assetItem):
287
288
288
289
def createActions (self ):
289
290
290
- zoom_in_icon = str ( PACKAGE_DIR / "images" / "zoomIn.png" )
291
+ zoom_in_icon = image_path ( "zoomIn.png" )
291
292
self .zoomInAction = QAction (QIcon (zoom_in_icon ), "ZoomIn" , self )
292
293
self .zoomInAction .triggered .connect (self .zoomIn )
293
294
294
- zoom_out_icon = str ( PACKAGE_DIR / "images" / "zoomOut.png" )
295
+ zoom_out_icon = image_path ( "zoomOut.png" )
295
296
self .zoomOutAction = QAction (QIcon (zoom_out_icon ), "ZoomOut" , self )
296
297
self .zoomOutAction .triggered .connect (self .zoomOut )
297
298
298
299
#undo Action
299
- undo_icon = str ( PACKAGE_DIR / "images" / "undoIcon.png" )
300
+ undo_icon = image_path ( "undoIcon.png" )
300
301
self .undoAction = QAction (QIcon (undo_icon ), "Undo" , self )
301
302
self .undoAction .setShortcut ("Ctrl+z" )
302
303
self .undoAction .triggered .connect (self .scene .undoStack .undo )
303
304
304
305
#redo Action
305
- redo_icon = str ( PACKAGE_DIR / "images" / "redoIcon.png" )
306
+ redo_icon = image_path ( "redoIcon.png" )
306
307
self .redoAction = QAction (QIcon (redo_icon ), "Redo" , self )
307
308
self .redoAction .setShortcut ("Ctrl+Shift+z" )
308
309
self .redoAction .triggered .connect (self .scene .undoStack .redo )
309
310
310
311
#cut Action
311
- cut_icon = str ( PACKAGE_DIR / "images" / "cutIcon.png" )
312
+ cut_icon = image_path ( "cutIcon.png" )
312
313
self .cutAction = QAction (QIcon (cut_icon ), "Cut" , self )
313
314
self .cutAction .setShortcut ("Ctrl+x" )
314
315
self .cutAction .triggered .connect (lambda : self .scene .cutAssets (self .scene .selectedItems ()))
315
316
316
317
#copy Action
317
- copy_icon = str ( PACKAGE_DIR / "images" / "copyIcon.png" )
318
+ copy_icon = image_path ( "copyIcon.png" )
318
319
self .copyAction = QAction (QIcon (copy_icon ), "Copy" , self )
319
320
self .copyAction .setShortcut ("Ctrl+c" )
320
321
self .copyAction .triggered .connect (lambda : self .scene .copyAssets (self .scene .selectedItems ()))
321
322
322
323
#paste Action
323
- paste_icon = str ( PACKAGE_DIR / "images" / "pasteIcon.png" )
324
+ paste_icon = image_path ( "pasteIcon.png" )
324
325
self .pasteAction = QAction (QIcon (paste_icon ), "Paste" , self )
325
326
self .pasteAction .setShortcut ("Ctrl+v" )
326
327
self .pasteAction .triggered .connect (lambda : self .scene .pasteAssets (QPointF (0 ,0 )))
327
328
328
329
#delete Action
329
- delete_icon = str ( PACKAGE_DIR / "images" / "deleteIcon.png" )
330
+ delete_icon = image_path ( "deleteIcon.png" )
330
331
self .deleteAction = QAction (QIcon (delete_icon ), "Delete" , self )
331
332
self .deleteAction .setShortcut ("Delete" )
332
333
self .deleteAction .triggered .connect (lambda : self .scene .deleteAssets (self .scene .selectedItems ()))
@@ -409,7 +410,7 @@ def createToolbar(self):
409
410
self .toolbar .addSeparator ()
410
411
411
412
#Fit To Window
412
- fit_to_view_icon = str ( PACKAGE_DIR / "images" / "fitToView.png" )
413
+ fit_to_view_icon = image_path ( "fitToView.png" )
413
414
fitToViewButton = QPushButton (QIcon (fit_to_view_icon ), "Fit To View" )
414
415
self .toolbar .addWidget (fitToViewButton )
415
416
fitToViewButton .clicked .connect (self .fitToViewButtonClicked )
0 commit comments