forked from shotgunsoftware/tk-multi-loader2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdialog.py
More file actions
2027 lines (1676 loc) · 81.8 KB
/
Copy pathdialog.py
File metadata and controls
2027 lines (1676 loc) · 81.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) 2015 Shotgun Software Inc.
#
# CONFIDENTIAL AND PROPRIETARY
#
# This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit
# Source Code License included in this distribution package. See LICENSE.
# By accessing, using, copying or modifying this work you indicate your
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.
import sgtk
from sgtk import TankError
from sgtk.platform.qt import QtCore, QtGui
from .model_hierarchy import SgHierarchyModel
from .model_entity import SgEntityModel
from .model_latestpublish import SgLatestPublishModel
from .model_status import SgStatusModel
from .proxymodel_latestpublish import SgLatestPublishProxyModel
from .proxymodel_entity import SgEntityProxyModel
from .delegate_publish_thumb import SgPublishThumbDelegate
from .delegate_publish_list import SgPublishListDelegate
from .model_publishhistory import SgPublishHistoryModel
from .delegate_publish_history import SgPublishHistoryDelegate
from .search_widget import SearchWidget
from .banner import Banner
from .loader_action_manager import LoaderActionManager
from .utils import resolve_filters
from .framework_qtwidgets import ShotgunFilterMenu
from . import constants
from . import model_item_data
from .ui.dialog import Ui_Dialog
# import frameworks
shotgun_model = sgtk.platform.import_framework(
"tk-framework-shotgunutils", "shotgun_model"
)
settings = sgtk.platform.import_framework("tk-framework-shotgunutils", "settings")
help_screen = sgtk.platform.import_framework("tk-framework-qtwidgets", "help_screen")
overlay_widget = sgtk.platform.import_framework(
"tk-framework-qtwidgets", "overlay_widget"
)
shotgun_search_widget = sgtk.platform.import_framework(
"tk-framework-qtwidgets", "shotgun_search_widget"
)
task_manager = sgtk.platform.import_framework(
"tk-framework-shotgunutils", "task_manager"
)
shotgun_globals = sgtk.platform.import_framework(
"tk-framework-shotgunutils", "shotgun_globals"
)
ShotgunModelOverlayWidget = overlay_widget.ShotgunModelOverlayWidget
class AppDialog(QtGui.QWidget):
"""
Main dialog window for the App
"""
# enum to control the mode of the main view
(MAIN_VIEW_LIST, MAIN_VIEW_THUMB) = range(2)
# settings keys
FILTER_MENU_STATE = "filter_menu_state"
SPLITTER_STATE = "splitter_state"
# signal emitted whenever the selected publish changes
# in either the main view or the details history view
selection_changed = QtCore.Signal()
def __init__(self, action_manager, parent=None):
"""
Constructor
:param action_manager: The action manager to use - if not specified
then the default will be used instead
:param parent: The parent QWidget for this control
"""
QtGui.QWidget.__init__(self, parent)
self._action_manager = action_manager
# The loader app can be invoked from other applications with a custom
# action manager as a File Open-like dialog. For these managers, we won't
# be using the banner system.
# We will support the banners only for the default loader.
if isinstance(action_manager, LoaderActionManager):
self._action_banner = Banner(self)
self._action_manager.pre_execute_action.connect(self._pre_execute_action)
self._action_manager.post_execute_action.connect(
lambda _: self._action_banner.hide_banner()
)
# create a settings manager where we can pull and push prefs later
# prefs in this manager are shared
self._settings_manager = settings.UserSettings(sgtk.platform.current_bundle())
# create a background task manager
self._task_manager = task_manager.BackgroundTaskManager(
self, start_processing=True, max_threads=2
)
shotgun_globals.register_bg_task_manager(self._task_manager)
# set up the UI
self.ui = Ui_Dialog()
self.ui.setupUi(self)
#################################################
# maintain a list where we keep a reference to
# all the dynamic UI we create. This is to make
# the GC happy.
self._dynamic_widgets = []
# maintain a special flag so that we can switch profile
# tabs without triggering events
self._disable_tab_event_handler = False
#################################################
# hook a helper model tracking status codes so we
# can use those in the UI
self._status_model = SgStatusModel(self, self._task_manager)
#################################################
# details pane
self._details_pane_visible = False
self._details_action_menu = QtGui.QMenu()
self.ui.detail_actions_btn.setMenu(self._details_action_menu)
self.ui.info.clicked.connect(self._toggle_details_pane)
self.ui.thumbnail_mode.clicked.connect(self._on_thumbnail_mode_clicked)
self.ui.list_mode.clicked.connect(self._on_list_mode_clicked)
self._publish_history_model = SgPublishHistoryModel(self, self._task_manager)
self._publish_history_model_overlay = ShotgunModelOverlayWidget(
self._publish_history_model, self.ui.history_view
)
self._publish_history_proxy = QtGui.QSortFilterProxyModel(self)
self._publish_history_proxy.setSourceModel(self._publish_history_model)
# now use the proxy model to sort the data to ensure
# higher version numbers appear earlier in the list
# the history model is set up so that the default display
# role contains the version number field in shotgun.
# This field is what the proxy model sorts by default
# We set the dynamic filter to true, meaning QT will keep
# continously sorting. And then tell it to use column 0
# (we only have one column in our models) and descending order.
self._publish_history_proxy.setDynamicSortFilter(True)
self._publish_history_proxy.sort(0, QtCore.Qt.DescendingOrder)
self.ui.history_view.setModel(self._publish_history_proxy)
self._history_delegate = SgPublishHistoryDelegate(
self.ui.history_view, self._status_model, self._action_manager
)
self.ui.history_view.setItemDelegate(self._history_delegate)
# event handler for when the selection in the history view is changing
# note! Because of some GC issues (maya 2012 Pyside), need to first establish
# a direct reference to the selection model before we can set up any signal/slots
# against it
self._history_view_selection_model = self.ui.history_view.selectionModel()
self._history_view_selection_model.selectionChanged.connect(
self._on_history_selection
)
self._multiple_publishes_pixmap = QtGui.QPixmap(
":/res/multiple_publishes_512x400.png"
)
self._no_selection_pixmap = QtGui.QPixmap(":/res/no_item_selected_512x400.png")
self._no_pubs_found_icon = QtGui.QPixmap(":/res/no_publishes_found.png")
self.ui.detail_playback_btn.clicked.connect(self._on_detail_version_playback)
self._current_version_detail_playback_url = None
# set up right click menu for the main publish view
self._refresh_history_action = QtGui.QAction("Refresh", self.ui.history_view)
self._refresh_history_action.triggered.connect(
self._publish_history_model.async_refresh
)
self.ui.history_view.addAction(self._refresh_history_action)
self.ui.history_view.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
# if an item in the list is double clicked the default action is run
self.ui.history_view.doubleClicked.connect(self._on_history_double_clicked)
#################################################
# setup publish model
self._publish_model = SgLatestPublishModel(self, None, self._task_manager)
self._publish_main_overlay = ShotgunModelOverlayWidget(
self._publish_model, self.ui.publish_view
)
# set up a proxy model to cull results based on type selection
self._publish_proxy_model = SgLatestPublishProxyModel(self)
self._publish_proxy_model.setSourceModel(self._publish_model)
# whenever the number of columns change in the proxy model
# check if we should display the "sorry, no publishes found" overlay
self._publish_model.cache_loaded.connect(self._on_publish_content_change)
self._publish_model.data_refreshed.connect(self._on_publish_content_change)
self._publish_proxy_model.layoutChanged.connect(
lambda parents, hint: self._on_publish_content_change()
)
# hook up view -> proxy model -> model
self.ui.publish_view.setModel(self._publish_proxy_model)
# set up custom delegates to use when drawing the main area
self._publish_thumb_delegate = SgPublishThumbDelegate(
self.ui.publish_view, self._action_manager
)
self._publish_list_delegate = SgPublishListDelegate(
self.ui.publish_view, self._action_manager
)
# recall which the most recently mode used was and set that
main_view_mode = self._settings_manager.retrieve(
"main_view_mode", self.MAIN_VIEW_THUMB
)
self._set_main_view_mode(main_view_mode)
# if an item in the table is double clicked the default action is run
self.ui.publish_view.doubleClicked.connect(self._on_publish_double_clicked)
# event handler for when the selection in the publish view is changing
# note! Because of some GC issues (maya 2012 Pyside), need to first establish
# a direct reference to the selection model before we can set up any signal/slots
# against it
self.ui.publish_view.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
self._publish_view_selection_model = self.ui.publish_view.selectionModel()
self._publish_view_selection_model.selectionChanged.connect(
self._on_publish_selection
)
# set up right click menu for the main publish view
self._refresh_action = QtGui.QAction("Refresh", self.ui.publish_view)
self._refresh_action.triggered.connect(self._publish_model.async_refresh)
self.ui.publish_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.ui.publish_view.customContextMenuRequested.connect(
self._show_publish_actions
)
#################################################
# popdown publish filter widget for the main view
# note:
# we parent the widget to a frame that flows around the
# main publish area - this is in order to avoid a scenario
# where the overlay that sometimes pops up on top of the
# publish area and the search widget would be competing
# for the same z-index. The result in some of these cases
# is that the search widget is hidden under the "publishes
# not found" overlay. By having it parented to the frame
# instead, it will always be above the overlay.
self._search_widget = SearchWidget(self.ui.publish_frame)
# hook it up with the search button the main toolbar
self.ui.search_publishes.clicked.connect(self._on_publish_filter_clicked)
# hook it up so that it signals the publish proxy model whenever the filter changes
self._search_widget.filter_changed.connect(
self._publish_proxy_model.set_search_query
)
#################################################
# checkboxes, buttons etc
self.ui.show_sub_items.toggled.connect(self._on_show_subitems_toggled)
#################################################
# thumb scaling
scale_val = self._settings_manager.retrieve("thumb_size_scale", 140)
# position both slider and view
self.ui.thumb_scale.setValue(scale_val)
self.ui.publish_view.setIconSize(QtCore.QSize(scale_val, scale_val))
# and track subsequent changes
self.ui.thumb_scale.valueChanged.connect(self._on_thumb_size_slider_change)
#################################################
# setup history
self._history = []
self._history_index = 0
# state flag used by history tracker to indicate that the
# current navigation operation is happen as a part of a
# back/forward operation and not part of a user's click
self._history_navigation_mode = False
self.ui.navigation_home.clicked.connect(self._on_home_clicked)
self.ui.navigation_prev.clicked.connect(self._on_back_clicked)
self.ui.navigation_next.clicked.connect(self._on_forward_clicked)
#################################################
# set up cog button actions
self._help_action = QtGui.QAction("Show Help Screen", self)
self._help_action.triggered.connect(self.show_help_popup)
self.ui.cog_button.addAction(self._help_action)
self._doc_action = QtGui.QAction("View Documentation", self)
self._doc_action.triggered.connect(self._on_doc_action)
self.ui.cog_button.addAction(self._doc_action)
self._reload_action = QtGui.QAction("Reload", self)
self._reload_action.triggered.connect(self._on_reload_action)
self.ui.cog_button.addAction(self._reload_action)
# Set up filter menu
self._filter_menu = ShotgunFilterMenu(self, refresh_on_show=False)
self._filter_menu.set_accept_fields(
[
"Asset.code",
"Asset.sg_asset_type",
"PublishedFile.created_at",
"PublishedFile.created_by",
"PublishedFile.description",
"PublishedFile.entity",
"PublishedFile.name",
"PublishedFile.project",
"PublishedFile.published_file_type",
"PublishedFile.sg_status_list",
"PublishedFile.task",
"PublishedFile.task.Task.due_date",
"PublishedFile.task.Task.sg_status_list",
"PublishedFile.version_number",
]
)
self._filter_menu.set_filter_model(self._publish_proxy_model)
self.ui.filter_menu_btn.setMenu(self._filter_menu)
#################################################
# set up preset tabs and load and init tree views
self._entity_presets = {}
self._current_entity_preset = None
#################################################
# restore user app ui settings
self.restore_state()
self._load_entity_presets()
#################################################
# restore user app ui settings
self.restore_state()
# load visibility state for details pane
show_details = self._settings_manager.retrieve("show_details", False)
self._set_details_pane_visiblity(show_details)
def _show_publish_actions(self, pos):
"""
Shows the actions for the current publish selection.
:param pos: Local coordinates inside the viewport when the context menu was requested.
"""
# Build a menu with all the actions.
menu = QtGui.QMenu(self)
actions = self._action_manager.get_actions_for_publishes(
self.selected_publishes, self._action_manager.UI_AREA_MAIN
)
menu.addActions(actions)
# Qt is our friend here. If there are no actions available, the separator won't be added, yay!
menu.addSeparator()
menu.addAction(self._refresh_action)
# Wait for the user to pick something.
menu.exec_(self.ui.publish_view.mapToGlobal(pos))
@property
def selected_publishes(self):
"""
Get the selected sg_publish details
"""
# check to see if something is selected in the details history view:
selection_model = self.ui.history_view.selectionModel()
if selection_model.hasSelection():
# only handle single selection atm
proxy_index = selection_model.selection().indexes()[0]
# the incoming model index is an index into our proxy model
# before continuing, translate it to an index into the
# underlying model
source_index = proxy_index.model().mapToSource(proxy_index)
# now we have arrived at our model derived from StandardItemModel
# so let's retrieve the standarditem object associated with the index
item = source_index.model().itemFromIndex(source_index)
sg_data = item.get_sg_data()
if sg_data:
return [sg_data]
sg_data_list = []
# nothing selected in the details view so check to see if something is selected
# in the main publish view:
selection_model = self.ui.publish_view.selectionModel()
if selection_model.hasSelection():
for proxy_index in selection_model.selection().indexes():
# the incoming model index is an index into our proxy model
# before continuing, translate it to an index into the
# underlying model
source_index = proxy_index.model().mapToSource(proxy_index)
# now we have arrived at our model derived from StandardItemModel
# so let's retrieve the standarditem object associated with the index
item = source_index.model().itemFromIndex(source_index)
sg_data = item.get_sg_data()
sg_data = item.get_sg_data()
if sg_data and not item.data(SgLatestPublishModel.IS_FOLDER_ROLE):
sg_data_list.append(sg_data)
return sg_data_list
def closeEvent(self, event):
"""
Executed when the main dialog is closed.
All worker threads and other things which need a proper shutdown
need to be called here.
"""
# display exit splash screen
splash_pix = QtGui.QPixmap(":/res/exit_splash.png")
splash = QtGui.QSplashScreen(splash_pix, QtCore.Qt.WindowStaysOnTopHint)
splash.setMask(splash_pix.mask())
splash.show()
QtCore.QCoreApplication.processEvents()
try:
# clear the selection in the main views.
# this is to avoid re-triggering selection
# as items are being removed in the models
#
# note that we pull out a fresh handle to the selection model
# as these objects sometimes are deleted internally in the view
# and therefore persisting python handles may not be valid
self.ui.history_view.selectionModel().clear()
self.ui.publish_view.selectionModel().clear()
# disconnect some signals so we don't go all crazy when
# the cascading model deletes begin as part of the destroy calls
for p in self._entity_presets:
self._entity_presets[
p
].view.selectionModel().selectionChanged.disconnect(
self._on_treeview_item_selected
)
# gracefully close all connections
shotgun_globals.unregister_bg_task_manager(self._task_manager)
self._task_manager.shut_down()
except:
app = sgtk.platform.current_bundle()
app.log_exception("Error running Loader App closeEvent()")
# close splash
splash.close()
# Save app user settings on close
self.save_state()
# okay to close dialog
event.accept()
def is_first_launch(self):
"""
Returns true if this is the first time UI is being launched
"""
ui_launched = self._settings_manager.retrieve(
"ui_launched", False, self._settings_manager.SCOPE_ENGINE
)
if ui_launched == False:
# store in settings that we now have launched
self._settings_manager.store(
"ui_launched", True, self._settings_manager.SCOPE_ENGINE
)
return not (ui_launched)
def save_state(self):
"""Save the app UI settings."""
# Save the filters
current_menu_state = self._filter_menu.save_state()
self._settings_manager.store(self.FILTER_MENU_STATE, current_menu_state)
# Save the splitter layout state
self._settings_manager.store(
self.SPLITTER_STATE, self.ui.splitter.saveState(), pickle_setting=False
)
def restore_state(self):
"""Restore the app UI settings."""
# Restore the filters
filter_menu_state = self._settings_manager.retrieve(
self.FILTER_MENU_STATE, None
)
if not filter_menu_state:
# Default menu state will show the published file type filter group when
# there are no app user settings saved.
filter_menu_state = {
"PublishedFile.published_file_type": {},
}
self._filter_menu.restore_state(filter_menu_state)
# Restore the splitter layout state
splitter_state = self._settings_manager.retrieve(self.SPLITTER_STATE, None)
self.ui.splitter.restoreState(splitter_state)
########################################################################################
# info bar related
def _on_history_selection(self, selected, deselected):
"""
Called when the selection changes in the history view in the details panel
:param selected: Items that have been selected
:param deselected: Items that have been deselected
"""
# emit the selection_changed signal
self.selection_changed.emit()
def _on_history_double_clicked(self, model_index):
"""
When someone double clicks on a publish in the history view, run the
default action
:param model_index: The model index of the item that was double clicked
"""
# the incoming model index is an index into our proxy model
# before continuing, translate it to an index into the
# underlying model
proxy_model = model_index.model()
source_index = proxy_model.mapToSource(model_index)
# now we have arrived at our model derived from StandardItemModel
# so let's retrieve the standarditem object associated with the index
item = source_index.model().itemFromIndex(source_index)
# Run default action.
sg_item = shotgun_model.get_sg_data(model_index)
default_action = self._action_manager.get_default_action_for_publish(
sg_item, self._action_manager.UI_AREA_HISTORY
)
if default_action:
default_action.trigger()
def _on_publish_filter_clicked(self):
"""
Executed when someone clicks the filter button in the main UI
"""
if self.ui.search_publishes.isChecked():
self.ui.search_publishes.setIcon(
QtGui.QIcon(QtGui.QPixmap(":/res/search_active.png"))
)
self._search_widget.enable()
else:
self.ui.search_publishes.setIcon(
QtGui.QIcon(QtGui.QPixmap(":/res/search.png"))
)
self._search_widget.disable()
def _on_thumbnail_mode_clicked(self):
"""
Executed when someone clicks the thumbnail mode button
"""
self._set_main_view_mode(self.MAIN_VIEW_THUMB)
def _on_list_mode_clicked(self):
"""
Executed when someone clicks the list mode button
"""
self._set_main_view_mode(self.MAIN_VIEW_LIST)
def _set_main_view_mode(self, mode):
"""
Sets up the view mode for the main view.
:param mode: either MAIN_VIEW_LIST or MAIN_VIEW_THUMB
"""
if mode == self.MAIN_VIEW_LIST:
self.ui.list_mode.setIcon(
QtGui.QIcon(QtGui.QPixmap(":/res/mode_switch_card_active.png"))
)
self.ui.list_mode.setChecked(True)
self.ui.thumbnail_mode.setIcon(
QtGui.QIcon(QtGui.QPixmap(":/res/mode_switch_thumb.png"))
)
self.ui.thumbnail_mode.setChecked(False)
self.ui.publish_view.setViewMode(QtGui.QListView.ListMode)
self.ui.publish_view.setItemDelegate(self._publish_list_delegate)
self._show_thumb_scale(False)
elif mode == self.MAIN_VIEW_THUMB:
self.ui.list_mode.setIcon(
QtGui.QIcon(QtGui.QPixmap(":/res/mode_switch_card.png"))
)
self.ui.list_mode.setChecked(False)
self.ui.thumbnail_mode.setIcon(
QtGui.QIcon(QtGui.QPixmap(":/res/mode_switch_thumb_active.png"))
)
self.ui.thumbnail_mode.setChecked(True)
self.ui.publish_view.setViewMode(QtGui.QListView.IconMode)
self.ui.publish_view.setItemDelegate(self._publish_thumb_delegate)
self._show_thumb_scale(True)
else:
raise TankError("Undefined view mode!")
self.ui.publish_view.selectionModel().clear()
self._settings_manager.store("main_view_mode", mode)
def _show_thumb_scale(self, is_visible):
"""
Shows or hides the scale widgets.
:param bool is_visible: If True, scale slider will be shown.
"""
self.ui.thumb_scale.setVisible(is_visible)
self.ui.scale_label.setVisible(is_visible)
def _toggle_details_pane(self):
"""
Executed when someone clicks the show/hide details button
"""
if self.ui.details.isVisible():
self._set_details_pane_visiblity(False)
else:
self._set_details_pane_visiblity(True)
def _set_details_pane_visiblity(self, visible):
"""
Specifies if the details pane should be visible or not
"""
# store our value in a setting
self._settings_manager.store("show_details", visible)
if visible == False:
# hide details pane
self._details_pane_visible = False
self.ui.details.setVisible(False)
self.ui.info.setText("Show Details")
else:
# show details pane
self._details_pane_visible = True
self.ui.details.setVisible(True)
self.ui.info.setText("Hide Details")
# if there is something selected, make sure the detail
# section is focused on this
selection_model = self.ui.publish_view.selectionModel()
self._setup_details_panel(selection_model.selectedIndexes())
def _setup_details_panel(self, items):
"""
Sets up the details panel with info for a given item.
"""
def __make_table_row(left, right):
"""
Helper method to make a detail table row
"""
return (
"<tr><td><b style='color:#2C93E2'>%s</b> </td><td>%s</td></tr>"
% (left, right)
)
def __set_publish_ui_visibility(is_publish):
"""
Helper method to enable disable publish specific details UI
"""
# disable version history stuff
self.ui.version_history_label.setEnabled(is_publish)
self.ui.history_view.setEnabled(is_publish)
# hide actions and playback stuff
self.ui.detail_actions_btn.setVisible(is_publish)
self.ui.detail_playback_btn.setVisible(is_publish)
def __clear_publish_history(pixmap):
"""
Helper method that clears the history view on the right hand side.
:param pixmap: image to set at the top of the history view.
"""
self._publish_history_model.clear()
self.ui.details_header.setText("")
self.ui.details_image.setPixmap(pixmap)
__set_publish_ui_visibility(False)
# note - before the UI has been shown, querying isVisible on the actual
# widget doesn't work here so use member variable to track state instead
if not self._details_pane_visible:
return
if len(items) == 0:
__clear_publish_history(self._no_selection_pixmap)
elif len(items) > 1:
__clear_publish_history(self._multiple_publishes_pixmap)
else:
model_index = items[0]
# the incoming model index is an index into our proxy model
# before continuing, translate it to an index into the
# underlying model
proxy_model = model_index.model()
source_index = proxy_model.mapToSource(model_index)
# now we have arrived at our model derived from StandardItemModel
# so let's retrieve the standarditem object associated with the index
item = source_index.model().itemFromIndex(source_index)
# render out details
thumb_pixmap = item.icon().pixmap(512)
self.ui.details_image.setPixmap(thumb_pixmap)
sg_data = item.get_sg_data()
if sg_data is None:
# an item which doesn't have any sg data directly associated
# typically an item higher up the tree
# just use the default text
folder_name = __make_table_row("Name", item.text())
self.ui.details_header.setText("<table>%s</table>" % folder_name)
__set_publish_ui_visibility(False)
elif item.data(SgLatestPublishModel.IS_FOLDER_ROLE):
# folder with sg data - basically a leaf node in the entity tree
status_code = sg_data.get("sg_status_list")
if status_code is None:
status_name = "No Status"
else:
status_name = self._status_model.get_long_name(status_code)
status_color = self._status_model.get_color_str(status_code)
if status_color:
status_name = (
"%s <span style='color: rgb(%s)'>█</span>"
% (status_name, status_color)
)
if sg_data.get("description"):
desc_str = sg_data.get("description")
else:
desc_str = "No description entered."
msg = ""
display_name = shotgun_globals.get_type_display_name(sg_data["type"])
msg += __make_table_row(
"Name", "%s %s" % (display_name, sg_data.get("code"))
)
msg += __make_table_row("Status", status_name)
msg += __make_table_row("Description", desc_str)
self.ui.details_header.setText("<table>%s</table>" % msg)
# blank out the version history
__set_publish_ui_visibility(False)
self._publish_history_model.clear()
else:
# this is a publish!
__set_publish_ui_visibility(True)
sg_item = item.get_sg_data()
# sort out the actions button
actions = self._action_manager.get_actions_for_publish(
sg_item, self._action_manager.UI_AREA_DETAILS
)
if len(actions) == 0:
self.ui.detail_actions_btn.setVisible(False)
else:
self.ui.detail_playback_btn.setVisible(True)
self._details_action_menu.clear()
for a in actions:
self._dynamic_widgets.append(a)
self._details_action_menu.addAction(a)
# if there is an associated version, show the play button
if sg_item.get("version"):
sg_url = sgtk.platform.current_bundle().shotgun.base_url
url = "%s/page/media_center?type=Version&id=%d" % (
sg_url,
sg_item["version"]["id"],
)
self.ui.detail_playback_btn.setVisible(True)
self._current_version_detail_playback_url = url
else:
self.ui.detail_playback_btn.setVisible(False)
self._current_version_detail_playback_url = None
if sg_item.get("name") is None:
name_str = "No Name"
else:
name_str = sg_item.get("name")
type_str = shotgun_model.get_sanitized_data(
item, SgLatestPublishModel.PUBLISH_TYPE_NAME_ROLE
)
msg = ""
msg += __make_table_row("Name", name_str)
msg += __make_table_row("Type", type_str)
version = sg_item.get("version_number")
vers_str = "%03d" % version if version is not None else "N/A"
msg += __make_table_row("Version", "%s" % vers_str)
if sg_item.get("entity"):
display_name = shotgun_globals.get_type_display_name(
sg_item.get("entity").get("type")
)
entity_str = "<b>%s</b> %s" % (
display_name,
sg_item.get("entity").get("name"),
)
msg += __make_table_row("Link", entity_str)
# sort out the task label
if sg_item.get("task"):
if sg_item.get("task.Task.content") is None:
task_name_str = "Unnamed"
else:
task_name_str = sg_item.get("task.Task.content")
if sg_item.get("task.Task.sg_status_list") is None:
task_status_str = "No Status"
else:
task_status_code = sg_item.get("task.Task.sg_status_list")
task_status_str = self._status_model.get_long_name(
task_status_code
)
msg += __make_table_row(
"Task", "%s (%s)" % (task_name_str, task_status_str)
)
# if there is a version associated, get the status for this
if sg_item.get("version.Version.sg_status_list"):
task_status_code = sg_item.get("version.Version.sg_status_list")
task_status_str = self._status_model.get_long_name(task_status_code)
msg += __make_table_row("Review", task_status_str)
self.ui.details_header.setText("<table>%s</table>" % msg)
# tell details pane to load stuff
sg_data = item.get_sg_data()
self._publish_history_model.load_data(sg_data)
self.ui.details_header.updateGeometry()
def _on_detail_version_playback(self):
"""
Callback when someone clicks the version playback button
"""
# the code that sets up the version button also populates
# a member variable which olds the current media center url.
if self._current_version_detail_playback_url:
QtGui.QDesktopServices.openUrl(
QtCore.QUrl(self._current_version_detail_playback_url)
)
########################################################################################
# history related
def _compute_history_button_visibility(self):
"""
compute history button enabled/disabled state based on contents of history stack.
"""
self.ui.navigation_next.setEnabled(True)
self.ui.navigation_prev.setEnabled(True)
if self._history_index == len(self._history):
self.ui.navigation_next.setEnabled(False)
if self._history_index == 1:
self.ui.navigation_prev.setEnabled(False)
def _add_history_record(self, preset_caption, std_item):
"""
Adds a record to the history stack
"""
# self._history_index is a one based index that points at the currently displayed
# item. If it is not pointing at the last element, it means a user has stepped back
# in that case, discard the history after the current item and add this new record
# after the current item
if (
not self._history_navigation_mode
): # do not add to history when browsing the history :)
# chop off history at the point we are currently
self._history = self._history[: self._history_index]
# append our current item to the chopped history
self._history.append({"preset": preset_caption, "item": std_item})
self._history_index += 1
# now compute buttons
self._compute_history_button_visibility()
def _history_navigate_to_item(self, preset, item):
"""
Focus in on an item in the tree view.
"""
# tell rest of event handlers etc that this navigation
# is part of a history click. This will ensure that no
# *new* entries are added to the history log when we
# are clicking back/next...
self._history_navigation_mode = True
try:
self._select_item_in_entity_tree(preset, item)
finally:
self._history_navigation_mode = False
def _get_item_from_entity(self, ctx, model):
"""
Retrieve the item object based on
entity type and entity id.
:param Sgtk Context ctx: Context object.
:param model: The SG model.
:returns: Model item object or None if not found.
"""
ctx_object = ctx.task if ctx.task else ctx.entity
return model.item_from_entity(ctx_object["type"], ctx_object["id"])
def _on_home_clicked(self):
"""
User clicks the home button.
"""
# first, try to find the "home" item by looking at the current app context.
found_preset = None
found_hierarchy_preset = None
found_item = None
# get entity portion of context
ctx = sgtk.platform.current_bundle().context
if ctx.entity:
# now step through the profiles and find a matching entity
for preset_index, preset in self._entity_presets.items():
if isinstance(preset.model, SgHierarchyModel):
# Found a hierarchy model, we select it right away, since it contains the
# entire project, no need to scan for other tabs.
found_hierarchy_preset = preset_index
break
else:
# Check if there's a task associated with this
# context.If there is, let's check if it does match entity profile.
# this also avoids that the wrong tab gets selected.
# For example if we launch into a Task context, we expect the
# tab that matches with the Task entity profile to be selected.
if (
ctx.task
and preset.entity_type == ctx.task.get("type")
or preset.entity_type == ctx.entity.get("type")
and not ctx.task
):
# found an at least partially matching entity profile.
found_preset = preset_index
# now see if our context object also exists in the tree of this profile
model = preset.model
# retrieve the item
item = self._get_item_from_entity(ctx, model)
if item is not None:
# find an absolute match! Break the search.
found_item = item
break
if found_hierarchy_preset:
# We're about to programmatically set the tab and then the item, so inform
# the tab switcher that this is a combo operation and shouldn't be tracked
# by the history.
self._select_tab(found_hierarchy_preset, track_in_history=False)
# Kick off an async load of an entity, which in the context of the loader
# is always meant to switch select that item.
preset.model.async_item_from_entity(ctx.entity)
return
else:
if found_preset is None:
# no suitable item found. Use the first tab
found_preset = self.ui.entity_preset_tabs.tabText(0)