Monday, January 19, 2009

First GUI "Hello World!" using Python

This is exciting!! I always want to learn how to program a GUI application for Linux (GNOME). Finally I made it!

There are many programming language can do a GUI application for Linux. I myself is a Web application programming using ASP and PHP. Sometimes I also program application for Windows using Delphi. The reason I use Python is simply because it is pre-installed. :P~ And lot of people saying that program Python using Glade is very simple and fast especially the graphical interface.

Lets try a simply one first. Open the terminal, and type gedit helloworld.py. Copy and paste the codes below:-

#!/usr/bin/python

import pygtk
pygtk.require('2.0')
import gtk

class Whc:
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("destroy", self.destroy)
self.window.set_title("Hello World!")
self.window.set_default_size(200,100);

self.label = gtk.Label("Hello World!")
self.window.add(self.label)
self.label.show()
self.window.show()

def destroy(self, widget, data=None):
gtk.main_quit()

def main(self):
gtk.main()

if __name__ == "__main__":
base = Whc()
base.main()

Save and close it. Then type python helloworld.py and a window with the word "Hello World!" will appear on the top left side of your desktop.



You can also make it become self executable. Just change its mode using chmod command: sudo chmod +x helloworld.py

Then you can type ./helloworld.py to run it.

Python also allows you to compile it into Bytecode (.pyc). Just type python in the terminal and press enter. At the >>> prompt, type the codes below line by line:-

import compiler

compiler.compileFile("helloworld.py")

exit()


Then a file called helloworld.pyc will be generated. Change its mode to executable:

sudo chmod +x helloworld.pyc

and you can run it directly now:

./helloworld.pyc
.


You can also create a simple compiler yourself that can save a lot of time typing the codes in Python everytime. Create a file called pycompiler.py and paste the codes below:-

#!/usr/bin/python

import sys
import compiler

compiler.compileFile(sys.argv[1])


Immediately use it to compile itself:-

python pycompiler.py pycompiler.py

And change it to executable mode.

sudo chmod +x pycompiler.pyc

Next time you can use it to compile the .py file, the usage is:

./pycompiler.pyc FILE...

:)~



Additional links:

GNOME information @ wikipedia
GTK information @ wikipedia
PHP-GTK information @ wikipedia

Tutorial video of Building a GUI applications with Python, GTK and Glade

Monday, January 12, 2009

Remote Desktops Client

There is a pre-installed program called Terminal Server Client similar like the Remote Desktop Client in Windows. This is how it looks like:-

It support RDPv5 (Windows XP and newer version) and RDP (Windows 2000 and older version) protocol. Easy to use.

Tuesday, January 6, 2009

DVD Ripper

I like AcidRip. It is very easy to use and the outcome is good! :) It can be install from package manager, look for AcidRip DVD Ripper. So here is it:-


First, clicked the Load button. Then the track list will be shown.

In the general tab, you can set the video(avi/mpg) and sound(copy/pcm/mp3lame/lavc/twolame/faac) format, language and subtitle.


In the Video tab, you can set the video codec (copy/raw/nuv/lavc/libdv/xvid/x264), Crop (Widht/Heigt) and Scale (Widht/Heigt).

For those who not familiar in DVD Ripper, video and audio codec, here is the tips:-

General:
Filename Extension: .avi

Audio:
Audio Codec: mp3lame

Video:
Video Codec: xvid
Crop: no (un-tick)
Scale: no (un-tick)

The rest just use default setting. Select the track and click Start.

Tips #2: If you feel that the Video quality is not good, you can change the bitrate in the video tab. Audio bitrate can be change in the General tab - Audio Option: br=128. To cancel the ripping process, click on the Full view button, and then click the Stop button.



Saturday, January 3, 2009

Sound Convertor

I got a friend asked me if I can convert the Ogg format to MP3. So I opened the Package Manager, search the keyword Ogg. I found an application called OggConvert, without reading the long description, I installed it.

Then I found out that I make a mistake, this application actually converting other sound format to Ogg format. Anyway, it's very light, simple and easy to use. Here is how it looks like:-


When I clicked on the Advanced option, it only can convert to Ogg and Matroska format.

Alright, time to find another converter. By using the same keyword, I found an application called Sound Converter. Oh~ why can't I see it in the first place? Because the OggConvert is on top of it. haha.


So this is Sound Converter. Looks very simple too. But when I opened the Preferences, I notice that the MP3 radio button is not active. And I saw this words: "See this howto to enable mp3 encoding" at the bottom. So just click the howto, and then click the Ubuntu 7.10 and more... it will start install the GStreamer MP3 Encoding.


Finally restart the Sound Converter. Yes, can select MP3 now.

Friday, January 2, 2009

New Author!

Yep~ this blog has a new author now.

Let's welcome ultrasong.


He is one of my friends who doing networking (mostly in Windows platform).

He is major in network security (Router, firewall, anti-virus.... etc).

He is good in Chinese (can find lot information from Chinese website).

He is good in gaming (always kill me in dota :\ ).

And the most important thing is... he want to learn Linux now, so immediately I invite him into my blog. My Ubuntu gang getting bigger and bigger now. :D yea~~~~~~~~~~~~

blankblankblankblankblankblbelated
Wishing all of you a Happy ^ New Year. :)~