def _on_entity_created(self, entity): """ Callback when an entity is created by an underlying widget. :param entity: The Shotgun entity that was created. """ if entity["type"] == "Note": try: from sgtk.util.metrics import EventMetric fields = [] # reserved for future use annotations = {} # reserved for future use properties = { "Source": "Activity Stream", "Linked Entity Type": entity.get("type", "Unknown"), "Field Used": fields, "Annotations": annotations } EventMetric.log(EventMetric.GROUP_MEDIA, "Created Note", properties=properties, bundle=self._bundle) except: # ignore all errors. ex: using a core that doesn't support metrics pass if self.notes_are_selectable: self._select_on_arrival = entity self.entity_created.emit(entity)
def _on_entity_created(self, entity): """ Callback when an entity is created by an underlying widget. :param entity: The Shotgun entity that was created. """ if entity["type"] == "Note": try: from sgtk.util.metrics import EventMetric fields = [] # reserved for future use annotations = {} # reserved for future use properties = { "Source": "Activity Stream", "Linked Entity Type": entity.get("type", "Unknown"), "Field Used": fields, "Annotations": annotations } EventMetric.log( EventMetric.GROUP_MEDIA, "Created Note", properties=properties, bundle=self._bundle ) except: # ignore all errors. ex: using a core that doesn't support metrics pass if self.notes_are_selectable: self._select_on_arrival = entity self.entity_created.emit(entity)
def _on_reply_clicked(self, note_id): """ Callback when someone clicks reply to note :param note_id: Note id to reply to """ # TODO - refactor to avoid having this code in two places # create reply dialog window reply_dialog = ReplyDialog(self, self._task_manager, note_id) # position the reply modal dialog above the activity stream scroll area pos = self.mapToGlobal(self.ui.reply_scroll_area.pos()) x_pos = ( pos.x() + (self.ui.reply_scroll_area.width() / 2) - (reply_dialog.width() / 2) - 10 ) y_pos = ( pos.y() + (self.ui.reply_scroll_area.height() / 2) - (reply_dialog.height() / 2) - 20 ) reply_dialog.move(x_pos, y_pos) # show the dialog, and while it's showing, # enable a transparent overlay on top of the existing replies # in order to make the reply window stand out. try: self.__small_overlay.show() if reply_dialog.exec_() == QtGui.QDialog.Accepted: self._data_manager.rescan() try: from sgtk.util.metrics import EventMetric properties = {"Source": "Reply List"} EventMetric.log( EventMetric.GROUP_MEDIA, "Created Reply", properties=properties, bundle=self._bundle, ) except: # ignore all errors. ex: using a core that doesn't support metrics pass finally: self.__small_overlay.hide()
def execute(self, parent_ui): """ Shows the task creation form and creates the task. :param parent_ui: Parent widget for the dialog. :returns: If True, task creation was completed, returns False otherwise. """ if not self._entity: return False # show new task dialog: app = sgtk.platform.current_bundle() res, new_task_form = app.engine.show_modal( "Create New Task", app, NewTaskForm, self._entity, self._step, g_user_cache.current_user, parent_ui, ) if res != QtGui.QDialog.Accepted: return False try: from sgtk.util.metrics import EventMetric pipeline_step = new_task_form._get_pipeline_step() properties = { "Linked Entity Type": pipeline_step.get("type", "Unknown"), "Method": "Form", # since this was created from the Qt widget, "Task Name": pipeline_step.get("code", "unknown"), } # Log usage statistics about the Shotgun Desktop executable and the desktop startup. EventMetric.log( EventMetric.GROUP_TASKS, "Created Task", properties=properties, bundle=app, ) except ImportError as e: # ignore all errors. ex: using a core that doesn't support metrics pass return True
def _log_metric_viewed_panel(self, entity_type): """ Module local metric logging helper method for the "Viewed Panel" metric :param entity_type: str of an entity_type e.g.: HumanUser, Project, Shot etc """ try: from sgtk.util.metrics import EventMetric properties = {"Entity Type": entity_type} EventMetric.log(EventMetric.GROUP_NAVIGATION, "Viewed Panel", properties=properties, bundle=self) except: # ignore all errors. ex: using a core that doesn't support metrics pass
def _log_metric_launched_action(self, action_title): """ Module local metric logging helper method for the "Launched Action" metric :param action_title: str of an action which can be most anything """ try: from sgtk.util.metrics import EventMetric properties = {"Action Title": action_title} EventMetric.log(EventMetric.GROUP_TOOLKIT, "Launched Action", properties=properties, bundle=self) except: # ignore all errors. ex: using a core that doesn't support metrics pass
def _on_reply_clicked(self, note_id): """ Callback when someone clicks reply to note :param note_id: Note id to reply to """ # TODO - refactor to avoid having this code in two places # create reply dialog window reply_dialog = ReplyDialog(self, self._task_manager, note_id) # position the reply modal dialog above the activity stream scroll area pos = self.mapToGlobal(self.ui.reply_scroll_area.pos()) x_pos = pos.x() + (self.ui.reply_scroll_area.width() / 2) - (reply_dialog.width() / 2) - 10 y_pos = pos.y() + (self.ui.reply_scroll_area.height() / 2) - (reply_dialog.height() / 2) - 20 reply_dialog.move(x_pos, y_pos) # show the dialog, and while it's showing, # enable a transparent overlay on top of the existing replies # in order to make the reply window stand out. try: self.__small_overlay.show() if reply_dialog.exec_() == QtGui.QDialog.Accepted: self._data_manager.rescan() try: from sgtk.util.metrics import EventMetric properties = { "Source": "Reply List", } EventMetric.log( EventMetric.GROUP_MEDIA, "Created Reply", properties=properties, bundle=self._bundle ) except: # ignore all errors. ex: using a core that doesn't support metrics pass finally: self.__small_overlay.hide()
def execute(self, parent_ui): """ Shows the task creation form and creates the task. :param parent_ui: Parent widget for the dialog. :returns: If True, task creation was completed, returns False otherwise. """ if not self._entity: return False # show new task dialog: app = sgtk.platform.current_bundle() res, new_task_form = app.engine.show_modal("Create New Task", app, NewTaskForm, self._entity, self._step, g_user_cache.current_user, parent_ui) if res != QtGui.QDialog.Accepted: return False try: from sgtk.util.metrics import EventMetric pipeline_step = new_task_form._get_pipeline_step() properties = { "Linked Entity Type": pipeline_step.get("type", "Unknown"), "Method": "Form", # since this was created from the Qt widget, "Task Name": pipeline_step.get("code","unknown"), } # Log usage statistics about the Shotgun Desktop executable and the desktop startup. EventMetric.log( EventMetric.GROUP_TASKS, "Created Task", properties=properties, bundle=app ) except ImportError as e: # ignore all errors. ex: using a core that doesn't support metrics pass return True
def _log_metric_viewed_panel(self, entity_type): """ Module local metric logging helper method for the "Viewed Panel" metric :param entity_type: str of an entity_type e.g.: HumanUser, Project, Shot etc """ try: from sgtk.util.metrics import EventMetric properties = { "Entity Type": entity_type } EventMetric.log( EventMetric.GROUP_NAVIGATION, "Viewed Panel", properties=properties, bundle=self ) except: # ignore all errors. ex: using a core that doesn't support metrics pass
def _on_reply_clicked(self, note_id): """ Callback when someone clicks reply on a given note :param note_id: The id of the Shotgun Note entity being replied to. """ self.reply_dialog.note_id = note_id # Position the reply modal dialog above the activity stream scroll area. pos = self.mapToGlobal(self.ui.activity_stream_scroll_area.pos()) x_pos = pos.x() + (self.ui.activity_stream_scroll_area.width() / 2) - (self.reply_dialog.width() / 2) - 10 y_pos = pos.y() + (self.ui.activity_stream_scroll_area.height() / 2) - (self.reply_dialog.height() / 2) - 20 self.reply_dialog.move(x_pos, y_pos) # and pop it try: self.__small_overlay.show() if self.reply_dialog.exec_() == QtGui.QDialog.Accepted: self.load_data(self._sg_entity_dict) try: from sgtk.util.metrics import EventMetric properties = { "Source": "Activity Stream", } EventMetric.log(EventMetric.GROUP_MEDIA, "Created Reply", properties=properties, bundle=self._bundle) except: # ignore all errors. ex: using a core that doesn't support metrics pass finally: self.__small_overlay.hide()
def _on_reply_clicked(self, note_id): """ Callback when someone clicks reply on a given note :param note_id: The id of the Shotgun Note entity being replied to. """ self.reply_dialog.note_id = note_id # Position the reply modal dialog above the activity stream scroll area. pos = self.mapToGlobal(self.ui.activity_stream_scroll_area.pos()) x_pos = pos.x() + (self.ui.activity_stream_scroll_area.width() / 2) - (self.reply_dialog.width() / 2) - 10 y_pos = pos.y() + (self.ui.activity_stream_scroll_area.height() / 2) - (self.reply_dialog.height() / 2) - 20 self.reply_dialog.move(x_pos, y_pos) # and pop it try: self.__small_overlay.show() if self.reply_dialog.exec_() == QtGui.QDialog.Accepted: self.load_data(self._sg_entity_dict) try: from sgtk.util.metrics import EventMetric properties = { "Source": "Activity Stream", } EventMetric.log( EventMetric.GROUP_MEDIA, "Created Reply", properties=properties, bundle=self._bundle ) except: # ignore all errors. ex: using a core that doesn't support metrics pass finally: self.__small_overlay.hide()
def _log_metric_launched_action(self, action_title): """ Module local metric logging helper method for the "Launched Action" metric :param action_title: str of an action which can be most anything """ try: from sgtk.util.metrics import EventMetric properties = { "Action Title": action_title } EventMetric.log( EventMetric.GROUP_TOOLKIT, "Launched Action", properties = properties, bundle=self ) except: # ignore all errors. ex: using a core that doesn't support metrics pass
# # On any failure relating to metric logging we just silently # catch and continue normal execution. try: from sgtk.util.metrics import EventMetric action = actions[0] action_title = action.get("name") publish_type = action.get("sg_publish_data").get("published_file_type").get("name") properties = { "Publish Type": publish_type, "Action Title": action_title } EventMetric.log( EventMetric.GROUP_TOOLKIT, "Loaded Published File", properties=properties, bundle=self._app ) except: # ignore all errors. ex: using a core that doesn't support metrics pass finally: self.post_execute_action.emit(qt_action) def _show_in_sg(self, entity): """ Callback - Shows a shotgun entity in the web browser :param entity: std sg entity dict with keys type, id and name
def _execute_hook(self, qt_action, actions): """ callback - executes a hook """ self._app.log_debug("Calling scene load hook.") self.pre_execute_action.emit(qt_action) try: self._app.execute_hook_method("actions_hook", "execute_multiple_actions", actions=actions) except Exception as e: self._app.log_exception( "Could not execute execute_action hook: %s" % e) QtGui.QMessageBox.critical( QtGui.QApplication.activeWindow(), "Hook Error", "Error: %s" % e, ) else: # Logging the "Loaded Published File" toolkit metric # # We're deliberately not making any checks or verification in the # code below, as we don't want to be logging exception or debug # messages relating to metrics. # # On any failure relating to metric logging we just silently # catch and continue normal execution. try: from sgtk.util.metrics import EventMetric action = actions[0] action_title = action.get("name") publish_type = (action.get("sg_publish_data").get( "published_file_type").get("name")) creator_id = (action.get("sg_publish_data").get( "created_by", dict()).get("id")) current_user = login.get_current_user(self._app.sgtk) # The creator_generated property doesn't match the natural # language format of the other properties, but it does match # the form of the same property in other metrics being logged # elsewhere. Inconsistency here means consistency where it's # best to have it. properties = { "Publish Type": publish_type, "Action Title": action_title, "creator_generated": current_user.get("id") == creator_id, } EventMetric.log( EventMetric.GROUP_TOOLKIT, "Loaded Published File", properties=properties, bundle=self._app, ) except: # ignore all errors. ex: using a core that doesn't support metrics pass finally: self.post_execute_action.emit(qt_action)
"created_by", dict()).get("id") current_user = login.get_current_user(self._app.sgtk) # The creator_generated property doesn't match the natural # language format of the other properties, but it does match # the form of the same property in other metrics being logged # elsewhere. Inconsistency here means consistency where it's # best to have it. properties = { "Publish Type": publish_type, "Action Title": action_title, "creator_generated": current_user.get("id") == creator_id } EventMetric.log(EventMetric.GROUP_TOOLKIT, "Loaded Published File", properties=properties, bundle=self._app) except: # ignore all errors. ex: using a core that doesn't support metrics pass finally: self.post_execute_action.emit(qt_action) def _show_in_sg(self, entity): """ Callback - Shows a shotgun entity in the web browser :param entity: std sg entity dict with keys type, id and name """