Skip to content

Commit b4ba7d3

Browse files
committed
webview: Swap parents, connect aboutToQuit signal
1 parent 102bfe1 commit b4ba7d3

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

src/windows/views/webview.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177
) from ex
178178

179179

180-
class TimelineWebView(WebViewClass, updates.UpdateInterface):
180+
class TimelineWebView(updates.UpdateInterface, WebViewClass):
181181
""" A Web(Engine)View QWidget used to load the Timeline """
182182

183183
# Path to html file
@@ -191,11 +191,11 @@ def page_ready(self):
191191
@pyqtSlot(result=str)
192192
def get_thumb_address(self):
193193
"""Return the thumbnail HTTP server address"""
194-
thumb_server_details = get_app().window.http_server_thread.server_address
194+
thumb_server_details = self.window.http_server_thread.server_address
195195
while not thumb_server_details:
196196
log.info('No HTTP thumbnail server found yet... keep waiting...')
197197
time.sleep(0.25)
198-
thumb_server_details = get_app().window.http_server_thread.server_address
198+
thumb_server_details = self.window.http_server_thread.server_address
199199

200200
thumb_address = "http://%s:%s/thumbnails/" % (thumb_server_details[0], thumb_server_details[1])
201201
return thumb_address
@@ -226,7 +226,7 @@ def changed(self, action):
226226
if action.type == "load":
227227
# Set the scale again (to project setting)
228228
initial_scale = get_app().project.get("scale") or 15
229-
get_app().window.sliderZoom.setValue(secondsToZoom(initial_scale))
229+
self.window.sliderZoom.setValue(secondsToZoom(initial_scale))
230230

