Wednesday, December 30, 2015

wxFormBuilder - Tutorial on “A GUI for making GUIs” for Python

Graphical User Interfaces (GUIs) in Python are commonly created using Tk via the Tkinter package. However, at the moment of writing this post, designing GUI via the Tkinter package is done purely in code (python syntax) which means that a simple dialog window may consist of approximately 100+ lines of code.
Wouldn’t it be pleasant if we had a visual tool for making GUIs? That is “A GUI for making GUIs”. Creating GUI with code (WxPython) is too tedious work and it requires lots of attention and time. With WXFormBuilder, you create GUI much faster and efficiently in less time. In most cases this is faster than writing this code by hand.

That is what ‘wxFormBuilder’ is set to realize. WxFormBuilder is a Rapid Application Development (RAD) tool for wxWidgets GUI design. It is an open source GUI designer application for wxWidgets toolkit, which allows creating cross-platform applications.

WxFormBuilder allows you to design your GUIs visually and save them in a wxFormBuilder Project File - *.fbp file (which is just an XML file listing every component in your GUI and defining each component’s properties). Then, the *.fbp file can be converted automatically into a Python *.py file ready to be imported into your Python program. It also serves as Source code generation other programming languages are supported such as: C++, PHP, Lua and XRC.

Tutorial objective:
I will guide you through the basics of wxFormBuilder as used with wxPython generated code. The goal is for you to build a usable First GUI in Python.

We are going to create a little application that will take selected text from the user and append/print the chosen text to a static text box that has “Hello…” on it.
The end result will be a GUI (as sketched below) that just outputs: Hello… World, or Hello… Africa, or Hello… Asia, or Hello… Europe, or Hello… America - on the displayed static text box.

We need to have the following packages installed:-
~ Python 2.7
~ wxpython
~ wxformbuilder 3.5-RC1
~ Pyinstaller to freeze the application (create an .exe on Windows or a .app on osx)
~ Text editor (Sublime Text, Notepad++, Pycharm or anything similar).

Combination of any versions will do as long as they are compatible with each other. I used Python 2.7.10 Anaconda 2.3.0 (64-bit), wxPython (msw-unicode), wxFormBuilder 3.5-RC1 (unicode) and Sublime Text 3. The prerequisite packages most be installed as above in the order mentioned and we should be good to go.

Saturday, September 12, 2015

How to install wxPython (Phoenix) on Python 3.x

Am going talk about How to install wxPython Phoenix for Python 3.x.

Note: this instruction may not be valid if wxPython Phoenix project is fully migrated for python 3.x. Am sure by then, an executable file (.exe) would have been provided for download as is with classic wxPython for python 2.x.

wxPython’s Project Phoenix is a new incarnation of the wxPython toolkit in which everything that existed before will be cast into the flames in the hopes that that which emerges from the ashes will be better, brighter, stronger and faster than before.

If you can’t wait for the executable file for Phoenix project to be released, then read on as I guide you to getting wxPython Phoenix up and running for Python 3.x.
You can achieve this in two basic ways namely; auto installation (using pip) and manual installation. Let’s explain each one after the other.

Method 1: Auto Installation
To use this method to install wxPython Phoenix on Python 3.x, open your command window and run this code below;
pip install -U --pre -f wxPython_Phoenix


c:\Python34\Scripts\pip install -U --pre -f wxPython_Phoenix

With that, you should get you the latest version of Phoenix on any OS as the Python wheel file formats are now supported.

Note these two points;
1) You need the latest version of pip to install a wheel. Make sure you have the latest. Once you do, you can run above code to install wxPython Phoenix

2) There is space between "" and "wxPython_Phoenix"

Method 2: Manual Installation
Visit the build url at; and download the latest release of wxPython Phoenix build. The file will likely be in a .tar.gz or .whl file format.

Extract it using 7zip or WinRAR applications.

Copy the wx folder and paste it in your python 3.x site-packages directory (something like: C:\Python34\Lib\site-packages) and you are done!

Open your python 3.x cmd and run import wx to verify.

This should install wxPython Phoenix on your Python 3.x installation.

