Tuesday, September 8, 2015

Geo-processing with Python Books to read

Hi,
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
    Oceanography
    Meteorology
    Parks
    Resource Management
    Climate Change/Environmental Monitoring
Source: https://en.wikipedia.org/wiki/Geomatics

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.

    Django=1.3.1
    South>=0.7
    django-debug-toolbar


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 “gui.py” 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 “setup.py” and type this code below in it and save.

from distutils.core import setup
import py2exe

setup(windows=['gui.py'])
~~ Run the following on the command prompt to create an executable for our app.
python setup.py 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 “gui.py” 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.

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

I will talk about COMPILING, PACKAGING AND DISTRIBUTING OUR COMPLETED APP in the next class.





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')

frame.Show()

app.MainLoop()


Save the code in a python file (I saved mine as frame.py) 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.




Bye!


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 “eval.py”. See image-7 below.

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

~~ If you run/launch the “eval.py” 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 “eval.py” 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 eval.py) 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 “eval.py” 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 “eval.py” 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.

PHPRunner - PHP IDE
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
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: www.getbootstrap.com

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

Enjoy!

Thursday, May 20, 2010

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




Installing and testing our installations

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

Basically, all the 5 programs we needed for this tutorial (as listed above) have fairly simple installation procedure. Generally all you have to do is download the Windows Binaries respectively and run it to install on your PC.
Note: you most install “Python” first before installing “wxPython” and “Py2exe”, because they are both python’s extensions/libraries.

Now let’s be sure that all we have installed are working perfectly;
For wxFormBuilder and InnoSetup Compiler, you should see their icons on your desktop or windows start pane. Launch the programs to be sure they are working!

For Python 2.x, wxPython, and Py2exe; you will have to follow the procedures below to verify they are installed properly.

~~ Open command prompt and type python and hit enter. If you got error like on image-1 below, then python is not recognized on your PC. Now do any of Option1 or Option2
~~ Option1: assuming you installed python on this path “C:\Python27” run this code below on the command prompt to fix it automatically (note: if your path is different, replace to the correct path).

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User" )

~~ Option2: If Option1 above didn’t work for you, add the path manually as follow; open your computer’s “Control Panel” and follow 1-6 as shown on image-2 below (i.e.: Control Panel > System and Security > System > Advanced system settings > Advance > EnvironmentVariable...).
~~ On the window that opens after clicking “EnvironmentVariable...”, select “Path” then click on “Edit” and add your python path starting with semi-column as shown on image-3. Then click on “Ok” three times to apply the path.
~~ If all went well, retyping python on the command prompt will open a Python Shell as shown in image-4 below.

Still on the Python Shell, to test for wxpython and py2exe installations just type import wx and hit enter then type import py2exe and hit enter. If no any message is displayed as in image-5, then you are good to go your installations are in order.



Thanks for reading!

If you can't wait for the next blog post, download the completed tutorial as a .pdf file from this link: http://umaryusuf.com/wxpy/wxPython-gui-tutorial.pdf

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

I have done this tutorial series elsewhere, but now I decide to repeat it on my blog.... This post is the part 1. Enjoy! 

Learn Quickly Creating Professional Looking Desktop Application Using Python2.7/wxPython, wxFormBuilder, Py2exe and InnoSetup Take your ability to develop powerful applications for desktop to the next level today.

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


This tutorial will show you how to design and build a fully-functional desktop Graphical User Interface (GUI) application for maths Expression Evaluation using a combination of Python 2.x, wxPython, wxFormBuilder, Py2exe and InnoSetup Compiler. The app we will build is going to be a mini calculator that can perform valid Mathematical Expression Operations of addition, subtraction, multiplication, and division.

First of all, I will use python syntax (leveraging on the eval() python function) to make a Console/CLI (Command Line Interface) program, then convert it into a Graphical User Interface (GUI) app so that users have much more control of it.
I will use the CLI program to explain some python basic syntax for those who may be struggling with understanding of the python basics.


If you feel you need to learn/refresh your python knowledge, then I recommend reading this book “A Bytes of Python” by Swaroop C H.

By the way, some popular software vendors using what we are about to learn to power there software include;- Taskcoach.org, Bittorrent.com, Editra.org, and dropbox.com (Source: www.wikipedia.org/wiki/WxPython)

Basic requirements for this class are:-
~ Basic knowledge of Python programming – I will do my best to simplify the process of this tutorial as much as possible, so everyone will be able to follow along.
~ A Windows Operating System (OS) machine (other OS users can follow along as well) - I am using 32-bit OS computer using the Windows-7 operating system.
~ Python2 interpreter, Text editor, wxPython library, wxFormBuilder, Py2Exe, and Inno Setup Compiler – I will show you how to get and install all of these software soon.

Before we start installing and configuring the software we will be using, let me quickly explain what each of them will be used for and where to get/download them;-

Python 2.x interpreter
Python is an easy to learn, dynamic and powerful modern programming language. Two similar but incompatible versions of Python are in widespread use (Python2.x and Python3.x). Pls note that we will use Python2.x for this class, download the version for your OS below.

wxPython
wxPython is a free GUI toolkit which can be used to build Python GUIs. It is a wrapper for the cross-platform C++ GUI API wxWidgets. Some other GUI library/toolkits for Python include; Tkinter, PySide/PyQt, Kivy and PyGTK

Py2exe
Py2Exe is a Python Distutils extension which converts python scripts into executable windows programs, able to run without requiring a python installation. Some other Python extension/library which converts python scripts into executable programs are; PyInstaller, Py2app, cx_Freeze, bbFreeze, and vendorID

wxFormBuilder
wxFormBuilder is a free Python GUI constructor toolkit for wxWidgets GUI design which can be used to build Python GUIs. Similar python GUI constructor toolkits are wxGlade, Boa Constructor, PythonCard and wxDesigner

InnoSetup Compiler
Inno Setup is used to create installer for Windows programs. Similar programs are NSIS and WiX
Download link: www.innosetup.com

For sure, you also need a text editor if you don’t have one already, you can get NotePad++ at: www.notepad-plus-plus.org

Hope you enjoyed this class? See you next time!