summaryrefslogtreecommitdiff
path: root/ext/tk/lib/tkextlib/blt.rb
blob: 965886762eb82e2541316affc3af383703bcb1ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#
#  BLT support
#                               by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#

require 'tk'
require 'tk/variable'

# call setup script for general 'tkextlib' libraries
require 'tkextlib/setup.rb'

# call setup script
require 'tkextlib/blt/setup.rb'

# load all image format handlers
#TkPackage.require('BLT', '2.4')
TkPackage.require('BLT')

module Tk
  module BLT
    TkComm::TkExtlibAutoloadModule.unshift(self)

    extend TkCore

    VERSION = tk_call('set', 'blt_version')
    PATCH_LEVEL = tk_call('set', 'blt_patchLevel')

    begin
      lib = INTERP._invoke('set', 'blt_library')
    rescue
      lib = ''
    end
    LIBRARY  = TkVarAccess.new('blt_library', lib)

    begin
      lib = INTERP._invoke('set', 'blt_libPath')
    rescue
      lib = ''
    end
    LIB_PATH = TkVarAccess.new('blt_libPath', lib)
    

    def self.package_version
      begin
        TkPackage.require('BLT')
      rescue
        ''
      end
    end

    ####################################################

    def self.beep(percent = 50)
      tk_call('::blt::beep', percent)
    end

    def self.bgexec(*args)
      if args[0].kind_of?(TkVariable)
        var = args.shift
      else
        var = TkVariable.new
      end
      params = [var]

      params.concat(hash_kv(args.shift, true)) if args[0].kind_of?(Hash)

      params << '--'
      params.concat(args)

      tk_call('::blt::bgexec', *params)
      var
    end

    def self.detach_bgexec(*args)
      if args[0].kind_of?(TkVariable)
        var = args.shift
      else
        var = TkVariable.new
      end
      params = [var]

      params.concat(hash_kv(args.shift, true)) if args[0].kind_of?(Hash)

      params << '--'
      params.concat(args)
      params << '&'

      [var, tk_split_list(tk_call('::blt::bgexec', *params))]
    end

    def self.bltdebug(lvl = nil)
      if lvl
        tk_call('::blt::bltdebug', lvl)
      else
        number(tk_call('::blt::bltdebug'))
      end
    end

    def self.crc32_file(name)
      tk_call_without_enc('::blt::crc32', name)
    end
    def self.crc32_data(dat)
      tk_call_without_enc('::blt::crc32', '-data', dat)
    end

    ####################################################

    autoload :PlotComponent,'tkextlib/blt/component.rb'

    autoload :Barchart,     'tkextlib/blt/barchart.rb'
    autoload :Bitmap,       'tkextlib/blt/bitmap.rb'
    autoload :Busy,         'tkextlib/blt/busy.rb'
    autoload :Container,    'tkextlib/blt/container.rb'
    autoload :CutBuffer,    'tkextlib/blt/cutbuffer.rb'
    autoload :DragDrop,     'tkextlib/blt/dragdrop.rb'
    autoload :EPS,          'tkextlib/blt/eps.rb'
    autoload :Htext,        'tkextlib/blt/htext.rb'
    autoload :Graph,        'tkextlib/blt/graph.rb'
    autoload :Spline,       'tkextlib/blt/spline.rb'
    autoload :Stripchart,   'tkextlib/blt/stripchart.rb'
    autoload :Table,        'tkextlib/blt/table.rb'
    autoload :Tabnotebook,  'tkextlib/blt/tabnotebook.rb'
    autoload :Tabset,       'tkextlib/blt/tabset.rb'
    autoload :Ted,          'tkextlib/blt/ted.rb'
    autoload :Tile,         'tkextlib/blt/tile.rb'
    autoload :Tree,         'tkextlib/blt/tree.rb'
    autoload :TreeView,     'tkextlib/blt/treeview.rb'
    autoload :Hiertable,    'tkextlib/blt/treeview.rb'
    # Hierbox is obsolete
    autoload :Vector,       'tkextlib/blt/vector.rb'
    autoload :VectorAccess, 'tkextlib/blt/vector.rb'
    autoload :Watch,        'tkextlib/blt/watch.rb'
    autoload :Winop,        'tkextlib/blt/winop.rb'
    autoload :WinOp,        'tkextlib/blt/winop.rb'

    # Unix only
    autoload :DnD,          'tkextlib/blt/unix_dnd.rb'

    # Windows only
    autoload :Printer,      'tkextlib/blt/win_printer.rb'
  end
end