def onChangeImage(self):
     """Change canvas background image"""
     image_path = self.getImage()
     if not image_path:
         return
     width, height = imageProp(image_path)
     bkgd_url = path2url(image_path)
     mw.ImgOccEdit.svg_edit.eval("""
                     svgCanvas.setBackground('#FFF', '%s');
                     svgCanvas.setResolution(%s, %s);
                     //svgCanvas.zoomChanged('', 'canvas');
                 """ %(bkgd_url, width, height))
     self.image_path = image_path
    def occlude(self, image_path=None):

        note = self.ed.note
        isIO = (note and note.model() == mw.col.models.byName(IO_MODEL_NAME))

        if not image_path:
            if self.origin == "addcards":
                image_path = self.getNewImage(parent=self.ed.parentWindow)
                if not image_path:
                    return False
            elif isIO:
                msg, image_path = self.getIONoteData(note)
                self.mode = "edit"
                if not image_path:
                    tooltip(msg)
                    return False
            else:
                image_path = self.getImageFromFields(note.fields)
                if image_path:
                    tooltip("Non-editable note.<br>"
                            "Using image to create new IO note.")

        if not image_path:
            tooltip(("This note cannot be edited, nor is there<br>"
                     "an image to use for an image occlusion."))
            return False

        self.setPreservedAttrs(note)
        self.image_path = image_path

        width, height = imageProp(image_path)
        if not width:
            tooltip("Not a valid image file.")
            return False

        self.callImgOccEdit(width, height)
Exemple #3
0
    def callImgOccEdit(self):
        """Set up variables, call and prepare ImgOccEdit"""
        width, height = imageProp(self.image_path)
        if not width:
            tooltip("Not a valid image file.")
            return False
        ofill = self.sconf['ofill']
        scol = self.sconf['scol']
        swidth = self.sconf['swidth']
        fsize = self.sconf['fsize']
        font = self.sconf['font']

        bkgd_url = path2url(self.image_path)
        opref = self.opref
        onote = self.ed.note
        mode = self.mode
        flds = self.mflds
        deck = mw.col.decks.nameOrNone(opref["did"])

        try:
            mw.ImgOccEdit is not None
            mw.ImgOccEdit.resetWindow()
            # use existing IO instance when available
        except AttributeError:
            mw.ImgOccEdit = ImgOccEdit(mw)
            mw.ImgOccEdit.setupFields(flds)
            logging.debug("Launching new ImgOccEdit instance")
        dialog = mw.ImgOccEdit
        dialog.switchToMode(self.mode)

        url = QUrl.fromLocalFile(svg_edit_path)
        url.setQueryItems(svg_edit_queryitems)
        url.addQueryItem('initFill[color]', ofill)
        url.addQueryItem('dimensions', '{0},{1}'.format(width, height))
        url.addQueryItem('bkgd_url', bkgd_url)
        url.addQueryItem('initStroke[color]', scol)
        url.addQueryItem('initStroke[width]', str(swidth))
        url.addQueryItem('text[font_size]', str(fsize))
        url.addQueryItem('text[font_family]',
                         "'%s', %s" % (font, svg_edit_fonts))

        if mode != "add":
            url.addQueryItem('initTool', 'select'),
            for i in flds:
                fn = i["name"]
                if fn in self.ioflds_priv:
                    continue
                dialog.tedit[fn].setPlainText(onote[fn].replace(
                    '<br />', '\n'))
            svg_url = path2url(opref["omask"])
            url.addQueryItem('url', svg_url)
        else:
            url.addQueryItem('initTool', 'rect'),

        dialog.svg_edit.setUrl(url)
        dialog.deckChooser.deck.setText(deck)
        dialog.tags_edit.setCol(mw.col)
        dialog.tags_edit.setText(opref["tags"])

        for i in self.ioflds_prsv:
            if i in onote:
                dialog.tedit[i].setPlainText(onote[i])

        dialog.visible = True
        if mode == "add":
            dialog.show()
        else:
            # modal dialog when editing
            dialog.exec_()