def update_gait_duration(self, duration): rescale_setpoints = self.scale_setpoints_check_box.isChecked() if self.gait.has_setpoints_after_duration( duration) and not rescale_setpoints: if not self.gait.has_multiple_setpoints_before_duration(duration): QMessageBox.question( self._widget, 'Could not update gait duration', 'Not all joints have multiple setpoints before duration ' + str(duration), QMessageBox.Ok) return discard_setpoints = QMessageBox.question( self._widget, 'Gait duration lower than highest time setpoint', 'Do you want to discard any setpoints higher than the given ' 'duration?', QMessageBox.Yes | QMessageBox.No) if discard_setpoints == QMessageBox.No: self.duration_spin_box.setValue(self.gait.duration) return self.gait.set_duration(duration, rescale_setpoints) self.time_slider.setRange(0, 100 * self.gait.duration) was_playing = self.time_slider_thread is not None self.stop_time_slider_thread() self.create_joint_settings() if was_playing: self.start_time_slider_thread()
def open(self): ''' Deletes all current frames and instead loads an animation from a json file ''' if len(self._widget.frameList) > 1: message = "This will discard your current Animation. Continue?" sure = QMessageBox.question(self._widget, 'Sure?', message, QMessageBox.Yes | QMessageBox.No) if sure == QMessageBox.No: return my_file = QFileDialog.getOpenFileName()[0] if my_file: status = self._recorder.load_animation(my_file) if status == "": status = "Load successful." self._widget.statusBar.showMessage(status) animstate = self._recorder.get_animation_state() for i in animstate: try: self._checkBoxesPower[i['name']] = i['torque'] except KeyError: self._checkBoxesPower[i['name']] = {} for key in self.ids: self._checkBoxesPower[i['name']][key] = 2 self.update_frames() metadata = self._recorder.get_meta_data() self._widget.lineAnimationName.setText(metadata[0]) self._widget.lineAuthor.setText(metadata[2]) self._widget.lineVersion.setText(str(metadata[1])) self._widget.fieldDescription.setPlainText(metadata[3])
def press_save_yaml(self): ret = QMessageBox.question( self._widget, "Save YAML", 'Do you want to save changes to current YAML file, overwitting its content?', QMessageBox.Ok, QMessageBox.Cancel) if ret == QMessageBox.Ok: self.save_yaml()
def press_load_yaml(self): ret = QMessageBox.question( self._widget, "Load YAML", 'Do you want to load a new YAML and discard current changes?', QMessageBox.Ok, QMessageBox.Cancel) if ret == QMessageBox.Ok: self.load_yaml()
def export_to_file(gait, gait_directory): if gait_directory is None or gait_directory == '': return # Name and version will be empty as it's stored in the filename. subgait_msg = gait.to_subgait_msg() output_file_directory = os.path.join( gait_directory, gait.gait_name.replace(' ', '_'), gait.subgait_name.replace(' ', '_')) output_file_path = os.path.join( output_file_directory, gait.version.replace(' ', '_') + '.subgait') file_exists = os.path.isfile(output_file_path) if file_exists: overwrite_file = QMessageBox.question( None, 'File already exists', 'Do you want to overwrite ' + str(output_file_path) + '?', QMessageBox.Yes | QMessageBox.No) if overwrite_file == QMessageBox.No: return rospy.loginfo('Writing gait to ' + output_file_path) if not os.path.isdir(output_file_directory): os.makedirs(output_file_directory) with open(output_file_path, 'w') as output_file: output_file.write(str(subgait_msg)) user_interface_controller.notify('Gait Saved', output_file_path)
def question_yn( qmsg='Message', title='Question' ): msgbox = QMessageBox() result = msgbox.question( msgbox, title, qmsg, msgbox.Yes | msgbox.No, msgbox.No ) if result == msgbox.Yes: return True else: return False
def new(self): ''' Deletes all currently recorded frames ''' if len(self._widget.frameList) > 1: message = "This will discard your current Animation. Continue?" sure = QMessageBox.question(self._widget, 'Sure?', message, QMessageBox.Yes | QMessageBox.No) if sure == QMessageBox.Yes: self._recorder.clear() self.update_frames()
def _handle_custom_keypress(self, event, old_keyPressEvent=QTableView.keyPressEvent): """ Handles the delete key. The delete key removes the tableview's selected rows from the datamodel """ if event.key() == Qt.Key_Delete and len(self._model._messages) > 0: delete = QMessageBox.Yes if len(self.table_view.selectionModel().selectedIndexes()) == 0: delete = QMessageBox.question(self, self.tr('Message'), self.tr("Are you sure you want to delete all messages?"), QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if delete == QMessageBox.Yes and event.key() == Qt.Key_Delete and event.modifiers() == Qt.NoModifier: if self._delete_selected_rows(): event.accept() return old_keyPressEvent(self.table_view, event)
def _handle_custom_keypress(self, event, old_keyPressEvent=QTableView.keyPressEvent): """ Handles the delete key. The delete key removes the tableview's selected rows from the datamodel """ if event.key() == Qt.Key_Delete and len(self._model._messages) > 0: delete = QMessageBox.Yes if len(self.table_view.selectionModel().selectedIndexes()) == 0: delete = QMessageBox.question( self, self.tr('Message'), self.tr("Are you sure you want to delete all messages?"), QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if delete == QMessageBox.Yes and \ event.key() == Qt.Key_Delete and \ event.modifiers() == Qt.NoModifier: if self._delete_selected_rows(): event.accept() return old_keyPressEvent(self.table_view, event)
def question_yn(qmsg='Message', title='Question'): ''' Asking Yes or No using PyQt QMessgageBox() Return 'True' only in the case that 'Yes' is chosen. @type qmsg : str @param qmsg : Question message for Yes/No answer (Default='Message') @type title : str @param title : Title of the message box window (Default='Question') @rtype : bool @return : Return when 'Yes' is chosen. ''' msgbox = QMessageBox() result = msgbox.question(msgbox, title, qmsg, msgbox.Yes | msgbox.No, msgbox.No) if result == msgbox.Yes: return True else: return False
def yes_no_question(self, title: str = None, msg: str = None) -> bool: answer = QMessageBox.question(self, title, msg, QMessageBox.Yes | QMessageBox.No) return answer == QMessageBox.Yes
def message(self, title: str = None, msg: str = None) -> None: QMessageBox.question(self, title, msg, QMessageBox.Ok)
def yes_no_question(self, title=None, msg=None): answer = QMessageBox.question(self, title, msg, QMessageBox.Yes | QMessageBox.No) return answer == QMessageBox.Yes
def message(self, title=None, msg=None): QMessageBox.question(self, title, msg, QMessageBox.Ok)