Category Archives: Python

My coding and hacking experiences with Python (and other related stuff)

How to Embed Web Browser in Python GTK application using pymozembed

Embedding web browser or a screen for parsing HTML is easy in PyGTK. You only need to import the pymozembed, and add a few lines of code in your pygtk library, and you are set to go.

Here’s a sample PyGTK application that embeds a web-browser as well as a “Back” button for demonstration purpose :

PyGTK + browser Screenshot
PyMozEmbed PyGTK+ Mypapit Demo

[python]
#!/usr/bin/python
#
# demo by mypapit ([email protected]) – Sept 2009
# http://blog.mypapit.net/
#
import pygtk
pygtk.require(’2.0′)
import gtk
import gtkmozembed

class PyMoz:

def delete_event(self,widget,data=None):
print(“Exit”)
return False

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

def button_clicked(self,widget,data):
data.go_back()

def __init__(self):
#init mozembed
self.moz = gtkmozembed.MozEmbed()
#create a Vertical Box Container to whole the browser
#and the “Back Button”
box = gtk.VBox(False,0)

#create a basic GTK+ window
win = gtk.Window()
win.add(box)

#create and connect “Back” button, to add functionality
self.button = gtk.Button(“Back”)
self.button.connect(“clicked”,self.button_clicked,self.moz)

#include both back button and the browser in the vertical box
#and the GTK+ window
box.pack_start(self.button,False,False,0)
box.pack_start(self.moz,True,True,0)

