Saturday, February 21, 2009

Inkscape slicer

Download Inkscape slice effect a.k.a. 'slicer' 0.1.1 (bugfix)

Usage:

1.) Create layer e.g. named 'slices'.
2.) Create rectangles as your slices, set their Label* (select rect and Object -> Object properties) as the output filename (without extension).
3.) Run Effects -> Export -> Slicer, specify directory where you want your slices to be saved and Apply.

What program does:

1.) It takes all rectangles you give, puts opacity 0, stroke to none.
2.) And tries to save contents inside rectangles to new files.
3.) Returns the style to original value.

Installation:

Copy these two files (slicer.py, slicer.inx) to share/extensions directory inside inkscape, do not create directory for these files.

Extensions dir in common platforms:
Ubuntu 8.10 user scope: ~/.inkscape/extensions/
Ubuntu 8.10 global scope: /usr/share/inkscape/extensions/
Windows: c:\Program Files\Inkscape\share\extensions\

Thanks

Original idea from Matt Harrison:
WARNING, Matt's version didn't work with latest Ubuntu (8.10) and Inkscape 0.46, major API differences, that was the reason I rewrote whole script with features I needed. I have no intention to ripoff Matt's effort, so I fully thank Matt for his work, and if you somehow feel that I have broken the license in Matt's file you can contact me through comments in this blog.

* Label allows all characters, where as ID allows only few. I need ability to use spaces in filenames so ID is no go. One can switch it to back to ID by changing line in slicer.py:
basename = rect_label.lstrip("#")
to
basename = rect_id

Thursday, February 12, 2009

Django and Eclipse

(When I have interest, I have planned to convert this to HTML, for now, let it be Plain text)
Anyone is welcome to edit, repost and/or distribute the following instructions, I just have a little wish: Provide link for this post.

Used: Eclipse Classic Ganymede (3.4.1), Django 1.0.2, PyDev

Install Pydev
=============
... TODO ...

Python interpreters (Eclipse preferences -> Pydev -> Interpreter - Python)
--------------------------------------------------------------------------
Press `New`
Type (Ubuntu) `/usr/bin/python`
Type (Windows) `C:\Python25\python.exe` *** Warning: not tested!
Press `Ok`
*IMPORTANT!*
If you have installed Django to site-packages
*UNCHECK* I repeat *UN*CHECK the Django from the Pythonpath list
(Or remove from the list)
(We are *NOT* going to use the site-packages django to this for development purposes)

Django project for Eclipse
==========================

File -> New -> Pydev project
Project name: `Django`
Grammar version: `2.5`
Uncheck `Create default `src` folder and add it to the pythonpath?`
Error about interpreter?: `Click here to configure an interpreter not listed` see above Install Pydev section


Pydev Package Explorer (the "file tree" on the left) -> Django (right click) -> Properties
PyDev - PYTHONPATH
Add source folder -> Choose `Django` (the project's "root" directory, for why, see (*1))

(Ubuntu) in terminal (go to your eclipse workspace directory):
cd Django/
svn co http://code.djangoproject.com/svn/django/tags/releases/1.0.2/ .

(Windows) Extract the django release to the Django/ dir:
(after extraction you should have directories like `Django/django`, `Django/examples`, `Django/docs` ...)

Pydev Package Explorer (the "file tree" on the left) -> Django (right click) -> Refresh (now zip some coffee, this might take while)

All is set for Django project.

(*1) Why root? Because for instance `django` and `examples` directories in django distribution should be in pythonpath and they are in root, this is only reasonable way since we won't relocate them.


My django project:
==================

VERY IMPORTANT! DO THE DAMN `Django project for Eclipse` section FIRST! SINCE YOU WON'T GET THE AUTOCOMPLETE/*PLUGGABLE DJANGO VERSION BETWEEN APPLICATIONS* WITHOUT IT.

File -> New -> Pydev project
Project name: `Django Poll`
Grammar version: `2.5`
*Check* I repeat *Check* (It should be checked by default) the `Create default `src` folder and add it to the pythonpath?`
Error about interpreter?: This can't be, you set it up on `Django project for Eclipse`
Click `Next`
(In reference page)
Check `Django` (the Django project you created earlier, remember that?)
Press `Finish`

Django-admin.py from within Eclipse:
------------------------------------

Run -> External tools -> External tools configurations
Left side tree: Right click `Program` -> New
Name: `Django-admin (for project src directory)`
Location (Ubuntu): `/bin/bash`
Location (Windows): `c:\Windows\system32\cmd.exe` *** Warning: Not tested
Working directory: `${project_loc}/src`

Environment tab:
New (from right)
Name: `PATH`
Value (Ubuntu): `${env_var:PATH}:${workspace_loc:Django/django/bin}`
Value (Windows): `${env_var:PATH};${workspace_loc:Django/django/bin}` *** Warning: Not tested
Click `Ok`
New (from right)
Name: `PYTHONPATH`
Value (Ubuntu): `${project_loc}/src:${workspace_loc:Django/}`
Value (Windows): `${project_loc}/src;${workspace_loc:Django/}` *** Warning: Not tested
Click `Ok`

Press `Apply` and `Close` (Don't try to Run, it will (most likely) give error)

Run -> External tools -> Organize favorites
Click `Add`
Choose `Django-admin (for project src directory)`
Click `Ok`
Click `Ok`

Now in order to run this tool one must do *TWO* things:

1.) Pydev Package Explorer (the "file tree" on the left) -> Click on the `Django Poll` project (even if it is selected, just click it (to get focus on it))

2.) Run -> External tools -> `Django-admin (for project src directory)`
*** If you get error about `Variable references empty selection: ${project_loc}`, you didn't do 1.) well enough, you *MUST* click it first and nothing else afterwards, the *project folder* in *Pydev Package Explorer* must have *focus* (being selected is not enough)!