WooHoo! Phoenix runs on Python 3!! See it in action, check it out on YouTube.

Classic vs Phoenix
you will learn the most common wxPython functions, classes and Window / Sizer methods which need to be changed to a new syntax in Phoenix; it presents the modification in a 2-columns, space-separated table containing the old wxPython (Classic) name on the left and the new (if it exists) Phoenix name on the right.
Read documentation at:

 Happy Coding!

Tuesday, September 8, 2015

Geo-processing with Python Books to read

Here I present to you some quality books to learn Geospatial Technology in Python programming language.

What is Geospatial Technology?
Geospatial technology (also known as Geomatics or geomatics engineering, or geomatic engineering, géomatique in French) is the discipline of gathering, storing, processing, and delivering geographic information, or spatially referenced information. In other words, it "consists of products, services and tools involved in the collection, integration and management of geographic data".

Geospatial technology refers to equipment used in visualization, measurement, and analysis of earth's features, typically involving such systems as GPS (global positioning systems), GIS (geographical information systems), and RS (remote sensing).

Fundamentals of this technology include: Geodesy, Geodynamics, Land Surveying, Cartography, and History

Application areas include:
    Aeromagnetic surveys
    Airborne geophysics
    Air navigation services
    Archaeological excavation and survey for GIS applications
    Coastal zone management and mapping
    Disaster informatics for disaster risk reduction and response
    The environment
    Infrastructure management
    Land management and reform
    Natural resource monitoring and development
    Seismic Interpretation
    Subdivision planning
    Urban planning
    Resource Management
    Climate Change/Environmental Monitoring

Ok, here are some books to learning Python programming as applicable to the field of Geospatial Technology;-

Monday, September 7, 2015

How to install multiple python modules at once with one single installation

Hi there,

Today's post will throw light on how to install multiple python modules at a go. That is you only download one file, run it and have python interpreter installed together with other useful modules including: NumPy, SciPy, Matplotlib, guiqwt, PyQt, Spyder, IPython, etc.

All of these done with one single installation.

Before, I go on let me quickly go over the traditional way of installing python with other modules.

Here is how you usually do it:
1) Download python from the official website
2) Install it on your PC, then anytime you want to install a module you will use
3) easy install or pip to achieve the module installation.
OK. That is pretty good, but how about if you have many modules to install? Won't it be fantastic if you just have a file you run once and install all the necessary modules installed at once? That is the aim of this blog post.

Ok, you can also use the "requirements.txt" file to install multiple modules at a go, however you need some tech skills... as below;

pip install -r requirements.txt

and in the requirements.txt file you put your modules in a list, with one item per line.


Here are the boom ways for non-tech dudes. Designed for scientists, thanks to the integrated libraries NumPy, SciPy, Matplotlib, guiqwt, PyQt, Spyder, IPython, with another 340 packages available with a simple install.

Learn Quickly Creating Professional Looking Desktop Application Using Python - Part 7 of 7

Compiling, Packaging and Distributing Our Completed App

Quick links to other parts of this blog series:
Part-1 | Part-2 | Part-3 | Part-4 | Part-5 | Part-6 | Part-7

Am glad you read this far, we are almost there!
For sure, we can zip the “” file and distribute it by emails or other means. But the problem with this is that only users with Python and wxPython lib installed on their PC can run the application (so we have a BIG drawback here).

The primary aim of today's class is to take our application to the next level by making it possible for every computer system to run it with or without Python installed on it. To achieve this, we make use of two programs we have installed earlier (i.e. Py2exe and Inno Setup Compiler).

~~ First we use the "Py2exe" python library to create an executable for our application, then we use "Inno Setup Compiler" to create an installer for our app.

~~ Now create a blank file name “” and type this code below in it and save.

from distutils.core import setup
import py2exe

~~ Run the following on the command prompt to create an executable for our app.
python py2exe

This will run and generate to folders named “build” and “dist” in our project folder. Open the “dist” folder, the app executable will be seen there and the “build” folder is no longer essential. See image-27 below.

