Monday, March 30, 2009

It's your dream also isn't it? Now, confess!

Mine for sure.


Image by XKCD

Sunday, March 29, 2009

The Treat of the Week #001

An old advertisement to remember where we were and make us think where we want to be in the future.

Copyright owner(s) is(are) unknown to me. I found this picture from juffrouwjo's photostream. Here I reproduce it under the terms of the Fair Use

Friday, March 27, 2009

Manchester Mark I - Loveletters

I know I'm quite late (or early) for a St. Valentine article but I just got late and really can't wait until the 2010 cupid.
I just wanna share with you this curious piece of history of the information technology.


The Manchester Mark I, also nicknamed "The Baby" is known to be one of the earliest electronic computers and, as the name suggests, it was developed by the University of Manchester, UK, starting from August 1948.
The Mark I is also famous because from its academic environment it spawned the world's first commercially available general-purpose electronic computer, the Ferranti Mark I.
Programming one of these illustrious ancestors was tricky. They had no defined assembly language and the instructions had to be submitted in binary code. On one intermediary version of the machine, the programmer had to manipulate switches to input programs. The output device consisted in a CRT (cathode ray tube) "screen" displaying a series of dots.
From August 1953 to May 1954 strange love letters began to appear on the the notice board of Manchester University's Computer Department. Something similar to the following example.

HONEY LOVE
YOU ARE MY DEAR PASSION: MY ADORABLE FERVOUR: MY ARDENT INFATUATION: MY ARDENT DEVOTION. MY PASSIONATE LUST BREATHLESSLY HOPES FOR YOUR LIKING. 
YOURS BURNINGLY
M. U. C.



All these letters were signed M.U.C. and I bet they were quite a chat facilitator for the campus people which did spot them, day after day, on the notice board. Remember that we were in the fifties and certain expressions of love and passion were maybe far too frank for the taste of the well bred people of the time. I can imagine the surprise when those people discovered that those proofs of feelings came from the "mind" of a machine. As a matter of fact "M.U.C." stood for "Manchester University Computer", and the love letters originated from a programme designed and written by Christopher Strachey (1916-1975), one of the researcher on the Manchester machine. Exploiting the built-in random generator of the Ferranti Mark I, the first commercial computer in history, he managed to generate texts with a purpose.
Years before, on 1949, the Manchester Mark 1 -an early academic-only computer- had successfully run a programme to search for Mersenne primes. The announcement of the success of this task caught the interest of the British press which widely reported the event using the sentence "electronic brain". This description on its turn generated a discontent in the Manchester University's Department of Neurosurgery. Sir Geoffrey Jefferson, of neurosurgery at Manchester University, expressed on the following terms when relating about the subject:
Not until a machine can write a sonnet or compose a concerto because of thoughts and emotions felt, and not by the chance fall of symbols, could we agree that machine equals brain-that is, not only write it but know that it had written it. No machine could feel pleasure at its success, grief when its valves fuse, be warmed by flattery, be made miserable by its mistakes, be charmed by sex, be angry or miserable when it cannot get what it wants.
I don't know if Strachey took inspiration to this debate for writing his programme, but true is that his intent was to show that the computer could be set up to produce artifacts which could arouse emotions into those who interacted with its output. Maybe it's also worth remembering that Manchester University's Computer Department was also the work place of Alan Turing (1912 - 1954), the father of modern computer science and one of the fathers of artificial intelligence. In 1950 Turing created the so called Turing Test with the purpose of being a reference upon which testing the ability of a machine to "disguise" itself as a human.
By the way, fast forwarding the years until nowadays, Mr. David Link created a Manchester Mark I web-emulator which runs the loveletter program by Christopher Strachey. You can access the page here.



Here's a list of resources on the subject.
Pictures and media are Copyright of David Link and The University of Manchester. They are here reproduced under the terms of the Fair Use.

Sunday, March 22, 2009

How to upgrade ALSA - The Easy Way

