class Shul::Window

Attributes

height[R]
width[R]

Public Class Methods

new(shoes, doc) click to toggle source
# File lib/shul.rb, line 452
def initialize(shoes, doc)
  
  @shoes = shoes
  @width, @height = 100, 100
  
  @doc = doc
  
  def @doc.element_by_id(id)
    self.root.element("//*[@id='#{id}']")
  end      

  @doc.root.elements.each do |x| 
    method(x.name.sub(':','_').to_sym).call(x) unless x.name == 'script'
  end   
  
  @doc.root.xpath('script').each {|x| script x }
  
  h = @doc.root.attributes
  
  if h[:onkeypress] then
    shoes.keypress do |k| 
      method(h[:onkeypress][/^[a-z]\w+/].to_sym).call(k)
    end
  end
  
  
  icon = h[:icon]
  
  if icon then
    
    file = Tempfile.new('shoes').path
    File.write file, RXFHelper.read(icon).first
    shoes.win.icon = file
    
  end            

end

Public Instance Methods

add_element(node) click to toggle source
# File lib/shul.rb, line 490
def add_element(node)

  node.obj = method(node.name.sub(':','_').to_sym).call(node)                  
  refresh()

end
refresh() click to toggle source
# File lib/shul.rb, line 497
def refresh
  @shoes.flush if @shoes
end
remove_element(node) click to toggle source
# File lib/shul.rb, line 501
def remove_element(node)

  node.obj.clear
  node.obj = nil
  refresh()
end

Private Instance Methods

button(e) click to toggle source
# File lib/shul.rb, line 510
def button(e)

  buttonx e
  
end
buttonx(e, label = :label, oncommand = :oncommand) click to toggle source
# File lib/shul.rb, line 516
def buttonx(e, label = :label, oncommand = :oncommand)

  h = e.attributes
  label = h[label]
  command = h[oncommand]    
  
  e.obj = @shoes.button label do
    eval command if command
  end
  
  def e.label=(v)
    self.obj.style[:text] = v
  end
  
end
checkbox(e) click to toggle source
# File lib/shul.rb, line 532
def checkbox(e)
  
  h = e.attributes
      
  @shoes.flow do
    c = @shoes.check      
    c.checked = h[:checked] == 'true'
    @shoes.para h[:label]
  end
  
end
description(e) click to toggle source
# File lib/shul.rb, line 544
def description(e)
  e.obj = @shoes.para e.attributes[:value]
end
doc() click to toggle source
# File lib/shul.rb, line 548
def doc()
  @doc
end
editbox(e, name = :edit_line) click to toggle source
# File lib/shul.rb, line 552
def editbox(e, name = :edit_line)
      
  obj = @shoes.method(name).call
  obj.text = e.attributes[:value]
  obj.change {|x| e.value = x.text() if x.text != e.text}

  
  def e.value()
    self.attributes[:value]
  end
    
  def e.value=(v) 
    self.attributes[:value] = v
    self.obj.text = v
  end    
  
  e.obj =  obj
  
end
flow(e)
Alias for: hbox
grid(e) click to toggle source

This method is under-development

# File lib/shul.rb, line 575
def grid(e)
  
  # get the grid width
  #grid_width = 100
  
  # get the columns
  columns = e.element 'columns'
  cols = columns.xpath 'column'
  cols_flex = cols.map {|x| x.attributes[:flex].to_s.to_i}
  
  # get the rows
  rows = e.element 'rows'
  rows.each do |row|
    a = row.xpath 'row'
    # resize the width of each item
    a.each do |x|
      #x.width = 400
      #puts "x: %s width: %s" + [x.inspect,  x.width]
    end
  end
end
hbox(e) click to toggle source
# File lib/shul.rb, line 597
def hbox(e)
  
  h2 = {}
  h = e.attributes
  
  h2.merge!({margin: h[:margin].to_i})
  h2.merge!({width: h[:width].to_i}) if h[:width]
        
  flow = @shoes.flow  h2 do
    @shoes.background h[:bgcolor] if h[:bgcolor]
    
    if e.text then
      para_style = {}
      
      para_style = {size: e.style[:'font-size'].to_f} if e.style[:'font-size']
      @shoes.para e.text.strip, para_style
    end        
    
    if e.style.has_key? :'background-color' then
      @shoes.background e.style[:'background-color'] 
    end
    
    e.elements.each {|x|  method(x.name.sub(':','_').to_sym).call(x) }
  end
  e.obj = flow

end
Also aliased as: flow
html_a(e) click to toggle source
# File lib/shul.rb, line 627
def html_a(e)

  command = e.attributes[:oncommand]

  @shoes.para(
    e.obj = @shoes.link(e.text).click do
      eval command if command
    end
  )

end
html_b(e)
Alias for: html_strong
html_em(e) click to toggle source
# File lib/shul.rb, line 639
def html_em(e)
  e.obj = obj =  @shoes.em(e.text)
  @shoes.para()
end
Also aliased as: html_i
html_i(e)
Alias for: html_em
html_input(e) click to toggle source
# File lib/shul.rb, line 646
def html_input(e)
  
  case e.attributes[:type]
  when 'text'
    editbox e
  when 'button'
    buttonx e, :value, :onclick
  end