~~ Contents of your “dist” folder should look like mine below (image-28); the executable file is shown with arrow (that is: gui.exe).
Double clicking the executable file (gui.exe) should open up the Expression Evaluator Application, BOOM!

~~ Now we can rename the “dist” folder to the name of our app (Expression Evaluator) and zip it for distribution. Any windows PC would be able to run our Expression Evaluator application with or without Python/wxPython library installed on the computer.

To add more professionalism to our program, we will compile it into an installer using the Inno Setup Compiler.

~~ Launch the Inno Setup Compiler and chose “create a new script file using wizard” and click “Ok”. See image-29.

~~ On the next couple of screens press “Next” and fill the appropriate details.

~~ On the “Application file” page, click “Browse” then navigate to the “dist” folder and select the executable file (gui.exe). See image-30

~~ Click on “Add files” button to add all the files within the “dist” folder. See image-31

~~ On the next window chose option that suite your needs. I will accept default options and go to next page “Application documentation” then select your setup language(s).

~~ On the “Compiler settings” window, you can select an icon for the installer setup file and you can also set password for the installer.
Select “Yes” when you see the screen (See image-32) below to compile instantly.

~~ Save your script and inno setup compiler does its thing... This script can be edited using Pascal programming language. See image-33

Sunday, September 6, 2015

Learn Quickly Creating Professional Looking Desktop Application Using Python - Part 6 of 7

Binding Events to Methods

Quick links to other parts of this blog series:
Part-1 | Part-2 | Part-3 | Part-4 | Part-5 | Part-6 | Part-7 

All GUI applications are event-driven. An application reacts to different event types which are generated during its life. Events are generated mainly by the user of an application.

Working with events is straightforward in wxPython. There are three steps:
- Identify the event name
- Create an event handler. This is a function/method that is called when an event is generated
- Bind an event to an event handler

There are different types of events to different wxWidgets. For our expression Evaluator App, we will use only one event type called “OnButtonClick”. This event is generated when a user clicks on a button.

Let’s hook our buttons to event handler by following the steps above;-
~~ From our project (Eval_Project) in wxFormBuilder, select button1 (that’s Evaluate button) and the go to “Object Properties” panel on th right-hand side then select “Events” tab, you should see “OnButtonClick” event. See image-23
Type in the name of the event handler, I named mine “EvaluateFunc” (it can be any name meaningful). Do the same for button2 (that’s Close button), name it “CloseFunc”.

~~ Now regenerate the code file “” and open it in a text editor. Scrolling down (see image-24), you should notice that the file has been modified (wxPython minimum code will not be there) that means the file got replaced.

~~ As can see, the event handler names we defined for our buttons (“EvaluateFunc” and “CloseFunc”) are names for the functions or methods that are called when an “OnButtonClick” event is generated.
To create the “EvaluateFunc” function for the first button, override the event handler functions, by replacing the “event.Skip()” methods with the code that does whatever you want the buttons to do.

~~ We want the first button to evaluate an entered expression in the “EnterExpression” text box, so we will write a code for doing just that within the function.
As for the second button, we want it to close the frame so we will write a code that too inside the function.
Hence, the codes within our (“EvaluateFunc” and “CloseFunc”) function should look like the screen image-25 below;-

~~ Now, our Expression Evaluator App should work as expected if we entered a valid expression and clicked “Evaluate” button image-26. If an invalid expression is entered, error report is printed out.

That is it; our Expression Evaluator Application is now ready to be package and distributed!


Learn Quickly Creating Professional Looking Desktop Application Using Python - Part 5 of 7

Creating the GUI

Quick links to other parts of this blog series:
Part-1 | Part-2 | Part-3 | Part-4 | Part-5 | Part-6 | Part-7 

This is where the fun begins!
It is in this section we will start to make use of the wxPython GUI library.
There are lots of codes to learn in wxPython library which we cannot cover at once in this tutorial. I will only introduce you to the basics of wxPython code and to a tool (wxFormBuilder) that generates the wxPython GUI codes for us.

