Keywords

.NET (3) .rb (1) *.cod (1) 3110c (1) Algorithm (1) Amazon Cloud Drive (1) amkette (1) Android (1) Apex (6) apex:dynamic (1) API (1) API version (1) Application Development Contest (2) Artificial Intelligence (2) Atricore (1) b2g (1) Binary Search Tree (1) Blackberry Application Development (1) Blackberry Java Development Environment (1) Blender Game Engine (1) bluetooth (2) Boot2Gecko (1) bug fix (1) C (1) C++ (2) Cloud computing (1) Cloud Storage (1) Code Blocks (1) Code for a Cause (2) codejam (1) Coding (1) const_cast (1) Custom Help (1) Dancing With the Googlers (1) Data Structures (1) desktop environment (5) Doubly Linked List (1) Dropbox (1) dynamic visualforce component (1) dynamic_cast (1) Enterprise WSDL (1) Execution Context (1) fedora 14 (1) fedora 17 (5) Firefox OS (1) Flashing Nokia 3110c handset (1) Force.com (7) Gaia (1) Game Developement (1) GCC (2) GDG (2) Goank (1) Google (4) Google Developer Group (2) Google Drive (1) GTK+ (5) HACK2012 (2) Hall of Mirrors (1) help for this page (1) HTML5 (2) HTTP Web Server (1) IDE (1) Identity Provider (1) Intelligent Systems (1) Java (1) JDE (1) JOSSO (1) location based social network (1) me.social (1) MinGW (1) Natural Language Processing (1) Natural Language Toolkit (1) neckphone (1) NLKT (1) Nokia Pheonix (1) Notebook (1) Numeric XML Tags (1) OAuth2.0 (1) OLPC (7) OLPC-XO-1 (7) One Laptop per Child (5) Override custom help (1) Paas (1) Partner WSDL (1) Polymorphism (1) programming contest (1) PyGTK (4) Python (10) Recycled Numbers (1) reinterpret_cast (1) Research (1) REST (1) RM-237 (1) Robotics (1) Ruby (1) Saas (2) Salesforce.com (7) SDK (1) Service Provider (1) Single sign on (1) SOAP (3) Speaking in Tongues (1) SSO Agent (1) SSO Gateway (1) static_const (1) sugar (7) sugar activity (4) sugarlabs (7) SVG (2) Symbiotic AI (1) Tabbed container (1) TCP/IP (1) TCP/IP stack (1) Typecasting (1) typeid (1) ubuntu 13.10 (1) UDP (1) Upgrade Assembly (1) Visualforce (2) Web Server (1) Web Services (3) Web2.0 (1) wikipedia (1) wikipediaHI (1) WSDL (1) XML tags (1)

Thursday, December 20, 2012

gtk.Notebook widget within Sugar Activity !


This post describes how to use gtk.Notebook widget within a Sugar Activity.
In this blog you can find how to use gtk.Notebook widget to create PyGTK application native to GNOME. Now we will consider how sugar shell understands this Notebook widget and renders it for Sugar Desktop Environment.


Consider we have sugar activity DevelopWeb with following directory structure:
Here we have created weblib.py to include class WebToolBox that renders a toolbox on left hand side pane and tabbed container, i.e. Notebook on right side pane. Note that we are using HBox to hold this WebToolbox and Notebook widgets. Since there are only two widgets added to HBox we are using terms left side pane and right side pane.

weblib.py looks like this:

Here you can observe that we have added all the widgets in the constructor of WebToolbox class. We have used HBox as parent container. Then we have used a VBox as elementBox or  toolbox for this activity to hold the web elements. Then we set few properties for scrollable window inside elementBox. We add the buttons in this elementbox with appropriate properties. Then we add the Notebook widget with gtk.POS_TOP ( i.e. tabs will be visible on top).

Now we add the pages to this notebook instance using a custom method "addPage"(Refer to image below). You can see in the definition that a page is a container HBox as immediate child of Notebook within a page. Each page requires a Label widget as page label:

The basic activity file looks like :
Here within constructor of DevelopWeb class you can observe that we have use instance of WebToolBox class which inturn uses Notebook widget. we have used this WebToolBox instance to be placed as viewport of the activity. You can create a setup.py file required for activity.

