def dropEvent(self, event): # Get filename(s) filenames = [] for url in event.mimeData().urls(): filenames.append(str(url.toLocalFile())) # Send message(s) with filenames. for filename in sorted(filenames): [file_type, error_text] = params.fileType(filename) if (file_type == "parameters"): self.xml_directory = os.path.dirname(filename) self.guiMessage.emit( halMessage.HalMessage(m_type="new parameters file", data={"filename": filename})) elif (file_type == "shutters"): self.xml_directory = os.path.dirname(filename) self.guiMessage.emit( halMessage.HalMessage(m_type="new shutters file", data={"filename": filename})) else: if error_text: halMessageBox.halMessageBoxInfo("XML file parsing error " + error_text + ".") else: halMessageBox.halMessageBoxInfo( "File type not recognized.")
def handleErrors(self, message): """ Don't override.. """ for m_error in message.getErrors(): data = m_error.source + ": " + m_error.message if m_error.hasException(): if not self.handleError(message, m_error): m_error.printException() return False else: if not self.handleWarning(message, m_error): halMessageBox.halMessageBoxInfo(data) return True
def handleErrors(self, message): """ Don't override.. """ for m_error in message.getErrors(): data = m_error.source + ": " + m_error.message if m_error.hasException(): if not self.handleError(message, m_error): m_error.printException() return False else: if not self.handleWarning(message, m_error): halMessageBox.halMessageBoxInfo(data) return True
def handleErrors(self, message): """ Handle errors in messages from 'core' """ for m_error in message.getErrors(): msg = "from '" + m_error.source + "' of type '" + m_error.message + "'!" # Just print the error and crash on exceptions. if m_error.hasException(): m_error.printException() self.cleanUp() # Use a informational box for warnings. else: msg = "Got a warning" + msg halMessageBox.halMessageBoxInfo(msg)
def handleErrors(self, message): """ Handle errors in messages from 'core' """ for m_error in message.getErrors(): msg = "from '" + m_error.source + "' of type '" + m_error.message + "'!" # Just print the error and crash on exceptions. if m_error.hasException(): m_error.printException() self.cleanUp() # Use a informational box for warnings. else: msg = "Got a warning" + msg halMessageBox.halMessageBoxInfo(msg)
def newParametersFile(self, filename, is_default): """ Load new parameters from a file. """ new_p = params.halParameters(filename) [p, unrecognized] = params.copyParameters(self.default_parameters, new_p) if (len(unrecognized) > 0): msg = "The following parameters were not recognized: " msg += ", ".join( unrecognized ) + ". Perhaps they are not in the correct sub-section?" halMessageBox.halMessageBoxInfo(msg) # Mark as not having been used. p.set("initialized", False) # In the current state, this will only work if the 'default' parameters # are also the currently selected parameters. This should not be a problem # for now as is_default will only be True at startup. if is_default: # Get the parameters labeled 'default'. They should exist because # we only expect to have to handle this at initialization. q_item = self.ui.settingsListView.getQItemByValue("default") # Replace them with these parameters. self.ui.settingsListView.setItemParameters(q_item, p) # Also set there parameters as default. # # FIXME: We'll have issues if the new default parameters are # bad, as there is no pathway to reset the default parameters. # self.default_parameters = p.copy() # Emit a 'new parameters' message. self.newParameters.emit(p, True) # Otherwise, just add the parameters to the ListView. else: self.addParameters(p)
def newParametersFile(self, filename, is_default): """ Load new parameters from a file. """ new_p = params.halParameters(filename) [p, unrecognized] = params.copyParameters(self.default_parameters, new_p) if (len(unrecognized) > 0): msg = "The following parameters were not recognized: " msg += ", ".join(unrecognized) + ". Perhaps they are not in the correct sub-section?" halMessageBox.halMessageBoxInfo(msg) # Mark as not having been used. p.set("initialized", False) # In the current state, this will only work if the 'default' parameters # are also the currently selected parameters. This should not be a problem # for now as is_default will only be True at startup. if is_default: # Get the parameters labeled 'default'. They should exist because # we only expect to have to handle this at initialization. q_item = self.ui.settingsListView.getQItemByValue("default") # Replace them with these parameters. self.ui.settingsListView.setItemParameters(q_item, p) # Also set there parameters as default. # # FIXME: We'll have issues if the new default parameters are # bad, as there is no pathway to reset the default parameters. # self.default_parameters = p.copy() # Emit a 'new parameters' message. self.newParameters.emit(p, True) # Otherwise, just add the parameters to the ListView. else: self.addParameters(p)
def dropEvent(self, event): # Get filename(s) filenames = [] for url in event.mimeData().urls(): filenames.append(str(url.toLocalFile())) # Send message(s) with filenames. for filename in sorted(filenames): [file_type, error_text] = params.fileType(filename) if (file_type == "parameters"): self.xml_directory = os.path.dirname(filename) self.guiMessage.emit(halMessage.HalMessage(m_type = "new parameters file", data = {"filename" : filename})) elif (file_type == "shutters"): self.xml_directory = os.path.dirname(filename) self.guiMessage.emit(halMessage.HalMessage(m_type = "new shutters file", data = {"filename" : filename})) else: if error_text: halMessageBox.halMessageBoxInfo("XML file parsing error " + error_text + ".") else: halMessageBox.halMessageBoxInfo("File type not recognized.")
def handleResponses(self, message): if message.isType("current parameters"): # Update our copy of the current parameters. for response in message.getResponses(): data = response.getData() if "parameters" in data: self.view.updateCurrentParameters( response.source, data["parameters"].copy()) # Start the editor. self.view.startParameterEditor() elif message.isType("new parameters"): # Check if we got any errors. if message.hasErrors(): # Create a message box with the first error. msg = "New Parameters:\n\n" for m_error in message.getErrors(): msg += "Got an error from '" + m_error.source + "' of type '" + m_error.message + "'!\n\n" msg += "Attempting to revert to the last known good parameters." halMessageBox.halMessageBoxInfo(msg) # Attempt reversion. # Replace the 'bad' parameters with their previous 'good' values. if message.getData()["is_edit"]: for response in message.getResponses(): data = response.getData() if "old parameters" in data: self.view.updateCurrentParameters( response.source, data["old parameters"]) self.sendMessage( halMessage.HalMessage( m_type="new parameters", data={ "parameters": self.view.getCurrentParameters(), "is_edit": True })) # Otherwise set the current selection back to previous selection. # This will automatically send a 'new parameters' message. else: self.view.revertSelection() else: # # If this is in response to a 'new parameters' message triggered by # the editor then we don't want to update the previous parameters. # is_edit = message.getData()["is_edit"] if not is_edit: for response in message.getResponses(): data = response.getData() if "old parameters" in data: self.view.updatePreviousParameters( response.source, data["old parameters"]) for response in message.getResponses(): data = response.getData() if "new parameters" in data: self.view.updateCurrentParameters( response.source, data["new parameters"].copy()) # Let modules, such as feeds.feeds know that all of the modules # have updated their parameters. self.waiting_on = copy.copy(self.wait_for) self.sendMessage( halMessage.HalMessage( m_type="updated parameters", data={ "parameters": self.view.getCurrentParameters().copy() })) elif message.isType("updated parameters"): # No waits requested, so the parameter change is complete if (len(self.waiting_on) == 0): self.updateComplete()
def handleResponses(self, message): if message.isType("current parameters"): # Update our copy of the current parameters. for response in message.getResponses(): data = response.getData() if "parameters" in data: self.view.updateCurrentParameters(response.source, data["parameters"].copy()) # Start the editor. self.view.startParameterEditor() elif message.isType("new parameters"): # Check if we got any errors. if message.hasErrors(): # Create a message box with the first error. msg = "New Parameters:\n\n" for m_error in message.getErrors(): msg += "Got an error from '" + m_error.source + "' of type '" + m_error.message + "'!\n\n" msg += "Attempting to revert to the last known good parameters." halMessageBox.halMessageBoxInfo(msg) # Attempt reversion. # Replace the 'bad' parameters with their previous 'good' values. if message.getData()["is_edit"]: for response in message.getResponses(): data = response.getData() if "old parameters" in data: self.view.updateCurrentParameters(response.source, data["old parameters"]) self.sendMessage(halMessage.HalMessage(m_type = "new parameters", data = {"parameters" : self.view.getCurrentParameters(), "is_edit" : True})) # Otherwise set the current selection back to previous selection. # This will automatically send a 'new parameters' message. else: self.view.revertSelection() else: # # If this is in response to a 'new parameters' message triggered by # the editor then we don't want to update the previous parameters. # is_edit = message.getData()["is_edit"] if not is_edit: for response in message.getResponses(): data = response.getData() if "old parameters" in data: self.view.updatePreviousParameters(response.source, data["old parameters"]) for response in message.getResponses(): data = response.getData() if "new parameters" in data: self.view.updateCurrentParameters(response.source, data["new parameters"].copy()) # Let modules, such as feeds.feeds know that all of the modules # have updated their parameters. self.waiting_on = copy.copy(self.wait_for) self.sendMessage(halMessage.HalMessage(m_type = "updated parameters", data = {"parameters" : self.view.getCurrentParameters().copy()})) elif message.isType("updated parameters"): # No waits requested, so the parameter change is complete if (len(self.waiting_on) == 0): self.updateComplete()