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

#file: helloworld_qt.rb

require 'Qt'

    a = Qt::Application.new( ARGV )

    hello = Qt::PushButton.new( "Hello world!", nil )
    hello.resize( 100, 30 )
 
    Qt::Object::connect( hello, SIGNAL('clicked()'), a, SLOT('quit()') )
 
    a.setMainWidget( hello )
    hello.show()
 
    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
#!/usr/bin/env ruby
#
# This file is generated by ruby-glade-create-template 1.1.4.
#
require 'libglade2'

class Helloworld3Glade
  include GetText

  attr :glade
  
  def initialize(path_or_data, root = nil, domain = nil, localedir = nil, flag = GladeXML::FILE)
    bindtextdomain(domain, localedir, nil, "UTF-8")
    @glade = GladeXML.new(path_or_data, root, domain, localedir, flag) {|handler| method(handler)}
    @window1 = @glade.get_widget("window1") # hand coded
    @window1.show # hand coded      
  end
  
  def on_button1_clicked(widget)
    #puts "on_button1_clicked() is not implemented yet." # removed this code by hand
    @window1.title = 'Hello World!' # hand coded  
  end
  def on_quit(widget, arg0)
    #puts "on_quit() is not implemented yet." # removed this code by hand
    Gtk.main_quit # hand coded
  end
end

# Main program
if __FILE__ == $0
  # Set values as your own application. 
  PROG_PATH = "helloworld3.glade"
  PROG_NAME = "YOUR_APPLICATION_NAME"
  Helloworld3Glade.new(PROG_PATH, nil, PROG_NAME)
  Gtk.main
end

file: helloworld3.glade
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.0 on Tue Mar 18 17:39:53 2008 -->
<glade-interface>
  <widget class="GtkWindow" id="window1">
    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
    <signal name="delete_event" handler="on_quit"/>
    <child>
      <widget class="GtkButton" id="button1">
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="receives_default">True</property>
        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
        <property name="label" translatable="yes">button</property>
        <property name="response_id">0</property>
        <signal name="clicked" handler="on_button1_clicked"/>
      </widget>
    </child>
  </widget>
</glade-interface>

Hello ruby

// description of your code here

puts 'hello ruby'

appuifw.note allow global note in pys60 1.3.1

# note in 1.2 
note(text, type)
# note in 1.3.1
note(text[, type[, global]])

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

ForLoop: a simple for loop in xslt

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
### begin_: file metadata
    ### <region-file_info>
    ### main:
    ###   - name : ForLoop: a simple for loop in xslt
    ###     desc : |
    ###         Do a simple for loop in xslt displaying hello world.
    ###         Call this from any source xml file.
    ###         It works independently of the data in the xml.
    ###     date : created="Thu 2005-12-01 11:30:52"
    ###     last : lastmod="Thu 2005-12-01 11:30:57"
    ###     lang    : xslt
    ###     tags    : xml xslt loop for hello_world
    ### </region-file_info>
    -->
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>

<xsl:template match="/">

<html>
<head><title>Say Hello Ten Times!</title></head>
<body>
    <b>I am going to say hello Ten Times!</b>
<!-- begin_: Send_Loop_To_HTML -->
    <xsl:call-template name="for.loop">
     <xsl:with-param name="i">1</xsl:with-param>
     <xsl:with-param name="count">10</xsl:with-param>
    </xsl:call-template>
</body>
</html>

</xsl:template>


<!--begin_: Define_The_Output_Loop -->
  <xsl:template name="for.loop">

   <xsl:param name="i"      />
   <xsl:param name="count"  />

   <!--begin_: Line_by_Line_Output -->
   <xsl:if test="$i &lt;= $count">
      <br /> <b><xsl:value-of select="$i" />.</b>Hello world!
   </xsl:if>

   <!--begin_: RepeatTheLoopUntilFinished-->
   <xsl:if test="$i &lt;= $count">
      <xsl:call-template name="for.loop">
          <xsl:with-param name="i">
              <xsl:value-of select="$i + 1"/>
          </xsl:with-param>
          <xsl:with-param name="count">
              <xsl:value-of select="$count"/>
          </xsl:with-param>
      </xsl:call-template>
   </xsl:if>

  </xsl:template>
</xsl:stylesheet>

MyJava

hello

Hello World Tcl

Mostly just playing with this site which seems pretty cool.

#!/bin/sh

# Next line restarts using tclsh \
exec tclsh "$0" "$@"

puts "Hello World."
exit

Hello World - C

#include <stdio.h>

main()
{
  for(;;)
      { 
          printf ("Hello World!\n");
      }
}

hello world in javascript

<script language='javascript'>
alert('hello world')
</script>

Hello world in python for series 60

import appuifw
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