tixgrid added

--HG--
branch : aspn
This commit is contained in:
baloan
2014-02-05 19:45:44 +01:00
parent a4221e12a7
commit 0844b8e8fc
2 changed files with 2250 additions and 0 deletions

2151
tixgrid/Tix.py Normal file

File diff suppressed because it is too large Load Diff

99
tixgrid/test.py Normal file
View File

@@ -0,0 +1,99 @@
from Tix import *
root = Tk()
sg = ScrolledGrid(root)
sg.pack(fill='both', expand=1)
g = sg.grid_# sg.grid_ == sg.subwidget('grid') ; the usual shortcut sg.grid does not work here, because of the grid() geometry method
def on_size():
print 'sizecmd called'
g.config(selectunit='cell', sizecmd=on_size)
# define a bunch of cells
for i in range(5):
for j in range(8):
if i == 0 and j == 0:
newtext = ''
elif i == 0:
newtext = j
elif j == 0:
newtext = i
else:
newtext = 'column %d -- row %d'%(i, j)
g.set(i, j, itemtype='text', text=newtext)
# shows how to query the size of a row or column
g.size_column('default', size='auto', pad0=5, pad1=10)
print 'size of column 1:', g.size_column(1), '\n'
# this shows how to use edit_xxx() and format() - commands
def edit_done(x, y):
new = g.entrycget(x, y, 'text')
print 'Cell %s, %s : new text "%s"' %(x, y, new)
def edit_notify(x, y):
try:
if x == '0' or y == '0':
return 0
old = g.entrycget(x, y, 'text')
print 'Cell %s, %s : old text "%s"' %(x, y, old)
return 1
except TclError:
# a mouse-click beyond the defined cells
return 0
def format(region, x0, y0, x1, y1):
if region in ('x-margin', 'y-margin', 's-margin'):
g.format_border(x0, y0, x1, y1, relief='raised', bd=1, bg='black')
elif region == 'main':
g.format_grid(x0, y0, x1, y1, bg='white', bordercolor='gray80', filled=1)
g.config(editdonecmd=edit_done, editnotifycmd=edit_notify, formatcmd=format)
# this shows how to change two column's position
#g.move('column', 1, 1, 7)
#g.move('column', 0, 0, 1)
#g.move('column', 8, 8, -8)
#
# this shows how to use the anchor_() methods
g.anchor_set( 'end', 4)
print 'anchor_get() returns:', g.anchor_get()
g.anchor_clear()
print 'anchor_get() returns:', g.anchor_get(), '\n'
# this shows how to use sort_xxx()
def sortcmd(a, b):
print a, b
if a < b:
return 1
return 0
def do_sort(event):
g.sort_row(1, 3, command=sortcmd, key=0)
g.bind('<F4>', do_sort)
# this shows how to use nearest() geometryinfo() and info_exists()
def nearest(ev):
print 'event.x: %d, event.y: %d, nearest cell:' % (ev.x, ev.y), g.nearest(ev.x, ev.y)
print 'Cell at %d, %d exists: ' % (ev.x, ev.y), g.info_exists(*g.nearest(ev.x, ev.y))
print 'geometryinfo(%d, %d): ' % (ev.x, ev.y), g.geometryinfo(ev.x, ev.y)# ???
g.bind('<3>', nearest)
# dragsite and dropsite commands seem to work, but what to do with them?
g.dropsite_set(0, 0)
g.dragsite_set(1,1)
print 'dragsite:', g.dragsite_get(), 'dropsite:', g.dropsite_get()
# selection
g.select_clear()
g.select_set(1, 1)
g.select_adjust(2, 2, 3, 3)
root.mainloop()