PHP-GTK Tutorial: Creating menus in PHP-GTK using GTK+

This article is brought to you by Ben Stones, guest editor for DPS Computing Ltd.

What is PHP-GTK?

First and foremost, what is GTK+? GTK (short for GIMP Tool Kit) is an extensive library of methods for creating cross-platform graphical user interfaces using the GTK+ library with a language of your choice. There are extensive language bindings to GTK+ – from Python, to C++, C# and much more – including PHP-GTK.

PHP-GTK is not as widely used as one would hope, but there is a community of PHP-GTK developers and the #php-gtk channel in Freenode is a good place to get help on matters concerning PHP-GTK – although sometimes you may be waiting a short while for a response – but the channel is active daily.

So with the ease and use and flexibility of the PHP programming language – one would wish it could be used to create desktop applications. And of course, with PHP-GTK, this is possible using the GTK+ library. Installing PHP-GTK is not as easy as it could be; although for Windows users, you’re in luck – there are pre-compiled binaries for you to download and use without requiring any complicated installation procedures. However, for installing on Linux distributions, it is fairly easy. If you Google “How to install PHP-GTK on Ubuntu” you’ll find a post on another forum with instructions on how to install PHP-GTK on Linux distributions, including Ubuntu.

How do I create menus in PHP-GTK?

Creating menus are not as simple as you would first imagine. But once you understand how the methods work, it will make sense. Essentially, the GtkMenuItem is not just for menu items within a menu option. They are also used to create a top-level menu item, too. Let’s take a look at some sample PHP-GTK code.

// add menu bar
$this->addMenu();

public function addMenu()
{
/* create the menu */
$file = new GtkMenuItem(“File”);
$help = new GtkMenuItem(“Help”);

// create the menubar
$menubar = new GtkMenuBar();
$menubar->append($file);
$menubar->append($help);

// append the menu options
$menu = new GtkMenu();

$menu2 = new GtkMenu();

$open = new GtkMenuItem(“Open”);
$this->menuSaveItem = new GtkMenuItem(“Save As…”);
$quit = new GtkMenuItem(“Quit”);

$about = new GtkMenuItem(“About”);

// connect the signals

$quit->connect_simple(‘activate’,array($this,’menuOptionClicked’),”quit”);
$open->connect_simple(‘activate’,array($this,’menuOptionClicked’),”open”);

$menu->append($open);
$menu->append($this->menuSaveItem);
$menu->append($quit);

$menu2->append($about);

$file->set_submenu($menu);
$help->set_submenu($menu2);

$help->set_submenu($menu2);

$this->init_vbox->pack_start($menubar,FALSE,FALSE);
}

Original publication – August 2012.

Disclaimer: DPS Computing Ltd., its employees and the author of this article disclaims all liability with respect to the accuracy, reliability and security of any application code and routines that are provided in this article, as well as in respect to the accuracy and reliability of the article itself. We cannot guarantee that the application code in this article will work as expected or not cause any damage to your operating system, any software or not cause loss of, or damage to, data. Your use of the application code and routines provided in this article is at your sole risk and responsibility.

Slow Websites Are Worse Than No Websites

Web Servers - Author: Widjaya Ivan (CC)You’ve probably been told by at least one or two of your tech friends that if you own a business, are self employed, a contractor etc that there is nothing worse than having no website these days.  And that is quite true…. apart from one golden commandment.  And that is:

Slow websites are worse than no websites

All this snappy line means is that the one thing worse than having no Internet presence, is having an Internet presence where your visitors feel like they have been thrust back to the medieval times of dial up.  For sure, the most infuriating thing for your visitors will not be that you don’t have a web presence (which by the way, is extremely bad) but that they’ve got enough time to brew up between page loads.

There’s many fancy tools on the Internet for checking the speed of your website, such as the tool developed by Pingdom.

Here you can quickly enter your website (either your main domain or the url of any web page on your website that you want to check) and get some fairly fast and detailed results about your website.  Of course it’s fast, after all the irony of a website that tests a websites speed being slow itself would just be too much to handle ;).  Entering your main domain name (such as www.dpscomputing.com) is probably the best idea to begin with – after all, if your main page is slow, your visitors aren’t going to be around to follow links through to any one of your other pages.

So throw in your domain and hit the ‘Test Now’ button:

 

At first you’ll be presented with the Waterfall tab.  While this is a very interesting tab providing a lot of good information, unless you’re a developer it’s probably not going to be all that useful to you.  So lets click on the ‘Performance’ tab and we can see some quick stats regarding the websites performance.

 

Now as you can see from our results, we’ve done quite a lot of work and scored quite consistently highly.  However, we’ve let our caching slip (we’ve got short cache times on things that should probably be extended) but overall we score 82/100 which while not perfect, is pretty good.

