November 30, 2015

Principles or a GUI and their practical application using wxPthon

From today's training - a private course that was brief Python revision followed by an introduction to GUIs (in the form of wxPython ...

I started with a generic intordcution to GUIs ... written in the form of a source code file in Python:

  # principles of a GUI
  # Provides a "Framework" and "Helpers"
  # (somewhere here - load / initialse model)
  # 1. Define components ("widgets")
  # 2. Define a geometry ("layout")
  # 3. Define my events
  # BEFORE you
  # (4. Display initial view)
  # 5. Await an event
  # 6. Process that event
  # 7. go to step 5

and then I went on to add real code into each of the sections. Here is the implementation for each step:

# Provides a "Framework" and "Helpers"
  import wx

# load / initialse model
  import mymodel

# Create an empty shell for the various els.
  app = wx.PySimpleApp()
  class RailStationApp(wx.Frame):
    def __init__(this):
      wx.Frame.__init__(this, None,wx.ID_ANY,"About rail places", (600,200))

# 1. Define components ("widgets")
  this.myWoof = wx.Button(this,1,"Gypsy")
  this.myYap = wx.Button(this,2,"Billy")

# 2. Define a geometry ("layout")
  this.geom = wx.BoxSizer(wx.VERTICAL)

# 3. Define my events
  def feed(this,event): print "We are out of Bonios"
  def walk(this,event): print "Peeing down with rain"

# 4. Display initial view

# 5. Await an event
# 6. Process that event
# 7. go to step 5

There's a few more wrapper and invocation lines - compete template [here] and the full implementation[here].

Having put the rudiments of each step into place, I moved on to ...

