Skip to content

Commit 3a721bd

Browse files
committed
Various local code changes
1 parent 86cc658 commit 3a721bd

File tree

6 files changed

+84
-87
lines changed

6 files changed

+84
-87
lines changed

bookmarks/external/ffmpeg.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def convert(
396396
tc = ''
397397

398398
# Get all properties and construct the ffmpeg command
399-
input_path=_input_path_from_seq(seq)
399+
input_path = _input_path_from_seq(seq)
400400
cmd = preset.format(
401401
BIN=ffmpeg_bin,
402402
FRAMERATE=_get_framerate(server, job, root),
@@ -435,7 +435,8 @@ def convert(
435435
if common.message_widget.isVisible():
436436
common.message_widget.title_label.setText('Making movie...')
437437
common.message_widget.body_label.setText(
438-
f'Converting frame {int(match.group(1))} of {int(endframe)}')
438+
f'Converting frame {int(match.group(1))} of {int(endframe)}'
439+
)
439440
QtWidgets.QApplication.instance().processEvents()
440441

441442
# Verify the output

bookmarks/items/asset_items.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,15 @@ def item_generator(self, path):
330330
entry.path.replace('\\', '/'),
331331
section='links/asset'
332332
)
333+
333334
for link in links:
334335
v = f'{path}/{entry.name}/{link}'
335336
_entry = common.get_entry_from_path(v)
336337
if not _entry:
337338
log.error(f'Could not get entry from link {v}')
338339
continue
339340
yield _entry
341+
340342
if links:
341343
continue
342344

bookmarks/items/delegate.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""Item delegate used to draw bookmark, asset and file items.
32
43
Defines :class:`ItemDelegate`, the base delegate class, subclasses and helper functions.
@@ -844,7 +843,7 @@ def draw_gradient_background(*args):
844843
painter.drawRect(rect)
845844

846845

847-
class ItemDelegate(QtWidgets.QAbstractItemDelegate):
846+
class ItemDelegate(QtWidgets.QStyledItemDelegate):
848847
"""The main delegate used to represent lists derived from `base.BaseItemView`.
849848
850849
"""
@@ -915,12 +914,6 @@ def setModelData(self, editor, model, index):
915914
db = database.get(*source_path[0:3])
916915
db.set_value(k, 'description', common.sanitize_hashtags(v))
917916

918-
def paint(self, painter, option, index):
919-
"""Paints an item.
920-
921-
"""
922-
raise NotImplementedError('Abstract method must be implemented by subclass.')
923-
924917
def get_rectangles(self, index):
925918
"""Return all rectangles needed to paint an item.
926919

bookmarks/items/task_items.py

Lines changed: 42 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from .. import common
1919
from .. import contextmenu
2020
from .. import images
21+
from .. import log
2122
from ..tokens import tokens
2223

2324

@@ -49,28 +50,28 @@ class TaskItemViewDelegate(delegate.ItemDelegate):
4950

5051
def paint(self, painter, option, index):
5152
"""The main paint method.
52-
53+
5354
"""
5455
args = self.get_paint_arguments(painter, option, index)
5556
self.paint_background(*args)
5657
self.paint_name(*args)
5758

5859
def get_description_rect(self, *args, **kwargs):
5960
"""Get description rectangle.
60-
61+
6162
"""
6263
return QtCore.QRect()
6364

6465
def get_text_segments(self, *args, **kwargs):
6566
"""Get text segments.
66-
67+
6768
"""
6869
return []
6970

7071
@delegate.save_painter
7172
def paint_background(self, *args):
7273
"""Paints the background.
73-
74+
7475
"""
7576
rectangles, painter, option, index, selected, focused, active, archived, \
7677
favourite, hover, font, metrics, cursor_position = args
@@ -117,7 +118,7 @@ def paint_background(self, *args):
117118
def paint_name(self, *args):
118119
"""Paints the name and the number of files available for the given
119120
task item.
120-
121+
121122
"""
122123
rectangles, painter, option, index, selected, focused, active, archived, \
123124
favourite, hover, font, metrics, cursor_position = args
@@ -163,7 +164,6 @@ def paint_name(self, *args):
163164
rect = rect.marginsRemoved(QtCore.QMargins(o * 2, 0, o, 0))
164165

165166
text = index.data(QtCore.Qt.DisplayRole)
166-
width = 0
167167
width = common.draw_aliased_text(
168168
painter, font, rect, text, QtCore.Qt.AlignVCenter | QtCore.Qt.AlignLeft,
169169
color
@@ -235,6 +235,24 @@ def data_type(self):
235235
"""
236236
return common.FileItem
237237

238+
def item_generator(self, path):
239+
try:
240+
it = os.scandir(path)
241+
except OSError as e:
242+
log.error(e)
243+
return
244+
245+
# Get folders from the root of the bookmark item
246+
for entry in it:
247+
if self._interrupt_requested:
248+
return
249+
if entry.name.startswith('.'):
250+
continue
251+
if not entry.is_dir():
252+
continue
253+
254+
yield entry
255+
238256
@common.status_bar_message('Loading task folders...')
239257
@models.initdata
240258
@common.error
@@ -243,23 +261,29 @@ def init_data(self):
243261
"""Collects the data needed to populate the task item model.
244262
245263
"""
264+
p = self.source_path()
265+
k = self.task()
266+
t = self.data_type()
267+
268+
if not p or not all(p) or not k or t is None:
269+
return
270+
271+
data = common.get_data(p, k, t)
272+
source = '/'.join(p)
273+
246274
flags = (
247275
QtCore.Qt.ItemIsSelectable |
248276
QtCore.Qt.ItemIsEnabled
249277
)
250-
data = self.model_data()
278+
251279
source_path = self.source_path()
252280
if not source_path or not all(source_path):
253281
return
254282
_source_path = '/'.join(source_path)
255283

256284
config = tokens.get(*source_path[0:3])
257285

258-
entries = sorted(
259-
([f for f in os.scandir(_source_path)]), key=lambda x: x.name
260-
)
261-
262-
for entry in entries:
286+
for entry in self.item_generator(source):
263287
if entry.name.startswith('.'):
264288
continue
265289
if not entry.is_dir():
@@ -269,6 +293,7 @@ def init_data(self):
269293

270294
idx = len(data)
271295
description = config.get_description(entry.name)
296+
272297
data[idx] = common.DataDict(
273298
{
274299
QtCore.Qt.DisplayRole: entry.name,
@@ -300,9 +325,9 @@ def init_data(self):
300325
common.ThumbnailLoaded: True,
301326
#
302327
common.SortByNameRole: entry.name.lower(),
303-
common.SortByLastModifiedRole: 0,
304-
common.SortBySizeRole: 0,
305-
common.SortByTypeRole: entry.name,
328+
common.SortByLastModifiedRole: entry.name.lower(),
329+
common.SortBySizeRole: entry.name.lower(),
330+
common.SortByTypeRole: entry.name.lower(),
306331
#
307332
common.IdRole: idx,
308333
#
@@ -343,43 +368,6 @@ def file_count(self, source):
343368
break
344369
return count
345370

346-
@classmethod
347-
def item_generator(cls, path):
348-
"""Used to iterate over all files in a given folder.
349-
350-
Yields:
351-
DirEntry: A DirEntry instance.
352-
353-
"""
354-
try:
355-
it = os.scandir(path)
356-
except:
357-
return
358-
359-
n = 0
360-
while True:
361-
n += 1
362-
if n > 999:
363-
return
364-
365-
try:
366-
entry = next(it)
367-
368-
if entry.name.startswith('.'):
369-
continue
370-
371-
if entry.is_symlink():
372-
continue
373-
374-
if not entry.is_dir():
375-
yield entry
376-
except OSError:
377-
continue
378-
except StopIteration:
379-
return
380-
381-
yield from cls.item_generator(entry.path)
382-
383371

384372
class TaskItemView(views.ThreadedItemView):
385373
"""The view responsible for displaying the available data-keys.
@@ -512,10 +500,10 @@ def eventFilter(self, widget, event):
512500

513501
if event.type() == QtCore.QEvent.Paint:
514502
painter = QtGui.QPainter()
515-
painter.begin(self)
503+
painter.begin(widget)
516504
painter.setPen(QtCore.Qt.NoPen)
517505
painter.setBrush(common.color(common.color_separator))
518-
painter.drawRect(self.rect())
506+
painter.drawRect(widget.rect())
519507
painter.end()
520508
return super().eventFilter(widget, event)
521509

bookmarks/items/views.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,7 @@ class ListsWidget(QtWidgets.QStackedWidget):
243243
def __init__(self, parent=None):
244244
super().__init__(parent=parent)
245245
self.setObjectName('BrowserStackedWidget')
246-
self.animation = QtCore.QParallelAnimationGroup(self)
247-
self.animation.finished.connect(self.animation_finished)
246+
248247
common.signals.tabChanged.connect(self.setCurrentIndex)
249248

250249
def setCurrentIndex(self, idx):
@@ -280,11 +279,18 @@ def setCurrentIndex(self, idx):
280279
if current_index == idx:
281280
return
282281

283-
a = self.animation.animationAt(0)
284-
if a and a.currentTime() < a.totalDuration():
285-
return
282+
@QtCore.Slot()
283+
def animation_finished(a):
284+
anim = a.animationAt(1)
285+
if not anim:
286+
return
287+
if isinstance(anim.targetObject(), QtWidgets.QWidget):
288+
_idx = self.indexOf(anim.targetObject())
289+
super(ListsWidget, self).setCurrentIndex(_idx)
290+
common.signals.tabChanged.emit(_idx)
286291

287-
self.animation.clear()
292+
animation = QtCore.QParallelAnimationGroup()
293+
animation.finished.connect(functools.partial(animation_finished, animation))
288294

289295
duration = 200
290296
# Create animation for outgoing widget
@@ -320,23 +326,13 @@ def setCurrentIndex(self, idx):
320326
in_op.setStartValue(0.0)
321327
in_op.setEndValue(1.0)
322328

323-
self.animation.addAnimation(out_anim)
324-
self.animation.addAnimation(in_anim)
325-
self.animation.addAnimation(out_op)
326-
self.animation.addAnimation(in_op)
329+
animation.addAnimation(out_anim)
330+
animation.addAnimation(in_anim)
331+
animation.addAnimation(out_op)
332+
animation.addAnimation(in_op)
327333

334+
animation.start()
328335
self.widget(idx).show()
329-
self.animation.start()
330-
331-
@QtCore.Slot()
332-
def animation_finished(self):
333-
anim = self.animation.animationAt(1)
334-
if not anim:
335-
return
336-
if isinstance(anim.targetObject(), QtWidgets.QWidget):
337-
idx = self.indexOf(anim.targetObject())
338-
super().setCurrentIndex(idx)
339-
common.signals.tabChanged.emit(idx)
340336

341337
def showEvent(self, event):
342338
"""Event handler.
@@ -497,8 +493,8 @@ class BaseItemView(QtWidgets.QTableView):
497493
resized = QtCore.Signal(QtCore.QRect)
498494

499495
ThumbnailContextMenu = ThumbnailsContextMenu
500-
Delegate = NotImplementedError
501-
ContextMenu = NotImplementedError
496+
Delegate = delegate.ItemDelegate
497+
ContextMenu = None
502498

503499
def __init__(self, icon='icon_bw', parent=None):
504500
super().__init__(parent=parent)
@@ -590,6 +586,7 @@ def __init__(self, icon='icon_bw', parent=None):
590586
self.delayed_reset_row_layout_timer.setSingleShot(True)
591587

592588
self.setItemDelegate(self.Delegate(parent=self))
589+
593590
self.init_model()
594591
self._connect_signals()
595592

bookmarks/scripts/sg_sync.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import functools
4242
import json
4343
import os
44+
import shutil
4445
import time
4546
import zipfile
4647

@@ -768,6 +769,21 @@ def process_entities(
768769
print(f'Patching {root}/{task_path}')
769770
self.patch_asset(asset_template_path, f'{root}/{task_path}')
770771

772+
# Check if the audio file exists
773+
audio_file_path = f"{bookmark_root}/{entity['code']}.wav"
774+
775+
if os.path.exists(audio_file_path):
776+
print(f'Copying audio file {entity["code"]}.wav to {root}/{task_path}/audio/{entity["code"]}.wav')
777+
task_audio_dir = os.path.join(f'{root}', task_path, 'audio')
778+
destination_audio_path = os.path.join(task_audio_dir, f"{entity['code']}.wav")
779+
780+
# Create 'audio' folder if it doesn't exist
781+
if not os.path.exists(task_audio_dir):
782+
os.makedirs(task_audio_dir)
783+
784+
# Copy the audio file
785+
shutil.copy2(audio_file_path, destination_audio_path)
786+
771787
# Update the .link files for Bookmarks
772788
if self.sg_sync_sync_data_to_bookmarks_editor.isChecked():
773789
common.message_widget.title_label.setText(f'Adding asset links...')

0 commit comments

Comments
 (0)