Never been to DZone Snippets before?

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

« Newer Snippets
Older Snippets »
Showing 1-10 of 12 total  RSS 

A QT 'Hello World' application

- getting started - (Using Ubuntu Linux 7.10)
1) Installed Qt bindings for Ruby

- Running the application
1) From the command line I typed ruby helloworld_qt.rb

   1  
   2  #file: helloworld_qt.rb
   3  
   4  require 'Qt'
   5  
   6      a = Qt::Application.new( ARGV )
   7  
   8      hello = Qt::PushButton.new( "Hello world!", nil )
   9      hello.resize( 100, 30 )
  10   
  11      Qt::Object::connect( hello, SIGNAL('clicked()'), a, SLOT('quit()') )
  12   
  13      a.setMainWidget( hello )
  14      hello.show()
  15   
  16      a.exec()

Source code copied from KDE Tutorial - p1 [kde.org]

A Glade 'Hello World' application

- getting started - (Using Ubuntu Linux 7.10)
1) Installed glade-3,libglade2-ruby
2) Executed glade-3

- Within glade-3 -
1) Selected from the glade-3 top menu View -> Palette appearance -> Text beside icons
2) Created a window (Toplevels)
3) Created a button on the window (Control and Display)
3) With button selected, from the properties panel I selected the Signals tab and chose 'clicked', then for the Handler -> on_button1_clicked and pressed enter.
4) With window select, from the properties panel I select the Signals tab and chose GtkWidget->delete-event, then for the Handler I typed on_quit and pressed enter.

- Generating and editing the code

-- From the command line -
1) Typed ruby-glade-create-template helloworld3.glade > helloworld3.rb

-- From the file helloworld3.rb - (see helloworld3.rb and how it relates to helloworld3.glade)
1) Implemented the initialise window routine
2) Implemented the button event handler

- Running the application
1) From the command line I typed ruby helloworld3.rb
2) stretched the window to a comfortable dimension.
3) clicked the button and observed the Window title change to 'Hello World!'

file: helloworld3.glade
   1  
   2  #!/usr/bin/env ruby
   3  #
   4  # This file is generated by ruby-glade-create-template 1.1.4.
   5  #
   6  require 'libglade2'
   7  
   8  class Helloworld3Glade
   9    include GetText
  10  
  11    attr :glade
  12    
  13    def initialize(path_or_data, root = nil, domain = nil, localedir = nil, flag = GladeXML::FILE)
  14      bindtextdomain(domain, localedir, nil, "UTF-8")
  15      @glade = GladeXML.new(path_or_data, root, domain, localedir, flag) {|handler| method(handler)}
  16      @window1 = @glade.get_widget("window1") # hand coded
  17      @window1.show # hand coded      
  18    end
  19    
  20    def on_button1_clicked(widget)
  21      #puts "on_button1_clicked() is not implemented yet." # removed this code by hand
  22      @window1.title = 'Hello World!' # hand coded  
  23    end
  24    def on_quit(widget, arg0)
  25      #puts "on_quit() is not implemented yet." # removed this code by hand
  26      Gtk.main_quit # hand coded
  27    end
  28  end
  29  
  30  # Main program
  31  if __FILE__ == $0
  32    # Set values as your own application. 
  33    PROG_PATH = "helloworld3.glade"
  34    PROG_NAME = "YOUR_APPLICATION_NAME"
  35    Helloworld3Glade.new(PROG_PATH, nil, PROG_NAME)
  36    Gtk.main
  37  end

file: helloworld3.glade
   1  
   2  <?xml version="1.0" encoding="UTF-8" standalone="no"?>
   3  <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
   4  <!--Generated with glade3 3.4.0 on Tue Mar 18 17:39:53 2008 -->
   5  <glade-interface>
   6    <widget class="GtkWindow" id="window1">
   7      <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
   8      <signal name="delete_event" handler="on_quit"/>
   9      <child>
  10        <widget class="GtkButton" id="button1">
  11          <property name="visible">True</property>
  12          <property name="can_focus">True</property>
  13          <property name="receives_default">True</property>
  14          <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
  15          <property name="label" translatable="yes">button</property>
  16          <property name="response_id">0</property>
  17          <signal name="clicked" handler="on_button1_clicked"/>
  18        </widget>
  19      </child>
  20    </widget>
  21  </glade-interface>