Console window (if not visible do Window -> Show view -> Console), type:
`django-admin.py`

If all went well you should get something like: `Type django-admin.py help for usage.`

Following is from official django tutorial http://docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01

Console window, type:
`django-admin.py startproject mysite`

PyDev Package Explorer (the tree on the left) -> `Django Poll` (right click) -> Refresh
(If all worked well you should now have directory `src/mysite` in your project)

Manage.py from within Eclipse
-----------------------------

PyDev package explorer (tree in the left) -> `Django Poll` (your project name) -> src -> manage.py (right click) -> Properties
(You should be in dialog called `Properties for manage.py`)
Click `New...`
Choose `Python Run`
(For reason unknown Eclipse doesn't prepopulate the following fields)
Name: `Django Poll -- Custom manage.py` (Yes you read it right, I prefixed it with project name for extra verbosity)

Main tab (default tab):
Project click `Browse`, choose your project `Django Poll`
Main module click `Browse`, choose `src -> mysite -> manage.py`, click `Ok` (it should now read ${workspace_loc:Django Poll/src/mysite/manage.py} )

Arguments tab:
Press `Variables` (from Program arguments)
Choose `string_prompt`
(It should have added this `${string_prompt}`)
Click `Ok`
Click `Ok`
Click `Ok`


Running test:

Locate Run button from toolbar (Green play button, with arrow downwards next to it), press the arrow -> Choose `Organize Favorites`
Press `Add...`
Check the `Django Poll: Custom manage.py`

Run button (press the arrow) -> `Django Poll -- Custom manage.py`
(If all went well, you should be given prompt)
Type: `help`
(If all worked well, you should get long list of commands, beginning:

`Type 'manage.py help <subcommand>' for help on a specific subcommand.`
...)


Lets create app:

Run button press the arrow -> `Django Poll -- Custom manage.py`
Type: `startapp polls`

Now refresh your project directory from Pydev Package explorer (the tree in the left)
(If all worked well you should now have directory `src/mysite/polls` in your project)


Running the development server
------------------------------
Run button (press the arrow) -> `Django Poll -- Custom manage.py`
Type: `runserver --noreload`

(You can use it without `--noreload`, but the console window is rather useless in that case, since Eclipse can't handle the refresh behaviour of `manage.py`.)


Other Eclipse preferences (optional), though highly recommended
===============================================================

More run configurations
-----------------------
Since you most likely need manage.py's commands `runserver`, `syncdb`, `reset` the most, create own run configurations for those, using similar steps as in "Manage.py from within Eclipse" section.


Tasks of project
----------------

Window -> Show view -> Tasks

Tasks (little `downward triangle` before minimize of tasks window) -> Configure contents
Right side of the window: check `On any element in same project`
Left side of the window: check `TODOs`