DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Demonstrating UI Controls On The N800

02.07.2010
| 2568 views |
  • submit to reddit
        Source: unknown author (/usr/bin/htest.rb on the N800)

#!/usr/bin/env ruby
require 'hildon'
    
class Test 
  def initialize
    @p = Hildon::Program.new
    @w = Hildon::Window.new
    @w.signal_connect("destroy") { Gtk.main_quit }
    @p.add_window( @w )
  end
  
  
# <a href="http://twitxr.com/image/310318/">http://twitxr.com/image/310318/</a> 
  def notes
    w = Gtk::Window.new 
    vbox = Gtk::VBox.new( false, 0)
    w.add( vbox )

    
# <a href="http://twitxr.com/image/310319/">http://twitxr.com/image/310319/</a> 
    note1 = Gtk::Button.new("Confirmation Note")
    vbox.pack_start( note1,true,true,0 )

    note1.signal_connect("clicked") {
      n = Hildon::Note.new_confirmation( w, "this is a confirmation note" )
      n.run
      n.destroy
    }
    
    
# <a href="http://twitxr.com/image/310320/">http://twitxr.com/image/310320/</a> 
    note1 = Gtk::Button.new("Confirmation Note add buttons")
    vbox.pack_start( note1,true,true,0 )

    note1.signal_connect("clicked") {
    n = Hildon::Note.new_information( w, "sorry .. not implemented yet !!" )
      n.run
      n.destroy
    }

    
# <a href="http://twitxr.com/image/310324/">http://twitxr.com/image/310324/</a> 
    note1 = Gtk::Button.new("Information Note with icon")
    vbox.pack_start( note1,true,true,0 )

    note1.signal_connect("clicked") {
    n = Hildon::Note.new_confirmation_with_icon_name( w, "this is a information note",Gtk::Stock::CDROM)
      n.run
      n.destroy
    }

    
# <a href="http://twitxr.com/image/310321/">http://twitxr.com/image/310321/</a> 
    note1 = Gtk::Button.new("Information Note with progress bar")
    vbox.pack_start( note1,true,true,0 )

    note1.signal_connect("clicked") {
      pbar = Gtk::ProgressBar.new 
      n = Hildon::Note.new_cancel_with_progress_bar( w, "this is an information note with progrss bar", pbar )
      n.run
      n.destroy
    }
    
    
# <a href="http://twitxr.com/image/310325/">http://twitxr.com/image/310325/</a> 
    note1 = Gtk::Button.new("Information Note")
    vbox.pack_start( note1,true,true,0 )

    note1.signal_connect("clicked") {
      n = Hildon::Note.new_information( w, "this is a information note" )
      n.run
      n.destroy
    }

    
# <a href="http://twitxr.com/image/310321/">http://twitxr.com/image/310321/</a> 
    note1 = Gtk::Button.new("Information Note with Icon")
    vbox.pack_start( note1,true,true,0 )

    note1.signal_connect("clicked") {
    n = Hildon::Note.new_information_with_icon_name( w, "this is a information note",Gtk::Stock::NETWORK )
      n.run
      n.destroy
    }

    note1 = Gtk::Button.new("Exit")
    vbox.pack_start( note1,true,true,0 )

    note1.signal_connect("clicked") {
      w.destroy
    }
    w.show_all
  end #notes

  