Add a label and change event handlers so that feedback appeared within the GUI (see [here].

Add a whole list of data elements and a loop of buttons, with a single event handler working for all of the buttons [here]

And finally switching to use data from my model to load the GUI and present dynamic information [here]

Image - samples of the four application examples

Posted by gje at 10:02 PM | Comments (0)
More about Graham Ellis of Well House Consultants
Related topics: via article database

November 29, 2015

What teach you in a week stays with you for a decade

As a teacher, I teach a lot of delegates and only hear from a few of them into the future. After all - it's my job to teach them to 'fly' and my role to stay onthe ground and teach the next lot too.

So it's really grattifying to bump into a delegate occasioanlly - as has just happened this Sunday evening on my way to Cambridge. Mark, who attended a Python course at Melksham a few years back, was telling me how he'd used it in his job for the employer who sent him, and now (in a new role with a new company) he's using it for his core work and for lots of other data manipulation too.

I'm delighted it working for him, that he's self supporting, and flattered that he recognised me. I'm afraid I failed to recognise him - which I can put partly down to my lousy memory, and partly down to the shere normallity of training and the number of people I see ... two Python courses again this week, for example.

Training on one of our courses is a short, sharp investment of time and money into learning a subject ... but what Mark learned over 4 days has made a significant difference to what he's doing now and going to still be doing 4 years later. If I was writing a sales pitch (!), I'ld be telling you to book now for your course in 2016, and you'll learn technologies and techniques that will take you forward to 2020, and probably way beyond.

Posted by gje at 07:39 PM | Comments (0)
Related topics: via article database

November 28, 2015

shell - bash. Writing conditional tests and statements - the options available

Every language that I teach has conditionals and loops, and the bash shell is no exception. From the three day bash course given last week - an example including lots of alternative tests (but by no means all varlients!

for tests in if

  if command ... ; then
The command is run and its return status is tested.

  if [ ... ] ; then
Shell tests such as if (is it a plain file) are run

  if test ... ; then
Shell tests such as if (is it a plain file) are run (same as test)

  if [[ ... ]] ; then
String comparison / expression tested

  if (( ... )) ; then
Numeric comparison / expression tested

bash also supports lazy and and or operators (&& and ||) which can be used for shortened conditional testng based on the return status of a command - which could be one of the above bracket expressions or a reguler command:

  WomanWithCat:bash grahamellis$ grep -q main demo.c || echo yes
  WomanWithCat:bash grahamellis$ grep -q main demo.c && echo yes
  WomanWithCat:bash grahamellis$ grep -q second demo.c && echo yes
  WomanWithCat:bash grahamellis$ grep -q second demo.c || echo yes
  WomanWithCat:bash grahamellis$
  You have new mail in /var/mail/grahamellis
  WomanWithCat:bash grahamellis$ [[ 4 == 5 ]] || echo one
  WomanWithCat:bash grahamellis$ [[ 4 == 5 ]] && echo two
  WomanWithCat:bash grahamellis$

(grep -q is quiet mode - supress output and just return a status)

Posted by gje at 11:31 AM | Comments (0)
Related topics: via article database

Extending your bash shell with aliases, functions and extra commands

Want a command to do some composite job, but it doesn't exist? You can add new commands into your bash script using

functions ... see example [here] from last week's course.

aliases ... here are the aliases that I'm using to provide my own extra / modified commands on our web server:
  -bash-4.1$ alias
  alias l.='ls -d .* --color=auto'
  alias ll='ls -l --color=auto'
  alias ls='ls --color=auto'
  alias pd='pushd'
  alias vi='vim'
  alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

another script ...

adding executables ...

Shell programming is so much about bolting together other programs and utilities - and they can include other shell programs as well as code in other languages. Paramaters can be passed in from the command line, data from STDIN, and from the environment - remember to use export if you want a shell variable / environmet variable to be shared with something you're running from your script.

Posted by gje at 08:54 AM | Comments (0)
Related topics: via article database

What is make? What is gcc?

Make is a tool which lets you define a whole series of commands you need to run to get from the basic data and program source files that you work on during development, or distribute to your technical customers into the final product / products that you need.

Typically and traditionally, make reads a file called makefile that takes a series of instructions on the commands that are used to make a "target" from a "dependency", and runs those instructions if (and only if) the target doesn't exist, or is older than any of its dependencies. The order of operations is taen into account, with some targets in a process being dependencies for the next stage of the process. Make is very clever in that it allows you to make a very limited number of changes in your sources, and will then only rerun the steps needed when your rebuild your final produt, skipping those unchanged. However, make is only the pilot and not the aircraft - it only controls the work rather than doing the hard work, and it's of no use without its tools of trade such as gcc

Gcc is the tool which converts your C or C++ (or other language) into binary 'object' files for your target processor and operating system, then connects these object files and standard libraries together into a final executable program file. There are a number of intermediate steps (usually run in an automatic sequence), and the gcc command bolts these steps together depending on command line options given to it, which can be long and complex. That's one of the reasons you need a script (or, better, a makefile) so you don't have to keep re-keying the steps at the keyboard.

Although "gcc" stood initially fot the "Gnu C Compiler", it's now the "Gnu Compiler Collection" and to it's no longer just C ... C++ is an obvious extension but it will handle other languages like Fortran and Java (via gcj) for example.

For the bash scripting course I ran last week, I provided a brief "hello world" intorduction to make and the compiler tools. Two program source files were provided - demo.c and more.c - the main program and subsidiary functions for a little C demonstration. I also provided a simple makefile to store / reuse / control the various invocations of gcc needed to build the final executable program.

Although the tradiational, and taught, use of make is in building executable programs, it can also be used for other jobs with similar characteistings - be it to build a website, documentation, a database. For example, the makefile that's distributed with the Apache httpd web server not only builds the executable, but also the documentation. And a separate make process can be used to go through the multisteps to install the executabela and documentation

Such a clever idea there are other tools that do something similar - you have ant for the Java world, and in Ruby you have rake which you'll typically use to rake over the results of one of your tests on a database and prepare for the next test - removing damaged tables and re-creating them from source data. It's not a compile, but it's very much a process of the same pattern.

Posted by gje at 07:43 AM | Comments (0)
Related topics: via article database

November 27, 2015

Bash ... some new scripts to - handling user input

I just completed a three day "bash shell programming" course and have uploaded a whole host of new examples, and updated some older ones too. Here are some examples that relate to inputting from STDIN ... further links to other groups of new examples to follow

Asking a question and read from STDIN in shell - [here] or offer a series of options from which the user should select one [here]

Usage line - and a loop to go through all command line paramters - [here]

Stopping ^C from exiting from the script with trap [here]

Posted by gje at 09:39 PM | Comments (0)
Related topics: via article database

November 26, 2015

Back in the saddle again - excellent open source course from Well House Consultants

Why should you come on a course I run at Well House Consultants? Because you want to learn, learn effectively, and enjoy the course, and pay a sensible price.

Those of you with whom I'm in touch from time to time will know that in the summer I was laid low with ear and balance problems, and took some time to get back. I now 'report' myself as back to 90% of what I was (won't ever be back to 100% hearing or balance) - but training again and providing what I'm told is still an excellent product. Last week, I presented a Ruby course for a third party - using my materials / techniques - in a very difficult situation where a previous course from another tutor had gone so wrong that it had been abandoned. This message - received today - make it all so worthwhile.

"I’ve just spoken to my contact at [company] with regards to the Ruby course you delivered and I wanted to pass on the below feedback to you. Thank you so much for a great delivery.
* Tutor was excellent
* Best course they have ever been on
* Loved Graham's teaching techniques
* Graham was technical and explained really well"

And - as you may have guessed - I really enjoyed giving that course!

Public course schedules are online already from January to June 2016 - see [here], and we're open for bookings for private courses - please email, use the enquiry form, Skype, Facebook, or phone to ask.

P.S. We teach Perl, PHP, Python, Ruby, C, C++, Tcl and Lua on scheduled public courses. We can also help with topics like shell (bash) and some Java, Linux, Apache Web Server, Cucumber, Django, Flask, CodeIgniter and Tomcat requirements too. Even if it's "just one delegate" please do ask.

Posted by gje at 07:33 PM | Comments (0)
Related topics: via article database

Well House Consultants Ltd.
Copyright 2015