L-system equations drawing tool

Terry Reedy tjreedy at udel.edu
Sat Jul 19 01:11:02 CEST 2014


On 7/17/2014 5:38 PM, Yaşar Arabacı wrote:
> Hi,
>
> I wrote a small program to draw L-system equations using tkinter. You
> can find it on https://github.com/yasar11732/tklsystem
>
> It is still under development, but seems to be working nice so far. I
> could only try it on windows, but it should work on Linux too.
>
> You will need Python 3.x to run it. PIL/Pillow is optional but highly
> recommended. It allows faster rendering and ability to save images.
>
> You can also save your equations and load them later.
>
> Try it and comment it if you are interested. Bug reports and
> contributions are also welcome.

As near as I can tell, this is a collection of modules rather than a 
package. This means that for imports like these to work:

from l_system_utils import cached_expand_string
from lsturtle import Turtle

the containing directory must be added to the search path, as is done by 
running from within the directory. That is ok for now and what I will try.


However, if your repository were a package, lsystem, with a blank 
__init__.py and __main__.py containing

from lsystem import main
main.main()

and main.py contained an expanded version of the current ending

def main():
     root = tk.Tk()
     app = Main(root)
     root.bind("<Return>", lambda _: app.render_image())
     app.run()

if __name__ == "__main__":
     main()

and the module names prefixed wither either 'lsystem/' or './' (for 
relative imports)

and the package were installed in lib/site-packages, it would then run 
with pythonw -m lsystem (or pyw -3 -m lsystem, I believe)

pip (at least by default) installs packages in site-packages. It will 
also add a file to /scripts though I don't know the setup to do that.
-----------------------

Copying the examples directory withing the non-package directory to my 
home directory with this

         self.lsf_dir = expanduser(join("~", "lsf-files"))
         if not isdir(self.lsf_dir):
             from shutil import copytree
             from os.path import dirname
             examples = join(dirname(__file__), "examples")
             copytree(examples, self.lsf_dir)

means that deleting the directory will not remove everything. Not nice. 
Also unnecessary. Regardless of where you save, read them from the 
original directory.

Actually, the files are so small, that you could instead make them 
entries in one examples.cfg file, much like Idle does with extensions 
(for instance) using configparser.ConfigParser.  You could then save to 
a single user.cfg file.  Example entry:

[dragon curve]
iterations= 12
angle= 90
axiom= FX
rule1= X:X+YF+
rule2= Y:-FX-Y
rule3=
rule4=
constants=

-------
If I hit 'load', the file dialog opens in idlelib.
If I hit [cancel], I get an error, probably from trying to open None.
Traceback (most recent call last):
   File "C:\Programs\Python34\lib\tkinter\__init__.py", line 1487, in 
__call__
     return self.func(*args)
   File "main.pyw", line 248, in load_from_file
     with open(fname, "r") as f:
FileNotFoundError: [Errno 2] No such file or directory: ''


-- 
Terry Jan Reedy





More information about the Python-list mailing list