Changes between Version 37 and Version 38 of Pic2Plot


Ignore:
Timestamp:
Jun 20, 2009 4:26:07 PM (9 years ago)
Author:
bousch
Comment:

new version of plugin, fixed error when exporting to directory with spaces

Legend:

Unmodified
Added
Removed
Modified
  • Pic2Plot

    v37 v38  
    2525The output image has a large canvas. If you want to crop this you will also need [http://www.imagemagick.org/script/index.php ImageMagick]
    2626
    27 The plugin has an options panel where you must configure the following settings:
    28  * path to the pic2plot executable
     27The plugin has an options panel where you can configure the following settings:
     28 * path to the pic2plot executable (mandatory)
    2929 * path to !ImageMagick folder
     30 * always crop output image
    3031
    3132== Examples ==
     
    339340{{{
    340341"""
    341 2009-05-25: changed argument pattern
    3423422009-05-20: created by bousch_AT_gmail.com
    343343Do with it what you want, no warranty whatsoever.
     344
     345Changes:
     346    2009-06-20: added option to always crop output images
     347    2009-06-20: fixed error when exporting to directory with spaces in name
     348    2009-05-25: changed argument pattern
     349
     350Description:
     351
     352This plugin enables you to use PIC Graphic language fragments in your pages
     353which are rendered as PNG images when previewed or exported.
     354
     355Save this file to your WikidPad/extensions folder
     356
     357Dependencies:
     358    GNU Plotutis
     359    ImageMagick (only if you want the images cropped automatically)
     360
     361Arguments:
     362
     363    pic2plot:
     364        If you want to pass arguments to pic2plot use the
     365        'args=' string as an appendix, see example
     366   
     367    crop:
     368        pic2plot renders an image on a large canvas.
     369        Use the crop argument if you want the image cropped.
     370        You can also use the 'Always crop image' option.
     371
     372Example:
     373
     374    [:pic:'''
     375    .PS 6
     376    box "START"; arrow; circle dashed filled; arrow
     377    circle diam 2 thickness 3 "This is a" "big, thick" "circle" dashed; up
     378    arrow from top of last circle; ellipse "loopback" dashed
     379    arrow dotted from left of last ellipse to top of last box
     380    arc cw radius 1/2 from top of last ellipse; arrow
     381    box "END"
     382    .PE
     383    ''';'args=-F HersheySans -f .02';'crop']
     384
    344385"""
    345386import os, os.path
     
    401442                "plugin_imagemagick_dirPath", "")
    402443
     444        self.alwaysCrop = str(self.app.getGlobalConfig().get("main",
     445                "plugin_pic2plot_alwaysCrop", u"")) == "True"
     446
    403447    def taskEnd(self):
    404448        """
     
    474518        srcfilepath = createTempFile(bstr, ".pic")
    475519        try:
    476             cmdline = '%s %s -T png %s > %s' % (self.extAppExe, arguments, srcfilepath, dstFullPath)
     520            cmdline = '%s %s -T png %s > "%s"' % (self.extAppExe, arguments, srcfilepath, dstFullPath)
    477521           
    478522            # Run external application
    479             #childIn, childOut, childErr = os.popen3(cmdline, "b")
    480 
    481523            from subprocess import Popen, PIPE
    482             p = Popen([cmdline], shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False)
     524            p = Popen(cmdline, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False)
    483525            p.wait() # Will wait for process to end
    484526            childIn, childOut, childErr = (p.stdin, p.stdout, p.stderr)
    485527
    486528            cropcmd = ''
    487             if crop:
    488                 cropcmd = '%s\convert -trim %s %s' % (self.imExtAppExe, dstFullPath, dstFullPath)
    489                 p2 = Popen([cropcmd], shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False)
     529            if crop or self.alwaysCrop:
     530                cropcmd = '%s -trim "%s" "%s"' % (os.path.join(self.imExtAppExe, 'convert'), dstFullPath, dstFullPath)
     531                p2 = Popen(cropcmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False)
    490532                p2.wait()
    491533                childIn2, childOut2, childErr2 =(p2.stdin, p2.stdout, p2.stderr)
     
    493535            if u"noerror" in [a.strip() for a in insToken.appendices]:
    494536                childErr.read()
    495 
    496537                errResponse = ""
    497538            else:
     
    547588    app.getDefaultGlobalConfigDict()[("main", "plugin_pic2plot_exePath")] = u""
    548589    app.getDefaultGlobalConfigDict()[("main", "plugin_imagemagick_dirPath")] = u""
     590    app.getDefaultGlobalConfigDict()[("main", "plugin_pic2plot_alwaysCrop")] = u"False"
     591
    549592    # Register panel in options dialog
    550593    app.addOptionsDlgPanel(Pic2plotOptionsPanel, u"  pic2plot")
     
    583626        mainsizer.Add(inputsizer, 0, wx.EXPAND)
    584627
     628        # add alwaysCrop checkbox
     629        self.alwaysCropCB = wx.CheckBox(self, -1, 'Always crop output images:')
     630        self.alwaysCropCB.SetToolTip(wx.ToolTip(
     631            "You will need ImageMagick for this"))
     632        pt = self.app.getGlobalConfig().get("main",
     633                "plugin_pic2plot_alwaysCrop", u"")
     634
     635        pt = (str(pt) == "True")
     636        self.alwaysCropCB.SetValue(pt)
     637        mainsizer.Add(self.alwaysCropCB, 0, wx.ALL | wx.EXPAND, 5)
     638        self.alwaysCropCB.Bind(wx.EVT_CHECKBOX, self.clickedCB)
     639
    585640        self.SetSizer(mainsizer)
    586641        self.Fit()
     642
     643    def clickedCB(self, event):
     644        if not self.ifPath.GetValue():
     645            wx.SafeShowMessage( "Error",
     646                    """
     647                    You need to set the path to ImageMagick to crop images.
     648                    """)
    587649
    588650    def setVisible(self, vis):
     
    621683        self.app.getGlobalConfig().set("main", "plugin_imagemagick_dirPath", pt)
    622684
    623 }}}
     685        pt = self.alwaysCropCB.GetValue()
     686        self.app.getGlobalConfig().set("main",
     687                "plugin_pic2plot_alwaysCrop", str(pt))
     688
     689}}}