I got recently pissed off by a major defect occurred to my system. All of a sudden the headphones just stopped working. Actually their behaviour is quite weird: once I plug the headphones the sound is fed for about one sec and then it just die. This is one of those bugs which make you willing to swear as they affect one basic feature you may or may not want to part from.
I already tried to follow some advices dug out from some forums and went rotten (lame of me I admit it). I basically tried to remove all ALSA packages to reinstall them from scratch, and this caused a system crash and, God knows why, the X user settings to be wiped off.
After reinstalling Ubuntu Intrepid I tried another approach to simply upgradeALSA in the hope of solving my problem. Well, this hasn't but maybe you can find anyway interesting this simple method to upgrade ALSA to the latest version.
This Soundcheck guy made a script to easily retrive and install the latest ALSAdriver. The script and discussion are located in this thread on Ununtu forumsbut I will report the instructions here for convenience.
First, let's introduce ALSA by reading a brief description directly from the website of the project.
The Advanced Linux Sound Architecture (ALSA) provides audio and MIDI functionality to the Linux operating system. ALSA has the following significant features:
* Efficient support for all types of audio interfaces, from consumer sound cards to professional multichannel audio interfaces.
* Fully modularized sound drivers.
* SMP and thread-safe design.
* User space library (alsa-lib) to simplify application programming and provide higher level functionality.
* Support for the older Open Sound System (OSS) API, providing binary compatibility for most OSS programs.
Now let's go on with the instruction to upgrade the driver to the latest version.
Important Note: please before updating ALSA consider the reason you're doing it it's important, make a beckup of your files (you never know) and read carefully the thread I mentioned above. The script author says that he wrote it to be as fail safe as possible but given that it will affect low level packages please be sure you know you're doing it at your own risk.
  1. First you must download the script which can be found somewhere at the bottom of the thread or here. Note that you must register to Ubuntu forums to download the script.
  2. Save the script in your /home or wherever you like and untar it either with File Roller or Ark, or with tar xvf AlsaUpgrade-1.0.x-rev-1.16.tarfrom a terminal
  3. If you haven't done yet, open a terminal and move to the script location with cd [download directory]
  4. Type sudo ./AlsaUpgrade-1.0.x-rev-1.16.sh
  5. On the first run the script will present all the options you can select when running it for actually doing its job.
  6. To download, compile and install the packages on a single pass typesudo ./AlsaUpgrade-1.0.x-rev-1.16.sh -di Note: -di is the option to do so but there are many more to suit your needs
  7. Wait for a fifteen minutes and then reboot
  8. Have fun with your freshly updated ALSA driver

Wednesday, March 18, 2009

How I messed up my laptop with Kubuntu 8.10 KDE 4.2

I took the decision to migrate my XP laptop to Linux mostly because I wanted to sail new waters after being a MS user since MS-DOS 5.0.

Until now I must say that my experience was pretty positive. I had no major problems switching to a new system. I found substitutes for most of the software I was used to and for those few I didn't find an alternative, I relied on VirtualBox OSE and my old XP home edition. I was quite impressed by the stability and safety of the system. My laptop and me experienced a new speed we weren't accustomed to. The only thing made me a bit crazy was the impossibility to run the composite manager with application based on OpenGL or which worked with video rendering (basically Google Earth and VLC for watching videos). I understood that this was because of my ATI video card yet I was disappointed by the fact that the situation remained always the same either with Hardy and lately with Intrepid.

