Skip to content

Commit daa88a7

Browse files
committed
Housekeeping: Eliminate all star imports, etc.
- Remove most unused variables - Reformat source to reduce overlong lines
1 parent c9a7896 commit daa88a7

19 files changed

+665
-383
lines changed

src/classes/app.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@
4242
try:
4343
# QtWebEngineWidgets must be loaded prior to creating a QApplication
4444
# But on systems with only WebKit, this will fail (and we ignore the failure)
45-
from PyQt5.QtWebEngineWidgets import QWebEngineView
45+
from PyQt5.QtWebEngineWidgets import QWebEngineView # noqa
4646
except ImportError:
4747
pass
4848

4949
try:
5050
# Solution to solve QtWebEngineWidgets black screen caused by OpenGL not loaded
51-
from OpenGL import GL
51+
from OpenGL import GL # noqa
5252
except ImportError:
5353
pass
5454

@@ -142,8 +142,11 @@ def __init__(self, *args, mode=None):
142142
libopenshot_version = openshot.OPENSHOT_VERSION_FULL
143143
if mode != "unittest" and libopenshot_version < info.MINIMUM_LIBOPENSHOT_VERSION:
144144
QMessageBox.warning(
145-
None, _("Wrong Version of libopenshot Detected"),
146-
_("<b>Version %(minimum_version)s is required</b>, but %(current_version)s was detected. Please update libopenshot or download our latest installer.") % {
145+
None,
146+
_("Wrong Version of libopenshot Detected"),
147+
_("<b>Version %(minimum_version)s is required</b>, but %(current_version)s was detected. \
148+
Please update libopenshot or download our latest installer.")
149+
% {
147150
"minimum_version": info.MINIMUM_LIBOPENSHOT_VERSION,
148151
"current_version": libopenshot_version,
149152
})

src/classes/ui_util.py

+38-14
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@
3232

3333
# Try to get the security-patched XML functions from defusedxml
3434
try:
35-
from defusedxml import ElementTree
35+
from defusedxml import ElementTree
3636
except ImportError:
37-
from xml.etree import ElementTree
37+
from xml.etree import ElementTree
3838

3939
from PyQt5.QtCore import QDir, QLocale
4040
from PyQt5.QtGui import QIcon
41-
from PyQt5.QtWidgets import *
41+
from PyQt5.QtWidgets import QApplication, QWidget, QTabWidget, QAction
4242
from PyQt5 import uic
4343

4444
from classes.logger import log
4545
from classes import settings
4646

47-
from . import openshot_rc
47+
from . import openshot_rc # noqa
4848

4949
DEFAULT_THEME_NAME = "Humanity"
5050

@@ -73,7 +73,7 @@ def load_ui(window, path):
7373
# race condition. [zipimport.ZipImportError: can't decompress data; zlib not available]
7474
# This error only happens when cx_Freeze is used, and the app is launched.
7575
error = None
76-
for attempt in range(1,6):
76+
for attempt in range(1, 6):
7777
try:
7878
# Load ui from configured path
7979
uic.loadUi(path, window)
@@ -143,14 +143,19 @@ def get_icon(theme_name):
143143

144144

145145
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."""
147148

148149
type_filter = 'action'
149150
if isinstance(elem, QWidget): # Search for widget with name instead
150151
type_filter = 'widget'
151152
# 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:
154159
if not theme_name:
155160
theme_name = iconset.get('theme', '')
156161
# Get Icon (either current theme or fallback)
@@ -170,15 +175,31 @@ def init_element(window, elem):
170175
connect_auto_events(window, elem, name)
171176

172177
# 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+
):
174183
elem.setText(_translate("", elem.text()))
175184
if hasattr(elem, 'setToolTip') and hasattr(elem, 'toolTip') and elem.toolTip() != "":
176185
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+
):
178191
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+
):
180197
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+
):
182203
elem.setPlaceholderText(_translate("", elem.placeholderText()))
183204
if hasattr(elem, 'setLocale'):
184205
elem.setLocale(QLocale().system())
@@ -226,8 +247,10 @@ def init_ui(window):
226247
# Loop through all actions
227248
for action in window.findChildren(QAction):
228249
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+
231254

232255
def center(window):
233256
"""Center a window on the main window"""
@@ -238,5 +261,6 @@ def center(window):
238261
frameGm.moveCenter(centerPoint)
239262
window.move(frameGm.topLeft())
240263

264+
241265
def transfer_children(from_widget, to_widget):
242266
log.info("Transferring children from '{}' to '{}'".format(from_widget.objectName(), to_widget.objectName()))

0 commit comments

Comments
 (0)