Sha256: 84214d30bc818c8e51c40a03efc95b08b1feb3b79c9f99aa2a4c9a6d45cf1748

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

#!/usr/bin/env ruby

require "bundler/setup"
require "tk_component"
require "pry"

class DataSource
  @@shared_data_source = nil

  def self.shared
    @@shared_data_source ||= self.new
  end

  def items_for_path(path)
    path = [] if path.blank?
    path_str = File.join(ENV['HOME'], *path)
    return nil unless Dir.exist?(path_str)
    Dir.children(path_str)
  end

  def title_for_path(path, items)
    path.blank? ? ENV['HOME'] : path.last
  end
end
  
class DemoRoot < TkComponent::Base
  def render(p, parent_component)
    p.vframe(sticky: 'wens', x_flex: 1, y_flex: 1) do |f|
      f.label(text: "Directory of #{DataSource.shared.title_for_path(nil, [])}")
      f.insert_component(TkComponent::BrowserComponent, self,
                         data_source: DataSource.shared,
                         paned: true,
                         sticky: 'nsew', x_flex: 1, y_flex: 1) do |bc|
        bc.on_event'PathChanged', ->(e) do
          puts "PathChanged: " + e.data_object.selected_path.to_s
        end
      end
    end
  end
end

@tk_root = TkComponent::Window.new(title: "BrowserComponent Demo", root: true)
@main_component = DemoRoot.new
@tk_root.place_root_component(@main_component)

Tk.mainloop

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tk_component-0.2.0 bin/browser_demo.rb