]> SALOME platform Git repositories - tools/eficas.git/blob - Pmw/Pmw_1_2/demos/ScrolledText.py
Salome HOME
Modif V6_4_°
[tools/eficas.git] / Pmw / Pmw_1_2 / demos / ScrolledText.py
1 title = 'Pmw.ScrolledText demonstration'
2
3 # Import Pmw from this directory tree.
4 import sys
5 sys.path[:0] = ['../../..']
6
7 import os
8 import math
9 import string
10 import Tkinter
11 import Pmw
12
13 class Demo:
14     def __init__(self, parent):
15
16         # Create the ScrolledText with headers.
17         fixedFont = Pmw.logicalfont('Fixed')
18         self.st = Pmw.ScrolledText(parent,
19                 # borderframe = 1,
20                 labelpos = 'n',
21                 label_text='ScrolledText with headers',
22                 columnheader = 1,
23                 rowheader = 1,
24                 rowcolumnheader = 1,
25                 usehullsize = 1,
26                 hull_width = 400,
27                 hull_height = 300,
28                 text_wrap='none',
29                 text_font = fixedFont,
30                 Header_font = fixedFont,
31                 Header_foreground = 'blue',
32                 rowheader_width = 3,
33                 rowcolumnheader_width = 3,
34                 text_padx = 4,
35                 text_pady = 4,
36                 Header_padx = 4,
37                 rowheader_pady = 4,
38         )
39
40         self.st.pack(padx = 5, pady = 5, fill = 'both', expand = 1)
41
42         funcs = 'atan cos cosh exp log log10 sin sinh sqrt tan tanh'
43         funcs = string.split(funcs)
44
45         # Create the header for the row headers
46         self.st.component('rowcolumnheader').insert('end', 'x')
47
48         # Create the column headers
49         headerLine = ''
50         for column in range(len(funcs)):
51             headerLine = headerLine + ('%-7s   ' % (funcs[column],))
52         headerLine = headerLine[:-3]
53         self.st.component('columnheader').insert('0.0', headerLine)
54
55         self.st.tag_configure('yellow', background = 'yellow')
56
57         # Create the data rows and the row headers
58         numRows = 50
59         tagList = []
60         for row in range(1, numRows):
61             dataLine = ''
62             x = row / 5.0
63             for column in range(len(funcs)):
64                 value = eval('math.' + funcs[column] + '(' + str(x) + ')')
65                 data = str(value)[:7]
66                 if value < 0:
67                     tag1 = '%d.%d' % (row, len(dataLine))
68                     tag2 = '%d.%d' % (row, len(dataLine) + len(data))
69                     tagList.append(tag1)
70                     tagList.append(tag2)
71                 data = '%-7s' % (data,)
72                 dataLine = dataLine + data + '   '
73             dataLine = dataLine[:-3]
74             header = '%.1f' % (x,)
75             if row < numRows - 1:
76                 dataLine = dataLine + '\n'
77                 header = header + '\n'
78             self.st.insert('end', dataLine)
79             self.st.component('rowheader').insert('end', header)
80         apply(self.st.tag_add, ('yellow',) + tuple(tagList))
81
82         # Prevent users' modifying text and headers
83         self.st.configure(
84             text_state = 'disabled',
85             Header_state = 'disabled',
86         )
87
88 ######################################################################
89
90 # Create demo in root window for testing.
91 if __name__ == '__main__':
92     root = Tkinter.Tk()
93     Pmw.initialise(root)
94     root.title(title)
95
96     exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
97     exitButton.pack(side = 'bottom')
98     widget = Demo(root)
99     root.mainloop()