~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to ext/tk/sample/tkextlib/tktable/debug.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
##
 
3
## debug.rb
 
4
##
 
5
## This demo uses most features of the table widget
 
6
##
 
7
## ( based on 'debug.tcl' included source archive of tktable extension )
 
8
##
 
9
require 'tk'
 
10
require 'tkextlib/tktable'
 
11
 
 
12
# create the table
 
13
ary  = TkVariable.new_hash
 
14
rows = 25
 
15
cols = 20
 
16
 
 
17
# fill table variable
 
18
((-(rows))..rows).each{|x|
 
19
  ((-(cols))..cols).each{|y|
 
20
    ary[x,y] = "r#{x},c#{y}"
 
21
  }
 
22
}
 
23
 
 
24
lbl = TkLabel.new(:text=>"TkTable v2 Example")
 
25
 
 
26
table = Tk::TkTable.new(:rows=>rows, :cols=>cols, :variable=>ary, 
 
27
                        :width=>6, :height=>6, 
 
28
                        :titlerows=>1, :titlecols=>2, 
 
29
                        :roworigin=>-5, :colorigin=>-2, 
 
30
                        :coltagcommand=>proc{|col|
 
31
                          col = Integer(col)
 
32
                          (col>0 && col%2 == 1)? 'OddCol': ''
 
33
                        }, 
 
34
                        :selectmode=>:extended, :flashmode=>true, 
 
35
                        :rowstretch=>:unset, :colstretch=>:unset,
 
36
                        :selecttitles=>false, :drawmode=>:single)
 
37
 
 
38
sx = table.xscrollbar(TkScrollbar.new)
 
39
sy = table.yscrollbar(TkScrollbar.new)
 
40
 
 
41
btn = TkButton.new(:text=>'Exit', :command=>proc{exit})
 
42
 
 
43
Tk.grid(lbl, '-', :sticky=>:ew)
 
44
Tk.grid(table, sy, :sticky=>:news)
 
45
Tk.grid(sx, :sticky=>:ew)
 
46
Tk.grid(btn, :sticky=>:ew, :columnspan=>2)
 
47
 
 
48
Tk.root.grid_columnconfig(0, :weight=>1)
 
49
Tk.root.grid_rowconfig(1, :weight=>1)
 
50
 
 
51
table.tag_configure('OddCol', :bg=>'brown', :fg=>'pink')
 
52
table.tag_configure('title',  :bg=>'red',   :fg=>'green', :relief=>:sunken)
 
53
table.tag_configure('dis',    :state=>:disabled)
 
54
 
 
55
first = table[:colorigin]
 
56
%w(n s e w nw ne sw se c).each_with_index{|anchor, idx|
 
57
  table.tag_configure(anchor, :anchor=>anchor)
 
58
  table.tag_row(anchor, idx)
 
59
  table.set([idx,first], anchor)
 
60
}
 
61
courier = TkFont.new(:family=>'Courier', :size=>10)
 
62
table.tag_configure('s', :font=>courier, :justify=>:center)
 
63
 
 
64
logo = TkPhotoImage.new(:file=>File.join(File.dirname(File.expand_path(__FILE__)), 'tcllogo.gif'))
 
65
table.tag_configure('logo', :image=>logo, :showtext=>true)
 
66
table.tag_cell('logo', [1,2], [2,3], [4,1])
 
67
table.tag_cell('dis', [2,1], [1,-1], [3,0])
 
68
table.set_width([-2,8], [-1,9], [0, 12], [4, 14])
 
69
 
 
70
table.set([1,1], "multi-line\ntext\nmight be\ninteresting", 
 
71
          [3,2], "more\nmulti-line\nplaying\n", 
 
72
          [2,2], "null\0byte")
 
73
 
 
74
# This is in the row span
 
75
l = TkLabel.new(table, :text=>'Window s', :bg=>'yellow')
 
76
table.window_configure([6,0], :sticky=>:s, :window=>l)
 
77
 
 
78
# This is in the row titles
 
79
l = TkLabel.new(table, :text=>'Window ne', :bg=>'yellow')
 
80
table.window_configure([4,-1], :sticky=>:ne, :window=>l)
 
81
 
 
82
# This will get swallowed by a span
 
83
l = TkLabel.new(table, :text=>'Window ew', :bg=>'yellow')
 
84
table.window_configure([5,3], :sticky=>:ew, :window=>l)
 
85
 
 
86
# This is in the col titles
 
87
l = TkLabel.new(table, :text=>'Window news', :bg=>'yellow')
 
88
table.window_configure([-5,1], :sticky=>:news, :window=>l)
 
89
 
 
90
l = TkLabel.new(table.winfo_parent, :text=>'Sibling l', :bg=>'orange')
 
91
table.window_configure([5,1], :sticky=>:news, :window=>l)
 
92
 
 
93
if table.span_list.empty?
 
94
  table.set_spans([-1,-2], [0,3], [1,2], [0,5], [3,2], [2,2], [6,0], [4,0])
 
95
end
 
96
 
 
97
puts "Table is #{table.path} with array #{(table['variable'])}"
 
98
 
 
99
# table.postscript(:file=>'out.ps', :first=>:origin, :last=>[2,2])
 
100
 
 
101
Tk.mainloop