Now when you create symbolic link for this activity using : python setup.py dev the Sugar Desktop Environment can use this activity.
When you start Sugar session you can see DevelopWeb activity:

When you launch this activity you can see elementBox on left side and Notebook on right side with two tabs or pages in it:


This example shows how you can use Notebook, the tabbed container in your sugar activity. I hope this post helps you.

Stay tuned for more Sugar Action !

Tuesday, December 18, 2012

Notebook: Tabbed container in PyGTK

Hi,

I am writing this post to share my experience with Notebook, the tabbed container in PyGTK. If you are planning to develop your application in platform independent form, I would prefer you should go for PyGTK.

GTK+, or the GIMP Toolkit, is a multi-platform toolkit for creating graphical user interfaces. Offering a complete set of widgets, GTK+ is suitable for projects ranging from small one-off tools to complete application suites. This consists of toolkit which runs on Windows based and Linux based system. Thus you can write your application using GTK+ and run on any OS. Python bindings for GTK+ is known as PyGTK.  PyGTK lets you to easily create programs with a graphical user interface using the Python programming language.

Another prominent OS or Desktop Environment or Shell which used across XO Laptops as part of OLPC project that can run applications developed in PyGTK is Sugar. Few days ago I was looking for Tabbed container in PyGTK for a Sugar Activity I am working on. I came across Notebook.  It is similar to TabControl in .Net framework but with few dissimilarities.

Lets dive into code:
1. Import required modules: In order to use GTK modules in your python program you need to include gtk and pygtk modules.
Apart  from modules you can import specific widgets like Window, Label or Button and Notebook. Otherwise you need to use gtk.Window, gtk.Notebook.

2. Now lets write a class KartikNoteBookExample. You can see the constructor __init__(self) where we have created an instance of Window[line 13]. Then we set the title and default size for window in next two lines. In line 16, we have linked a callback function that will be invoked when when destroy signal will be sent by window widget. you can observe that we have defined a destroy method which inturn calls gtk's main_quit() method to close the main thread which was initially started using the main() method.



We now proceed by creating an instance(i.e. mynb) of Notebook [line 18]. In line 19, you can see we are using method set_tab_pos which is used to set the position of tabs. It can take one of the following values:
gtk.POS_LEFT, gtk.POS_RIGHT, gtk.POS_TOP or gtk.POS_BOTTOM. In line 20, we have connected a method to be called on "switch-page" event of Notebook. Whenever the page is changed in Notebook this event is fired. Since now you have connected "self.pageChanged" method on this event, it will be fired whenever page is switched. After that we have called a method "addPage" to add the page in Notebook. In below code, you can see we have created a HBox widget and a Label widget. Label widget is required to add label for tab whereas HBox is used as child for that page. We have added page in Notebook using "append_page" method which takes childWidget and Label as parameters. In line 24, we have added notebook instance as child of window widget.

In line 26, we have defined a method "showall" to show all widgets added so far.
From line 45 to 49, we have added a method "pageChanged" to detect the page switch event or signal for Notebook. The widget passes following parameters to the callback function : notebook instance, page instance and page number instance. We get the selected page using the method "get_nth_page" and passing the page number as  parameter[line 47]. We get the label associated with page using method get_tab_label and passing the immediate child of the Notebook as parameter[line 48]. Now using the "get_text" method of label we can get the text in it and print it.

From line 52 onwards, we are checking if the program is invoked using "python" i.e not imported we create an instance of the KartikNoteBookExample class and invoke its main method.


After saving this if it is invoked like: python .py

You will see a window with two tabs, Tab1 and Tab2.

As you click on Tab pages you can see in terminal that which page has been selected based on page number as clickedMe is called for page switch event.

So we saw how we use Notebook in PyGTK in your application. You may download the source file here.
Stay tuned to see how to create tabbed Notebook for a Sugar Activity.

Friday, October 26, 2012

Force.com API demystified using SoapUI

I am working on a project to create Salesforce.com library for Python. I always wished for fastest web service invocation when it comes to multiple systems interacting with each other. Salesforce.com's Force.com platform exposes its API through enterprise, partner and metadata WSDL. For this purpose I scrutinized the WSDL file very closely and used SoapUI to generate the stub.

