Showing posts with label Internship. Show all posts
Showing posts with label Internship. Show all posts

Monday, September 1, 2008

Internship @ Pardus

I've entered my TOEFL exam and it was pretty good, except for the listening part in which I lost my attention and thought about the examination software (it was written in Java but the Cambridge, Longman etc. preparation CDs are prepared in Shockwave as I saw). I asked myself: "Why don't they write them in Java too so that I can use them on Linux? And guess what, at that moment, a lecture was being given on the computer and I lost lots of details :D

Nevermind, I started my third internship last week, in TÜBİTAK (National Scientific Research Center) on Pardus Linux Distribution Project. It's been very beneficial for me so far. I've learned lots of things about software, python, GUI design and opensource. I want to share what I've learned in this blog as much as I can do. You can see examples here. I've written a program called Sahip, which is an XML generator. It produces the installation settings for Yali (installation software of Pardus) to perform silent installs.

PyQt4 GUI Building
Let's start with PyQt4 GUI building. I used to think that we could not import GUI files from python modules and this caused us to refactor our python code whenever we wanted to change the gui, unlike GTK with Glade (you can import XML from python). But I was wrong. There was some options I could follow. One of them is the kdedesigner module for python. But I used the other one, inheriting the compiled GUI.

After you design a GUI on Qt Designer 4, you can compile it to Python code with:

pyuc4 gui.ui -o mygui.py -x


and after that we can import and inherit it as written below:

from PyQt4 import QtCore, QtGui
from sahip.usergui import Ui_UserDialog

class UserDialog(QtGui.QDialog):
def __init__(self, caller=None, user=None):
QtGui.QDialog.__init__(self, None)
self.ui = Ui_UserDialog()
self.ui.setupUi(self)

self.ui.lineEdit.setText('test')
# All the other stuff here or in other methods.

if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
UserDia = UserDialog(None)
UserDia.show()
sys.exit(app.exec_())


That's all!

Opening up a new dialog
I imported UserDialog class above and used it as a dialog.

def slotUserNew(self):
self.userDialog = QtGui.QDialog(self)
self.userDialog.ui = UserDialog(self) # caller=self
self.userDialog.ui.show()


Lists items with checkboxes

You can set all the items of a list have a checkbox near it with the following code:

for i in range(count):
item = self.ui.groupList.item(i)
item.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
item.setCheckState(QtCore.Qt.Checked)


Handlers
In lists, I could only store the username of a user but the rest of the information should be stored somewhere else. That could be a dictionary, list etc. Dictionary was the most convenient for me but I had to define a dictionary for each list/combobox. That was a replication of code! So I wrote WidgetHandler, and specialized ListHandler, ComboBoxHandler to store them and defined addItem/removeItem, etc. methods to update both the dictionary and the widget. It was much more clear.


i18n

I have always wondered about internationalization and I saw that it was pretty easy. What you should do is to add the following code to the beginning of each of your files you want to be translated.

import gettext
__trans = gettext.translation('sahip', fallback=True)
_ = __trans.ugettext

and you will use _('string') instead of 'string' if you want that string to be translated. And here comes the pot file generation part. As you can see the example project on the link above, I have a tools, po and sahip directory. So I recommend you to create such directories. I put pot generator sh file into tools dir and po/pot files into po dir. After creating an empty po dir, you can execute the following script (above po dir)

#!/bin/bash
LANGUAGES=`ls po/*.po`
set -x

