Back to index

python3.2  3.2.2
Classes | Functions | Variables
ss1 Namespace Reference

Classes

class  Sheet
class  SheetParser
class  BaseCell
class  NumericCell
class  StringCell
class  FormulaCell
class  SheetGUI

Functions

def ljust
def center
def rjust
def sum
def translate
def cellname
def colname2num
def colnum2name
def test_basic
def test_gui
 if os.path.isfile("sheet1.xml"): print "Loading from sheet1.xml" a.load("sheet1.xml")

Variables

dictionary align2action = {LEFT: ljust, CENTER: center, RIGHT: rjust}
dictionary align2xml = {LEFT: "left", CENTER: "center", RIGHT: "right"}
dictionary xml2align = {"left": LEFT, "center": CENTER, "right": RIGHT}
dictionary align2anchor = {LEFT: "w", CENTER: "center", RIGHT: "e"}

Function Documentation

def ss1.cellname (   x,
  y 
)

Definition at line 466 of file ss1.py.

00466 
00467 def cellname(x, y):
00468     "Translate a cell coordinate to a fancy cell name (e.g. (1, 1)->'A1')."
00469     assert x > 0 # Column 0 has an empty name, so can't use that
00470     return colnum2name(x) + str(y)

Here is the call graph for this function:

Here is the caller graph for this function:

def ss1.center (   x,
  n 
)

Definition at line 17 of file ss1.py.

00017 
00018 def center(x, n):
    return x.center(n)

Here is the caller graph for this function:

def ss1.colname2num (   s)

Definition at line 471 of file ss1.py.

00471 
00472 def colname2num(s):
00473     "Translate a column name to number (e.g. 'A'->1, 'Z'->26, 'AA'->27)."
00474     s = s.upper()
00475     n = 0
00476     for c in s:
00477         assert 'A' <= c <= 'Z'
00478         n = n*26 + ord(c) - ord('A') + 1
00479     return n

Here is the call graph for this function:

Here is the caller graph for this function:

def ss1.colnum2name (   n)

Definition at line 480 of file ss1.py.

00480 
00481 def colnum2name(n):
00482     "Translate a column number to name (e.g. 1->'A', etc.)."
00483     assert n > 0
00484     s = ""
00485     while n:
00486         n, m = divmod(n-1, 26)
00487         s = chr(m+ord('A')) + s
00488     return s

Here is the call graph for this function:

Here is the caller graph for this function:

def ss1.ljust (   x,
  n 
)

Definition at line 15 of file ss1.py.

00015 
00016 def ljust(x, n):
    return x.ljust(n)

Here is the caller graph for this function:

def ss1.rjust (   x,
  n 
)

Definition at line 19 of file ss1.py.

00019 
00020 def rjust(x, n):
    return x.rjust(n)

Here is the caller graph for this function:

def ss1.sum (   seq)

Definition at line 28 of file ss1.py.

00028 
00029 def sum(seq):
00030     total = 0
00031     for x in seq:
00032         if x is not None:
00033             total += x
00034     return total

def ss1.test_basic ( )

Definition at line 813 of file ss1.py.

00813 
00814 def test_basic():
00815     "Basic non-gui self-test."
00816     import os
00817     a = Sheet()
00818     for x in range(1, 11):
00819         for y in range(1, 11):
00820             if x == 1:
00821                 cell = NumericCell(y)
00822             elif y == 1:
00823                 cell = NumericCell(x)
00824             else:
00825                 c1 = cellname(x, 1)
00826                 c2 = cellname(1, y)
00827                 formula = "%s*%s" % (c1, c2)
00828                 cell = FormulaCell(formula)
            a.setcell(x, y, cell)

Here is the call graph for this function:

def ss1.test_gui ( )

if os.path.isfile("sheet1.xml"): print "Loading from sheet1.xml" a.load("sheet1.xml")

Definition at line 835 of file ss1.py.

00835 
00836 def test_gui():
00837     "GUI test."
00838     if sys.argv[1:]:
00839         filename = sys.argv[1]
00840     else:
00841         filename = "sheet1.xml"
00842     g = SheetGUI(filename)
00843     g.root.mainloop()

def ss1.translate (   formula)
Translate a formula containing fancy cell names to valid Python code.

Examples:
    B4 -> cell(2, 4)
    B4:Z100 -> cells(2, 4, 26, 100)

Definition at line 443 of file ss1.py.

00443 
00444 def translate(formula):
00445     """Translate a formula containing fancy cell names to valid Python code.
00446 
00447     Examples:
00448         B4 -> cell(2, 4)
00449         B4:Z100 -> cells(2, 4, 26, 100)
00450     """
00451     out = []
00452     for part in re.split(r"(\w+(?::\w+)?)", formula):
00453         m = re.match(r"^([A-Z]+)([1-9][0-9]*)(?::([A-Z]+)([1-9][0-9]*))?$", part)
00454         if m is None:
00455             out.append(part)
00456         else:
00457             x1, y1, x2, y2 = m.groups()
00458             x1 = colname2num(x1)
00459             if x2 is None:
00460                 s = "cell(%s, %s)" % (x1, y1)
00461             else:
00462                 x2 = colname2num(x2)
00463                 s = "cells(%s, %s, %s, %s)" % (x1, y1, x2, y2)
00464             out.append(s)
00465     return "".join(out)

Here is the call graph for this function:


Variable Documentation

dictionary ss1.align2action = {LEFT: ljust, CENTER: center, RIGHT: rjust}

Definition at line 21 of file ss1.py.

dictionary ss1.align2anchor = {LEFT: "w", CENTER: "center", RIGHT: "e"}

Definition at line 26 of file ss1.py.

dictionary ss1.align2xml = {LEFT: "left", CENTER: "center", RIGHT: "right"}

Definition at line 23 of file ss1.py.

dictionary ss1.xml2align = {"left": LEFT, "center": CENTER, "right": RIGHT}

Definition at line 24 of file ss1.py.