Lets jump into steps on how we do it:
1. Create a new project and select WSDL file to load and generate stub by hitting OK button.


 Once the stub is generated you can expand the node to see the list of operations exposed by the server as SOAP interface :

3. Login method:
On expanding any service node, you will see "Request" under it. Double click it to open new window on right side pane. This window will allow you to make HTTP POST requests to server. You can see the SOAP enevelope is already created in left pane in new window. All you need to do is fill in the parameters for the request and hit submit button. IMP: Make sure you set the endpoint properly. You can find this endpoint in bottom part of WSDL file as an attribute of any of SOAP 1.1 or 1.2 binding.
I entered my username and password(password+security token) here and submitted the request. On right side pane you can see the response envelope with my data like sessionId, serverURL, userInfo.

4. Creating Sobject records:
In case you need to perform further operations you need to pay extra attention here. Consider we need to create a case record through SoapUI. Double click on create operation and get the request window. Fill the parameter values as shown. Before submitting make sure you set the endpoint as the URL returned as serverUrl in the response of login method.
On successfully executing this server will return the recordId of Sobject record.


I hope this blog helps you get started on understanding how API works and more specifically the detailed flow of data on HTTP using SoapUI.

Cheers!
Kartik

Wednesday, September 19, 2012

Natural Language Processing with Python

NLTK is a leading platform for building Python programs to work with human language data. It provides easy-to-use interfaces to over 50 corpora and lexical resources such as WordNet, along with a suite of text processing libraries for classification, tokenization, stemming, tagging, parsing, and semantic reasoning.Natural Language Processing with Python provides a practical introduction to programming for language processing. Written by the creators of NLTK, it guides the reader through the fundamentals of writing Python programs, working with corpora, categorizing text, analyzing linguistic structure, and more.

Lets start with steps to install NLTK and other utilities.

Steps:
  1. Install Python: http://www.python.org/download/releases/2.7.3/
  2. Install Numpy (optional):http://sourceforge.net/projects/numpy/files/NumPy/1.6.2/numpy-1.6.2-win32-superpack-python2.7.exe
  3. Install NLTK: http://pypi.python.org/pypi/nltk
  4. Install PyYAML: http://pyyaml.org/wiki/PyYAML
Now if you type the command import nltk at IDLE shell you'll get the nltk module loaded and cursor will come to next line.

Power of NLTK:
1. Tokenizer: This returns you list of tokens present in a sentence you provide as parameter to tokenizer.




2. Part of Speech tagger: This tags the tokens within sentence with appropriate tags like NP, VP, JJ, etc.

It is possible that you get such error:

You can resolve this with command nltk.download(). This will bring the NLTK downloader:

Select the "book" entry and hit download button. This will start downloading required packages associated with book. In this step we are actually downloading corporus for NLTK.

Once you download the corporus, rerun the same command and you will see sentence being tagged with Nouns, Verbs, Adjective,etc. :

3. Parse Tree using Context Free Grammar(CFG)
Now lets see the power of recursive descent parser in recognizing a sentence apropos to a context free grammar. Consider we have a context free grammar:
S -> NP VP
VP -> V NP | V NP PP
PP -> P NP
V -> "saw" | "ate" | "walked"
NP -> "John" | "Mary" | "Bob" | Det N | Det N PP
Det -> "a" | "an" | "the" | "my"
N -> "man" | "dog" | "cat" | "telescope" | "park"
P -> "in" | "on" | "by" | "with"

Sample sentence that can be produced by this grammar is :
Mary saw Bob

Let see how it works:


- We start with specifying the grammar 
- We split the sentence in tokens by " "( blank space)
- We create instance of recursive descent parser using this grammar
- We create a tree by calling parse method of the parser
- As a result we get the parse tree for the sentence


I hope this post throws some light on natural language processing capabilities of python.





Tuesday, August 7, 2012

Writing Your First Sugar Activity !


The best open source project to work with is "Sugar" primarily developed by SugarLabs and developers, contributors around the world. As a  Sugar Evangelist, I take this opportunity to share this post that describes on how you can get started with your first Sugar activity. The program that runs on Sugar Desktop environment is called as an Activity.