If you’re consistently scoring below 50 for two or three categories above or below 70/100 overall, you are opening yourself up to the possibility of using a fair number of visitors simply because your website is not being efficient enough for them to bother hanging around.

In todays world of super fast broadband (and increasingly, fibre optic) people won’t hang around to see your website as they did in the good old days of dial up. Design is king – and part of design that should always be considered is the speed.  Speed is an often overlooked part of the design and implementation process.

Sure the cursor trails on your home page might have looked cool in the 90s, but all that extra scripting is leading to extra load time.  The 10s are the decade of decluttification – or simply, removing the crap.

Less can be more sometimes, so make sure that your homepage is inviting, has a good navigation system, a video or other small multimedia file and obviously, some quick snappy information about what you and your website are about.

Alternatively….

Alternatively, if you would like a quick, non-technical way of testing the speed of your website, do the on site testing plan that I’ll detail here.

For this to work properly make sure that you’re using a different browser than your usual one (remembering to delete all the temporary files / cache) or simply clear the temporary files / cache from your usual browser.  The reason for this is that we don’t want our local cache (basically, a temporary version of websites that we have visited) influencing (and by influencing, I mean improving artificially) the load time of our website.

After that’s done, visit your websites home page.  Do you have time to day dream about your next holiday?  Do you have time to mull over the points that your significant other raised during your last argument?  Do you have time to use a post it note to pick out that fingernail dirt that you’ve been itching to get rid of all day?

If you answer yes to any of these then your page is loading waaaaaaaay to slowly!  Unless you’re still on dial up, or facing serious issues with your broadband, all simple pages (including general multimedia and scripting – short videos, images etc) should be loading fairly quickly after clicking the link or typing in the address.  Load times over a second are entering the territory of being way to slow.

The Usual Suspects….

No not the film, but the usual candidates causing slow page loads are:

  • Scripts
  • Large, unoptimised images
  • Large videos
  • Long pages

Unless it’s a complex page your looking at scripts should be short, efficient and snappy, images should be cropped, resized and optimised for the web, large videos should also be web optimised and trimmed where possible (i.e. would a 30 second intro to a longer video be sufficient rather than placing the whole video on the page – maybe a link to see the full video after watching the intro if people are interested?) and long pages are a no-no anywhere.

Images

Images loading bit by bit (‘line by line’) shouldn’t be happening in todays age of speedy web connections – so if they are, they’re likely far to big.  The usual cause of this is applying a size attribute to the code of an image rather than resizing the image itself.  For example, specifying the size of an image in HTML still loads the full, huge size image, and then resizes it.  To solve this issue, download the image, resize it in an image editor and the re-upload it.  Another advantage of doing this is that you shouldn’t have to specify the size of the image in the HTML / script now.

Scripts

Scripts should add something to the page – not just be there for a ‘cool’ effect.  Now there are some scripts which can create nifty menu bars etc, and used correctly these are fine.  After all, websites need a good navigation system and if this has a few low impact effects on it then this is completely fine.  However, cursor trails (Windows 98 anybody? 😉 ), exploding things, splash screens and the like are usually unnecessary and invariably annoying.

Large Videos

Not every user will be interested in the content of your video – show a preview clip with the option to go through to the full video if the user wishes to do so.  There’s no point in loading an hour interview with yourself (however interesting) if the user that is loading that page doesn’t want to watch it.  Give the user the power and they shall love you.

Long Pages

Long pages have never been cool.  Long pages belong in books, leaflets, handouts etc.  But not on the web – no they weren’t even cool in the 90s.

Pages on the Internet are not the same as pages in a book.  While paper costs money in the real world, more pages on the Internet don’t cost you.  Divide and subdivide your content into relevant sections.  Again this goes back to the “what’s the point in loading it if the user doesn’t want it” theory.

For example, if you have a massive page that loads all the products you sell, why no subdivide that into categories?  If you’re a bookstore and you list all the books you sell on one page and I come to your site looking for non-fiction books, then all the time I have to wait for the fiction books to load is time wasted.

Remember, unless you grab a users attention, they’re not likely to scroll to see anything ‘under the fold’.

Finally…

Remember, page speed is an important, and often overlooked, part of page design.  You could spend your entire life optimising your website and not get it 100% (which is impossible!) but there are a few quick things you can do, detailed above, which will give you massive speed increases, sometimes up to 80-90% depending on your website.

Remember, there’s no point in having the worlds best website if no one waits for it to load!

DPS Computing – Things Are About To Change…

DPS Computing

Firstly, apologies for the lack of recent updates to the blog – we’ve been quite busy!

Now, onto the main news for the moment.  Things are changing here at DPS Computing.  As director of DPS Computing Limited I have decided to revert DPS Computing back to a sole trader business.

