def updateNotes(self): """Update existing notes""" state = "default" self.uniq_id = self.opref['uniq_id'] self.occl_id = '%s-%s' % (self.uniq_id, self.occl_tp) omask_path = None self._findAllNotes() (svg_node, mlayer_node) = self._getMnodesAndSetIds(True) if not self.mnode_ids: tooltip("No shapes left. You can't delete all cards.<br>\ Are you sure you set your masks correctly?") return False mw.checkpoint("Editing Image Occlusion Cards") ret = self._deleteAndIdNotes(mlayer_node) if not ret: # confirmation window rejected return False else: (del_count, new_count) = ret self.new_svg = svg_node.toxml() # write changes to svg old_svg = self._getOriginalSvg() # load original svg if self.new_svg != old_svg or self.occl_tp != self.opref["occl_tp"]: # updated masks or occlusion type omask_path = self._saveMask(self.new_svg, self.occl_id, "O") qmasks = self._generateMaskSVGsFor("Q") amasks = self._generateMaskSVGsFor("A") state = "reset" old_img = fname2img(self.opref['image']) if fname2img(self.image_path) != old_img: # updated image col_image = self._addImageToCol() img = fname2img(col_image) else: img = old_img logging.debug("mnode_indexes %s", self.mnode_indexes) for nr, idx in enumerate(self.mnode_indexes): logging.debug("=====================") logging.debug("nr %s", nr) logging.debug("idx %s", idx) note_id = self.mnode_ids[idx] logging.debug("note_id %s", note_id) logging.debug("self.nids %s", self.nids) nid = self.nids[note_id] logging.debug("nid %s", nid) if omask_path: self._saveMaskAndReturnNote(omask_path, qmasks[nr], amasks[nr], img, note_id, nid) else: self._saveMaskAndReturnNote(None, None, None, img, note_id, nid) self.showUpdateTooltip(del_count, new_count) return state
def generateNotes(self): """Generate new notes""" state = "default" self.uniq_id = str(uuid.uuid4()).replace("-","") self.occl_id = '%s-%s' % (self.uniq_id, self.occl_tp) ( svg_node, layer_node ) = self._getMnodesAndSetIds() if not self.mnode_ids: tooltip("No cards to generate.<br>\ Are you sure you set your masks correctly?") return False self.new_svg = svg_node.toxml() # write changes to svg omask_path = self._saveMask(self.new_svg, self.occl_id, "O") qmasks = self._generateMaskSVGsFor("Q") amasks = self._generateMaskSVGsFor("A") image_path = mw.col.media.addFile(self.image_path) img = fname2img(image_path) mw.checkpoint("Adding Image Occlusion Cards") for nr, idx in enumerate(self.mnode_indexes): note_id = self.mnode_ids[idx] self._saveMaskAndReturnNote(omask_path, qmasks[nr], amasks[nr], img, note_id) tooltip("%s %s <b>added</b>" % self._cardS(len(qmasks)), parent=None) return state
def idAndCorrelateNotes(self, nids_by_nr, occl_id): """Update Note ID fields and omasks of all occlusion session siblings""" logging.debug("occl_id %s", occl_id) logging.debug("nids_by_nr %s", nids_by_nr) logging.debug("mnode_idxs %s", self.mnode_idxs) for nr in sorted(nids_by_nr.keys()): try: midx = self.mnode_idxs[nr] except IndexError: continue nid = nids_by_nr[nr] note = mw.col.getNote(nid) new_mnode_id = occl_id + '-' + str(nr + 1) self.mnode.childNodes[midx].setAttribute("id", new_mnode_id) note[self.ioflds['id']] = new_mnode_id note.flush() logging.debug("Adding ID for note nr %s", nr) logging.debug("midx %s", midx) logging.debug("nid %s", nid) logging.debug("note %s", note) logging.debug("new_mnode_id %s", new_mnode_id) new_svg = self.svg_node.toxml() omask_path = self._saveMask(new_svg, occl_id, "O") logging.debug("omask_path %s", omask_path) for nid in nids_by_nr.values(): note = mw.col.getNote(nid) note[self.ioflds['om']] = fname2img(omask_path) note.addTag(".io-converted") note.flush() logging.debug("Setting om and tag for nid %s", nid)
def _saveMaskAndReturnNote(self, omask_path, qmask, amask, img, note_id, nid=None): """Write actual note for given qmask and amask""" fields = self.fields model = self.model mflds = self.mflds fields[self.ioflds['im']] = img if omask_path: # Occlusions updated qmask_path = self._saveMask(qmask, note_id, "Q") amask_path = self._saveMask(amask, note_id, "A") fields[self.ioflds['qm']] = fname2img(qmask_path) fields[self.ioflds['am']] = fname2img(amask_path) fields[self.ioflds['om']] = fname2img(omask_path) fields[self.ioflds['id']] = note_id self.model['did'] = self.did if nid: note = mw.col.getNote(nid) else: note = Note(mw.col, model) # add fields to note note.tags = self.tags for i in mflds: fname = i["name"] if fname in fields: # only update fields that have been modified note[fname] = fields[fname] if nid: note.flush() logging.debug("!noteflush %s", note) else: mw.col.addNote(note) logging.debug("!notecreate %s", note)