#load the URL
self.moz.load_url(‘http://blog.mypapit.net/’)

#set the window title
title=self.moz.get_title()
win.set_title(“browser demo”)

#show all the stuffs on screen
win.show_all()

#connect the delete_event and destroy event to make sure
#the app quits when the window is closed
win.connect(“delete_event”,self.delete_event)
win.connect(“destroy”,self.destroy)

if __name__ == “__main__”:
PyMoz()
gtk.main()

[/python]

Download demo source code : pymoz.py

Working hard publishing papers and learning PyGTK

For the last few weeks I’ve been working hard to finish up my research project, most of it concerning about on mobile phone application usability and context-aware applications. This leaves me with less ┬átime to devote for this blog and I started to realise that I might have a ‘burn-out’ issue at the same time.

I’m still using Ubuntu in my daily work if you are curious (Ubuntu Netbook Remix 9.04 for netbook) and Ubuntu Jaunty Jackalope for my Intel Core 2 Duo Desktop PC. Besides writing those research papers, I’ve use what left of my time to learn PyGTK to enable me to code RAD app for GNU/Linux desktop environment.

I found out the references around the internet regarding PyGTK is very helpful to aid me in understanding the GTK+ bindings in python, which is not much different from its C counterpart.

Now that I’ve some time to spare until Hari Raya, I’ll try to use that time wisely to fill up this blog with a couple more of fresh new posts. So, keep reading!

Quick and Dirty Network File sharing with Python

Ever find yourself in need to share file over the network quickly, but find yourself lacking time to setup a proper NFS or samba share? Here’s a way to do this with the good old Python CLI.

  • First, go to the directory that you want to share, for example ~/Desktop
  • Then run this command "python -m SimpleHTTPServer"
  • You may access the folder from a remote computer using any webrowser using the url – http://192.168.1.20:8000, change the ip address accordingly
Simple HTTP Server
file sharing with python

You may find this technique offers limited options to share files, but its a real time saver!

Mitter: My favorite Ubuntu Linux Twitter client

Since I’ve been into twitter recently, I’m was looking for a twitter client that is suitable for my operating system. Thank god that search ended when I found mitter.

Among mitter features are :

  • clean interface: simple and easy to use
  • supports docking on systray
  • nicely integrated with GNOME desktop
  • has console client

Bonus for Ubuntu users : mitter is also available from GetDeb.net one-click-install portal

What are you waiting for? catch me on twitter (id: mypapit)

Ubuntu Hardy Python XML error bugfix – xml.dom.ext

This was brought to my attention when I’m working on a python code to parse xml documents. I found out that in Ubuntu Hardy, the python-xml package has moved xml.dom.ext.* package to /usr/lib/python2.5/site-packages/oldxml thus breaking python code which depended on python-xml.

One way to work around this bug is to append :

sys.path.append('/usr/lib/python%s/site-packages/oldxml' % sys.version[:3])

just before you import stuff from xml.dom.ext.*. Hope that would help you.

HP Officejet 5680 – How to Send Fax from Ubuntu Linux Computer

This serves as a continuity from my previous post, I got myself a new and flexible Printer – HP Officejet 5680 All in One.

HP Officejet All-in-One Under Ubuntu
Its all seems rather easy at the way I left off, the printer is fully functioning by just plugging it to my Ubuntu pc, the scanner works well without I having to do anything special, the phone is fully functioning (yeah it is included with the printer) and I am able to send and receive fax without a hitch, something that I cant do without installing 350MB of companion application (half of it was crapware) under WIndows Vista.

Everything worked, what left to do?
What left to do is figuring out how can I send fax directly from Ubuntu (or other Linux base operating system) using only digital files (*.txt, *.pdf, *.ps, *.jpeg), so I don’t have to print those files and fax them one by one anymore.

HP Linux Imaging and Printing project
Through googling, I found that Hewlett Packard (HP) has published open source software tool to deal with their printers. Free and Open Source drivers and printer-specific application directly from manufacturer, which is very cool!

Fortunately Ubuntu already installed HPLIP tools by default with CUPS in my machine. The next step that I should take is to run ‘hp-setup’ as root to configure my printer port and run the ‘hp-sendfax’ application to send the faxes.

Both of these tool requires python-qt3 package which is available from Ubuntu software repository.

Now I can fax my pdf documents directly without having to print them first, a huge saving over ink and paper cost.

hpfax11.png

hp2.png

Conclusion
If you are planning to get a new printer, then I would suggest you get a HP printer. Not only because HP printers are reliable, but they also comes with Free and Open Source drivers and applications for the Linux based operating system. Well that’s a good reason to get HP printers.

Please visit HPLIP project website for more information about HP printers support under Linux based operating system.

[tags]hp,hewlett packard,printer,linux,opensource,ubuntu,foss,drivers,hardware,scanner,officejet[/tags]

Gyach Enhanced Yahoo Messenger with Webcam and Voice support for Linux

Ditch gaim if you happen to use Linux and Yahoo messenger on your desktop. Gyach Enhanced is an open source Yahoo Messenger client that support most of the official Yahoo Messenger features out from the box including Webcam support and Voice Chat.

Unlike any other 3rd Party Yahoo Messenger Client, Gyach Enhanced only supports Yahoo Messenger protocol and available for GNU/Linux operating system only.

Among features supported by Gyach Enhanced :

  • Webcam (Receive and Broadcast)
  • Voice Chat
  • Address Book
  • Yahoo Chat
  • Yahoo Mail Alert
  • Yahoo News Alert
  • Mobile Messenger Buddy Group
  • ‘Invisible’ support
  • Spam Protection
  • Themable Smileys


Continue reading

Guido van Rossum – fun playing Python on S60 (pys60)

Nokia 6630 MypapitThe Python for Nokia is really exciting from the moment you download it, to the moment it runs on your phone. I know that experience first hand when I saw my Python applications was up and running on my phone! Previously I only had experience writing mobile applications in Java J2ME, but writing the same stuff in Python is a whole new experience for me. It seems that I’m not the only one having fun with Python for Nokia. Python creator Guido van Rossum, also states in a forum that he has too much fun with Nokia 6630 phone that he recently acquired.

He expressed that Nokia has done an outstanding job for porting Python to its own product line, incorporating Python library inside the phone. Additionaly, extensions also exists to handle phone’s operation like dial a call, snap a picture, send/receive SMS, Bluetooth, and Internet.

Finally, Nokia has made writing Symbian applications even easier with GUI modules that handles menu, alert, tab, canvas, event loop and other low-level event without the need of recompiling application. Python for Nokia is indeed fun. Why don’t you try it yourself now?

Original forum thread : http://www.artima.com/forums/

symbian,nokia,python,pys60,s60,mobile