# <a href="http://twitxr.com/image/310326/">http://twitxr.com/image/310326/</a> 
  def colors
    w = Gtk::Window.new 
    vbox = Gtk::VBox.new( false, 0)
    w.add( vbox )

    colour = Gtk::ColorSelection

    button = Gtk::Button.new("Color Dialog")
    vbox.pack_start( button,true,true,0 )

    button.signal_connect("clicked") {
      popup = Hildon::ColorChooserDialog.new
      popup.run
      color = popup.get_color
      # popup.set_color( color )
      popup.destroy 
	
    }

    button = Hildon::ColorChooser.new
    vbox.pack_start( button,true,true,0 )
    color = button.get_color
    button.set_color( color )

    button = Hildon::ColorButton.new
    #   color = button.get_color
    #  button.set_color( color )
    vbox.pack_start( button,true,true,0 )

    w.show_all
  end #colors

  def banners
    w = Gtk::Window.new 
    vbox = Gtk::VBox.new( false, 0)
    w.add( vbox )

    note1 = Gtk::Button.new("Information")
    vbox.pack_start( note1,true,true,0 )

    note1.signal_connect("clicked") {
      begin
	n = Hildon::Banner.show_information( w, Gtk::Stock::CDROM,"this is information" )
      rescue Exception => e
	puts "this is information"
      end      
    }

    note1 = Gtk::Button.new("Markup")
    vbox.pack_start( note1,true,true,0 )

    note1.signal_connect("clicked") {
      begin
	n = Hildon::Banner.show_information_with_markup( w, Gtk::Stock::CDROM,"this is markup" )
      rescue Exception => e
	puts "this is markup"
      end
    }

    note1 = Gtk::Button.new("Animation")
    vbox.pack_start( note1,true,true,0 )

    note1.signal_connect("clicked") {
      n = Hildon::Banner.show_animation( w, "animation name","animation title")
    }

    note1 = Gtk::Button.new("Progress")
    vbox.pack_start( note1,true,true,0 )

    note1.signal_connect("clicked") {
      pbar = Gtk::ProgressBar.new 
      n = Hildon::Banner.show_progress( w, pbar,"progress title" )
    }



    note1 = Gtk::Button.new("Exit")
    vbox.pack_start( note1,true,true,0 )
    note1.signal_connect("clicked") {
      w.destroy
    }
    w.show_all
  end #banners


  
# <a href="http://twitxr.com/image/310327/">http://twitxr.com/image/310327/</a> 
  def bars
    w = Gtk::Window.new 
    vbox = Gtk::VBox.new( false, 0)
    w.add( vbox )

    bar = Hildon::Controlbar.new
    bar.set_min 1
    bar.set_max 9
    bar.set_value 5
    val = bar.get_value
    vbox.pack_start( bar,true,true,0 )
    
    bar = Hildon::Hvolumebar.new
    vbox.pack_start( bar,true,true,0 )
    bar.get_mute
    bar.set_mute true
    level = bar.get_level
    bar.set_level( level + 0.1 )
    
    bar = Hildon::Seekbar.new
    vbox.pack_start( bar,true,true,0 )
    
    bar.set_total_time(15 )
    
    bar.set_position( 5 )
    level = bar.get_fraction
    bar.set_fraction( level  )
    val = bar.get_total_time
    level = bar.get_position

    w.show_all
  end #bars
    
  
# <a href="http://twitxr.com/image/310328/">http://twitxr.com/image/310328/</a> 
  def misc
    w = Gtk::Window.new 
    vbox = Gtk::VBox.new( false, 0)
    w.add( vbox )

    
# <a href="http://twitxr.com/image/310329/">http://twitxr.com/image/310329/</a> 
    button = Gtk::Button.new("Sort Dialog")
    vbox.pack_start( button,true,true,0 )
    
    button.signal_connect("clicked") {
      popup = Hildon::SortDialog.new( w)

      popup.run
      popup.destroy 	
    }
    
    
# <a href="http://twitxr.com/image/310330/">http://twitxr.com/image/310330/</a> 
    button = Gtk::Button.new("Wizard")
    vbox.pack_start( button,true,true,0 )
    
    button.signal_connect("clicked") {
      x = Gtk::Notebook.new 
      popup = Hildon::WizardDialog.new(w, "Wizard", x)

      popup.run
      popup.destroy 	
    }
    

    w.show_all
  end #misc
       
       
  
# <a href="http://twitxr.com/image/310332/">http://twitxr.com/image/310332/</a> 
  def codes
    w = Gtk::Window.new 
    vbox = Gtk::VBox.new( false, 0)
    w.add( vbox )
    
    
# <a href="http://twitxr.com/image/310333/">http://twitxr.com/image/310333/</a> 
    button = Gtk::Button.new("Set Password")
    vbox.pack_start( button,true,true,0 )
    
    button.signal_connect("clicked") {
      popup = Hildon::SetPasswordDialog.new( w, false, "default")

      popup.run
      popup.destroy 	
    }
    
    
# <a href="http://twitxr.com/image/310335/">http://twitxr.com/image/310335/</a> 
    button = Gtk::Button.new("Get Password")
    vbox.pack_start( button,true,true,0 )
    
    button.signal_connect("clicked") {
      popup = Hildon::GetPasswordDialog.new( w, false, "default")

      popup.run
      popup.destroy 	
    }
    
    
