For surely there is an end ...

... and thine expectation shall not be cut off.

First python 3.0 try !
[info]baijum81
Congratulations to Guido and all other Python developers !

Today I came to office for some works, but when I looked at planet.python.org
I found many posts about Python 3.0 alpha1 release. Then I downloaded Python 3.0
from here: http://www.python.org/download/releases/3.0/

Here is my first "Hello World" program after compilation:


And here is the digg story (Digg it!): http://digg.com/programming/Python_3_0a1_Released

BTW, it would be really useful if "2to3" is available as egg.

Zope 3 has started discussing about Python 3 port, but it looks like no one is interested.

One of my favorite toolkit is PyGTK, and see they are really going to port it soon. But it will be only released after Python 3.0 final release.
Tags: ,

Why I am biased?!
[info]baijum81
I was always biased towards many technologies. My favourite programming
language is Python, My favourite GUI toolkit is PyGTK. My favourite editor is
GNU Emacs. And my favourite web framework is Zope 3.

But I think I have to look into django now, because of these posts:
http://www.advogato.org/person/titus/diary.html?start=186
http://tabo.aurealsys.com/archives/2006/08/18/guido-van-rossum-and-django-redux/
http://pyre.third-bit.com/blog/archives/613.html
http://programming.reddit.com/info/dykr/comments
http://www.djangoproject.com/weblog/2006/aug/07/guidointerview/

BTW, Zope 3.3 is coming: http://www.zope.org/Products/Zope3 . Now I am a Zope 3
developer, want to learn the internals for contributing, only few minor commits
so far. I managed to create this page: http://kpug.zwiki.org/WhatIsNewInZope33

Functional/Acceptance Testing Using guitest
[info]baijum81
Introdution


