Category Archives: Ubuntu Trivia

Getting Started with GTK and GLade for GUI programming

Considering you have read the previous article on GUI programming, this article will give an insight about GTK.

When starting learning Glade, it is essential to learn the basic concepts of GTK+. Unfortunately there is a misconception that it’s enough to learn Glade for learning GUI designing rather than learning GTK+. Glade is definitely an easier way to implement GTK but it is impossible to create interface for your application with only Glade knowledge.

Official GTK+ tutorial is the best place to learn the Basic things about GTK+. Though reading the entire documentation may seem to be a herculean task, it would good to cover important topics like packing of widgets. After having a basic knowledge about GTK+, next step is having a look at the official Glade3 manual. Version that is supplied with Glade3 is outdated,you can find a simpler and more updated one here.

Now if you think, you are well and comfortable with GTK+ Basics, you will definitely want to try a real world example. Many authors provide tutorials with real world examples. I managed to find out two such, one by Micah carrick and other by Tadej Borovšak. It would be better to follow Tadej’s Tutorial as the former one does not use Glade3-3.6.7 which is latest version. Anyway you can also give a look at the tutorial by Micah. Now when you start seriously with GTK programming, never forget to visit GTK Forum for getting your doubts cleared.

Now if you are ready to spend a few bucks try to get a copy of  Foundations Of GTK development.

Here are a few other resources which would with worth giving a look though I haven’t tried them personally.

Tutorial for How to set the colour of a widget in GTK+
Tutorial

Gtk+ 2.0 Tree View tutorial
Tutorial Pdf

Gtk+ 2.0 Text View tutorial
Tutorial Pdf

Gtk+ 2.0 GtkComboBox Widget Tutorial
Part1
Part 2
Part 3

GtkDialog tutorial
Part 1
Part 2

Wrapping and resizing GtkLabel dynamically
Tutorial

Using pop-up windows
Tutorial

Gtk memory management in a nutshell
Tutorial
Gtk Menu Tutorial
Tutorial

Search man pages in linux for a particular word / command

Wikipedia defines man pages as “extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems”. Just as the definition goes sometimes the documentation is so extensive that you are unable to find the data you need.

Actually it’s not a big deal to find a particular word. You would have noticed that the usual Ctrl+F won’t work here.

For finding a particular word just access the man pages by man command.

Then for finding a particular ‘word’ type /word followed by Enter.

Now the first word will be highlighted. For the finding the instances of that word in next pages of the man page press Space and the ‘word’ in the next page will be highlighted. That’s it.

This same method also  can also  be used in vi for searching words.

Here is an example.

Install Softwares in Ubuntu 9.10 without internet connection

Weeks ago when I was trying to setup Ubuntu in my pc for the first time, installing new software you need in your new pc would be a impossible process without internet or any Repository DVDs. I managed to get a few resources from net and here I will explain it as a step by step procedure. First you should have another computer which is well connected to the internet or you should have an APTonCD created by someone. Once you install the required softwares with the help of internet connected PC, you could backup all the packages into a CD for using next time.

  • Generating List of required files to be downloaded.

After you have installed Ubuntu in your system, you will definetely need files to keep it updated. First of all you have to generate the list of files to be downloaded. You use the following command for generating the required files list.

sudo apt-get update -qq –print-uris |cut -d’ -f 2 > filelist.txt

This will generate a text file filelist.txt with all the essential update files to be downloaded.

Now if you want any specific softwares to installed like APTonCD you would need more files to be downloaded. To get the additional files to be downloaded use the following command

apt-get -qq –print-uris install ***packagename*** | cut -d’ -f2 >filelist2.txt

Move both filelist.txt and filelist2.txt into a removable media like pen drive.

  • Downloading the required files to be downloaded.

In the computer with internet connection create a folder called files in the desktop.
Copy the two text files into that folder.
Move to the folder with the following command in terminal

cd Desktop/files
wget -i filelist.txt -x
wget -i filelist2.txt -x

Now you will have all your required files downloaded to the new folder in separate directories. Also keep the two text files inside the pen drive itself.

  • Final installation process

Now move the files to the computer in which the new software are to be installed. Now you will have to open the file manager with root privileges to copy files into the root directory.

Press Alt+F2

In the popup window type

gksudo nautilus

Copy the folder into the root directory. You can move into the root directory by clicking the tab with the symbol of a harddisk in the upper part.

Now using the same file manager window move to ‘etc’ folder in root directory.
Now locate the sources.list found in ‘apt’ directory in ‘etc’./etc/apt/sources.list

Make a duplicate copy of that file and name it “sources.list.cpy” (right-click on the file, copy, and then paste). This is just a safety precaution in-case something goes wrong.

Now right-click the file sources.list and select “Open gedit” or any other text editor

