Good PyQt5 tutorial

I’ve been looking for a good PyQt5 tutorial. This is quite a good one. Its one major weakness, though, is that all of the examples I’ve studied so far could have been done much more easily with the Qt designer. Nevertheless, this tutorial is helping me understand better how things are put together when creating a GUI with PyQt.

2016-02-20 (1)
Qt Designer version 5.5.1

 

Exploring Conda — Warming up for PyQT

There are several big Python distributions largely put together by the scientific community. One such is Anaconda. I’ve used this a bit in the past but never learned that much about it. I’m trying to really study it now to facilitate my development of some of my coffee roasting utilities with PyQt, a Python tool kit using the Qt development platform. According to the Riverbank web site:

PyQt is a set of Python v2 and v3 bindings for The Qt Company’s Qt application framework and runs on all platforms supported by Qt including Windows, MacOS/X and Linux. PyQt5 supports Qt v5. PyQt4 supports Qt v4 and will build against Qt v5. The bindings are implemented as a set of Python modules and contain over 1,000 classes.

Qt is largely used to develop GUI based application although it may also be used to develop command line applications.

Another distribution I’ve used a lot in the past is Enthought Canopy. The Canopy interface is pretty nice but I thought that it didn’t include some of the packages that I’m using for my scripts and thought that Anaconda seemed to include more of them. But as I gain experience, I find it is not that important. New packages like Reportlab and PyQt are easily added.

Every Python distribution uses a package manager to install and manage packages. The Anaconda team have created a very capable one called Conda. Yesterday I learned that PyCharm, the  IDE that I use for Python, allows you to include Conda environments. This is very desirable because it permits me to use PyCharm and Anaconda together.

Python and Qt
Python and Qt (Photo credit: Wikipedia)

Update for creating Fedora 21 live usb with persistence

I’ve done quite a few of these installations now and have refined the configuration quite a bit. This version also adds helpful details.
To prepare:
authenticate with wifi lan
open terminal
# yum install livecd-tools
insert target USB
# dmesg
see something like:
[ 1613.056043] scsi 9:0:0:0: Direct-Access     SanDisk  Cruzer Contour   4.13 PQ: 0 ANSI: 2
[ 1613.057801] sd 9:0:0:0: Attached scsi generic sg4 type 0
[ 1613.059534] sd 9:0:0:0: [sdd] 32112269 512-byte logical blocks: (16.4 GB/15.3 GiB)
[ 1613.060376] sd 9:0:0:0: [sdd] Write Protect is off
[ 1613.060383] sd 9:0:0:0: [sdd] Mode Sense: 03 00 00 00
[ 1613.061176] sd 9:0:0:0: [sdd] No Caching mode page found
[ 1613.061182] sd 9:0:0:0: [sdd] Assuming drive cache: write through
[ 1613.075279]  sdd: sdd1
[ 1613.079792] sd 9:0:0:0: [sdd] Attached SCSI removable disk
[ 1613.611180] EXT4-fs (sdd1): mounted filesystem with ordered data mode. Opts: (null)
[ 1613.611194] SELinux: initialized (dev sdd1, type ext4), uses xattr
/dev/sdd will be the adress of this target USB
# df -Th will also display it
/dev/sdd1           ext4       15G  1.6G   13G  11% /run/media/liveuser/fedora21
or hit window key, type disk and a utility will come up showing details on all mounted devices.
The USB was automatically mounted when it was plugged in. The following command won’t complete until you unmount it for safety.
# umount /dev/sdd
Command to create USB with data persistence for Sandisk Cruzer 16GB:
# livecd-iso-to-disk –format –overlay-size-mb 8000 –home-size-mb 5065 –delete-home –unencrypted-home –label fedora21 /run/media/liveuser/2A00BAF300BAC55B/Users/Guest/Desktop/Downloads/Fedora-Live-Workstation-x86_64-21-5.iso /dev/sdd1
Same command for Voyager GT 4GB
# livecd-iso-to-disk –format –overlay-size-mb 2173 –label fed21-voyager /run/media/liveuser/2A00BAF300BAC55B/Users/Guest/Desktop/Downloads/Fedora-Live-Workstation-x86_64-21-5.iso /dev/sdd1
Actually, that command didn’t work. The USB wasn’t bootable. The following worked. I also got a warning that the label should probably be all caps, thus the change there.
livecd-iso-to-disk –format –reset-mbr –efi –overlay-size-mb 2200 –label fed21v /run/media/liveuser/2A00BAF300BAC55B/Users/Guest/Downloads/Fedora-Live-Xfce-x86_64-21-5.iso /dev/sdd
Tip: You can use the top command to show memory, cpu and processes. To just show memory usage you can use ‘free’.
The Fedora-Live-Xfce is very nice low memory Fedora ‘Spin’.
Items to configure:
vpn
Hi Kor, you would just install openvpNote: I’m avoiding installing this as it uses a lot more memory than the pre-installed firefox. I just install the Lastpass addon to firefox.n, normally *yum install openvpn* you may need to add the epel repo. Download our configs from our downloads page torguard.net/downloads.php – unzip them to /etc/openvpn

Then rename whichever config you want to connect to from extension .ovpn to .conf and run like so:

cd /etc/openvpn
openvpn some_config.conf
It will then ask for your user/pass to connect.
use the mv command to rename
edit the config file:
     replace
          auth-user-pass
     with
         auth-nocache
         auth-user-pass auth.txt
create script:
     #!/bin/bash
     openvpn /etc/openvpn/TorGuard.USA-LA.conf

