29
29
30
30
# Try to get the security-patched XML functions from defusedxml
31
31
try :
32
- from defusedxml import minidom as xml
32
+ from defusedxml import minidom as xml
33
33
except ImportError :
34
- from xml .dom import minidom as xml
34
+ from xml .dom import minidom as xml
35
35
36
36
from PyQt5 .QtCore import Qt , QSize
37
- from PyQt5 .QtGui import *
38
- from PyQt5 . QtWidgets import QMessageBox
39
- import openshot # Python module for libopenshot (required video editing module installed separately)
37
+ from PyQt5 .QtGui import QIcon , QPixmap , QStandardItem , QStandardItemModel
38
+
39
+ import openshot
40
40
41
41
from classes import info
42
42
from classes .logger import log
46
46
class BlenderModel ():
47
47
def update_model (self , clear = True ):
48
48
log .info ("updating effects model." )
49
- app = get_app ()
50
49
51
- # Get window to check filters
52
- win = app .window
53
- _ = app ._tr
50
+ _ = self .app ._tr
54
51
55
52
# Clear all items
56
53
if clear :
@@ -60,25 +57,24 @@ def update_model(self, clear=True):
60
57
# Add Headers
61
58
self .model .setHorizontalHeaderLabels ([_ ("Thumb" ), _ ("Name" )])
62
59
63
- # get a list of files in the OpenShot /effects directory
64
- effects_dir = os .path .join (info .PATH , "blender" )
65
- icons_dir = os .path .join (effects_dir , "icons" )
66
-
67
- for file in sorted (os .listdir (effects_dir )):
68
- if os .path .isfile (os .path .join (effects_dir , file )) and ".xml" in file :
69
- # Split path
70
- path = os .path .join (effects_dir , file )
60
+ # get a list of files in the application blender directory
61
+ blender_dir = os .path .join (info .PATH , "blender" )
62
+ icons_dir = os .path .join (blender_dir , "icons" )
71
63
64
+ for file in sorted (os .listdir (blender_dir )):
65
+ path = os .path .join (blender_dir , file )
66
+ if path in self .model_paths :
67
+ continue
68
+ if os .path .isfile (path ) and ".xml" in file :
72
69
# load xml effect file
73
70
xmldoc = xml .parse (path )
74
71
75
- # Get all attributes
72
+ # Get column data for model
76
73
title = xmldoc .getElementsByTagName ("title" )[0 ].childNodes [0 ].data
77
- description = xmldoc .getElementsByTagName ("description" )[0 ].childNodes [0 ].data
78
74
icon_name = xmldoc .getElementsByTagName ("icon" )[0 ].childNodes [0 ].data
79
75
icon_path = os .path .join (icons_dir , icon_name )
80
- category = xmldoc .getElementsByTagName ("category" )[0 ].childNodes [0 ].data
81
76
service = xmldoc .getElementsByTagName ("service" )[0 ].childNodes [0 ].data
77
+ xmldoc .unlink ()
82
78
83
79
# Check for thumbnail path (in build-in cache)
84
80
thumb_path = os .path .join (info .IMAGES_PATH , "cache" , "blender_{}" .format (icon_name ))
@@ -95,66 +91,51 @@ def update_model(self, clear=True):
95
91
# Reload this reader
96
92
clip = openshot .Clip (icon_path )
97
93
reader = clip .Reader ()
98
-
99
- # Open reader
100
94
reader .Open ()
101
95
102
- # Determine scale of thumbnail
103
- scale = 95.0 / reader .info .width
104
-
105
96
# Save thumbnail
106
- reader .GetFrame (0 ).Thumbnail (thumb_path , 98 , 64 , "" , "" ,
107
- "#000" , False , "png" , 85 , 0.0 )
97
+ reader .GetFrame (0 ).Thumbnail (
98
+ thumb_path , 98 , 64 , "" , "" ,
99
+ "#000" , False , "png" , 85 , 0.0 )
108
100
reader .Close ()
109
-
110
- except :
111
- # Handle exception
112
- log .info ('Invalid blender image file: %s' % icon_path )
113
- msg = QMessageBox ()
114
- msg .setText (_ ("{} is not a valid image file." .format (icon_path )))
115
- msg .exec_ ()
101
+ except Exception :
102
+ log .info ('Invalid blender image file: %s' , icon_path )
116
103
continue
117
104
118
105
row = []
119
-
106
+ flags = Qt . ItemIsSelectable | Qt . ItemIsEnabled | Qt . ItemIsUserCheckable
120
107
# Append thumbnail
121
- col = QStandardItem ()
122
- icon_pixmap = QPixmap (thumb_path )
123
- scaled_pixmap = icon_pixmap .scaled (QSize (93 , 62 ), Qt .IgnoreAspectRatio , Qt .SmoothTransformation )
124
- col .setIcon (QIcon (scaled_pixmap ))
125
- col .setText (self .app ._tr (title ))
108
+ col = QStandardItem (self .app ._tr (title ))
109
+ icon_pixmap = QPixmap (thumb_path ).scaled (
110
+ QSize (93 , 62 ), Qt .IgnoreAspectRatio , Qt .SmoothTransformation )
111
+ col .setIcon (QIcon (icon_pixmap ))
126
112
col .setToolTip (self .app ._tr (title ))
127
- col .setFlags (Qt . ItemIsSelectable | Qt . ItemIsEnabled | Qt . ItemIsUserCheckable )
113
+ col .setFlags (flags )
128
114
row .append (col )
129
115
130
116
# Append Name
131
- col = QStandardItem ("Name" )
117
+ col = QStandardItem (self . app . _tr ( title ) )
132
118
col .setData (self .app ._tr (title ), Qt .DisplayRole )
133
- col .setText (self .app ._tr (title ))
134
- col .setFlags (Qt .ItemIsSelectable | Qt .ItemIsEnabled | Qt .ItemIsUserCheckable )
119
+ col .setFlags (flags )
135
120
row .append (col )
136
121
137
122
# Append Path
138
- col = QStandardItem ("Path" )
123
+ col = QStandardItem (path )
139
124
col .setData (path , Qt .DisplayRole )
140
- col .setText (path )
141
- col .setFlags (Qt .ItemIsSelectable | Qt .ItemIsEnabled | Qt .ItemIsUserCheckable )
125
+ col .setFlags (flags )
142
126
row .append (col )
143
127
144
128
# Append Service
145
- col = QStandardItem ("Service" )
129
+ col = QStandardItem (service )
146
130
col .setData (service , Qt .DisplayRole )
147
- col .setText (service )
148
- col .setFlags (Qt .ItemIsSelectable | Qt .ItemIsEnabled | Qt .ItemIsUserCheckable )
131
+ col .setFlags (flags )
149
132
row .append (col )
150
133
151
- # Append ROW to MODEL (if does not already exist in model)
152
- if path not in self .model_paths :
153
- self .model .appendRow (row )
154
- self .model_paths [path ] = path
134
+ self .model .appendRow (row )
135
+ self .model_paths [path ] = path
155
136
156
137
# Process events in QT (to keep the interface responsive)
157
- app .processEvents ()
138
+ self . app .processEvents ()
158
139
159
140
def __init__ (self , * args ):
160
141
0 commit comments