Prerequisites:
  • Familiarity with Python and PyGTK(Python interface for GUI programming using GTK+)
  • Sugar Desktop environment( installed, build or emulator on qemu)
  • GTK+ packages installed on you Linux flavor.
The example Activity shared in the following section has been tested on Fedora 17( Beefy Miracle).

1. Create a directory structure :

mkdir -p KartikActivity.activity/activity

2.Create activity.info :

Create a file inside the "activity" sub directory with name "activity.info" to describe your bundle in the activity sub-directory. The Activity Bundles specification explain in detail the meaning of each field.Write downs attribute names and corresponding values in this file as :


[Activity]
name = Kartik
bundle_id = org.laptop.Kartik
exec = sugar-activity Kartik.KartikActivity
icon = myicon
activity_version = 1.0
show_launcher = yes



example :

3. Activity Icon:

Design an icon for your activity by following the instructions on making icons for Sugar and place it in the activity sub-directory. The file name should match the icon file name specified in the info file (e.g. myicon.svg).

I used the same icon as is used in paint :

4. Create setup.py:

Write the setup.py script in the top level directory (e.g. KartikActivity.activity/setup.py). The content should be like:

from sugar.activity import bundlebuilder
bundlebuilder.start()

A more advanced version, which supports building activity bundles without Sugar installed, looks like this:

 #!/usr/bin/env python
 try:
     from sugar.activity import bundlebuilder
     bundlebuilder.start()
 except ImportError:
     import os
     os.system("find ./ | sed 's,^./,KartikActivity.activity/,g' > MANIFEST")
     os.system('rm KartikActivity.xo')
     os.chdir('..')
     os.system('zip -r KartikActivity.xo KartikActivity.activity')
     os.system('mv KartikActivity.xo ./KartikActivity.activity')
     os.chdir('KartikActivity.activity')

5. Code your activity in Python:

The name you specified in the .info file as "class" is the name of the class which runs your code. For the activity.info file above, we specify a top-level module named KartikActivity.Kartik

The content in Katik.py file :

from sugar.activity import activity
import logging

import sys, os
import gtk

class KartikActivity(activity.Activity):
    def hello(self, widget, data=None):
        logging.info('Hello Kartik')      

    def __init__(self, handle):
        print "running activity init", handle
        activity.Activity.__init__(self, handle)
        print "activity running"

        # Creates the Toolbox. It contains the Activity Toolbar, which is the
        # bar that appears on every Sugar window and contains essential
        # functionalities, such as the 'Collaborate' and 'Close' buttons.
        toolbox = activity.ActivityToolbox(self)
        self.set_toolbox(toolbox)
        toolbox.show()

        # Creates a new button with the label "Hello Kartik".
        self.button = gtk.Button("Hello Kartik")

        # When the button receives the "clicked" signal, it will call the
        # function hello() passing it None as its argument.  The hello()
        # function is defined above.
        self.button.connect("clicked", self.hello, None)

        # Set the button to be our canvas. The canvas is the main section of
        # every Sugar Window. It fills all the area below the toolbox.
        self.set_canvas(self.button)

        # The final step is to display this newly created widget.
        self.button.show()

        print "AT END OF THE CLASS"

6. Create a MANIFEST:

(e.g. KartikActivity.activity/MANIFEST), containing the list of the files (relative to the directory that the MANIFEST is in) to include in the package. (Note: Be sure not to leave blank lines at the end of the file.) This script does that in linux (run it from within the KartikActivity.activity directory):

cd KartikActivity.activity
find . -type f | sed 's,^./,,g' > MANIFEST

Content of MANIFEST should look like this:

activity/myicon.svg
activity/activity.info
MANIFEST
Kartik.py
setup.py

7. Give permissions:

Make sure that all your python files have the required permissions to be used.

chmod a+x setup.py
chmod a+x Kartik.py

8. Bundle your Activity:

Setup your bundle for development (must be user olpc when you do this) to become user olpc, type: su - olpc
If you are prompted for a password, trying using: su

python setup.py dev

This just creates a symlink to your activity folder in ~/Activities, so that Sugar can find your activity.

9. Run your Activity !:

Restart Sugar using Ctrl-Alt-Erase and your activity will appear in the interface! (NOTE: By default, the Home view shows only the favorite activities. You should press Ctrl+2 or go the right-upper corner and change to the List View)