guitest (http://gintas.pov.lt/guitest) by Gintautas Miliauskas is a helper
library for unit-testing GUI applications written in Python. In this article I
will demonstrate how to test a PyGTK application. This article assume you are
familiar with ``unittest`` module and unit testing.


Installation


The latest version 0.3.1 released on 2005-11-26 is available from here:
http://gintas.pov.lt/guitest/guitest-0.3.1.tar.gz . Invoke `python setup.py
install` to install the library into the local python's site-packages
directory. Alternatively you may simply copy the guitest subdirectory to your
project's main source directory.


Getting Started


Consider this example ::
  import gtk

  class HelloWorld(object):

      def __init__(self):
          self.window = gtk.Window()
          self.button = gtk.Button("Hello")
          self.window.add(self.button)
          self.window.show_all()

      def main(self):
          gtk.main()

  if __name__ == '__main__':
      helloworld = HelloWorld()
      helloworld.main()

Now think what are the things you have to test. Let's say you want to make
sure that button is a child of window. And you want to test the label of
button is "Hello".

Just look in to this code, should be very easy to understand. ::
  import unittest
  import gtk
  from guitest.gtktest import GtkTestCase

  import hello1


  class TestHelloWorld(GtkTestCase):

      def test_simple_run(self):
          helloworld = hello1.HelloWorld()

      def test_button(self):
          helloworld = hello1.HelloWorld()
          button = helloworld.window.get_child()
          assert type(button) == gtk.Button

      def test_button_text(self):
          helloworld = hello1.HelloWorld()
          button = helloworld.window.get_child()
          assert button.get_label() == "Hello"


  def test_suite():
      suite = unittest.TestSuite()
      suite.addTest(unittest.makeSuite(TestHelloWorld))
      return suite


  if __name__ == '__main__':
      unittest.main()

The test case class is inheriting from ``GtkTestCase``. `test_simple_run` is
just running the app. Other two test cases are self explanatory, yes! you
should be familiar with gtk api, that's all.

When testing gui, dialog handlers will be very usefull. We will extend the
first example::
  import gtk

  class HelloWorld(object):

      def __init__(self):
          self.window = gtk.Window()
          self.button = gtk.Button("Hello")
          self.button.connect("clicked", self.on_button_clicked)
          self.window.add(self.button)
          self.window.show_all()

      def on_button_clicked(self, *args):
          dlg = gtk.MessageDialog(None, 0, gtk.MESSAGE_INFO, gtk.BUTTONS_OK)
          dlg.set_markup("OK")
          ret = dlg.run()
          dlg.destroy()
          return ret

      def main(self):
          gtk.main()

  if __name__ == '__main__':
      helloworld = HelloWorld()
      helloworld.main()

Here is setting a dialog handler for 'Hello' button and testing the label text::
  import unittest
  import gtk
  from guitest.gtktest import GtkTestCase, guistate

  import hello2

  class TestHelloWorld(GtkTestCase):

      def test_button_clicked(self):
          helloworld = hello2.HelloWorld()
          button = helloworld.button
          guistate.dlg_handler = self.handle_hello_clicked
          button.emit("clicked")

      def handle_hello_clicked(self, dlg, *args):
          label = dlg.label
          if label.get_label() == "OK":
              return gtk.RESPONSE_OK
          else:
              self.fail("Label is not 'OK'")


  def test_suite():
      suite = unittest.TestSuite()
      suite.addTest(unittest.makeSuite(TestHelloWorld))
      return suite


  if __name__ == '__main__':
      unittest.main()

For experimenting this code, just change the assertion, 'label.get_label() ==
"OK"'. If there is another dialog box coming after 'OK' button clicked, you
can add a new handler inside `handle_hello_clicked` function. For example::
  def handle_hello_clicked(self, dlg, *args):
      label = dlg.label
      if label.get_label() == "OK":
          guistate.dlg_handler = self.handle_ok_clicked
          return gtk.RESPONSE_OK
      else:
          self.fail("Label is not 'OK'")
Tags: ,

Singleton pattern for a database connection
[info]baijum81
I think I understood Singleton pattern, any suggestion?
from pyPgSQL import PgSQL

class Database(object):
    _sigletons = {}
    def __new__(cls):
        if cls not in cls._sigletons:
            cls._connection = PgSQL.connect(database='dbname',
                                            user='username',
                                            password='passwd',
                                            host='hostname')
            cls._sigletons[cls] = object.__new__(cls)
            pass
        return cls._sigletons[cls]
    
    def __init__(self):
        self.connection = Database._connection
        pass
    
    def cursor(self):
        return self.connection.cursor()
    
    #other methods follows here

#just to test logjam
Tags: ,

Culebra, my working copy
[info]baijum81
I am plannig to put my working copy of Culebra here :
http://baijum81.freezope.org/downloads/culebra.tar.bz2
Tags:

Culebra IDE
[info]baijum81
http://developer.berlios.de/projects/culebra/

This project originally called grad (started by fernado), then
I renamed to grade and hosted at sarovar.org, now it is moved
to berlios.de with a new name 'Culebra' which is a spanish word
with meaning snake (I don't know which snake). Actually
Python has nothing to do with reptiles, but I think many pythonistas
like snake names. I am a member of BangPypers (http://www.bangpypers.org),
they are planning a project called 'Uraga' which are reptiles with super
powers in indian classics. But I don't like reptiles, but the name 'Culebra'
sounds very good. Hope it will become a very successful project.
Tags:

Grade Project CVS
[info]baijum81
Yesterday, I imported Fernando's source as such to Sarovar CVS.
And I made two commits to Grade (http://sarovar.org/projects/grade)
Hope I will be able to improve it.

I set up two mailing lists, grade-devel@lists.sarovar.org
and grade-user@lists.sarovar.org, but not yet made any post.

To run grade first check out it from cvs,
then install gnome-python-extras
Now,
$export PYTHONPATH=$HOME/garnome/lib/python2.3/site-packages/:$PYTHONPATH
$python grad.py
Tags:

GRADE Project
[info]baijum81
I think I will be able to spend some time for
GRADE Project. http://sarovar.org/projects/grade
Tags: