32
32
33
33
# Try to get the security-patched XML functions from defusedxml
34
34
try :
35
- from defusedxml import ElementTree
35
+ from defusedxml import ElementTree
36
36
except ImportError :
37
- from xml .etree import ElementTree
37
+ from xml .etree import ElementTree
38
38
39
39
from PyQt5 .QtCore import QDir , QLocale
40
40
from PyQt5 .QtGui import QIcon
41
- from PyQt5 .QtWidgets import *
41
+ from PyQt5 .QtWidgets import QApplication , QWidget , QTabWidget , QAction
42
42
from PyQt5 import uic
43
43
44
44
from classes .logger import log
45
45
from classes import settings
46
46
47
- from . import openshot_rc
47
+ from . import openshot_rc # noqa
48
48
49
49
DEFAULT_THEME_NAME = "Humanity"
50
50
@@ -73,7 +73,7 @@ def load_ui(window, path):
73
73
# race condition. [zipimport.ZipImportError: can't decompress data; zlib not available]
74
74
# This error only happens when cx_Freeze is used, and the app is launched.
75
75
error = None
76
- for attempt in range (1 ,6 ):
76
+ for attempt in range (1 , 6 ):
77
77
try :
78
78
# Load ui from configured path
79
79
uic .loadUi (path , window )
@@ -143,14 +143,19 @@ def get_icon(theme_name):
143
143
144
144
145
145
def setup_icon (window , elem , name , theme_name = None ):
146
- """Using the window xml, set the icon on the given element, or if theme_name passed load that icon."""
146
+ """Using the window xml, set the icon on the given element,
147
+ or if theme_name passed load that icon."""
147
148
148
149
type_filter = 'action'
149
150
if isinstance (elem , QWidget ): # Search for widget with name instead
150
151
type_filter = 'widget'
151
152
# Find iconset in tree (if any)
152
- iconset = window .uiTree .find ('.//' + type_filter + '[@name="' + name + '"]/property[@name="icon"]/iconset' )
153
- if iconset != None or theme_name : # For some reason "if iconset:" doesn't work the same as "!= None"
153
+ iconset = window .uiTree .find (
154
+ './/' + type_filter + '[@name="' + name
155
+ + '"]/property[@name="icon"]/iconset'
156
+ )
157
+ # For some reason "if iconset:" doesn't work the same
158
+ if iconset is not None or theme_name :
154
159
if not theme_name :
155
160
theme_name = iconset .get ('theme' , '' )
156
161
# Get Icon (either current theme or fallback)
@@ -170,15 +175,31 @@ def init_element(window, elem):
170
175
connect_auto_events (window , elem , name )
171
176
172
177
# Handle generic translatable properties
173
- if hasattr (elem , 'setText' ) and hasattr (elem , 'text' ) and elem .text () != "" :
178
+ if (
179
+ hasattr (elem , 'setText' )
180
+ and hasattr (elem , 'text' )
181
+ and elem .text () != ""
182
+ ):
174
183
elem .setText (_translate ("" , elem .text ()))
175
184
if hasattr (elem , 'setToolTip' ) and hasattr (elem , 'toolTip' ) and elem .toolTip () != "" :
176
185
elem .setToolTip (_translate ("" , elem .toolTip ()))
177
- if hasattr (elem , 'setWindowTitle' ) and hasattr (elem , 'windowTitle' ) and elem .windowTitle () != "" :
186
+ if (
187
+ hasattr (elem , 'setWindowTitle' )
188
+ and hasattr (elem , 'windowTitle' )
189
+ and elem .windowTitle () != ""
190
+ ):
178
191
elem .setWindowTitle (_translate ("" , elem .windowTitle ()))
179
- if hasattr (elem , 'setTitle' ) and hasattr (elem , 'title' ) and elem .title () != "" :
192
+ if (
193
+ hasattr (elem , 'setTitle' )
194
+ and hasattr (elem , 'title' )
195
+ and elem .title () != ""
196
+ ):
180
197
elem .setTitle (_translate ("" , elem .title ()))
181
- if hasattr (elem , 'setPlaceholderText' ) and hasattr (elem , 'placeholderText' ) and elem .placeholderText () != "" :
198
+ if (
199
+ hasattr (elem , 'setPlaceholderText' )
200
+ and hasattr (elem , 'placeholderText' )
201
+ and elem .placeholderText () != ""
202
+ ):
182
203
elem .setPlaceholderText (_translate ("" , elem .placeholderText ()))
183
204
if hasattr (elem , 'setLocale' ):
184
205
elem .setLocale (QLocale ().system ())
@@ -226,8 +247,10 @@ def init_ui(window):
226
247
# Loop through all actions
227
248
for action in window .findChildren (QAction ):
228
249
init_element (window , action )
229
- except :
230
- log .info ('Failed to initialize an element on {}' .format (window .objectName ()))
250
+ except Exception :
251
+ log .info (
252
+ 'Failed to initialize an element on %s' , window .objectName ())
253
+
231
254
232
255
def center (window ):
233
256
"""Center a window on the main window"""
@@ -238,5 +261,6 @@ def center(window):
238
261
frameGm .moveCenter (centerPoint )
239
262
window .move (frameGm .topLeft ())
240
263
264
+
241
265
def transfer_children (from_widget , to_widget ):
242
266
log .info ("Transferring children from '{}' to '{}'" .format (from_widget .objectName (), to_widget .objectName ()))
0 commit comments