wifi
time
printer
Applications to install:
google-chrome-stable
Note: I’m avoiding installing this as it uses a lot more memory than the pre-installed firefox. I just install the Lastpass addon to firefox.
# su –
# cat << EOF > /etc/yum.repos.d/google-chrome.repo
[google-chrome]
name=google-chrome – $basearch
baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
EOF
# yum install google-chrome-stable
hugin
filezilla
vim
Optional:
livecd-tools
liveusb-creator
UNetbootin

My trials and tribulations with Fedora live USB installation

I spent the past three days working on installing Linux live on a USB stick. The reason I got started on this senseless waste of time is because I now have a laptop to use for part of the time I’ll be in New Zealand. The only problem is that I don’t have admin access so I can’t install anything, not even my VPN configuration. I finally came up with the idea of installing Linux on one of the two USB sticks I brought with me.

There are several windows utilities that,all in one operation, allow you to download and create a bootable USB stick with a live version of Fedora linux. I couldn’t run them without administrative access on the PC though. Luckily I had a blank DVD and was able to burn the iso on that. A DVD is pretty unsatisfactory for a live OS though. In case you don’t know, a live OS is one that you can run from CD/DVD or USB on any machine that it can boot from. It doesn’t touch or jeopardize anything on any of the drives of that machine. But launching from the DVD is extremely slow! Installing on a USB makes a much quicker system. Luckily I have a 4GB and a 16GB USB with me.
 it
Since I don’t have admin access to windows on the laptop my only option for creating the disk was to do it from my live Fedora Linux installation. I managed to do this the first time without too much problem but then I started to dwell on the other deficiencies of the system. The good news was that boot-up compared to DVD was very fast–maybe a minute or so. The big deficiency is that none of your configuration changes, including authenticating with the wi-fi, get saved, so you have to do it over every time you boot. I guess I was still reading documentation about installing Fedora to a USB and I noticed that you can install it with what they call data persistence. In it doing so, any changes made will be saved. So I decided to create such an installation but it was at this point that I really began having a rough time trying to accomplish my goal.
 called
There is a tool for Fedora called liveusb-creator that is very easy to use and it is what I used to create my first successful USB installation. There are two installation options, destructive or non-destructive. When I used the non-destructive method, everything seemed to work until I tried to boot from the USB. It wouldn’t boot! On the other hand, the destructive method yielded a bootable installation but the data persistence part didn’t work. I finally realized that data persistence with liveusb-creator only works if you chose the non-destructive method, the one that always resulted in a non-bootable stick.
I finally gave up on that tool and started playing with a tool called livecd-iso-to-disk-format. After three days of fooling around with various tools I was finally able to create the live USB with data persistence. It works quite well but one problem is that, although there is quite a bit of extra room on the 16GB stick, once you install something or copy it to the USB, even if you uninstall or delete, you never recover the space you originally used!
I discovered a third option that helps with this. With the livecd-tools (the package that contains livecd-iso-to-disk-format) you can also reserve space for a home directory. Anything that gets saved to the home directory can be deleted and you recover the space that was used. I re-installed my 16 GB stick in this configuration painlessly now that I had ironed out the problems of previous attempts.it I spent the past three days working on installing Linux live on a USB stick. The reason I got started on this senseless waste of time is because I now have a laptop to use for part of the time I’ll be in New Zealand. The only problem is that I don’t have admin access so I can’t install anything, not even my VPN configuration. I finally came up with the idea of installing Linux on one of the two USB sticks I brought with me.
OK. Next problem–one of the main reasons that I came up with the plan of running Linux to begin with was that not having admin privileges on the laptop kept me from being able to configure VPN. Now that I had finally managed to get the USB configuration that I wanted, I thought it should be a snap to configure VPN. But in looking for documentation from TorGuard, my VPN service, I only saw documentation for ubuntu Linux. Darn! Well to make a long story short I managed to install Ubuntu Linux with data persistence but with no option for a home directory. I was also able to configure VPN pretty easily, at which point, I realized the procedure to configure it on Fedora should be identical. I guess I created the Ubuntu disk for nothing because the VPN works fine on Fedora!
 I spent the past three days working on installing Linux live on a USB stick. The reason I got started on this senseless waste of time is because I now have a laptop to use for part of the time I’ll be in New Zealand. The only problem is that I don’t have admin access so I can’t install anything, not even my VPN configuration. I finally came up with the idea of installing Linux on one of the two USB sticks I brought with me.
I know this is all very boring and seems like a colossal waste of time, which is probably true but it’s the kind of thing I really enjoy doing, as long as I can succeed in a reasonable amount of time. Four days seems reasonable to me but it was exhausting and frustrating work.
This is a screenshot of my live fedora 21 desktop

Programming Foundations with Python

I’m still on track to create a Python GUI interface for my Roastmaster report application but have sidetracked. To use any of the Python GUI modules it is important to be comfortable with classes and OOP (object-oriented programming). To help me out in that area, I started another Udacity course. This one is called Programming Foundations with Python which has a specific goal of introducing you to Python classes and OOP. This course is pretty easy and a lot of fun since you get introduced to some very fun and practical applications of Python. A fun project was creating a very small application you can use to send texts to phones. To do this you need to set up an account on Twilio. The very first thing you learn how to do is to display a web page. It’s great to be able to do these things right away on a higher level and not having to spend hours and hours with the details of programming first. I think this can give a beginner incentive to learn the language in-depth after being given a taste of what can easily be accomplished with the right publicly available modules.

Learning python GUI programming

I’ve been working on reports for the Roastmaster app that I use for roasting coffee beans. I’m getting a handle on creating SQLite queries to create the reports. Then I wrapped up a query with Python. But you can’t do anything interactive. To make it interactive I figured I might as well go straight to a GUI interface. I’ve never done any GUI programming other than playing around with Visual Basic about ten years ago so I’m not sure if I can actually create something useful or not.