Now add all the contents of filelist2.txt at the end of sources.list
Now using the Replace option under the Search menu in gedit replace all http:/ on that file with file:/files

Ubuntu

Next everything will be over with

sudo apt-get update

Download Youtube Videos in Ubuntu Linux the easiest way

If you are using a linux based operating system like Ubuntu, literally downloading the youtube videos is as easy as just watching it. I mean it when I said it. Anyway here I explain the best and the easiest options I found in downloading the youtube videos.

1.Just Watch the video.
One thing you would have rarely noticed is that when a video is buffered completely in Youtube, a copy of that video is saved in /tmp directory. So after watching the video make sure the you do not close or change the page in the browser. After the video is streamed fully in the browser just move to the /tmp directory and you can find a .flv file with name beginning with Flash*. Just copy that file into your desktop and it’s done. This is not the case with just youtube videos but any flash videos on net can be downloaded this way.

2.Command Line way.
If are comfortable with using command line, this way is for you. Youtube-dl is a Python script, which  can run under Linux, Mac OS X, or Windows platforms as long a latest version of python is installed. For installing the script in Ubuntu just type

sudo apt-get install youtube-dl

Now for downloading a youtube video, in the terminal type

youtube-dl **video page url***

There are also a number of options available for you with this python script. You can view this by typing

youtube-dl –help

Options:
-h, –help            print this help text and exit
-v, –version         print program version and exit
-u USERNAME, –username=USERNAME
account username
-p PASSWORD, –password=PASSWORD
account password
-o FILE, –output=FILE
output video file name
-q, –quiet           activates quiet mode
-s, –simulate        do not download video
-t, –title           use title in file name
-l, –literal         use literal title in file name
-n, –netrc           use .netrc authentication data
-g, –get-url         print final video URL only
-2, –title-too       used with -g, print title too
-f FORMAT, –format=FORMAT
append &fmt=FORMAT to the URL
-b, –best-quality    alias for -f 18

3. Grabber websites.
There are many websites like keepvid.com which allow users to download the youtube video by entering the url. But in many cases I have found this way do not work well.

4.Firefox plugins
If you are a Mozilla Firefox user there are a number of plugins which automatically detect any flash videos being played in the page. It need not be a ‘you’ tube page. This supports most of the other favourite websites. The below are just a few to name.

1-Click YouTube Video Download

Download Flash and Video

Flash Video Downloader

Fast YouTube Download

This is way I personally follow :)

How to add GUI for your applications?

When do you think you are ready for creating your own application? You have to be good enough with coding but obviously that is not enough. The applications which you are creating for your targeted users, be it commercially or just for fun sake, need not be professional coders but are mere end users. The users want the developers to build applications that meet their needs and also help with it the easiest way. You needn’t be an artist for creating the best interfaces but should be able to deliver what the users want the easiest way.

GTK and Qt ,the same toolkits behind GNOME and KDE, are the best graphical toolkits fit for this job. Providing the same functionality they have their own advantages and disadvantages.

The GTK+ toolkit, otherwise known as the GIMP toolkit is coded in C but has got bindings for just all of the favourite languages programmers speak nowadays. Ruby-gtk2, PyGTK, Gtk# are just a few to name. The GNOME desktop utilities are built on GTK+ libraries. The popular music player – Banshee, Photo Organizer – F-spot, Evolution – official personal information manager and workgroup information management tool for GNOME, popular IM client – Pidgin are just a few of the popular Linux Based applications built with GTK+ libraries and it’s various bindings. The code for the interface of your application actually consists of pages of codes but now the coding the interface has been simplified with various tools like Glade for GTK+. These GUI builders help in easily designing the interface without having it code it manually. Glade gives output as what is referred to as a “glade file” which is actually an XML file which describes the heirachy of the widgets comprising the interface. The most interesting aspect of GTK is the GNU LGPL 2.1 which binds it ( not GPL ). This allows development of both free and proprietary software with GTK+ without any license fees or royalties.

Qt is another popular cross-platform application development framework, widely used for the development of GUI programs. Originally released by Trolltech now it’s development is controlled by Nokia’s Qt Development Frameworks division after Nokia’s recent acquisition.Google Earth, KDE, Opera, OPIE, VoxOx, Skype, VLC media player and VirtualBox are a few of the popular applications with Qt. Qt is implemented in C++  and it has got full fledged support libraries  for database manipulation, multimedia operations, OpenGL graphics, scripting, Web-based programming through WebKit and not just GUI construction. Qt comes with a load of developer tools in it’s kitty including Qt Designer GUI designer, Qt Linquist, Qt Assistant and QMake for building and distribution of software packages.

In my next post I will be discussing about getting started in GUI development with GTK and Glade.