Skip to content

Commit 152bfc3

Browse files
committed
Simplify Unity Launcher logic
- Only try to connect to launcher one time, during `__init__()` - Don't even connect slots if there's no launcher (removes need to receive signal every frame, just to ignore it 99% of the time) - We only have one desktop ID now (AppImage uses same), so no looping - Store ID in `info.DESKTOP_ID` rather than hardcoding
1 parent 7678e02 commit 152bfc3

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

src/classes/info.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
BACKUP_PATH = os.path.join(USER_PATH)
4646
BLENDER_PATH = os.path.join(USER_PATH, "blender")
4747
ASSETS_PATH = os.path.join(USER_PATH, "assets")
48-
RESOURCES_PATH = os.path.join(PATH, "resources")
48+
RESOURCES_PATH = os.path.join(PATH, "resources")
4949
THUMBNAIL_PATH = os.path.join(USER_PATH, "thumbnail")
5050
CACHE_PATH = os.path.join(USER_PATH, "cache")
5151
PREVIEW_CACHE_PATH = os.path.join(USER_PATH, "preview-cache")
@@ -68,22 +68,25 @@
6868
# names of all contributors, using "u" for unicode encoding
6969
JT = {"name": u"Jonathan Thomas", "email": "[email protected]", "website":"http://openshot.org/developers/jonathan"}
7070

71+
# Desktop launcher ID, for Linux
72+
DESKTOP_ID = "org.openshot.OpenShot.desktop"
73+
7174
# Languages
7275
CMDLINE_LANGUAGE = None
7376
CURRENT_LANGUAGE = 'en_US'
7477
SUPPORTED_LANGUAGES = ['en_US']
7578

7679
try:
7780
from language import openshot_lang
78-
language_path=":/locale/"
81+
language_path = ":/locale/"
7982
except ImportError:
80-
language_path=os.path.join(PATH, 'language')
83+
language_path = os.path.join(PATH, 'language')
8184
print("Compiled translation resources missing!")
8285
print("Loading translations from: {}".format(language_path))
8386

8487
# Compile language list from :/locale resource
8588
langdir = QDir(language_path)
86-
langs = langdir.entryList(['OpenShot.*.qm'], QDir.NoDotAndDotDot|QDir.Files,
89+
langs = langdir.entryList(['OpenShot.*.qm'], QDir.NoDotAndDotDot | QDir.Files,
8790
sort=QDir.Name)
8891
for trpath in langs:
8992
SUPPORTED_LANGUAGES.append(trpath.split('.')[1])

src/windows/main_window.py

+24-28
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ def load_settings(self):
21052105

21062106
# Load Recent Projects
21072107
self.load_recent_menu()
2108-
2108+
21092109
# The method restoreState restores the visibility of the toolBar,
21102110
# but does not set the correct flag in the actionView_Toolbar.
21112111
self.actionView_Toolbar.setChecked(self.toolBar.isVisibleTo(self))
@@ -2391,33 +2391,22 @@ def InitCacheSettings(self):
23912391
self.cache_object = new_cache_object
23922392

23932393
def FrameExported(self, title_message, start_frame, end_frame, current_frame):
2394-
"""Connect to Unity launcher (for Linux)"""
2394+
"""Update progress in Unity Launcher (if connected)"""
23952395
try:
2396-
if sys.platform == "linux" and self.has_launcher:
2397-
if not self.unity_launchers:
2398-
# Get launcher only once
2399-
from gi.repository import Unity
2400-
self.unity_launchers.append(Unity.LauncherEntry.get_for_desktop_id("openshot-qt.desktop"))
2401-
self.unity_launchers.append(Unity.LauncherEntry.get_for_desktop_id("appimagekit-openshot-qt.desktop"))
2402-
2403-
# Set progress and show progress bar
2404-
for launcher in self.unity_launchers:
2405-
launcher.set_property("progress", current_frame / (end_frame - start_frame))
2406-
launcher.set_property("progress_visible", True)
2407-
2408-
except:
2396+
# Set progress and show progress bar
2397+
self.unity_launcher.set_property("progress", current_frame / (end_frame - start_frame))
2398+
self.unity_launcher.set_property("progress_visible", True)
2399+
except Exception:
24092400
# Just ignore
2410-
self.has_launcher = False
2401+
pass
24112402

24122403
def ExportFinished(self, path):
2413-
"""Export has completed"""
2404+
"""Show completion in Unity Launcher (if connected)"""
24142405
try:
2415-
if sys.platform == "linux" and self.has_launcher:
2416-
for launcher in self.unity_launchers:
2417-
# Set progress on Unity launcher and hide progress bar
2418-
launcher.set_property("progress", 0.0)
2419-
launcher.set_property("progress_visible", False)
2420-
except:
2406+
# Set progress on Unity launcher and hide progress bar
2407+
self.unity_launcher.set_property("progress", 0.0)
2408+
self.unity_launcher.set_property("progress_visible", False)
2409+
except Exception:
24212410
pass
24222411

24232412
def transformTriggered(self, clip_id):
@@ -2642,11 +2631,18 @@ def __init__(self, mode=None):
26422631
self.tutorial_manager = TutorialManager(self)
26432632

26442633
# Connect to Unity DBus signal (if linux)
2645-
if sys.platform == "linux":
2646-
self.unity_launchers = []
2647-
self.has_launcher = True
2648-
self.ExportFrame.connect(self.FrameExported)
2649-
self.ExportEnded.connect(self.ExportFinished)
2634+
self.unity_launcher = None
2635+
if "linux" in sys.platform:
2636+
try:
2637+
# Get connection to Unity Launcher
2638+
from gi.repository import Unity
2639+
self.unity_launcher = Unity.LauncherEntry.get_for_desktop_id(info.DESKTOP_ID)
2640+
except Exception:
2641+
# Guess we're not on Ubuntu
2642+
pass
2643+
else:
2644+
self.ExportFrame.connect(self.FrameExported)
2645+
self.ExportEnded.connect(self.ExportFinished)
26502646

26512647
# Save settings
26522648
s.save()

0 commit comments

Comments
 (0)