Re: Render a xml graph as an image

2009-11-27 Thread David Williams
Maybe I am missing something, but according to this example,
http://code.google.com/p/python-graph/wiki/Example, python-graph can
export to at least PNG format.  Another option, transform the XML into
GraphML (http://graphml.graphdrawing.org/) using XSLT (assuming it is not
already in that format), and then to SVG
(http://www.w3.org/Graphics/SVG/).  From there it should be easy to either
directly display or get it into any bitmap format you want.  On the
GraphML website their is an XSL to transform GraphML to SVG.

David

> hi all.
>  Am looking to display a graph as an image.. the graph is in the
> format of a xml file(basically the output of a python-graph
> package).. Is there a package that already does it??
> ==
> Anand J
> http://sites.google.com/a/cbcs.ac.in/students/anand
> ==
> The man who is really serious,
> with the urge to find out what truth is,
> has no style at all. He lives only in what is.
>  ~Bruce Lee
>
> Love is a trade with no accounting policies.
> ~Aang Jie
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a 100-line indentation-based preprocessor for HTML

2009-11-27 Thread David Williams
You might want to take a look at this:

http://www.ghrml.org/

David

> Python has this really neat idea called indentation-based syntax, and
> there are folks that have caught on to this idea in the HTML
> community.
>
> AFAIK the most popular indentation-based solution for generating HTML
> is a tool called HAML, which actually is written in Ruby.
>
> I have been poking around with the HAML concepts in Python, with the
> specific goal of integrating with Django.   But before releasing that,
> I thought it would be useful to post code that distills the basic
> concept with no assumptions about your target renderer.  I hope it
> also serves as a good example of what you can do in exactly 100 lines
> of Python code.
>
> Here is what it does...
>
> You can use indentation syntax for HTML tags like table.
>
> From this...
>
> table
> tr
> td
> Left
> td
> Center
> td
> Right
>
> ...you get this:
>
> 
> 
> 
> Left
> 
> 
> Center
> 
> 
> Right
> 
> 
> 
>
> Lists and divs work the same way, and note that attributes are not
> a problem.
>
> From this...
>
> div class="spinnable"
> ul
> li id="item1"
>One
> li id="item2"
>Two
>
> ...you get this:
>
> 
> 
> 
>One
> 
> 
>Two
> 
> 
> 
>
> You can still use raw HTML tags where appropriate (such as when
> converting
> legacy markup to the new style).
>
> From this...
>
> 
> tr
> td
> Hello World!
> 
>
> ...you get this:
>
> 
> 
> 
> Hello World!
> 
> 
> 
>
> And here is the code:
>
> import re
>
> def convert_text(in_body):
> '''
> Convert HAML-like markup to HTML.  Allow raw HTML to
> fall through.
> '''
> indenter = Indenter()
> for prefix, line, kind in get_lines(in_body):
> if kind == 'branch' and '<' not in line:
> html_block_tag(prefix, line, indenter)
> else:
> indenter.add(prefix, line)
> return indenter.body()
>
>
> def html_block_tag(prefix, line, indenter):
> '''
> Block tags have syntax like this and only
> apply to branches in indentation:
>
> table
> tr
> td class="foo"
> leaf #1
> td
> leaf #2
> '''
> start_tag = '<%s>' % line
> end_tag = '' % line.split()[0]
> indenter.push(prefix, start_tag, end_tag)
>
>
> class Indenter:
> '''
> Example usage:
>
> indenter = Indenter()
> indenter.push('', 'Start', 'End')
> indenter.push('', 'Foo', '/Foo')
> indenter.add ('', 'bar')
> indenter.add ('', 'yo')
> print indenter.body()
> '''
> def __init__(self):
> self.stack = []
> self.lines = []
>
> def push(self, prefix, start, end):
> self.add(prefix, start)
> self.stack.append((prefix, end))
>
> def add(self, prefix, line):
> if line:
> self.pop(prefix)
> self.insert(prefix, line)
>
> def insert(self, prefix, line):
> self.lines.append(prefix+line)
>
> def pop(self, prefix):
> while self.stack:
> start_prefix, end =  self.stack[-1]
> if len(prefix) <= len(start_prefix):
> whitespace_lines = []
> while self.lines and self.lines[-1] == '':
> whitespace_lines.append(self.lines.pop())
> self.insert(start_prefix, end)
> self.lines += whitespace_lines
> self.stack.pop()
> else:
> return
>
> def body(self):
> self.pop('')
> return '\n'.join(self.lines)
>
> def get_lines(in_body):
> '''
> Splits out lines from a file and identifies whether lines
> are branches, leafs, or blanks.  The detection of branches
> could probably be done in a more elegant way than patching
> the last non-blank line, but it works.
> '''
> lines = []
> last_line = -1
> for line in in_body.split('\n'):
> m = re.match('(\s*)(.*)', line)
> prefix, line = m.groups()
> if line:
> line = line.rstrip()
> if last_line >= 0:
> old_prefix, old_line, ignore = lines[last_line]

Re: TypeError: can only concatenate list (not "tuple") to list

2010-01-04 Thread David Williams
> Is there any reason for this error? Apart from "nobody cared to write the
> code"
>
> py> [1,2,3] + (4,5)
> Traceback (most recent call last):
>  File "", line 1, in 
> TypeError: can only concatenate list (not "tuple") to list
>
> In-place addition += does work:
>
> py> a = [1,2,3]
> py> a += (4,5)
> py> a
> [1, 2, 3, 4, 5]
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

They are different types.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: can only concatenate list (not "tuple") to list

2010-01-04 Thread David Williams

> Is there any reason for this error? Apart from "nobody cared to write the
> code"
>
> py> [1,2,3] + (4,5)
> Traceback (most recent call last):
>  File "", line 1, in 
> TypeError: can only concatenate list (not "tuple") to list
>
> In-place addition += does work:
>
> py> a = [1,2,3]
> py> a += (4,5)
> py> a
> [1, 2, 3, 4, 5]
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


I guess to expand a bit more on what I said...  What should the result be?
 A list or a tuple?  The reason += works is because the end result is
clear; a list.  But it is ambiguous in the case of concatenation: did you
want a tuple or a list?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Editing PDF files usig Python

2009-11-07 Thread David Williams
Maybe try ReportLab, its pretty much the most advanced Python PDF toolkit
I know of:

http://www.reportlab.org/

> Hi All,
>
> Greetings,
>
> I am a newbie in Python, i have a requirement to develop a component in
> python that can "text" water mark the PDF file both digitallly and
> visibly.
> I have already devloped this kind of a component in .Net using iTextSharp
> library. So i know a thing or 2 about water marking :-)
> i also need to able to read back the water mark text that was put in to
> the
> PDF (both digital and visible).
>
> I looked around on google and found that pyPDF, win32Client etc which may
> be
> the one i will have to use. using neither of them i could put a text and
> hidden text in to the pdf files. Any light thrown in this direction will
> be
> of great help to me. Appcreciate your help with this.
>
> Thanks
> Subrah
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://mail.python.org/mailman/listinfo/python-list