With the advent of the 8.10 "Intrepid Ibex" release I decided to try again something new and switched to the Kubuntu fork. At the beginning I felt both dizzy and bewildered by the KDE4 environment. It took me some times to get somewhat accustomed to the new desktop manager which sets a complete new concept of user interface. The learning curve wasn't so flat but I judged the worth the effort. On the other face of the coin the stability of the system was terrible. Panels got messed up once in a while causing me to swear first and sweat after to get everything in place. Contextual menu were sometimes weird (I couldn't open a pdf from the web on the fly but was forced to download and open it after), the ark tool won't compress -it didn't see them- some kind of files (like pdf) and folders, trying to erase a file caused the system to drain an insane amount of resources without apparent reason (but pressing shift+canc didn't), etc... With KDE4.2 version things im proved quite much and this was a great relief. However something dark was coming...

Out of the blue the headphones just stopped working. The weird was that by inserting the jack I got the feed for about one sec and then all went silent. After searching forums I did understand that the problem was probably related to ALSA and they advised to uninstall it and recompile. You know how it is when you happen to have an uncommon problem; the resources are few and often contrasting. As I said I'm a freshman and what is worse, a freshman without the time and will to learn bash and compiling and stuff the way I used to enjoy with MS-DOS when I was a teen. So I did what I usually do when I don't know where to slam my head against what in Linux. I opened Adept and looked for ALSA related package. And I had the great idea to uninstall one package (probably libasound-2, or alsa-base). The computer crashed and I was forced to restart. Guess what it happened when I tried to access to my user session again? See below...

Then I got scared. The computer was full of documents, all expendable except the fact I had a big bunch of new pictures of my son I didn't backuped. I was cold sweating and already thinking of my wife chasing me down like Sauron with the Fellowship of the Ring, except I wasn't likely to make it... I accessed my user from console to try to backup the pictures directory by cp-ing it to the external drive. But I could find the external drive in the /media directory and all my attempts to mount it were a failure. At this point I booted from the live cd and managed to have access to the folder and copy it to a safe location. At least I managed to sleep that night...

The day after (which is two days ago) I wiped the hard disk and installed Ubuntu 8.10 which is now running onto my laptop. I enjoy a immediate feel of improved stability and boosted speed. However the headphones problem keeps on haunting me!

I've grown loving Linux but there are things that really piss me off. I worship over all the concept of ergonomics and elegance in all human manufactured products, so also for what concerns software. In their way the distros I used are ergonomic and elegant but there are a few things I can't stand. Installing new software is a completely insane process. Left behind the add/remove tool, all what remains is chaos. Sometimes you just download a software from a website, double click and it installs and goes into the right place of the menu (Truecryp on Ubuntu). Sometimes you download it and then you must go and search for instructions to install it, copy&paste those on the terminal and that's it (Google Earth) but then how you uninstall it?? Sometimes you must add the repositories and, if you're lucky, the software get installed without issues and goes in the right menu place. Some other times you must mess with bash to copy files to some root place with sudo etc... As far as I'm concerned this is something crazy and one of the things which keeps new user at bay from say Ubuntu. Nowadays many people are willing and able to search the internet for open source alternative software, but how many of them can or want to the same to learn how to install it? Again, let's be frank, apart from the add/remove and, in a shorter range, synaptic, tool it needs a super user to install software on Ubuntu.

Anyway I could stand all this installation matter and bound to let's time be my teacher. The headphones trouble is though something completely unacceptable. We're speaking of a pretty basic function and a priority one. I will probably take my time and try some solution in a protected environment like VirtualBox but again this takes time and to me it's really a pain in the rear to waste a lot of time trying to solve this headphones related issue!

I won't surely go back to Windows, but I'm looking forward an iMac as my next computer.

Monday, March 16, 2009

Many Dead Things: The Art of Alex CF

Hello, my name is Alex, i am a professional "cryptozoological scientific assemblage artist" and illustrator, i made up this term to describe what i make - i create items and objects from a past that wasn't; to fashion the things i wish existed in forgotten attics or secret rooms...

This is the incipit of the About page in the web site of this marvellous and talented artist. Alex brings to life things that don't exist in this world but swarm in the mind of so many of us. Alex has the touch of the magician because he manufactures these horrific relics in way that make you feel a sense of uneasiness, a sensation which reminds me of what I felt by reading some Lovecraft's tales during certain cold fall's nights of my youth.
Up to now I haven't had any chance to admire one of Alex's creation but just by looking at the low res pictures on his web site one can undoubtedly perceive the imaginary power which streams from the objects. This effect is obtained because all of the care which is behind the creation, from the which is behind the bill of materials and the artistic study for the whole assembly.
Speaking of materials and style, the care for the details is magnificent, and produces images that remains vivid in the imagination of the observe.
Alex's creations stay at the crossroads of science and magic, in that space where reason and madness fight for the supremacy of the human mind.Indeed they and yet they're not just scattered pieces of rotting meat and worn out parchments; every piece of art has a story and it's part of a fictional world that distills from the sinister archetypes of old legends and pieces of literature.They're salvaged from exotic places, conjured from abyss of terror, excavated out of long forgotten lands, in the name of science by the aristocratic evolutionary biologist and cryptobiologist Lord Merrylin, or the exobiology department of Miskatonic university, Massachusetts.
Here's a few example as a treat of the artist's craft.

Plesiosaurus: specimen number 12 in the Merrylin cryptid collection

Expedition to the Plateau - Lost World Exploration Case


Severed "Draco Alatus" Head

Experiments in extra dimensions; The Cheshire cat


Alex's currently putting together a book illustrating his work, the characters and the story behind them.The book is titled "Many Dead Things" - the cryptozoological scientific art of Alex CF" and scheduled to be issued within 2009.
Alex's art is of course for sale and the artist states the pricing often varies from 800£ to 1000£ (about 1125$ to 1400$ and 860€ to 1100€) depending of the size and detail of the job.
If you wish you can stay tuned with the news from Alex's work by subscribing to his newsletter here.
Note: All the pictures are copyright of Alex CF at http://alexcf.com/blog/

Wednesday, March 11, 2009

Qt 4.5 released: Kudos to Nokia for showing a smart way to steward a project

Qt Software, formerly known as Trlltech, released the 4.5 version of their popular C++ user interface framework.
Up to today Qt has always been know especially for two things: to be a powerful and modern cross-platform tool and to be far to expensive for being used by independent and small software workshops.
On the summer of 2008 Nokia bought Trolltech and renamed it Qt Software. Qt 4.5 is the first release of the Nokia era and it’s already showing Nokia’s view for this award winning application.



License
The first and most visible changement is about licensing. Up to now Qt was traditionally available with two license versions: a commercial version (very expensive) and a GPL version (completely free). This basically meant that it addressed either to high-budget companies to produce commercial software or to anybody willing to produce and distribute completely open source software. This two-tail licensing cut completely off independent developers and small software houses which clearly hadn’t the budget to buy a commercial license. Competing frameworks filled this gap and what is worse user support for this application was only bound to the official forum as the popularity among the developers was low.
Nokia changed that by introducing a third license option: the Lesser General Public License (LGPL) version 2.1. By paraphrasing Qt Software's own statement “This version of Qt is appropriate for the development of Qt applications (proprietary or open source) provided you can comply with the terms and conditions contained in the GNU LGPL version 2.1.” Thus, provided that you can comply with the LGPL license, you can have a free copy of Qt and produce and sell commercial software.
This is the first big improvement Nokia’s done to increase the software development market penetration of Qt. This is also a very good news for developers because Qt is an extremely powerful tool which will be a asset to companies. Often, open source software comes from developers who put their skills and time at the community’s service. Given that those skills are often derived from an educational or job environment, this new license means that more people are likely able to choose, learn and develop with Qt, which a payback to the community in terms of better software available to users.
Qt is ported to different languages such as Java, Python, C, Perl etc.. From this it comes to my mind one possible drawback of this new license option. PyQt, the Python binding, is currently made by a software house, named Riverbank Computing Limited, which lets you acquire either your free GPL version or the commercial one. The rationale is obviously that the comply with Qt policy by giving away the GPL version and make a living of the commercial PyQt version. Right now, however, I can imagine Riverbank guys being a bit concerned about the LGPL Qt license as they will surely suffer a purchases loss from those which are now satisfied with producing commercial products which comply with LGPL license. Right now there’s no 4.5 PyQt available and all we can do is basically see how the Riverbank’s guys decide to move.

New features
Qt 4.5 accomplish two major design goals: increasing performance, enabling hybrid web/native development.
The performance improvement involves the whole framework and can be seen in a faster runtime, enhanced performances of key functionalities as data handling and graphics syste. You can find more information here. Qt 4.5 fullfills now the goal of providing richer user experiences by enabling a better integration with WebKit rendering engine to blend local and web based content. To this aspect Qt applications can now include flash content (like the YouTube player) as well as high end web technologies like HTML5CSS3 and SquirrelFish, WebKit's JavaScript engine.
To Mac development Qt now supports the new Cocoa framework instead of the deprecated Carbon.
From this summary of improvements it is clear to me that the will of Qt, therefore Nokia, is to become a fundamental player in the new generation applications. The web integration is the aspect which I think it’s the more interesting. Right now there’s a lot of chatting about cloud computing and how the desktop based application are doomed to migrate to the web. I am one of those which are not completely comfortable with this scenario. Web applications are not the Saint Grail of modernity. Just like everything in the world,web infrastructure has its technical and usage pros and cons and to exasperate the web migration of just everything running on top of desktop machines it’s probably not the right approach. I tend to prefer an approach more focused in exploiting the best of the two worlds, desktop and web, by integrating, when it’s the case, web resources in desktop applications. This seems to be also the way Nokia’s seeing it and Qt 4.5 provides the tools to create applications which make use of the best web technologies available on the scene.


Qt Creator
This Qt version comes, as usual, with a bundle of tools among which is the new Qt Creator.
Qt Creator is a cross-platform IDE (integrated development environment) specifically design to work with Qt in a cross-platform scope. This is the first version of this tool so rough edges must be expected but, up to Ars Tecnica, the application is perfectly usable. It provides the usual functions and tools like auto completion, text highlights, fast search etc.. but specifically focused on the Qt framework. If I can see a defect on this, which is also referred to the framework in general, is the absence of support for languages other than C++. To provides branches for different languages is surely an asset to a framework focused on setting the benchmark of graphical user interfaces. I know that my opinion is probably biased but the fast coding and high productivity provided by Python for example could be a reason for a developer to use this language to produce an application which maybe doesn’t need the power and velocity of the C++. As already mentioned Qt has its own unofficial branches to several other languages, however it would be great a stronger support from Qt Software to the developers in order to give those developers working with other very popular languages to exploit the best of Qt.[youtube=http://www.youtube.com/watch?eurl=http%3A%2F%2Fwww.qtsoftware.com%2Fproducts&feature=player_embedded&v=U7yje3D1UM4&gl=US]

My general opinion of Qt is very good and now with the introduction of the LGPL license, I can finally strongly advise to choose Qt as your framework. If you have some doubts regarding the power of Qt just know that software such as Google Earth, Adobe Photoshop Elements, KDE desktop environment, Skype and the popular VLC player are made with Qt. Qt library is used for projects in world wide leading companies like Lucasfilm LTD, Walt Disney Animation Studios, Next Limit Technologies etc.

Qt is currently available for Embedded Linux, Mac OS X, Windows, Linux/X11, Windows CE, S60*

*Qt on S60 is not released as a stable product yet, it's still under development and currently Nokia only provides pre-releases

Friday, March 6, 2009

My PyQt Scribbles (Python and Qt) #5: Event-Handling Mechanism (QEvent: moveEvent() and closeEvent())

In this installment of My PyQt Scribbles we will have a look to the event-handling mechanism.

As I already mentioned it's my custom to explore new concepts through examples. What I call ‘useful examples' are the implementation of concepts in plausibly real situation. This means that I won't just write an example by detaching a particular mechanism from the whole app. I will not write something which is too abstract or that does something that replicate an useless function. This scribbles of mine are mostly an exercise and a tool I exploit to study a subject I like. As far as I can I will implement all the concepts into the building of a specific application which will slowly grow and increase its functionality as I explore further subjects.

Today we will make our application more fashionable by replicating the transparency feature you can see on KDE (with composition manager enabled), Mac OSX and Vista. Basically, our app will get transparent when we move it around the screen. We will also implement a dialog widget which pops up when we try to close the application to ask us if we're sure to quit or not.

Events are members of the QEvent class and a sort of low level objects that represent things that have happened either in the outside environment or inside the application. They're processed at different level by the Qt application.
Events can be divided in three different types:

Spontaneous events à they originate outside the application (window system) and are queued and processed by the event loop
Posted events à they are generated by Qt or the application and are queued and processed by the event loop
Sent events à they are generated by Qt or the application but instead to be managed by the loop they're sent directly to the target object

When an event happens, Qt generates a specific object to represent that specific event. This event is then shipped to the children/parents chain for handling and, if no Object handles it in some way the event object is just discarded.
A corollary to this is that we usually don't need to send (sendEvent() )or post (postEvent() ) events explicitly because most events are generated automatically by Qt or by the window system when they happen. If you want to "manually" send an event, you can call high-level functions to do this (i.e. update() and repaint()).




Events in Qt can be processed on five different levels but the first two are the most common and needed. The last three are rarely used so you don't need to go deeper in the concept related to them unless you're a Qt guru (in this case you're probably wasting your time reading this ‘scrible').

• Reimplementing a specific event handler.
QObject and QWidget provide many specific event handlers for different types of events (for example, moveEvent() for handling the movements).
• Reimplementing QObject::event().
The event() function is the ancestor of all the object's events. The default behaviour in QObject and QWidget simply forward the events to the specific event handlers.
• Installing an event filter on a QObject.
An event filter is an object that receives another object's events before they reach the intended target.
• Installing an event filter on qApp. Exceptionally, an event filter on qApp monitors all events sent to all objects in the application.
• Reimplementing QApplication::notify(). Qt's event loop and sendEvent() call this function to dispatch events. By reimplementing it, you get to see events before anybody else.

As I said before some type of events can be propagated to the children/parents chain. In this situation, if a target object doesn't process the event, Qt passes the event to other receivers until reaching the top-level parent object.

This is a brief explanation about what events are and how they work. If you find it confusing just try to grab the basic concepts by studying the code below. One approach I find very useful is not just to copy and paste the code as it is but try to modify it in your own way. You can maybe try to reimplement the basic concept to explore different events or handling them in a different way.
If you want to increase your knowledge you can check the following links and read the articles.
http://doc.trolltech.com/4.4/eventsandfilters.html
http://doc.trolltech.com/qq/qq11-events.html

So lets go on with the example.
As usual only the new parts are commented.

from PyQt4.QtCore import *
from PyQt4.QtGui import *

class WizAndChipsCal(QWidget):

        def __init__(self, parent = None):
                QWidget.__init__(self)
                self.setWindowTitle("Wiz and Chips Calendar")
                self.setWindowIcon(QIcon("C:/Python26/PyQt/Icon/date.png"))
                self.setToolTip("Hello to this Wiz and Chips fancy calendar!")
                self.title = (""\
                              + "Wiz and Chips Pushable Calendar!"\
                              + "")
                self.Label = QLabel(self.title)
                self.Label.setAlignment(Qt.AlignCenter | Qt.AlignJustify)

                self.calendar = QCalendarWidget()
                self.calendar.setGridVisible(1)
                self.calendar.setMinimumHeight(180)
                self.calendar.setMinimumWidth(110)

                self.check1 = QCheckBox("check1")
                self.check2 = QCheckBox("check2")
                self.TextBox = QTextEdit("type something here")
                self.TextBox.setMaximumHeight(50)

                self.dateLabel = QLabel("Date:")
                self.dateLabel.setMaximumWidth(80)
                CurrDate = QDate.currentDate()
                self.date = QDateEdit(CurrDate)
                self.date.setMaximumWidth(80)

                self.CloseButton = QPushButton("&Quit")
                self.CloseButton.setToolTip(""\
                                            + "Press here to Quit"\
                                            + "")
                self.CloseButton.setMaximumSize(50, 25)

                self.infobox = QGroupBox("Info Box")
                self.infobox.setCheckable(1)
                self.infobox.setChecked(0)

                dateLayout = QHBoxLayout()
                dateLayout.addWidget(self.dateLabel)
                dateLayout.addWidget(self.date)
                dateLayout.addSpacing(170)

                GBoxLayout = QVBoxLayout(self.infobox)
                GBoxLayout.setSpacing(1)

                GBoxLayout.addLayout(dateLayout)
                GBoxLayout.addWidget(self.check1)
                GBoxLayout.addWidget(self.check2)
                GBoxLayout.addWidget(self.TextBox)

                Layout = QGridLayout()
                Layout.addWidget(self.Label, 0, 0)
                Layout.addWidget(self.calendar, 1, 0)
                Layout.addWidget(self.CloseButton, 4, 0)
                Layout.addWidget(self.infobox, 3, 0)
                self.setLayout(Layout)

                self.connect(self.CloseButton,
                             SIGNAL("pressed()"),
                             self.close)
        def moveEvent(self, event):
                self.setWindowOpacity(0.7)
                QTimer.singleShot(50, self.opac)
        def opac(self):
                self.setWindowOpacity(1)

        def closeEvent(self, event):

                self.CloseDialog = QMessageBox.question(self, "The application is being closed",
                                                        "Do you really want to exit?",
                                                        QMessageBox.Save|QMessageBox.Yes|QMessageBox.Discard,
                                                        QMessageBox.Discard)
                if self.CloseDialog == QMessageBox.Yes:
                        event.accept()
                elif self.CloseDialog == QMessageBox.Save or QMessageBox.Discard:
                        event.ignore()

app = QApplication(sys.argv)
main_window = WizAndChipsCal()
main_window.show()
app.exec_()

def moveEvent(self, event):
self.setWindowOpacity(0.7)
QTimer.singleShot(50, self.opac)

Everytime the widget is moved (this includes the first time it's painted on the screen) the function change the widget opacity to make it transparent.
moveEvent() event handler is implemented to receive widget move events which are passed in the event parameter. When the widget receives this event, it is already at the new position.
Once the movement is finished we call QTimer.singleShot which counts a certain number of milliseconds and then calls another function which sets the opacity to 1 thus making the widget opaque again. singleShot is needed to tell QTimer to count just one time. Otherwise the count is made at intervals

def opac(self):
self.setWindowOpacity(1)

setWindowOpacity(1) property holds the level of opacity for the window. The range is from 1.0 (completely opaque) to 0.0 (completely transparent).
Note: This feature is only available on Mac OS X, X11 platforms that support the Composite extension, and Windows 2000 and later.

def closeEvent(self, event):
                self.CloseDialog = QMessageBox.question(self, "The application is being closed",
                                                        "Do you really want to exit?",
                                                        QMessageBox.Save|QMessageBox.Yes|QMessageBox.Discard,
                                                        QMessageBox.Discard)

This event handler is called with the given event when Qt receives a window close request for a top-level widget from the window system.
We create a dialog widget by implementing QmessageBox.question(). This class displays a dialog widget with an informative text for the user and provides standard buttons to enable the user to interact. By default QMessageBox support preformatted (layout, icons etc..) message boxes for questions (QMessageBox.question()), information (QMessageBox.information()), warning (QMessageBox.warning()) and critical (QMessageBox.critical()).

The configuration of our question box is: QMessageBox.question ( QWidget * parent, QString=title, Qstring=text, StandardButtons=buttons, StandardButton=defaultButton)
Our default button must be picked from the buttons already used, we pick discard in order to make our exit procedure safer. Note: save button will now have the same behaviour of ‘discard'. We will reserve the function for later usage.
There are several standard buttons already specified by the API.
For more information about message boxes see http://doc.trolltech.com/4.5/qmessagebox.html

if self.CloseDialog == QMessageBox.Yes:
                        event.accept()
                elif self.CloseDialog == QMessageBox.Save or QMessageBox.Discard:
                        event.ignore()

By default, closeEvent eventt is accepted and the widget is closed. We instead reimplement this function to change the way the widget responds to the close request.
If the user press ‘Yes' we call accept() and the window is closed. If the button pressed is ‘Save' or ‘Discard' we call ignore() and the event is thrown away.