MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / Sheet

Class Sheet

tools/python-3.11.9-amd64/Tools/demo/spreadsheet.py:35–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33 return total
34
35class Sheet:
36
37 def __init__(self):
38 self.cells = {} # {(x, y): cell, ...}
39 self.ns = dict(
40 cell = self.cellvalue,
41 cells = self.multicellvalue,
42 sum = sum,
43 )
44
45 def cellvalue(self, x, y):
46 cell = self.getcell(x, y)
47 if hasattr(cell, 'recalc'):
48 return cell.recalc(self.ns)
49 else:
50 return cell
51
52 def multicellvalue(self, x1, y1, x2, y2):
53 if x1 > x2:
54 x1, x2 = x2, x1
55 if y1 > y2:
56 y1, y2 = y2, y1
57 seq = []
58 for y in range(y1, y2+1):
59 for x in range(x1, x2+1):
60 seq.append(self.cellvalue(x, y))
61 return seq
62
63 def getcell(self, x, y):
64 return self.cells.get((x, y))
65
66 def setcell(self, x, y, cell):
67 assert x > 0 and y > 0
68 assert isinstance(cell, BaseCell)
69 self.cells[x, y] = cell
70
71 def clearcell(self, x, y):
72 try:
73 del self.cells[x, y]
74 except KeyError:
75 pass
76
77 def clearcells(self, x1, y1, x2, y2):
78 for xy in self.selectcells(x1, y1, x2, y2):
79 del self.cells[xy]
80
81 def clearrows(self, y1, y2):
82 self.clearcells(0, y1, sys.maxsize, y2)
83
84 def clearcolumns(self, x1, x2):
85 self.clearcells(x1, 0, x2, sys.maxsize)
86
87 def selectcells(self, x1, y1, x2, y2):
88 if x1 > x2:
89 x1, x2 = x2, x1
90 if y1 > y2:
91 y1, y2 = y2, y1
92 return [(x, y) for x, y in self.cells

Callers 2

__init__Method · 0.85
test_basicFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_basicFunction · 0.68