231231
# The setValue() above doesn't trigger update_zoom when a project file is
232232
# loaded on the command line (too early?), so also call the JS directly
@@ -275,8 +275,8 @@ def update_clip_data(self, clip_json, only_basic_props=True, ignore_reader=False
275275

276276
# Update the preview and reselect current frame in properties
277277
if not ignore_refresh:
278-
get_app().window.refreshFrameSignal.emit()
279-
get_app().window.propertyTableView.select_frame(self.window.preview_thread.player.Position())
278+
self.window.refreshFrameSignal.emit()
279+
self.window.propertyTableView.select_frame(self.window.preview_thread.player.Position())
280280

281281
# Add missing transition
282282
@pyqtSlot(str)
@@ -389,8 +389,8 @@ def update_transition_data(self, transition_json, only_basic_props=True, ignore_
389389

390390
# Update the preview and reselct current frame in properties
391391
if not ignore_refresh:
392-
get_app().window.refreshFrameSignal.emit()
393-
get_app().window.propertyTableView.select_frame(self.window.preview_thread.player.Position())
392+
self.window.refreshFrameSignal.emit()
393+
self.window.propertyTableView.select_frame(self.window.preview_thread.player.Position())
394394

395395
# Prevent default context menu, and ignore, so that javascript can intercept
396396
def contextMenuEvent(self, event):
@@ -954,10 +954,10 @@ def Transform_Triggered(self, action, clip_ids):
954954
# Emit signal to transform this clip (for the 1st clip id)
955955
if clip_ids:
956956
# Transform first clip in list
957-
get_app().window.TransformSignal.emit(clip_ids[0])
957+
self.window.TransformSignal.emit(clip_ids[0])
958958
else:
959959
# Clear transform
960-
get_app().window.TransformSignal.emit("")
960+
self.window.TransformSignal.emit("")
961961

962962
def Show_Waveform_Triggered(self, clip_ids):
963963
"""Show a waveform for the selected clip"""
@@ -974,7 +974,7 @@ def Show_Waveform_Triggered(self, clip_ids):
974974
file_path = clip.data["reader"]["path"]
975975

976976
# Find actual clip object from libopenshot
977-
c = get_app().window.timeline_sync.timeline.GetClip(clip_id)
977+
c = self.window.timeline_sync.timeline.GetClip(clip_id)
978978
if c and c.Reader() and not c.Reader().info.has_single_image:
979979
# Find frame 1 channel_filter property
980980
channel_filter = c.channel_filter.GetInt(1)
@@ -2268,15 +2268,15 @@ def Time_Triggered(self, action, clip_ids, speed="1X", playhead_position=0.0):
22682268
del clip.data["time"]["Points"][-1]
22692269

22702270
# Find actual clip object from libopenshot
2271-
c = get_app().window.timeline_sync.timeline.GetClip(clip_id)
2271+
c = self.window.timeline_sync.timeline.GetClip(clip_id)
22722272
if c:
22732273
# Look up correct position from time curve
22742274
start_animation_frames_value = c.time.GetLong(start_animation_frames)
22752275

22762276
# Do we already have a volume curve? Look up intersecting frame # from volume curve
22772277
if len(clip.data["volume"]["Points"]) > 1:
22782278
# Find actual clip object from libopenshot
2279-
c = get_app().window.timeline_sync.timeline.GetClip(clip_id)
2279+
c = self.window.timeline_sync.timeline.GetClip(clip_id)
22802280
if c:
22812281
# Look up correct volume from time curve
22822282
start_volume_value = c.volume.GetValue(start_animation_frames)
@@ -3025,7 +3025,7 @@ def dropEvent(self, event):
30253025

30263026
elif self.item_type == "os_drop":
30273027
# Add new files to project
3028-
get_app().window.filesView.dropEvent(event)
3028+
self.window.filesView.dropEvent(event)
30293029

30303030
# Add clips for each file dropped
30313031
for uri in event.mimeData().urls():
@@ -3045,8 +3045,8 @@ def dropEvent(self, event):
30453045
self.item_id = None
30463046

30473047
# Update the preview and reselct current frame in properties
3048-
get_app().window.refreshFrameSignal.emit()
3049-
get_app().window.propertyTableView.select_frame(self.window.preview_thread.player.Position())
3048+
self.window.refreshFrameSignal.emit()
3049+
self.window.propertyTableView.select_frame(self.window.preview_thread.player.Position())
30503050

30513051
def dragLeaveEvent(self, event):
30523052
"""A drag is in-progress and the user moves mouse outside of timeline"""
@@ -3056,7 +3056,7 @@ def dragLeaveEvent(self, event):
30563056
event.accept()
30573057

30583058
# Clear selected clips
3059-
get_app().window.removeSelection(self.item_id, self.item_type)
3059+
self.window.removeSelection(self.item_id, self.item_type)
30603060

30613061
if self.item_type == "clip":
30623062
# Delete dragging clip
@@ -3099,10 +3099,10 @@ def render_cache_json(self):
30993099

31003100
# Get final cache object from timeline
31013101
try:
3102-
cache_object = get_app().window.timeline_sync.timeline.GetCache()
3102+
cache_object = self.window.timeline_sync.timeline.GetCache()
31033103
if cache_object and cache_object.Count() > 0:
31043104
# Get the JSON from the cache object (i.e. which frames are cached)
3105-
cache_json = get_app().window.timeline_sync.timeline.GetCache().Json()
3105+
cache_json = self.window.timeline_sync.timeline.GetCache().Json()
31063106
cache_dict = json.loads(cache_json)
31073107
cache_version = cache_dict["version"]
31083108

@@ -3118,28 +3118,29 @@ def __init__(self, window):
31183118
super().__init__()
31193119
self.setObjectName("TimelineWebView")
31203120

3121+
app = get_app()
31213122
self.window = window
31223123
self.setAcceptDrops(True)
31233124
self.last_position_frames = None
31243125

31253126
# Get settings & logger
3126-
self.settings_obj = settings.get_settings()
3127+
self.settings_obj = get_settings()
31273128
self.log_fn = log.log
31283129

31293130
# Add self as listener to project data updates (used to update the timeline)
3130-
get_app().updates.add_listener(self)
3131+
app.updates.add_listener(self)
31313132

31323133
# Connect zoom functionality
31333134
window.sliderZoom.valueChanged.connect(self.update_zoom)
31343135

31353136
# Connect waveform generation signal
3136-
get_app().window.WaveformReady.connect(self.Waveform_Ready)
3137+
window.WaveformReady.connect(self.Waveform_Ready)
31373138

31383139
# Local audio waveform cache
31393140
self.waveform_cache = {}
31403141

31413142
# Connect update thumbnail signal
3142-
get_app().window.ThumbnailUpdated.connect(self.Thumbnail_Updated)
3143+
window.ThumbnailUpdated.connect(self.Thumbnail_Updated)
31433144

31443145
# Copy clipboard
31453146
self.copy_clipboard = {}
@@ -3162,5 +3163,8 @@ def __init__(self, window):
31623163
self.cache_renderer.setInterval(500)
31633164
self.cache_renderer.timeout.connect(self.render_cache_json)
31643165

3166+
# Connect shutdown signals
3167+
app.aboutToQuit.connect(self.redraw_audio_timer.stop)
3168+
app.aboutToQuit.connect(self.cache_renderer.stop)
31653169
# Delay the start of cache rendering
31663170
QTimer.singleShot(1500, self.cache_renderer.start)

0 commit comments

Comments
 (0)