# <a href="http://twitxr.com/image/310336/">http://twitxr.com/image/310336/</a> 
    button = Gtk::Button.new("Login")
    vbox.pack_start( button,true,true,0 )
    
    button.signal_connect("clicked") {
      popup = Hildon::LoginDialog.new( w, "username", "password")

      popup.run
      popup.destroy 	
    }
    
    
# <a href="http://twitxr.com/image/310337/">http://twitxr.com/image/310337/</a> 
    button = Gtk::Button.new("Code")
    vbox.pack_start( button,true,true,0 )
    
    button.signal_connect("clicked") {
      popup = Hildon::CodeDialog.new

      popup.run
      popup.destroy 	
    }
    
    w.show_all
  end #codes
	  

  
# <a href="http://twitxr.com/image/310331/">http://twitxr.com/image/310331/</a> 
  def pickers
    w = Gtk::Window.new 
    vbox = Gtk::VBox.new( false, 0)
    w.add( vbox )  

    button = Gtk::Button.new("Time Picker")
    vbox.pack_start( button,true,true,0 )

    button.signal_connect("clicked") {
      t = Hildon::TimePicker.new @w
      t.set_time( 12, 37 )
      t.run
      t.destroy
    }
    
    pick = Hildon::WeekdayPicker.new
    vbox.pack_start( pick,true,true,0 )
    
    pick = Hildon::NumberEditor.new( 10, 20 )
    vbox.pack_start( pick,true,true,0 )
    
    editor = Hildon::TimeEditor.new 
    editor.set_time( 12, 37, 23 )
    vbox.pack_start( editor,true,true,0 )
    editor.get_time
    
    editor = Hildon::DateEditor.new 
    editor.set_date( 25, 05, 2008 )
    vbox.pack_start( editor,true,true,0 )
    editor.get_date
    
    
    pick = Hildon::RangeEditor.new
    pick.set_range( 2, 18 )
    vbox.pack_start( pick,true,true,0 )
    
    w.show_all    
  end #pickers
   
  
# <a href="http://twitxr.com/image/310317/">http://twitxr.com/image/310317/</a> 
  def top_level
    vbox = Gtk::VBox.new( false, 0)
    @w.add( vbox )

    button = Gtk::Button.new("Notes")
    vbox.pack_start( button,true,true,0 )
    button.signal_connect("clicked") {
      notes
    }

    button = Gtk::Button.new("Banners")
    vbox.pack_start( button,true,true,0 )
    button.signal_connect("clicked") {
      banners
    }

    button = Gtk::Button.new("Colours")
    vbox.pack_start( button,true,true,0 )
    button.signal_connect("clicked") {
	colors
    }

    button = Gtk::Button.new("Bars")
    vbox.pack_start( button,true,true,0 )
    button.signal_connect("clicked") {
	bars
    }
    button = Gtk::Button.new("Misc")
    vbox.pack_start( button,true,true,0 )
    button.signal_connect("clicked") {
	misc
    }

    button = Gtk::Button.new("Pickers")
    vbox.pack_start( button,true,true,0 )
    button.signal_connect("clicked") {
	pickers
    }

    button = Gtk::Button.new("Code Dialogs")
    vbox.pack_start( button,true,true,0 )
    button.signal_connect("clicked") {
	codes
    }

    
# <a href="http://twitxr.com/image/310338/">http://twitxr.com/image/310338/</a> 
    button = Gtk::Button.new("Calendar Popup")
    vbox.pack_start( button,true,true,0 )
    button.signal_connect("clicked") {
      popup = Hildon::CalendarPopup.new(@w,25,5,2008)
      popup.run
      popup.destroy 
    }

    
# <a href="http://twitxr.com/image/310339/">http://twitxr.com/image/310339/</a> 
    button = Gtk::Button.new("Font Dialog")
    vbox.pack_start( button,true,true,0 )
    button.signal_connect("clicked") {
      popup = Hildon::FontSelectionDialog.new( button ,"howdy" )
      popup.set_preview_text( "reality bites" )
      popup.run
      popup.destroy 
    }

    button = Gtk::Button.new("Exit Program")
    vbox.pack_start( button,true,true,0 )
    button.signal_connect("clicked") {
      Gtk.main_quit 
    }
  end # top_level

  def run
    @w.show_all
    Gtk.main
  end #run
      
end # Test

t = Test.new 
t.top_level
t.run