The effects to our clients and visitors should be minimal, if anything at all.  DPS Computing is still going to provide the same services that it provides at the moment (including the blog).  The only change is that we are once more going to be trading as an independent trader as opposed to a limited company.

There are a number of reasons for this.

Firstly, due to external opportunities that became available to myself, I am no longer able to put in full time hours at DPS Computing.  However, I am still involved in DPS Computing and working on its different products and services.  Any changes to products and services will be communicated via the website and directly to any current clients of our products or services.

Secondly, due to the fact that I am no longer working full time at DPS Computing, I want all the time that I put into DPS to be spent developing products and services, maintaining and supporting them, answering customer queries and providing a good quality service.  If I continued to run DPS as a limited company then a significant proportion of time would be taken by admin, taking away from the actual products and services that we provide.  Bearing this in mind, as I am not working full time at DPS Computing, becoming an independent trader once more will allow DPS to provide you with better products and services.

Thirdly, we will be able to streamline our business model for the benefit of our customers.

In conclusion, DPS Computing Limited is undergoing transition back to DPS Computing.  However, we’re still going to be here! (just like we were when we made the transition to a limited company).

You may notice changes to the website over the coming weeks and months due to the transition.  If you have any questions or queries please feel free to contact me.

I’d personally like to thank all our current clients, members and visitors for their continuing support and I hope that I can rely on your continuing support.

Thanks for your understanding and support!

David Smith.
Managing Director.
DPS Computing Limited

FTP & Transferring Files From Your Computer To Your Website

FTP Status

FTP (File Transfer Protocol) and it’s secure alternative SFTP (understandably meaning Secure File Transfer Protocol) is without doubt one of the most popular ways of transferring files from your computer to your web server (i.e. your website).

In days gone by, there were a number of ways to avoid using FTP/SFTP.  Most notably was during the ‘Frontpage generation’.  Anyone remember Microsoft Frontpage?  Well, for those that don’t, it was like a very basic Dreamweaver.  You could install ‘Frontpage Extensions‘ on your website and then upload your file directly from Frontpage using these extensions.

Why is Frontpage bad?

However, there were (and still are) many downsides to this.  First and foremost is security.  Frontpage extensions cause a whole load of security issues for your website and your server.  Most shared hosting providers won’t enable or allow you to have Frontpage extensions – but if you’re in control of your own server (i.e. have root access) then you would still be able to use them.  However, as Frontpage has reached its End of Life (EOL) now and is no longer updated, it is of course no longer recommended to use them.

Secondly, there’s crap.  What have Frontpage and crap got in common I hear you say?  Well Frontpage likes to crap…… as in place crap in every folder throughout your entire website (that’s those annoying _vti folders that some of us fondly remember!).

Thirdly, and finally, there is a better easier way!

Scary FTP?  A protocol for all systems…

For so long people have been scared by FTP.  For reasons unknown!  But it is really simple to use and there are many clients available out there for all operating systems including Windows, OS X, Linux and many many more – in fact, if you can find us an operating system without an FTP client, we’d like to know!

FileZilla logo

A common FTP shaped theme?

FTP was also supported in Frontpage, but the extensions usually got most of the attention.  The successor to Frontpage was Expression Web.  This was a slightly updated Frontpage.  It still included Frontpage extensions but the focus was changed to neutral again – no particular bias towards the extensions or to FTP.  And then you have newer, more superior and professional products such as Adobe Dreamweaver.  Dreamweaver supports FTP/SFTP – and thankfully, and obviously, doesn’t support Frontpage extensions!

See a common theme?  FTP/SFTP has survived through the times, the developers and the products.  It is now the standard in transferring files between your computer and your website.  And it is fast and efficient – especially if you are using a good FTP client (such as Filezilla).

The trusty old file manager.

There is of course another option which is still available and included in most web control panels.  That is ‘File Manager’ – you’ll notice them in control panels such as cPanel and Plesk.  However, one-file-at-a-time uploads aren’t really that productive.  They’re useful for changing the odd picture or the odd script here and there but not when you’re about to upload 100 new pictures or 1,000 new pages!

(Very short) Conclusion.

So FTP, FTP, FTP all the way (preferably SFTP – to add the bit of extra security to the transfers!).

FTP Status Image: dougww

DPS Computing Limited Launches Successfully

DPS ComputingThe official site of DPS Computing Limited has successfully launched, despite a few minor propagation issues for users and visitors in some parts of the world.  DPS Computing is proud to announce now that throughout the night, test servers in Europe, UK and the USA are all showing the propagation issues have been resolved.

Despite a few hiccups the launch was a success.  DPS Computing’s billing, customer and technical support areas will be opening later on today, allowing customers to order from our fantastic range of web hosting packages.

With prices starting from £2.30 / month, there has never been a better time to launch your website!

Work is still ongoing on the DPS Computing Limited website, however this work isn’t expected to have any impact on visitors or customers whatsoever.