# File karel/karel_window.rb, line 134
  def initialize(streets, avenues, size = $windowBottom, callback = nil)
    super()
    
    @root = TkRoot.new{
        title  ' Karel\'s World '
        width size + 60
        height size
        background 'white'
    }

    $windowBottom = size
    @height = size
    geometryString = ($windowBottom + 80).to_s + 'x' + ($windowBottom + 65).to_s + "+55+25" # 820 + 60 for the speed buttons
    @root.geometry(newGeometry = geometryString)
    
    bar = TkMenu.new
    def end_program(menu)
       exit()
    end
            
        fil = TkMenu.new
        fil.add_command(:label => 'Quit   ^Q', :command => lambda {|x='Quit'| end_program(x)})
        bar.add_cascade(:label => :File, :menu => fil)
        @root.configure(:menu =>  bar)   
        
        bind_all('Command-q'){end_program('Command-q')} # Mac standard
        bind_all('Control-q'){end_program('Control-q')} # Windows
        bind_all('Destroy'){end_program('Window Closed')}
        
        @_streets = streets
        @_avenues = streets # sic Avenues ignored
        @_gBeepers = {} #locations of the beeper imagess
        @_contents = [] # , walls, beepers that need to move on a rescale
        @_robots = []
        @_walls = [] 
        top = winfo_toplevel()
        TkGrid.rowconfigure(top, 2, :weight => 1)
        TkGrid.columnconfigure(top, 0, :weight => 1)
        
        TkGrid.rowconfigure(self, 2, :weight => 1)
        TkGrid.columnconfigure(self, 0, :weight => 1)
        
        
        TkGrid.rowconfigure(@root, 2, :weight => 1)
        TkGrid.columnconfigure(@root, 0, :weight => 1)
        
        @speedLevel = TkLabel.new(:text => "Speed " + (100-@@delay).to_s)
        @speedLevel.grid(:row => 0, :column => 0, :sticky=>"news")

        slower = TkButton.new(:text => "Slower", :command => lambda{
          @@delay = [@@delay + 10, 100].min
          RobotWorld.set_speed 100 - @@delay
          })
        slower.grid(:row => 0, :column => 1)
        
        faster = TkButton.new(:text => "Faster", :command => lambda{
          @@delay = [@@delay - 10, 0].max
          RobotWorld.set_speed 100 - @@delay
           })
        faster.grid(:row => 1, :column => 1)
        
        # @iv = TkVariable.new
        # @iv.value = 20
         
        # if callback
            # @iv.trace('r', callback)
            # @scale = Scale.new(:orient => 'horizontal')
             
            # # @scale.variable(@iv)
            # @scale.set(20)
            # @scale.grid(:row => 1, :column => 0, :sticky=>"ns")
        # end
        @height = @oldHeight = $windowBottom
        @_bottom = $windowBottom - $inset
        @_left = $inset
        @_top = $inset
        @_right = @height
        @inset = $inset
        
        @canvas = Canvas.new(root, :height => $windowBottom, :width => $windowBottom, :bg => 'white')
     # @canvas.cursor "X_cursor" # Set a new cursor
     # @canvas.cursor "dot" # Set a new cursor
     # @canvas.cursor "right_side" # Set a new cursor
     # @canvas.cursor "top_side" # Set a new cursor
     # @canvas.update # Make sure it updates  the screen
      # @canvas.pack
        @canvas.grid(:row => 2, :column => 0, :sticky=>"news")
        image1 = TkPhotoImage.new(:file => $images_base+'kareln.gif')
        image2 = TkPhotoImage.new(:file => $images_base+'karelw.gif')
        image3 = TkPhotoImage.new(:file => $images_base+'karels.gif')
        image4 = TkPhotoImage.new(:file => $images_base+'karele.gif')
        
        image5 = TkPhotoImage.new(:file => $images_base+'karelnOff.gif')
        image6 = TkPhotoImage.new(:file => $images_base+'karelwOff.gif')
        # image6.copy(image6, :zoom => [2, 2])
        image7 = TkPhotoImage.new(:file => $images_base+'karelsOff.gif')
        image8 = TkPhotoImage.new(:file => $images_base+'kareleOff.gif')
               
        # b = TkButton.new(@canvas, :image => image1, :command => proc{exit})
        # b.grid(:row => 3, :column => 5, :sticky => "news")
        # knOn = TkLabel.new(@canvas,  :image => image1, :width => 25, :height => 25, :borderwidth => 0)
        # kwOn = TkLabel.new(@canvas,  :image => image2, :width => 25, :height => 25, :borderwidth => 0)
        # ksOn = TkLabel.new(@canvas,  :image => image3, :width => 25, :height => 25, :borderwidth => 0)
        # keOn = TkLabel.new(@canvas,  :image => image4, :width => 25, :height => 25, :borderwidth => 0)
        # $imagesOn << knOn << kwOn << ksOn << keOn
        $imageMapOn[NORTH] = image1 #knOn
        $imageMapOn[WEST] = image2 #kwOn
        $imageMapOn[SOUTH] = image3 #ksOn
        $imageMapOn[EAST] = image4 #$keOn
        
        # knOff = TkLabel.new(@canvas,  :image => image5, :width => 25, :height => 25, :borderwidth => 0)
        # kwOff = TkLabel.new(@canvas,  :image => image6, :width => 25, :height => 25, :borderwidth => 0)
        # ksOff = TkLabel.new(@canvas,  :image => image7, :width => 25, :height => 25, :borderwidth => 0)
        # keOff = TkLabel.new(@canvas,  :image => image8, :width => 25, :height => 25, :borderwidth => 0)
        # $imagesOff << knOff << kwOff << ksOff << keOff
        $imageMapOff[NORTH] = image5 #knOff
        $imageMapOff[WEST] = image6 #kwOff
        $imageMapOff[SOUTH] = image7 #ksOff
        $imageMapOff[EAST] = image8 #keOff
        
        geometry(@height)
        set_size(streets)

  end