def apply(self): """ This button launches a solve, but can also be used to cancel a solve. """ running_state = lib_state.get_solver_is_running_state() if running_state is True: # Cancel out of a running solve if the user presses # the button again. lib_state.set_solver_user_interrupt_state(True) return undo_id = 'mmSolver: ' undo_id += str(datetime.datetime.isoformat(datetime.datetime.now())) undo_id += ' ' undo_id += str(uuid.uuid4()) with undo_utils.undo_chunk_context(undo_id): block = self.blockSignals(True) try: mmapi.set_solver_running(True) options = lib_collection.gather_execute_options() log_level = lib_state.get_log_level() col = lib_state.get_active_collection() lib_collection.run_solve_ui(col, options, log_level, self) finally: mmapi.set_solver_running(False) self.blockSignals(block) return
def run_solve(override_current_frame=None): """ Run the solver for the active collection. If the Solver UI is found, the window will update and show progress messages. This function is strongly dependant on the Solver UI. The following state information is set via the Solver UI. - Active Collection - Log Level - Refresh Viewport :param override_current_frame: Before running the solver, change the "override current frame" state to this value. :type override_current_frame: bool """ assert (override_current_frame is None or isinstance(override_current_frame, bool)) if override_current_frame is None: override_current_frame = False col = lib_state.get_active_collection() if col is None: msg = 'No active Collection found. Skipping solve.' LOG.warning(msg) return log_level = lib_state.get_log_level() layout = None win = solver_window.SolverWindow.get_instance() win_valid = uiutils.isValidQtObject(win) if win is None and win_valid: msg = 'Could not get window.' LOG.warning(msg) else: layout = win.getSubForm() # Set 'override current frame' value. tab = lib_col_state.get_solver_tab_from_collection(col) prev_value = None if override_current_frame is True: prev_value = __get_override_current_frame_value(col, tab) __set_override_current_frame_value(col, layout, tab, override_current_frame) # Run Solver options = lib_col.gather_execute_options() lib_col.run_solve_ui( col, options, log_level, win, ) # Restore previous value. if override_current_frame is True: __set_override_current_frame_value(col, layout, tab, prev_value) return
def apply(self): """ This button launches a solve, but can also be used to cancel a solve. """ running_state = lib_state.get_solver_is_running_state() if running_state is True: # Cancel out of a running solve if the user presses # the button again. lib_state.set_solver_user_interrupt_state(True) return undo_id = 'mmSolver: ' undo_id += str(datetime.datetime.isoformat(datetime.datetime.now())) undo_id += ' ' undo_id += str(uuid.uuid4()) with tools_utils.tool_context(use_undo_chunk=True, undo_chunk_name=undo_id, restore_current_frame=False, pre_update_frame=False, post_update_frame=False, use_dg_evaluation_mode=True, disable_viewport=False): block = self.blockSignals(True) try: mmapi.set_solver_running(True) options = lib_collection.gather_execute_options() log_level = lib_state.get_log_level() col = lib_state.get_active_collection() lib_collection.run_solve_ui(col, options, log_level, self) finally: mmapi.set_solver_running(False) self.blockSignals(block) return
def apply(self): self.setStatusLine(const.STATUS_EXECUTING) try: refresh_state = lib_state.get_refresh_viewport_state() log_level = lib_state.get_log_level() self.progressBar.setValue(0) self.progressBar.show() col = lib_state.get_active_collection() if col is None: msg = 'No active collection.' self.setStatusLine('ERROR: ' + msg) LOG.error(msg) ok = lib_collection.compile_collection(col) if ok is not True: msg = 'Cannot execute solver, collection is not valid.' msg += 'collection=%r' self.setStatusLine('Warning: ' + msg) LOG.warning(msg, col) else: lib_collection.execute_collection( col, log_level=log_level, refresh=refresh_state, prog_fn=self.progressBar.setValue, status_fn=self.setStatusLine, ) finally: self.progressBar.setValue(100) self.progressBar.hide() self.setStatusLine(const.STATUS_FINISHED) return
def apply(self): """ Tbis button launches a solve, but can also be used to cancel a solve. """ undo_id = 'mmSolver: ' + str(uuid.uuid4()) with undo_utils.undo_chunk(undo_id): running_state = lib_state.get_solver_is_running_state() if running_state is True: lib_state.set_solver_user_interrupt_state(True) return refresh_state = lib_state.get_refresh_viewport_state() force_update_state = lib_state.get_force_dg_update_state() do_isolate_state = lib_state.get_isolate_object_while_solving_state( ) image_plane_state = lib_state.get_display_image_plane_while_solving_state( ) log_level = lib_state.get_log_level() col = lib_state.get_active_collection() lib_collection.run_solve_ui(col, refresh_state, force_update_state, do_isolate_state, image_plane_state, log_level, self) return
def addMenuBarContents(self, menubar): # File Menu file_menu = QtWidgets.QMenu('File', menubar) # New Collection label = 'New Collection' tooltip = 'Create a new Collection node.' action = QtWidgets.QAction(label, file_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.createNewCollectionNodeCB)) file_menu.addAction(action) # Rename Collection label = 'Rename Collection' tooltip = 'Rename a Collection node.' action = QtWidgets.QAction(label, file_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.renameCollectionNodeCB)) file_menu.addAction(action) file_menu.addSeparator() # Remove Collection label = 'Remove Collection' tooltip = 'Remove a Collection node.' action = QtWidgets.QAction(label, file_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.removeCollectionNodeCB)) file_menu.addAction(action) file_menu.addSeparator() # Close Window label = 'Close Window' tooltip = 'Close the mmSolver window.' action = QtWidgets.QAction(label, file_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.close)) file_menu.addAction(action) menubar.addMenu(file_menu) # Edit Menu edit_menu = QtWidgets.QMenu('Edit', menubar) edit_menu.setTearOffEnabled(True) if Qt.IsPySide2 or Qt.IsPyQt5: edit_menu.addSection('Undo / Redo') # Undo label = 'Undo (without UI update)' tooltip = ('Undo the Maya scene state, ' 'without updating the viewport or solver UI') action = QtWidgets.QAction(label, edit_menu) action.setStatusTip(tooltip) action.triggered.connect(self.undoTriggeredCB) edit_menu.addAction(action) # Redo label = 'Redo (without UI update)' tooltip = ('Redo the Maya scene state, ' 'without updating the viewport or solver UI') action = QtWidgets.QAction(label, edit_menu) action.setStatusTip(tooltip) action.triggered.connect(self.redoTriggeredCB) edit_menu.addAction(action) if Qt.IsPySide2 or Qt.IsPyQt5: edit_menu.addSection('Window Update') # Auto Update Solver Validation label = 'Auto-Update Solver Validation' tooltip = 'Auto-update details of the solver parameter/error numbers.' value = lib_state.get_auto_update_solver_validation_state() action = QtWidgets.QAction(label, edit_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(value) action.toggled.connect( self.subForm.solver_settings.autoUpdateSolverValidationChanged) edit_menu.addAction(action) if Qt.IsPySide2 or Qt.IsPyQt5: edit_menu.addSection('Solver Execution') # Pre-Solve Force Evaluation label = 'Pre-Solve Force Evaluation' tooltip = ('Before starting a solve, ' 'update the scene to force an evaluation.') pre_solve_force_eval = lib_state.get_pre_solve_force_eval_state() action = QtWidgets.QAction(label, edit_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(pre_solve_force_eval) action.toggled.connect(type(self).preSolveForceEvalActionToggledCB) edit_menu.addAction(action) # Refresh Viewport During Solve label = 'Refresh Viewport' tooltip = 'Refresh the viewport while Solving.' refresh_value = lib_state.get_refresh_viewport_state() action = QtWidgets.QAction(label, edit_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(refresh_value) action.toggled.connect(type(self).refreshActionToggledCB) edit_menu.addAction(action) # Force DG evaluation. label = 'Force DG Update' tooltip = 'Force Maya DG Evaluation while solving.' force_dg_update_value = lib_state.get_force_dg_update_state() action = QtWidgets.QAction(label, edit_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(force_dg_update_value) action.toggled.connect(type(self).forceDgUpdateActionToggledCB) edit_menu.addAction(action) menubar.addMenu(edit_menu) # View Menu view_menu = QtWidgets.QMenu('View', menubar) view_menu.setTearOffEnabled(True) if Qt.IsPySide2 or Qt.IsPyQt5: view_menu.addSection('Input Object Display') # Display Object Weight label = 'Weight Column' tooltip = 'Display Object weight column' value = lib_state.get_display_object_weight_state() action = QtWidgets.QAction(label, view_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(value) action.toggled.connect( self.subForm.object_browser.displayWeightColumnChanged) view_menu.addAction(action) # Display Object Frame Deviation label = 'Frame Deviation' tooltip = 'Display per-frame deviation for each Marker/Camera.' value = lib_state.get_display_object_frame_deviation_state() action = QtWidgets.QAction(label, view_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(value) action.toggled.connect( self.subForm.object_browser.displayFrameDeviationColumnChanged) view_menu.addAction(action) # Display Object Average Deviation label = 'Average Deviation' tooltip = 'Display average deviation column' value = lib_state.get_display_object_average_deviation_state() action = QtWidgets.QAction(label, view_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(value) action.toggled.connect( self.subForm.object_browser.displayAverageDeviationColumnChanged) view_menu.addAction(action) # Display Object Maximum Deviation label = 'Maximum Deviation' tooltip = 'Display maximum deviation column' value = lib_state.get_display_object_maximum_deviation_state() action = QtWidgets.QAction(label, view_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(value) action.toggled.connect( self.subForm.object_browser.displayMaximumDeviationColumnChanged) view_menu.addAction(action) if Qt.IsPySide2 or Qt.IsPyQt5: view_menu.addSection('Output Attribute Display') # Display Attribute State label = 'Display Attribute State' tooltip = 'Display Attribute State column' value = lib_state.get_display_attribute_state_state() action = QtWidgets.QAction(label, view_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(value) action.toggled.connect( self.subForm.attribute_browser.displayStateColumnChanged) view_menu.addAction(action) # Display Attribute Min/Max label = 'Display Attribute Min/Max' tooltip = 'Display Attribute Minimum and Maximum columns' value = lib_state.get_display_attribute_min_max_state() action = QtWidgets.QAction(label, view_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(value) action.toggled.connect( self.subForm.attribute_browser.displayMinMaxColumnChanged) view_menu.addAction(action) if Qt.IsPySide2 or Qt.IsPyQt5: view_menu.addSection('During Solve') # Display the Image Planes while solving. # # TODO: Add other object types to show/hide while solving, # such as camera, nurbsCurves, nurbsSurfaces, and locators. label = 'Display Image Planes' tooltip = 'Display Image Planes while solving.' value = lib_state.get_display_image_plane_while_solving_state() action = QtWidgets.QAction(label, view_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(value) action.toggled.connect( type(self).displayImagePlaneWhileSolvingActionToggledCB) view_menu.addAction(action) # Display the Meshes while solving. label = 'Display Meshes' tooltip = 'Display Meshes while solving.' value = lib_state.get_display_meshes_while_solving_state() action = QtWidgets.QAction(label, view_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(value) action.toggled.connect( type(self).displayMeshesWhileSolvingActionToggledCB) view_menu.addAction(action) # Isolate Objects while solving label = 'Isolate Objects' tooltip = 'Isolate visibility of all Markers and Bundles while solving.' isolate_value = lib_state.get_isolate_object_while_solving_state() action = QtWidgets.QAction(label, view_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(isolate_value) action.toggled.connect( type(self).isolateObjectWhileSolvingActionToggledCB) view_menu.addAction(action) menubar.addMenu(view_menu) # Log Menu # This menu depicts a radio button allowing the user to choose # how much information is returned to the console (the logging # level). log_menu = QtWidgets.QMenu('Log', menubar) # Errors label = 'Errors' tooltip = 'Send Errors to the log.' logErrorAction = QtWidgets.QAction(label, log_menu) logErrorAction.setStatusTip(tooltip) logErrorAction.setCheckable(True) logErrorAction.triggered.connect(partial(self.logErrorCB)) log_menu.addAction(logErrorAction) # Warnings label = 'Warnings' tooltip = 'Send Warnings to the log.' logWarningAction = QtWidgets.QAction(label, log_menu) logWarningAction.setStatusTip(tooltip) logWarningAction.setCheckable(True) logWarningAction.triggered.connect(partial(self.logWarningCB)) log_menu.addAction(logWarningAction) # Information label = 'Info' tooltip = 'Send Information to the log.' logInfoAction = QtWidgets.QAction(label, log_menu) logInfoAction.setStatusTip(tooltip) logInfoAction.setCheckable(True) logInfoAction.triggered.connect(partial(self.logInfoCB)) log_menu.addAction(logInfoAction) # Verbose label = 'Verbose' tooltip = 'Send Verboses to the log.' logVerboseAction = QtWidgets.QAction(label, log_menu) logVerboseAction.setStatusTip(tooltip) logVerboseAction.setCheckable(True) logVerboseAction.triggered.connect(partial(self.logVerboseCB)) log_menu.addAction(logVerboseAction) # Debug label = 'Debug' tooltip = 'Send Debug messages to the log.' logDebugAction = QtWidgets.QAction(label, log_menu) logDebugAction.setStatusTip(tooltip) logDebugAction.setCheckable(True) logDebugAction.triggered.connect(partial(self.logDebugCB)) log_menu.addAction(logDebugAction) # 'Radio' button for logging levels log_actionGroup = QtWidgets.QActionGroup(log_menu) log_actionGroup.addAction(logErrorAction) log_actionGroup.addAction(logWarningAction) log_actionGroup.addAction(logInfoAction) log_actionGroup.addAction(logVerboseAction) log_actionGroup.addAction(logDebugAction) log_level = lib_state.get_log_level() if log_level == const.LOG_LEVEL_ERROR: logErrorAction.setChecked(True) elif log_level == const.LOG_LEVEL_WARNING: logWarningAction.setChecked(True) elif log_level == const.LOG_LEVEL_INFO: logInfoAction.setChecked(True) elif log_level == const.LOG_LEVEL_VERBOSE: logVerboseAction.setChecked(True) elif log_level == const.LOG_LEVEL_DEBUG: logDebugAction.setChecked(True) else: LOG.warning('Invalid log level given: %r' % log_level) menubar.addMenu(log_menu) # Help Menu help_menu = QtWidgets.QMenu('Help', menubar) # Launch Help label = 'Help...' tooltip = 'Show help.' action = QtWidgets.QAction(label, help_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.launchHelpCB)) help_menu.addAction(action) # Launch System Info window. label = 'System Information...' tooltip = 'Display detailed information about software and hardware.' action = QtWidgets.QAction(label, help_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.launchSysInfoCB)) help_menu.addAction(action) # Launch About label = 'About mmSolver...' tooltip = 'About this software.' action = QtWidgets.QAction(label, help_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.launchAboutCB)) help_menu.addAction(action) menubar.addMenu(help_menu) return
def addMenuBarContents(self, menubar): # File Menu file_menu = QtWidgets.QMenu('File', menubar) # New Collection label = 'New Collection' tooltip = 'Create a new Collection node.' action = QtWidgets.QAction(label, file_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.createNewCollectionNodeCB)) file_menu.addAction(action) # Rename Collection label = 'Rename Collection' tooltip = 'Rename a Collection node.' action = QtWidgets.QAction(label, file_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.renameCollectionNodeCB)) file_menu.addAction(action) file_menu.addSeparator() # Remove Collection label = 'Remove Collection' tooltip = 'Remove a Collection node.' action = QtWidgets.QAction(label, file_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.removeCollectionNodeCB)) file_menu.addAction(action) file_menu.addSeparator() # Close Window label = 'Close Window' tooltip = 'Close the mmSolver window.' action = QtWidgets.QAction(label, file_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.close)) file_menu.addAction(action) menubar.addMenu(file_menu) # Edit Menu edit_menu = QtWidgets.QMenu('Edit', menubar) # Refresh Viewport During Solve label = 'Refresh Viewport' tooltip = 'Refresh the viewport while Solving.' refresh_value = lib_state.get_refresh_viewport_state() action = QtWidgets.QAction(label, edit_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(refresh_value) action.toggled.connect(type(self).refreshActionToggledCB) edit_menu.addAction(action) # Force DG evaluation. label = 'Force DG Update' tooltip = 'Force Maya DG Evaluation while solving.' force_dg_update_value = lib_state.get_force_dg_update_state() action = QtWidgets.QAction(label, edit_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(force_dg_update_value) action.toggled.connect(type(self).forceDgUpdateActionToggledCB) edit_menu.addAction(action) menubar.addMenu(edit_menu) # View Menu view_menu = QtWidgets.QMenu('View', menubar) # Display Object Weight label = 'Display Object Weight Column' tooltip = 'Display Object weight column' value = lib_state.get_display_object_weight_state() action = QtWidgets.QAction(label, view_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(value) action.toggled.connect(self.subForm.displayObjectWeightColumnChanged) view_menu.addAction(action) # Display Object Deviation label = 'Display Object Frame Deviation' tooltip = 'Display per-frame deviation for each Marker/Camera.' value = lib_state.get_display_object_frame_deviation_state() action = QtWidgets.QAction(label, view_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(value) action.toggled.connect( self.subForm.displayObjectFrameDeviationColumnChanged) view_menu.addAction(action) # Display Object Deviation label = 'Display Object Average Deviation' tooltip = 'Display deviation column' value = lib_state.get_display_object_average_deviation_state() action = QtWidgets.QAction(label, view_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(value) action.toggled.connect( self.subForm.displayObjectAverageDeviationColumnChanged) view_menu.addAction(action) # Display Object Deviation label = 'Display Object Maximum Deviation' tooltip = 'Display deviation column' value = lib_state.get_display_object_maximum_deviation_state() action = QtWidgets.QAction(label, view_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(value) action.toggled.connect( self.subForm.displayObjectMaximumDeviationColumnChanged) view_menu.addAction(action) view_menu.addSeparator() # Display Attribute State label = 'Display Attribute State' tooltip = 'Display Attribute State column' value = lib_state.get_display_attribute_state_state() action = QtWidgets.QAction(label, view_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(value) action.toggled.connect(self.subForm.displayAttributeStateColumnChanged) view_menu.addAction(action) # Display Attribute Min/Max label = 'Display Attribute Min/Max' tooltip = 'Display Attribute Minimum and Maximum columns' value = lib_state.get_display_attribute_min_max_state() action = QtWidgets.QAction(label, view_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(value) action.toggled.connect( self.subForm.displayAttributeMinMaxColumnChanged) view_menu.addAction(action) view_menu.addSeparator() # Display the Image Planes while solving. label = 'Display Image Planes (while solving)' tooltip = 'Display Image Planes while solving.' value = lib_state.get_display_image_plane_while_solving_state() action = QtWidgets.QAction(label, edit_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(value) action.toggled.connect( type(self).displayImagePlaneWhileSolvingActionToggledCB) view_menu.addAction(action) # Isolate Objects while solving label = 'Isolate Objects (while solving)' tooltip = 'Isolate visibility of all Markers and Bundles while solving.' value = lib_state.get_display_image_plane_while_solving_state() action = QtWidgets.QAction(label, edit_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(value) action.toggled.connect( type(self).isolateObjectWhileSolvingActionToggledCB) view_menu.addAction(action) menubar.addMenu(view_menu) # Tools Menu tools_menu = QtWidgets.QMenu('Tools', menubar) # Create Marker label = 'Create Marker' tooltip = 'Create Markers on the selected camera.' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.createMarkerCB)) tools_menu.addAction(action) # Convert to Marker label = 'Convert to Marker' tooltip = 'Convert the selection to Markers.' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.convertToMarkerCB)) tools_menu.addAction(action) # Load Markers label = 'Load Markers...' tooltip = 'Load Markers from a file.' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.loadMarkerCB)) tools_menu.addAction(action) tools_menu.addSeparator() # Create Bundle label = 'Create Bundle' tooltip = 'Create a default Bundle node.' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.createBundleCB)) tools_menu.addAction(action) tools_menu.addSeparator() # Link Marker + Bundle label = 'Link Marker + Bundle' tooltip = 'Link the selected Marker and Bundle together.' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.linkMarkerBundleCB)) tools_menu.addAction(action) # Unlink Marker from all Bundles label = 'Unlink Marker from all Bundles' tooltip = 'Unlink all selected Markers from their Bundle.' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.unlinkMarkerBundleCB)) tools_menu.addAction(action) tools_menu.addSeparator() # Toogle Marker / Bundle selection label = 'Toggle Marker / Bundle' tooltip = 'Select connected Markers, or Bundles.' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.toggleMarkerBundleSelectionCB)) tools_menu.addAction(action) # Select Marker / Bundle label = 'Select Marker + Bundle' tooltip = 'Select the connected Markers and Bundles.' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.selectBothMarkersAndBundlesCB)) tools_menu.addAction(action) # Rename Marker + Bundle label = 'Rename Markers + Bundles' tooltip = 'Rename the selected Markers and Bundles;' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.renameMarkerBundleCB)) tools_menu.addAction(action) menubar.addMenu(tools_menu) # Log Menu # This menu depicts a radio button allowing the user to choose # how much information is returned to the console (the logging # level). log_menu = QtWidgets.QMenu('Log', menubar) # Errors label = 'Errors' tooltip = 'Send Errors to the log.' logErrorAction = QtWidgets.QAction(label, log_menu) logErrorAction.setStatusTip(tooltip) logErrorAction.setCheckable(True) logErrorAction.triggered.connect(partial(self.logErrorCB)) log_menu.addAction(logErrorAction) # Warnings label = 'Warnings' tooltip = 'Send Warnings to the log.' logWarningAction = QtWidgets.QAction(label, log_menu) logWarningAction.setStatusTip(tooltip) logWarningAction.setCheckable(True) logWarningAction.triggered.connect(partial(self.logWarningCB)) log_menu.addAction(logWarningAction) # Information label = 'Info' tooltip = 'Send Information to the log.' logInfoAction = QtWidgets.QAction(label, log_menu) logInfoAction.setStatusTip(tooltip) logInfoAction.setCheckable(True) logInfoAction.triggered.connect(partial(self.logInfoCB)) log_menu.addAction(logInfoAction) # Verbose label = 'Verbose' tooltip = 'Send Verboses to the log.' logVerboseAction = QtWidgets.QAction(label, log_menu) logVerboseAction.setStatusTip(tooltip) logVerboseAction.setCheckable(True) logVerboseAction.triggered.connect(partial(self.logVerboseCB)) log_menu.addAction(logVerboseAction) # Debug label = 'Debug' tooltip = 'Send Debug messages to the log.' logDebugAction = QtWidgets.QAction(label, log_menu) logDebugAction.setStatusTip(tooltip) logDebugAction.setCheckable(True) logDebugAction.triggered.connect(partial(self.logDebugCB)) log_menu.addAction(logDebugAction) # 'Radio' button for logging levels log_actionGroup = QtWidgets.QActionGroup(log_menu) log_actionGroup.addAction(logErrorAction) log_actionGroup.addAction(logWarningAction) log_actionGroup.addAction(logInfoAction) log_actionGroup.addAction(logVerboseAction) log_actionGroup.addAction(logDebugAction) log_level = lib_state.get_log_level() if log_level == const.LOG_LEVEL_ERROR: logErrorAction.setChecked(True) elif log_level == const.LOG_LEVEL_WARNING: logWarningAction.setChecked(True) elif log_level == const.LOG_LEVEL_INFO: logInfoAction.setChecked(True) elif log_level == const.LOG_LEVEL_VERBOSE: logVerboseAction.setChecked(True) elif log_level == const.LOG_LEVEL_DEBUG: logDebugAction.setChecked(True) else: LOG.warning('Invalid log level given: %r' % log_level) menubar.addMenu(log_menu) # Help Menu help_menu = QtWidgets.QMenu('Help', menubar) # Launch Help label = 'Help...' tooltip = 'Show help.' action = QtWidgets.QAction(label, help_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.launchHelpCB)) help_menu.addAction(action) # Launch System Info window. label = 'System Information...' tooltip = 'Display detailed information about software and hardware.' action = QtWidgets.QAction(label, help_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.launchSysInfoCB)) help_menu.addAction(action) # Launch About label = 'About mmSolver...' tooltip = 'About this software.' action = QtWidgets.QAction(label, help_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.launchAboutCB)) help_menu.addAction(action) menubar.addMenu(help_menu) return
def run_solve(override_current_frame=None): """ Run the solver for the active collection. If the Solver UI is found, the window will update and show progress messages. This function is strongly dependant on the Solver UI. The following state information is set via the Solver UI. - Active Collection - Log Level - Refresh Viewport :param override_current_frame: Before running the solver, change the "override current frame" state to this value. :type override_current_frame: bool """ assert (override_current_frame is None or isinstance(override_current_frame, bool)) col = lib_state.get_active_collection() if col is None: msg = 'No active Collection found. Skipping solve.' LOG.warning(msg) return refresh_state = lib_state.get_refresh_viewport_state() log_level = lib_state.get_log_level() layout = None win = solver_window.SolverWindow.get_instance() if win is None: msg = 'Could not get window.' LOG.warning(msg) else: layout = win.getSubForm() # Set value. prev_value = None if override_current_frame is not None: prev_value = lib_col.get_override_current_frame_from_collection(col) if layout is None: lib_col.set_override_current_frame_on_collection( col, override_current_frame ) else: # The function should operate on the currently active # collection, so we don't need to pass a collection. layout.setOverrideCurrentFrame(col, override_current_frame) # Run Solver lib_col.run_solve_ui( col, refresh_state, log_level, win, ) # Restore previous value. if override_current_frame is not None: if layout is None: lib_col.set_override_current_frame_on_collection( col, prev_value ) else: layout.setOverrideCurrentFrame(col, prev_value) return
def addMenuBarContents(self, menubar): # File Menu file_menu = QtWidgets.QMenu('File', menubar) # New Collection label = 'New Collection' tooltip = 'Create a new Collection node.' action = QtWidgets.QAction(label, file_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.createNewCollectionNodeCB)) file_menu.addAction(action) # Rename Collection label = 'Rename Collection' tooltip = 'Rename a Collection node.' action = QtWidgets.QAction(label, file_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.renameCollectionNodeCB)) file_menu.addAction(action) file_menu.addSeparator() # Remove Collection label = 'Remove Collection' tooltip = 'Remove a Collection node.' action = QtWidgets.QAction(label, file_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.removeCollectionNodeCB)) file_menu.addAction(action) file_menu.addSeparator() # Close Window label = 'Close Window' tooltip = 'Close the mmSolver window.' action = QtWidgets.QAction(label, file_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.close)) file_menu.addAction(action) menubar.addMenu(file_menu) # Tools Menu tools_menu = QtWidgets.QMenu('Tools', menubar) # Create Marker label = 'Create Marker' tooltip = 'Create Markers on the selected camera.' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.createMarkerCB)) tools_menu.addAction(action) # Convert to Marker label = 'Convert to Marker' tooltip = 'Convert the selection to Markers.' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.convertToMarkerCB)) tools_menu.addAction(action) # Load Markers label = 'Load Markers...' tooltip = 'Load Markers from a file.' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.loadMarkerCB)) tools_menu.addAction(action) tools_menu.addSeparator() # Create Bundle label = 'Create Bundle' tooltip = 'Create a default Bundle node.' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.createBundleCB)) tools_menu.addAction(action) tools_menu.addSeparator() # Link Marker + Bundle label = 'Link Marker + Bundle' tooltip = 'Link the selected Marker and Bundle together.' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.linkMarkerBundleCB)) tools_menu.addAction(action) # Unlink Marker from all Bundles label = 'Unlink Marker from all Bundles' tooltip = 'Unlink all selected Markers from their Bundle.' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.unlinkMarkerBundleCB)) tools_menu.addAction(action) tools_menu.addSeparator() # Toogle Marker / Bundle selection label = 'Toggle Marker / Bundle' tooltip = 'Select connected Markers, or Bundles.' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.toggleMarkerBundleSelectionCB)) tools_menu.addAction(action) # Select Marker / Bundle label = 'Select Marker + Bundle' tooltip = 'Select the connected Markers and Bundles.' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.selectBothMarkersAndBundlesCB)) tools_menu.addAction(action) # Rename Marker + Bundle label = 'Rename Markers + Bundles' tooltip = 'Rename the selected Markers and Bundles;' action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.renameMarkerBundleCB)) tools_menu.addAction(action) tools_menu.addSeparator() # Refresh Viewport During Solve label = 'Refresh Viewport' tooltip = 'Refresh the viewport while Solving.' refresh_value = lib_state.get_refresh_viewport_state() action = QtWidgets.QAction(label, tools_menu) action.setStatusTip(tooltip) action.setCheckable(True) action.setChecked(refresh_value) action.toggled.connect(type(self).refreshActionToggledCB) tools_menu.addAction(action) menubar.addMenu(tools_menu) # Log Menu # This menu depicts a radio button allowing the user to choose # how much information is returned to the console (the logging # level). log_menu = QtWidgets.QMenu('Log', menubar) # Errors label = 'Errors' tooltip = 'Send Errors to the log.' logErrorAction = QtWidgets.QAction(label, log_menu) logErrorAction.setStatusTip(tooltip) logErrorAction.setCheckable(True) logErrorAction.triggered.connect(partial(self.logErrorCB)) log_menu.addAction(logErrorAction) # Warnings label = 'Warnings' tooltip = 'Send Warnings to the log.' logWarningAction = QtWidgets.QAction(label, log_menu) logWarningAction.setStatusTip(tooltip) logWarningAction.setCheckable(True) logWarningAction.triggered.connect(partial(self.logWarningCB)) log_menu.addAction(logWarningAction) # Information label = 'Info' tooltip = 'Send Information to the log.' logInfoAction = QtWidgets.QAction(label, log_menu) logInfoAction.setStatusTip(tooltip) logInfoAction.setCheckable(True) logInfoAction.triggered.connect(partial(self.logInfoCB)) log_menu.addAction(logInfoAction) # Verbose label = 'Verbose' tooltip = 'Send Verboses to the log.' logVerboseAction = QtWidgets.QAction(label, log_menu) logVerboseAction.setStatusTip(tooltip) logVerboseAction.setCheckable(True) logVerboseAction.triggered.connect(partial(self.logVerboseCB)) log_menu.addAction(logVerboseAction) # Debug label = 'Debug' tooltip = 'Send Debug messages to the log.' logDebugAction = QtWidgets.QAction(label, log_menu) logDebugAction.setStatusTip(tooltip) logDebugAction.setCheckable(True) logDebugAction.triggered.connect(partial(self.logDebugCB)) log_menu.addAction(logDebugAction) # 'Radio' button for logging levels log_actionGroup = QtWidgets.QActionGroup(log_menu) log_actionGroup.addAction(logErrorAction) log_actionGroup.addAction(logWarningAction) log_actionGroup.addAction(logInfoAction) log_actionGroup.addAction(logVerboseAction) log_actionGroup.addAction(logDebugAction) log_level = lib_state.get_log_level() if log_level == const.LOG_LEVEL_ERROR: logErrorAction.setChecked(True) elif log_level == const.LOG_LEVEL_WARNING: logWarningAction.setChecked(True) elif log_level == const.LOG_LEVEL_INFO: logInfoAction.setChecked(True) elif log_level == const.LOG_LEVEL_VERBOSE: logVerboseAction.setChecked(True) elif log_level == const.LOG_LEVEL_DEBUG: logDebugAction.setChecked(True) else: LOG.warning('Invalid log level given: %r' % log_level) menubar.addMenu(log_menu) # Help Menu help_menu = QtWidgets.QMenu('Help', menubar) # Launch Help label = 'Help...' tooltip = 'Show help.' action = QtWidgets.QAction(label, help_menu) action.setStatusTip(tooltip) action.triggered.connect(partial(self.launchHelpCB)) help_menu.addAction(action) # # Launch About # label = 'About...' # tooltip = 'About this software.' # action = QtWidgets.QAction(label, help_menu) # action.setStatusTip(tooltip) # action.triggered.connect(partial(self.launchAboutCB)) # help_menu.addAction(action) menubar.addMenu(help_menu) return
def apply(self): refresh_state = lib_state.get_refresh_viewport_state() log_level = lib_state.get_log_level() col = lib_state.get_active_collection() lib_collection.run_solve_ui(col, refresh_state, log_level, self) return