Hello ruby

// description of your code here

   1  
   2  puts 'hello ruby'

appuifw.note allow global note in pys60 1.3.1

   1  
   2  # note in 1.2 
   3  note(text, type)
   4  # note in 1.3.1
   5  note(text[, type[, global]])

type = 'info' (default) or 'error', 'conf'
global = 1 # display even if app is in background
   1  
   2  import appuifw
   3  appuifw.note(u'Hello World')             # simplest case
   4  appuifw.note(u'Cannot connect', 'error') # show error
   5  appuifw.note(u'New message', 'info', 1)  # alert from background

ForLoop: a simple for loop in xslt

   1  
   2  <?xml version="1.0" encoding="ISO-8859-1"?>
   3  <!--
   4  ### begin_: file metadata
   5      ### <region-file_info>
   6      ### main:
   7      ###   - name : ForLoop: a simple for loop in xslt
   8      ###     desc : |
   9      ###         Do a simple for loop in xslt displaying hello world.
  10      ###         Call this from any source xml file.
  11      ###         It works independently of the data in the xml.
  12      ###     date : created="Thu 2005-12-01 11:30:52"
  13      ###     last : lastmod="Thu 2005-12-01 11:30:57"
  14      ###     lang    : xslt
  15      ###     tags    : xml xslt loop for hello_world
  16      ### </region-file_info>
  17      -->
  18  <xsl:stylesheet version="1.0"
  19      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  20      <xsl:output method="html"/>
  21  
  22  <xsl:template match="/">
  23  
  24  <html>
  25  <head><title>Say Hello Ten Times!</title></head>
  26  <body>
  27      <b>I am going to say hello Ten Times!</b>
  28  <!-- begin_: Send_Loop_To_HTML -->
  29      <xsl:call-template name="for.loop">
  30       <xsl:with-param name="i">1</xsl:with-param>
  31       <xsl:with-param name="count">10</xsl:with-param>
  32      </xsl:call-template>
  33  </body>
  34  </html>
  35  
  36  </xsl:template>
  37  
  38  
  39  <!--begin_: Define_The_Output_Loop -->
  40    <xsl:template name="for.loop">
  41  
  42     <xsl:param name="i"      />
  43     <xsl:param name="count"  />
  44  
  45     <!--begin_: Line_by_Line_Output -->
  46     <xsl:if test="$i &lt;= $count">
  47        <br /> <b><xsl:value-of select="$i" />.</b>Hello world!
  48     </xsl:if>
  49  
  50     <!--begin_: RepeatTheLoopUntilFinished-->
  51     <xsl:if test="$i &lt;= $count">
  52        <xsl:call-template name="for.loop">
  53            <xsl:with-param name="i">
  54                <xsl:value-of select="$i + 1"/>
  55            </xsl:with-param>
  56            <xsl:with-param name="count">
  57                <xsl:value-of select="$count"/>
  58            </xsl:with-param>
  59        </xsl:call-template>
  60     </xsl:if>
  61  
  62    </xsl:template>
  63  </xsl:stylesheet>

MyJava

hello

Hello World Tcl

Mostly just playing with this site which seems pretty cool.

   1  
   2  #!/bin/sh
   3  
   4  # Next line restarts using tclsh \
   5  exec tclsh "$0" "$@"
   6  
   7  puts "Hello World."
   8  exit

Hello World - C

   1  
   2  #include <stdio.h>
   3  
   4  main()
   5  {
   6    for(;;)
   7        { 
   8            printf ("Hello World!\n");
   9        }
  10  }

hello world in javascript

   1  
   2  <script language='javascript'>
   3  alert('hello world')
   4  </script>

Hello world in python for series 60

   1  
   2  import appuifw
   3  appuifw.note(u"Hello", 'info')


The message to be display must be in unicode. See u"Hello"
« Newer Snippets
Older Snippets »
Showing 1-10 of 12 total  RSS