def remove_item(self, item: QtGui.QTreeWidgetItem) -> None: if self.min_number is not None and self.topLevelItemCount() <= self.min_number: warning(_('Unable to remove item'), _('At least %(s)d items are required.') % {'s': self.min_number}, only_ok=True) return index = self.indexOfTopLevelItem(item) self.takeTopLevelItem(index)
def add_item(self, item: QtGui.QTreeWidgetItem) -> None: if self.max_number is not None and self.topLevelItemCount() >= self.max_number: warning(_('Unable to add item'), _('Unable to add more than %(s)d items.') % {'s': self.max_number}, only_ok=True) return index = self.indexOfTopLevelItem(item) self.insert_item(values={}, index=index)
def base_open_document(self, filename=None): if self._base_check_is_modified(): return False if not filename: # noinspection PyCallByClass (filename, selected_filter) = QtGui.QFileDialog.getOpenFileName(p(self), _('Please select a file'), application.GlobalInfos.last_open_folder, self.document_known_extensions) if not filename: return False application.GlobalInfos.last_open_folder = os.path.dirname(filename) if not self.is_valid_document(filename): warning(_('Invalid document'), _('Unable to open document %(filename)s.') % {'filename': os.path.basename(filename)}, only_ok=True) return False self.unload_document() self.current_document_filename = filename self.current_document_is_modified = False self.base_window_title() self.base_add_recent_filename() self.load_document() return True
def _base_check_is_modified(self): return self.current_document_is_modified and not warning(_('The document has been modified'), _('The current document has been modified. ' 'Any change will be lost if you close it. ' 'Do you really want to continue?'))