Class: TkTreeCtrl_demo

Inherits:
Object show all
Defined in:
sample/tkextlib/treectrl/demo.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ TkTreeCtrl_demo

Returns a new instance of TkTreeCtrl_demo.



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
# File 'sample/tkextlib/treectrl/demo.rb', line 25

def initialize(dir)
  @ScriptDir = dir || '.'

  @thisPlatform = Tk::PLATFORM['platform']
  if @thisPlatform == 'unix' && Tk.windowingsystem == 'aqua'
    @thisPlatform = 'macosx'
  end

  @RandomN = [500]

  @images = Hash.new
  @sel_images = Hash.new

  @popup = Hash.new
  @mTree = Hash.new
  @mHeader = Hash.new

  @non_clear_list = []

  @demoCmd = Hash.new
  @demoFile = Hash.new

  # Get default colors
  w = TkListbox.new
  @SystemButtonFace    = w[:highlightbackground]
  @SystemHighlight     = w[:selectbackground]
  @SystemHighlightText = w[:selectforeground]
  w.destroy

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

  make_source_window()
  make_menubar()
  make_main_window()

  if $Version_1_1_OrLater
    begin
      @tree2[:backgroundimage]
      @has_bgimg = true
    rescue
      @has_bgimg = false
    end
  else
    @has_bgimg = false
  end

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

  make_list_popup()
  make_header_popup()

  init_pics('sky')

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

  @tree2.bind('ButtonPress-3',
              proc{|w, x, y, rootx, rooty|
                show_list_popup(w, x, y, rootx, rooty)
              }, '%W %x %y %X %Y')

  # Allow "scan" bindings
  if @thisPlatform == 'windows'
    @tree2.bind_remove('Control-ButtonPress-3')
  end

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

  init_demo_scripts_module()
  load_demo_scripts()
  init_demo_list()

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

  @tree1.notify_bind(@tree1, 'Selection',
                     proc{|c, t|
                       if c == 1
                         item = t.selection_get[0]
                         demo_set(@demoCmd[item], @demoFile[item])
                       end
                     }, '%c %T')

  # When one item is selected in the demo list, display the styles in
  # that item.
  # See DemoClear for why the tag "DontDelete" is used
  @tree2.notify_bind('DontDelete', 'Selection',
                     proc{|c, t|
                       display_styles_in_item(t.selection_get[0]) if c == 1
                     }, '%c %T')
end

Instance Method Details

#init_pics(*args) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'sample/tkextlib/treectrl/demo.rb', line 117

def init_pics(*args)
  args.each{|pat|
    unless TkImage.names.find{|img| (name = @images.key(img)) && File.fnmatch(pat, name)}
      Dir.glob(File.join(@ScriptDir, 'pics', "#{pat}.gif")).each{|file|
        name = File.basename(file, '.gif')
        img = TkPhotoImage.new(:file=>file)
        @images[name] = img
        @sel_images[name] = TkPhotoImage.new
        @sel_images[name].copy(img)
        Tk::TreeCtrl.image_tint(@sel_images[name], @SystemHighlight, 128)
      }
    end
  }
end