xgettext -L "python" -k__tr -k_ sahip/sahip sahip/*.py -o po/sahip.pot
for lang in $LANGUAGES
do
msgmerge -U $lang po/sahip.pot
done

As you might understand, this script crawls through the given paths (sahip/sahip and sahip/*.py) and generates pot file by reading the py files and main (non-extensioned) sahip file. You will then find the pot file in your po directory. You can translate and rename it to lang.po format (tr.po, de.po, es.po). Then the python setup script will probably compile po file into mo file and copy it into proper place.


Setting Icon
  1. Create a directory called images in the same directory of your codes.
  2. Put an image file in it, such as icon.png
  3. Create a qrc file such as resources.qrc and fill it with the content

    images/icon.png


  4. Open your GUI with Qt4 Designer and click on ... button of windowIcon on the Property Editor when main form is selected.
  5. A dialog will be shown, click on pen and then the open button (middle). Select the qrc file you created.
  6. Select the icon appeared on the right side of the dialog and click OK.
  7. Save the GUI.
  8. On the console, apply the following command:

    pyrcc4 resources.qrc -o resources_rc.py

  9. Generate your gui py file with pyuic4 and that's all!
Publishing the Code
I needed to copy YALI setup.py file and modify it for sahip. This file compiles po and qrc files, and then copy required files to the system for installation. Then I wrote a digestrelease.py script which copies the program directory to desktop and removes the unnecessary ones. Then the packager.py file compresses the directory and sha1sums it, updates a sample pisi pspec.xml file with the sha1sum, uploads the compressed targz file to ftp server and then build the pisi package, and install it.

It was a good way of automation for me. I could make modifications and try the result in seconds. I might have written this entry too confusing, sorry but I don't have much time. My next project is to develop a web site where files can be searched within the pisi packages so that for instance you can find which package the 'ls' file comes from. I'm currently writing the database generator and after I'll pass to the Django side.

Friday, August 8, 2008

New electrolyzers open up the way to Solar Century

In the earlier days of this week, while watching CNN International, I run into a wonderful news. The visitor was a professor from MIT and they were going to talk about a recent invention on storing solar energy.

As you may know, solar energy is known to be unlimited as long as the sun lives but limited as it can't be used efficiently because not only the solar panels can't absorb all the energy but also the energy can be obtained only during the daytime. It seems that the absorption is still a problem but the recent news promise in storing the excess energy.

The scientists at MIT, have found a new method to store the excess energy by dividing the water into its ingredients, Hydrogene and Oxygene. Heey, this is already being done worldwide, you might say. But this operation needed high maintenance costs and abnormal operation conditions(temperature, pressure, etc.). This new method, inspired by the photosynthesis, uses a new catalyst consisting of cobalt metal, phosphate and an electrode to produce Oxygen and another catalyst like platinum to produce Hydrogen and does not require any special conditions for the reaction to start.

As this is an easy-implementing method of storing energy, it is tought to change the world, contributing to the works on solutions for the global warming problem. But as the proffessor says, it will take 8 years for us to have these sets on our roofs. I wish it was closer if it was that easy to implement but maybe the other (efficient absorption) problem needs to be solved in order these products to be more efficient.

By the way, I have finished my internship. Nowadays I'm preparing for my TOEFL exam and working on Python as usual. My Python presentation went very well and I saw that most of the aspects of Python could be introduced in 2 hours! Such a beautiful language...

Friday, July 25, 2008

BOLO and Python

We worked on BOLO for some time but we found it very complex. The code is unnecessarily too much (less code could achieve the same functionality). One manager for each POJO is defined although those manager methods could be defined in POJOs. So, crawling in the code is a funny(!) way of spending time for us (me and Melih). We tried to implement the search by status functionality but got stuck at the enumarator types for the Status class properties. Showing them on JSF and selecting them is a problem. Then we tried to add a timestamp on the CVs uploaded. But finding the code where the file is uploaded, where the filepath is inserted into the database were the problem in that case. Moreover, the service had been giving "Out of memory" errors after 10 minutes of run.

Getting bored from all these stuff, I tried to write the model in Python/Django. It was a good try. I found a model to UML Diagram script and generated a database model diagram. Showing the diagram, Melih was impressed by the easiness and practicality. Then he wanted me to show my work to the team leader and I showed what I did:
But he did not welcome my work as much as I expected: "Good, but when your internship ends, there's nobody to maintain it here. I don't want my staff to learn Python for such a thing. Because nobody uses Python". I didn't know what to fell sorry for. For my effort, or the misknowledge for Python. Nevermind, I'm spending my time with some trying on that BOLO stuff, and some with fixing some errors in my Python projects.

By the way, some colleagues wanted me to give a talk about Python and how it is used. I'm going to get prepared for it and give a brief presentation called "Python for Java Geeks". So, first of all, I have to find some resources on the differences between Java and Python so that making it easier to understand, I can go faster. Maybe in 3 hours, instead of 8 hours that I had given at school for programming newbies.

Tuesday, July 22, 2008

BOLO

After the crazy boring minutes of trying to develop a new project with appfuse, my guide told me that he has found a project of his colleagues: BOLO. This is an interview manager, developed using appfuse (JSF+Hibernate) as a final thesis in Ege University. We are going to improve it by fixing some lackness and adding new features on it. We are going to work on it this evening (overtime) to understand its structure. Now, I'm preparing my internship report, filling the part for SOA. This is at the same time a preparation for my SOA presentation which will be at the end of my internship.