Skip to content

Commit

Permalink
Add property clipboard copy options
Browse files Browse the repository at this point in the history
  • Loading branch information
wgergely committed Nov 9, 2023
1 parent abb9117 commit 48f7432
Show file tree
Hide file tree
Showing 16 changed files with 568 additions and 279 deletions.
53 changes: 32 additions & 21 deletions bookmarks/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1713,40 +1713,51 @@ def remove_thumbnail(index):
source_index.model().updateIndex.emit(source_index)


@common.error
@common.debug
@common.error
@selection
def copy_asset_properties(index):
"""Copy asset properties to clipboard.
Args:
index (QModelIndex): Index of the currently selected item.
def copy_properties(index):
pp = index.data(common.ParentPathRole)
if not pp:
return

"""
server, job, root, asset = index.data(common.ParentPathRole)[0:4]
database.copy_properties(
server, job, root, asset, table=database.AssetTable
from . editor import clipboard
editor = clipboard.show(
*pp[0:3],
asset=pp[3] if len(pp) == 4 else None,
)

return editor


@common.error
@common.debug
@common.error
@selection
def paste_asset_properties(index):
"""Paste asset properties from clipboard to the selected item.
def paste_properties(index):
pp = index.data(common.ParentPathRole)
if len(pp) == 3:
table = database.BookmarkTable
clipboard = common.BookmarkPropertyClipboard
elif len(pp) == 4:
table = database.AssetTable
clipboard = common.AssetPropertyClipboard
else:
raise NotImplementedError('Not implemented.')

Args:
index (QModelIndex): Index of the currently selected item.
if not common.CLIPBOARD[clipboard]:
raise RuntimeError('Could not paste properties. Clipboard is empty.')

"""
server, job, root, asset = index.data(common.ParentPathRole)[0:4]
database.paste_properties(
server, job, root, asset, table=database.AssetTable
)
source = '/'.join(pp)

# Write the values to the database
for k in common.CLIPBOARD[clipboard]:
v = common.CLIPBOARD[clipboard][k]
database.get(*pp[0:3]).set_value(source, k, v, table=table)
log.success(f'Pasted {k} = {v} to {source}')


@common.error
@common.debug
@common.error
def toggle_active_mode():
"""Toggle the active path mode.
Expand Down
2 changes: 2 additions & 0 deletions bookmarks/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
job_editor = None
bookmark_property_editor = None
asset_property_editor = None
clipboard_editor = None
file_saver_widget = None
publish_widget = None
maya_export_widget = None
Expand All @@ -125,6 +126,7 @@
from .monitor import *
from .sequence import *
from .active_mode import *
from .clipboard import *
from .settings import *
from .setup import *
from .signals import *
Expand Down
16 changes: 16 additions & 0 deletions bookmarks/common/clipboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Internal clipboard data.
"""
from . import core


BookmarkPropertyClipboard = core.idx(start=0, reset=True)
AssetPropertyClipboard = core.idx()
ThumbnailClipboard = core.idx()


CLIPBOARD = {
BookmarkPropertyClipboard: {},
AssetPropertyClipboard: {},
ThumbnailClipboard: {},
}
15 changes: 8 additions & 7 deletions bookmarks/common/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,24 @@ def process_update_queue(self):
Emits the modelNeedsRefresh signal for each data dictionary in the update queue.
"""
refs = []
processed_data_dicts = []

for path in self.update_queue.copy():
print(path)
for data_type in (common.SequenceItem, common.FileItem):
data_dict = common.get_data_from_value(path, data_type, role=common.PathRole)

if not data_dict:
continue

ref = weakref.ref(data_dict)
if not ref in refs:
refs.append(data_dict)
else:
if data_dict in processed_data_dicts:
continue

ref().refresh_needed = True
data_dict.refresh_needed = True
common.widget(self.tab_idx).filter_indicator_widget.repaint()
self.modelNeedsRefresh.emit(ref)
self.modelNeedsRefresh.emit(weakref.ref(data_dict))

processed_data_dicts.append(data_dict)

self.update_queue.clear()
self.update_timer.stop()
Expand Down
44 changes: 43 additions & 1 deletion bookmarks/contextmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,7 @@ def publish_menu(self):
'action': actions.show_publish_widget,
}

def import_export_menu(self):
def import_export_properties_menu(self):
"""Export property
"""
Expand All @@ -1639,6 +1639,48 @@ def import_export_menu(self):
self.menu[k] = collections.OrderedDict()
self.menu[f'{k}:icon'] = ui.get_icon('settings')

self.separator(menu=self.menu[k])

pp = self.index.data(common.ParentPathRole)
if len(pp) == 3:
clipboard = common.BookmarkPropertyClipboard
elif len(pp) == 4:
clipboard = common.AssetPropertyClipboard
else:
clipboard = None

# Copy menu
if self.index.isValid() and clipboard:
self.menu[k][key()] = {
'text': 'Copy properties to clipboard...',
'action': actions.copy_properties,
'icon': ui.get_icon('settings'),
'shortcut': shortcuts.get(
shortcuts.MainWidgetShortcuts,
shortcuts.CopyProperties
).key(),
'description': shortcuts.hint(
shortcuts.MainWidgetShortcuts,
shortcuts.CopyProperties
),
}

# Paste menu
if self.index.isValid() and clipboard and common.CLIPBOARD[clipboard]:
self.menu[k][key()] = {
'text': 'Paste properties from clipboard',
'action': actions.paste_properties,
'icon': ui.get_icon('settings'),
'shortcut': shortcuts.get(
shortcuts.MainWidgetShortcuts,
shortcuts.PasteProperties
).key(),
'description': shortcuts.hint(
shortcuts.MainWidgetShortcuts,
shortcuts.PasteProperties
),
}

self.separator(menu=self.menu[k])
if self.index.isValid():
self.menu[k][key()] = {
Expand Down
10 changes: 1 addition & 9 deletions bookmarks/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
AssetTable: {
'id': {
'sql': 'TEXT PRIMARY KEY COLLATE NOCASE',
'type': str
'type': str,
},
'description': {
'sql': 'TEXT',
Expand All @@ -90,14 +90,6 @@
'sql': 'INT DEFAULT 0',
'type': int
},
'thumbnail_stamp': {
'sql': 'REAL',
'type': float
},
'user': {
'sql': 'TEXT',
'type': str
},
'shotgun_id': {
'sql': 'INT',
'type': int
Expand Down
11 changes: 8 additions & 3 deletions bookmarks/editor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,14 @@ def _add_row(self, v, group_widget):
row.setWhatsThis(v['description'])

if 'help' in v and v['help']:
ui.add_description(
v['help'], label=None, parent=group_widget
)
if 'widget' in v and v['widget']:
ui.add_description(
v['help'], label=None, parent=group_widget
)
else:
ui.add_description(
v['help'], label=None, parent=row
)

if 'button' in v and v['button']:
button = ui.PaintedButton(
Expand Down
Loading

0 comments on commit 48f7432

Please sign in to comment.