wxPython is primarily used for making GUIs, and largely all GUI apps most have a frame. It is the frame that holds all bunch of elements (such as button, text Boxes, labels, menus, status Bar, combo Boxes, images etc) for any app.
So the minimum code needed to create a frame using wxPython just like in any programming language is seen attached below on image-13 or as quoted below.

import wx

app = wx.App()

frame = wx.Frame(None, -1, 'My First Window App')



Save the code in a python file (I saved mine as and run it, you should see a blank frame/window pops up on your screen (image-14).
To add elements such as buttons, text Boxes, labels etc on the frame, we need to write the codes for all of that! But with wxFormBuilder, we don’t have to as it can be use to easily generate most of the python GUI codes needed on the fly with its WYSIWYG interface. It can also be used to generate codes for C++, PHP, XRC and Lua programming languages.

It is worthy to note that generally in any GUI development, coding is divided into two aspects namely; the GUI coding and the logical coding. We will use wxFormBuilder to generate the GUI code while we get our logical code from the console version of the program we developed earlier.

~~ Let’s get started with wxFormBuilder by creating the GUI interface for our Expression Evaluator App! Now let’s launch our wxFormBuilder software and save it as “Eval_Project” in the project’s folder.

~~ On the right hand side, you will see “Object Properties”, under the “Properties” tab set the Project name to “EvalProject”, set the file name to “gui” (this is the name for the generated python file) and set “code generation” to python. See image-15

~~ Under the “Form” tab in the designer view, create a frame and set its size to 250-Width by 300-Height (see image-16). Note the name of the frame is “MyFrame1”. This name will be used for our frame object class (that an OOP thing...).

Creating the GUI Continue...

~~ Switch to the “Layout” tab and add a “wxBoxSizer”, leave the orient property on wxVERTICAL, see image-17.

Let’s add the remaining widgets to our frame.

~~ Under the “Common” tab, select “wxStaticText” then EXPAND and STRETCH it by clicking on the respective icons on the toolbar (see image-18 below).
On the object property panel to the right-hand side, set the “wxStaticText” as follow;-
- Name to “DisplayResult”
-Style to wxALIGN_CENTRE
-Label to “DisplayResult”
-Font point size to 20

~~ Add the next widgets on the sketch, which is a Text box (“TextCtrl” as its being called in wxPython). Then EXPAND and STRETCH it as we did above see image-19.
On the object property, set the “wxTextCtrl” as follow;-
-Name to “EnterExpression”
-Style to “wxTE_CENTRE”
-Font point size to 20

The last two widgets on our sketch are the two buttons (Evaluate and Close buttons).

Learn Quickly Creating Professional Looking Desktop Application Using Python - Part 4 of 7

Sketching the App's GUI (Graphical User Interface)

Quick links to other parts of this blog series:
Part-1 | Part-2 | Part-3 | Part-4 | Part-5 | Part-6 | Part-7 

Today’s class is going to be the shortest and simplest class so far! It will not involve any technical idiom what so ever, but please don’t under rate this stage as doing so can lead you to waste vital time during your software design process.
All you will do here is to pick your paper and pencil, then sketch a beautiful interface for your app!

Keeping thing simple, I have brain stormed and came up with a simple user interface for our app! It consists of four major elements (widgets/control as they are being called in wxPython) on a window frame as follow;
From the top I placed a “Static Text Label” widget to display result of an expression. Then just below it I placed a “Text Input Box” widget to collect expression from the user. At the bottom, I placed two “Buttons” – the first-button will evaluate the given expression while the second-button will close the app’s window. See the image-12 below.


Learn Quickly Creating Professional Looking Desktop Application Using Python - Part 3 of 7

Developing the console program >> Part 1

Quick links to other parts of this blog series:
Part-1 | Part-2 | Part-3 | Part-4 | Part-5 | Part-6 | Part-7 

Welcome back! Hope u still remember the mission app we are going to build throughout this tutorial? If you don’t, kindly refer back to our introductory class where I mentioned that ...the app is going to be a mini calculator that can perform valid Mathematical Expression Operations of addition, subtraction, multiplication, and division.
Ok at this point, I wish to name the application "Expression Evaluator". Hope the name of our app is cool? Be free to suggest a name if you have something better in mind.

Today, I will explain how our app (Expression Evaluator) works on a command prompt (knowledge of Python basics will help). We will take advantage of on a powerful built-in python function used to evaluate mathematical expressions – the eval() function.

The completed code is attached below (image-6), if you understood every bit of it (the code), then go sleep and wait for the next class . But if you are struggling to read/understand/interpret the code, kindly be patient and follow along as I will explain every single line of the code soon.

~~ Now head over to your desktop or any location on your PC and create a project folder (this where we will save all our files) name it “EXPRESSION_EVALUATOR” then save a python file inside it from your text editor as “”. See image-7 below.

~~ Type the attached code (image-6) in your “” file and save it.

~~ If you run/launch the “” file by double clicking on it, you should see a command prompt as on image-8 asking you to enter an expression.

~~ Type a valid mathematical expression and press enter to see the result. If you entered an invalid expression, the program will out an error massage.
As shown on image-9 I tried expressing “2+2”, and it gave me “4” excellent!
When I tried expressing “2+a”, the console crashed after showing an error message - try it! This is because “a” isn’t a number and isn’t defined, making the expression invalid (hope you still remember your maths class!).

~~ A better way in my opinion of running the “” file is by opening the project folder then the file through a command prompt, this way your cmd prompt window will remain open no matter what happened and you can see all errors. Here is what I mean;-
From within the project folder, hold “Shift” button on your keyboard and right-click inside the folder then select “Open command window here” – see image-10. This will open the command prompt directly from the folder.

~~ Type python space then name of the file (that is: python and hit enter. You should see a screen similar to the previous one (except for the folder’s path on the first line) asking you to enter an expression. See image-11.

~~ This time even if we entered an invalid expression our program with never close automatically until we decide to close it manually. Or better still uncomment line-14 in “” file so however we ran our file it will never close until we press enter.

Ok, let’s dive into detail explanation of each line of code in “” file in the next class.
Till then digest today’s lesson and have a nice day!

Warning: Just a word of warning, the python “eval()” function can be dangerous if you do not know what you are doing (it can be use to delete system files). So in the meantime just use it for simple examples such as the ones shown here.

Saturday, August 29, 2015

How to build (create or design or develop) a Website on Android Mobile phone

How to build (create or design or develop) a Website on Android Mobile phone.

On this post I will like to share with you how I designed HTML + PHP website pages on mobile device (running Android Operating System).

If you know how to edit HTML, CSS, JS, and PHP on a PC to create a webpage, then here is how to do it on your mobile device running Android OS.

The Tools required for development include the following:-
  • PHPRunner - PHP IDE
  • Chrome Browser - Google
  • DroidEdit
  • VT Source Viewer
  • Bootstrap framework

 Let explain more about each of the tools. You can download all from Google play store for free as at the time of writing this post.

This is a PHP/MYSQL Server app for Android (Just like XAMPP or WAMP on PC
The program allows you to execute scripts php, supported mysql.
The program runs compiled for arm lighttp, PHP 5.4.9, MySQL.
When you first start, phprunner download the necessary files (~ 10Mb).
Runs:* PHP 5.4.9 *MySQL *Lighttpd server

Chrome Browser – Google
This is an Android Web Browser. Browse fast on your Android phone and tablet with the Google Chrome browser you love on desktop. Pick up where you left off on your other devices with tab sync, search by voice, and save up to 50% of data usage while browsing. 

DroidEdit is a text and source code editor (similar to Notepad++ or gedit) for android tablets and phones with powerful features such as: Syntax Highlighting for several languages (C, C++, C#, Java, HTML, CSS, Javascript, Python, Ruby, Lua, LaTeX, SQL, ...)

VT Source Viewer
This application can be used to view the HTML, CSS, JavaScript or XML sources of webpages and remotely located files.
It supports different syntax highlighting themes, adjustable colors, line numbers, text wrapping, in-source active links, mobile and desktop browser modes and other features.

Bootstrap framework
Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile first projects on the web. Read more about bootstrap at:

Note: there are alternatives to the tools mentioned above, be free to use/download and test whatever you want.