def selImage(self):
        """Select image and set up variables for the IO Editor"""
        note = self.ed.note
        opref = self.opref

        opref["tags"] = self.ed.tags.text()

        if self.mode != "add":
            note_id = None
            # can only get the deck of the current note/card via a db call:
            opref["did"] = mw.col.db.scalar(
                    "select did from cards where id = ?", note.cards()[0].id)
            note_id = note[self.ioflds['id']]
            note_id_grps = note_id.split('-')
            if note_id == None or len(note_id_grps) != 3:
                tooltip("Editing unavailable: Invalid Image Occlusion Note ID")
                return
            opref["note_id"] = note_id
            opref["uniq_id"] = note_id_grps[0]
            opref["occl_tp"] = note_id_grps[1]
            opref["image"] = img2path(note[self.ioflds['im']])
            opref["omask"] = img2path(note[self.ioflds['om']])
            if  None in [opref["omask"], opref["image"]]:
                tooltip("Editing unavailable: Missing Image or Original Mask")
                return
            image_path = opref["image"]
        else:
            opref["did"] = self.ed.parentWindow.deckChooser.selectedId()
            image_path = self.getImage(parent=self.ed.parentWindow)
            if not image_path:
                return

        self.image_path = image_path
        self.callImgOccEdit()
Ejemplo n.º 2
0
 def getImageFromFields(self, fields):
     """Parse fields for valid images"""
     image_path = None
     for fld in fields:
         image_path = img2path(fld)
         if image_path:
             break
     return image_path
Ejemplo n.º 3
0
    def getIONoteData(self, note):
        """Select image based on mode and set original field contents"""

        note_id = note[self.ioflds['id']]
        image_path = img2path(note[self.ioflds['im']])
        omask = img2path(note[self.ioflds['om']])

        if note_id == None or note_id.count("-") != 2:
            msg = "Editing unavailable: Invalid image occlusion Note ID"
            return msg, None
        elif not omask or not image_path:
            msg = "Editing unavailable: Missing image or original mask"
            return msg, None

        note_id_grps = note_id.split('-')
        self.opref["note_id"] = note_id
        self.opref["uniq_id"] = note_id_grps[0]
        self.opref["occl_tp"] = note_id_grps[1]
        self.opref["image"] = image_path
        self.opref["omask"] = omask

        return None, image_path
Ejemplo n.º 4
0
 def getOcclTypeAndNodes(self, note):
     """Determine oclusion type and svg mask nodes"""
     nr_of_masks = {}
     mnode_idxs = {}
     svg_mlayer = {}
     for i in ["qm", "om"]:  # om second, so that end vars are correct
         svg_file = img2path(note[self.ioflds[i]], True)
         svg_node = self.readSvg(svg_file)
         svg_mlayer = self.layerNodesFrom(svg_node)[-1]  # topmost layer
         mnode_idxs = self.getMaskNodes(svg_mlayer)
         nr_of_masks[i] = len(mnode_idxs)
     # decide on occl_tp based on nr of mask nodes in omask vs qmask
     if nr_of_masks["om"] != nr_of_masks["qm"]:
         occl_tp = "oa"
     else:
         occl_tp = "ao"
     self.svg_node = svg_node
     self.mnode = svg_mlayer
     self.mnode_idxs = mnode_idxs
     return occl_tp
Ejemplo n.º 5
0
 def getDataFromNamingScheme(self, note):
     """Get unique ID and note nr from qmask path"""
     qmask = note[self.ioflds['qm']]
     path = img2path(qmask, True)
     if not path:
         return (False, None)
     grps = path.split('_')
     try:
         if len(grps) == 2:
             logging.debug("Extracting data using IO 2.0 naming scheme")
             uniq_id = grps[0]
             note_nr = path.split(' ')[1].split('.')[0]
         else:
             logging.debug("Extracting data using IO Enhanced naming scheme")
             grps = path.split('-')
             uniq_id = grps[0]
             note_nr = int(grps[2]) - 1
         return (uniq_id, note_nr)
     except IndexError:
         return (False, None)