end
html_p(e) click to toggle source
# File lib/shul.rb, line 656
def html_p(e)
  e.obj = @shoes.para e.text
  e.elements.each {|x|  method(x.name.sub(':','_').to_sym).call(x) }
end
html_span(e) click to toggle source
# File lib/shul.rb, line 661
def html_span(e)
  e.obj = @shoes.span e.text
end
html_strong(e) click to toggle source
# File lib/shul.rb, line 665
def html_strong(e)
  e.obj = @shoes.strong e.text
end
Also aliased as: html_b
image(e) click to toggle source
# File lib/shul.rb, line 671
def image(e)
  h = e.attributes
  e.obj = @shoes.image h[:src], top: h[:top], left: h[:left]
end
label(e) click to toggle source

e.g. <label value='light' width='40' color='#45a'/>

# File lib/shul.rb, line 678
def label(e)
  
  h = { }
  h.merge!({width: e.attributes[:width]}) if e.attributes[:width]
  h.merge!({height: e.attributes[:height]}) if e.attributes[:height]
  h.merge!({margin: e.attributes[:margin].to_i}) if e.attributes[:margin]
  h.merge!({stroke: e.attributes[:color]}) if e.attributes[:color]
  h.merge!({size: e.style[:'font-size'].to_f}) if e.style[:'font-size']      
  
  # setting the para bgcolor doesn't work
  #h.merge!({fill: e.attributes[:bgcolor]}) if e.attributes[:bgcolor]
 
  e.obj = @shoes.para e.attributes[:value] || e.text.strip , h           
  
  def e.value()
    self.attributes[:value]
  end
    
  def e.value=(v) 
    self.attributes[:value] = v        
    self.obj.replace v        
  end          
  
end
listbox(e) click to toggle source
# File lib/shul.rb, line 722
def listbox(e)

  a = e.xpath('listitem/attribute::label').map(&:to_s)
  e.obj = @shoes.list_box items: a

end
listitem() click to toggle source
# File lib/shul.rb, line 729
def listitem()
end
location=(source) click to toggle source
# File lib/shul.rb, line 713
def location=(source)
  
  xml, _ = RXFHelper.read(source)
  doc = Rexle.new(xml)
  
  @shoes.close

end
progressmeter(e) click to toggle source
# File lib/shul.rb, line 732
def progressmeter(e)
  e.obj = @shoes.progress
end
quit() click to toggle source
# File lib/shul.rb, line 769
def quit()
  exit
end
radio(e) click to toggle source
# File lib/shul.rb, line 736
def radio(e)
  
  def e.value()   self.attributes[:value]        end
  def e.value=(v) self.attributes[:value] = v    end       
    
  e.value = e.attributes[:value].to_s
  
  h = e.attributes
  e.obj = @shoes.flow do
    r = @shoes.radio :radiogroup01
    r.click {e.parent.value = e.value}

    r.checked = h[:checked] == 'true'
    @shoes.para h[:label]
  end
      
end
radiogroup(e) click to toggle source
# File lib/shul.rb, line 754
def radiogroup(e)

  e.xpath('radio').each {|node| radio node }            
  
  h = e.attributes
  
  if h[:onkeypress] then
    @shoes.keypress do |k| 
      method(h[:onkeypress][/^[a-z]\w+/].to_sym).call(k)
    end
  end      
  
  Radiogroup.new e
end
reload()
Alias for: render_elements
render_elements() click to toggle source
# File lib/shul.rb, line 703
def render_elements()
  
  #@shoes.clear
  @doc.root.elements.each do |x| 
    method(x.name.sub(':','_').to_sym).call(x) unless x.name == 'script'
  end      
end
Also aliased as: reload
script(e) click to toggle source
# File lib/shul.rb, line 773
def script(e)
  eval "shoes = @shoes; " + e.text.unescape
end
stack(e)
Alias for: vbox
textbox(e) click to toggle source

e.g. <textbox id='tb' value='empty' size='40' multiline='true'/>

# File lib/shul.rb, line 778
def textbox(e)

  name = if e.attributes[:multiline] \
                    and e.attributes[:multiline] == 'true' then
    :edit_box
  else
    :edit_line
  end
  
  editbox e, name
  
end
vbox(e) click to toggle source
# File lib/shul.rb, line 791
def vbox(e)

  h2 = {}
  h = e.attributes
  
  h2.merge!({margin: h[:margin].to_i}) if h[:margin]
  h2.merge!({width: h[:width].to_i}) if h[:width]

  stack = @shoes.stack h2 do

    if e.text then
      para_style = {}
      
      para_style = {size: e.style[:'font-size'].to_f} if e.style[:'font-size']
      @shoes.para e.text.strip, para_style
    end
    
    @shoes.background h[:bgcolor] if h[:bgcolor]
    
    if e.style.has_key? :'background-color' then
      @shoes.background e.style[:'background-color'] 
    end
    e.elements.each {|x|  method(x.name.sub(':','_').to_sym).call(x) }
    
  end
  
  e.obj = stack      

end
Also aliased as: stack