Re: [Zim-wiki] New 'Pythonic' Plugin for Zim

2016-02-02 Thread Jaap Karssenberg
Hi David,

Sorry for not responding to your mail last month - trying to go over 1
month backlog :(

First look you plugin looks quite good, so might be a good candidate to
include, but will need to spend some more time consolidating stuff before I
get to integrating new plugins I'm afraid.

In the meantime, don't hesitate to publish it here:
https://github.com/jaap-karssenberg/zim-wiki/wiki/Plugins

The zim plugins dialog links to that page.

Regards,

Jaap




On Sat, Jan 30, 2016 at 11:39 PM, David Nolden <
zwabel+launch...@googlemail.com> wrote:

> Hi Jaap and others.
>
> I use zim for all my note-taking, planning, etc., and I also want to
> be able to do complex calculations right within zim, instead of doing
> them somewhere else and copying in the result. Therefore, I first took
> a look at the 'arithmetic' plugin, which is definitely going into the
> right direction, but it's very limited and has some bugs. I think that
> it doesn't make sense to maintain an own arithmetic syntax and parser
> etc. when we have a perfect solution available: python itself. I
> usually use python anyway to do all kinds of calculations. Therefore I
> created the attached plugin, which allows using python directly within
> zim, not only for arithmetic calculations but for any kind of
> calculations. I'm using this as a kind of Excel replacement. It's also
> a great replacement for the python CLI instance which I used to have
> open all the times for quick calculations.
>
> Obviously, it's potentially dangerous to execute python code from the
> zim notebook. Therefore this should only be used with own and
> trustworthy notebooks. On each zim wiki page, when executing the
> embedded python code for the first time, a popup will be shown which
> shows the exact embedded code that the plugin collected from the page
> and that will be executed, and the user has a chance to review the
> code and eventually abort execution. Python code is embedded using the
> '#' sign. For further information, please see the manual page I wrote.
>
> For example, of you want to calculate how many dollars you can make
> out of 500 dollars in 10 years with interest rates of 5%, you could do
> it like this:
> #dollars = 500; interest = 1.05; years = 10
> #dollars_after_10_years = dollars * (interest ** years)
> #dollars_after_10_years
> -> press F5, and get:
> #dollars_after_10_years ? 814.447313389
>
> I'd be happy if this plugin would be included in Zim in future,
> there's nothing similarly powerful available yet. I'm willing to keep
> maintaining it. Any feedback and discussion is welcome.
>
> Greetings, David
>
> ps. I already sent an older version of the plugin to Jaap, this is an
> improved version.
>
> ___
> Mailing list: https://launchpad.net/~zim-wiki
> Post to : zim-wiki@lists.launchpad.net
> Unsubscribe : https://launchpad.net/~zim-wiki
> More help   : https://help.launchpad.net/ListHelp
>
>
___
Mailing list: https://launchpad.net/~zim-wiki
Post to : zim-wiki@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zim-wiki
More help   : https://help.launchpad.net/ListHelp


[Zim-wiki] New 'Pythonic' Plugin for Zim

2016-01-30 Thread David Nolden
Hi Jaap and others.

I use zim for all my note-taking, planning, etc., and I also want to
be able to do complex calculations right within zim, instead of doing
them somewhere else and copying in the result. Therefore, I first took
a look at the 'arithmetic' plugin, which is definitely going into the
right direction, but it's very limited and has some bugs. I think that
it doesn't make sense to maintain an own arithmetic syntax and parser
etc. when we have a perfect solution available: python itself. I
usually use python anyway to do all kinds of calculations. Therefore I
created the attached plugin, which allows using python directly within
zim, not only for arithmetic calculations but for any kind of
calculations. I'm using this as a kind of Excel replacement. It's also
a great replacement for the python CLI instance which I used to have
open all the times for quick calculations.

Obviously, it's potentially dangerous to execute python code from the
zim notebook. Therefore this should only be used with own and
trustworthy notebooks. On each zim wiki page, when executing the
embedded python code for the first time, a popup will be shown which
shows the exact embedded code that the plugin collected from the page
and that will be executed, and the user has a chance to review the
code and eventually abort execution. Python code is embedded using the
'#' sign. For further information, please see the manual page I wrote.

For example, of you want to calculate how many dollars you can make
out of 500 dollars in 10 years with interest rates of 5%, you could do
it like this:
#dollars = 500; interest = 1.05; years = 10
#dollars_after_10_years = dollars * (interest ** years)
#dollars_after_10_years
-> press F5, and get:
#dollars_after_10_years ? 814.447313389

I'd be happy if this plugin would be included in Zim in future,
there's nothing similarly powerful available yet. I'm willing to keep
maintaining it. Any feedback and discussion is welcome.

Greetings, David

ps. I already sent an older version of the plugin to Jaap, this is an
improved version.
=== added file 'data/manual/Plugins/Pythonic.txt'
--- data/manual/Plugins/Pythonic.txt1970-01-01 00:00:00 +
+++ data/manual/Plugins/Pythonic.txt2016-01-30 22:14:02 +
@@ -0,0 +1,90 @@
+Content-Type: text/x-zim-wiki
+Wiki-Format: zim 0.4
+Creation-Date: 2016-01-02T01:00:41+01:00
+
+== Pythonic ==
+Created Samstag 02 Januar 2016
+
+This plugin allows you to embed arbitrary python code and python calculations 
in zim.
+
+__WARNING__: This plugin should only be used with own and trustworthy 
notebooks, because arbitrary code can be executed from within the notebook when 
the **F5** hotkey is pressed. However, the plugin will print a message which 
shows the executed code when pressing the hotkey for the first time on a page.
+
+Python blocks are started and terminated with the **#** sign. If a block isn't 
terminated using a **#** sign, then it must start at the beginning of the line; 
then it automatically ends at the end of the line. Multi-line blocks can be 
started/ended using **###** lines.
+
+If the python block is a simple expression, then the result of the expression 
will be printed at the end of the block behind a **?** sign. If the block is an 
assignment expression, then the result of the assignment can be printed by 
manually adding a **?** sign at the end of the block.
+
+You can also import python packages etc., the directory of the current 
document and its parent document are inserted into the module path.
+
+Press **F5** to evaluate all python code in the current document.
+
+**Example**:
+
+'''
+###
+dollars = 500
+interest = 1.05
+years = 10
+dollars_afterwards = dollars * (interest ** years)
+###
+
+#dollars_afterwards
+'''
+
+Pressing **F5** yields:
+
+'''
+#dollars_afterwards? 814.447313389
+'''
+
+Each time **F5** is pressed, the whole file is processed top-down, and all 
printed result values are updated accordingly.
+
+Result values can be requested explicitly even within multiline blocks, by 
appending **?** at the end of the line; the line is then processed as a 
single-line statement:
+
+'''
+###
+dollars = 500
+interest = 1.05
+years = 10
+dollars_afterwards = dollars * (interest ** years) ?
+###
+'''
+
+Pressing **F5** yields:
+
+'''
+###
+dollars = 500
+interest = 1.05
+years = 10
+dollars_afterwards = dollars * (interest ** years) ? 814.447313389
+###
+'''
+
+Newlines in result values are replaced by spaces, unless the results are 
printed within a multiline block. Additionally inserted lines are prefixed by 
**?** and some alignment spaces. Old results (or anything else behind a **?** 
sign) are deleted from the block whenever it is re-processed.
+
+**Example**:
+
+'''
+###
+a = "two\nlines"
+a?
+###
+
+#a
+'''
+
+Pressing **F5** yields:
+
+'''
+###
+a = "two\nlines"
+a? two
+? lines
+###
+
+#a? two lines
+'''
+
+__Note 1__: When the python code triggers an error, then the error is also 
printed like a result, preced