Now you can see your activity is visible within Journal:

Thursday, July 26, 2012

Firefox OS :: Boot to Gecko: Next Gen OS using WebApps from Mozilla !

Firefox OS
B2G Logo


Hello friends,

I was eagerly waiting to dig into Boot to Gecko, build it and run on my Linux machine. I am amazed by concept of using collection of webApps to act as Desktop environment for an OS. Boot to Gecko (B2G) is a new mobile operating system developed as part of the Mozilla project. It uses a Linux kernel and boots into a Gecko-based runtime engine, which lets users run applications developed entirely using HTML, JavaScript, and other open web application APIs.

So what does Boot to Gecko stands for ? Gecko is a Rendering Engine used by Firefox. So they want you to boot up your mobile device directly to Gecko rendering engine-which is responsible for rendering web pages in your firefox browser. Developers contributing to Mozilla have placed all the pieces together to create a complete desktop environment around the Linux Kernel. This is similar to what we have in most of Linux distributions where GNOME is the desktop environment for Linux Kernel.

Another core component of Boot to Gecko project is Gaia, a collection of web apps which make up the UI for the desktop enviroment. All you need to know in order to contribute to this project is HTML5 ! Yes, You read it right, its HTML5. You can develop apps on the fly with HTML5 and rich media and use it. 

Mobile applications are majorly categorized into 3 categories: Native app, Web app and the Hybrid app( mix  of both). So majority of applications being used in the current trend are Web apps and the hybrid apps built using HTML5. Thus, it is a great opportunity for app developers to publish, test their apps on Boot to Gecko and enhance them to explore rich API of the OS.

The concept is to use HTML tags to render application. application will consist of tree of widgets which are also written in HTML5. The rendering engine, Gecko is then responsible to interact with Gaia, run time engine and the Linux Kernel to perform operations. The best part here is that this projects allows developers to explore OS level API, phone level API using HTML tags itself.

So lets dive into steps on how to build B2G Desktop on your machine and start it.

Get the Nightly Build

You can download nightly builds of B2G desktop available here (specifically b2g-16.0a1.en-US.linux-i686.tar.bz2 from this location):  
http://ftp.mozilla.org/pub/mozilla.org/b2g/nightly/latest-mozilla-central/ 

Checkout Gaia

Now checkout Gaia in order to create a profile for running the desktop builds using git. This is a lengthy process, a .bz2 file of approx sixe~160MB is downloaded. So be patient: 
$ git clone git://github.com/mozilla-b2g/gaia



Build Gaia

Once you are done with checkout  you need to build gaia profile using following command:
$ make -C gaia profile



This step creates a profile to access gaia interface. This is very time taking step as it downloads another .bz2 file of approx ~332MB.

Run B2G

Once your make process is complete you can run the B2G desktop build by using this command(make sure you are within b2g directory):
$ ./b2g -profile gaia/profile




You're ready to use your Firefox OS !

Cheers!

Sunday, July 22, 2012

Sugar-build: an alternative to Sugar-JHbuild for Fedora 17




We have seen a complex process involved in building sugar on fedora 14 using JHBuild. Now we have an easy way out to build and run sugar by using sugar-build.

sugar-build it is an alternative of sugar-jhbuild developed by Daniel Narvaez that allow us to get a development version of Sugar easier than with sugar-jhbuild. Also, it works on Fedora 16, 17 and Ubuntu 12.

 Yesterday, I was able to build sugar on my Fedora release 17( Beefy Miracle). So here I am sharing my experience with sugar-build.


These are the steps to build and run sugar on the fly using sugar-build:

Get the source code
You need to get the latest repository of sugar using git

$ git clone git://git.sugarlabs.org/sugar-build/sugar-build.git

Make
Then run the make command to build it( It usually takes 20-30 mins depending on processor and RAM)
$ make

you will see such message once make is complete:



Run
Once the make process is complete you should be able to run your sugar environment
$ make run


and here you go....your sugar is up and running!
You can switch between your fedora environment and sugar by Ctrl+Alt+F1 and Ctrl+Alt+F3
Journal in Sugar

Activity List view in Sugar
Pippy Activity in Sugar

Saturday, July 21, 2012

Building Sugar using JHBuild on Fedora 14



In this post I will describe the process of building Sugar using JHBuild. You can use Debain, Fedora or Ubuntu for this process. Fedora is suggested to avoid conflicts of you want to share your code with community.

  • Make sure you don't follow the following process as root to avoid any unpredictable results that can affect your system.
  • Make sure you have these installed in your system before starting the build process:
    • python: The sugar-jhbuild command is a Python script, so you need the Python interpreter.
    • git: To get the source code of sugar-jhbuild itself and many other Sugar packages you need the git command-line tool from the distributed version control system of the same name. In many distributions the minimal package you need to install is "git-core". 
    • subversion: A few packages (as of January 2010, only squeak and part of etoys) do not use git, and you need the svn command-line tool from the Subversion version control system to get their source code. 
There are basically two ways to do: one is to git clone the sugar base and build it( This will bring out  latest code base from git) and other approach is to download the jhbuild zipped file, extract it and start building it.

 First approach: git clone the sugar base and build it( This will bring out  latest code base from git repository

The first approach gives issues most of the times. Let's dive in details and see what error it gives and what is the root cause for it ?

Check out sugar-JHBuild

Create a directory within your home directory:
So I will be checking out sugar-jhbuild within:/home/kartik/Sugar_Repository
Execute this command to checkout:

You will such output if checkout is successful:

Update Sugar base system and dependencies

Change directory :
cd sugar-jhbuild

Now update the sugar base system by executing this command:
./sugar-jhbuild update

In case you get such error : "ERROR: Could not run lsb_release. Is it installed ?"

It means your systems does not have redhat-lsb package( for Fedora 14)( for Fedora 17 the missing package  is redhat-lsb-core)

You can install this package executing yum command:
yum install redhat-lsb

This will install missing package:


Now rerun the update command:
This time it won't give any error and you see it will check 27 packages and update each of them is required.

After this check for any dependencies the sugar base system has by executing this command:
./sugar-jhbuild depscheck

It will list down list of packages the sugar base system is dependent on:

You can install these dependency packages by executing yum command( you need to use su command for this to go into root mode and then execute yum):
yum install

Once install is complete you can recheck if there is any dependency package left that is not yet installed. This time you get this message if all dependent packages are installed:
"All dependencies are installed"


Build Sugar

Now we can start building this by executing this command:
./sugar-jhbuild build


You will see the progress as :

this goes smooth till package 7. It throws error when building phase 8: telepathy-python:


Now even if we try to install librsvg package using yum, it will ask for gobject-introspection with version>=1.3.0:
checking for gobject-introspection... configure: error: You need to have gobject-introspection >= 1.30.0 installed to build sugar-toolkit-gtk3

you can try to resolve this by yum :
[root@fedora sugar-jhbuild]# yum install gobject-introspection-devel
Loaded plugins: langpacks, presto, refresh-packagekit
Adding en_US to language list
Setting up Install Process
Package gobject-introspection-devel-0.
9.3-1.fc14.i686 already installed and latest version
Nothing to do

 But fedora 14 can have gobject-introspection with version 0.
9.3. which can't be updated.
So this is roadblock in this approach while building sugar using latest JHbuild

Second approach : Download the jhbuild zipped file, extract it and start building it.
Lets dig into another approach where you download the JHBuild version specific to Fedora 14 and then build sugar.

Download the JHBuild zipped file from http://people.sugarlabs.org/
anish/sugar-jhbuild-dx3-0.92.
4dx3-20110725.tar.gz

Then extract the zipped file by executing this command:
 tar -xvf sugar-jhbuild-dx3-0.92.4dx3-20110725.tar.gz

Get into JHBuild directory:
cd sugar-jhbuild-dx3/

Install all packages specified by result of this command( This list down packages on which sugar base is dependent):
./sugar-jhbuild depscheck

Install the packages:
sudo rm -r install/

Build the sugar base:
./sugar-jhbuild build -n -a --clean

Once the build process is complete, you can start the sugar emulator with latest sugar base which you just build:
./sugar-jhbuild run sugar-emulator 

 and there you go ...your sugar desktop environment is up and running!


Courtesy: Anish Mangal for the second approach :)


Happy Hacking !