analitics

Pages

Tuesday, March 20, 2018

Python 3.6.4 : Testing PyQt5 with Spyder I.D.E.

Today I tested the PyQt5 python module with python version 3.6.4.
The script was created and tested with Spyder I.D.E. version 3.2.8.
The PyQt5 version is:
from PyQt5.Qt import PYQT_VERSION_STR
print("PyQt version:", PYQT_VERSION_STR)
PyQt version: 5.9.2
This is the python script:
import sys
from PyQt5.QtWidgets import (QWidget, QCalendarWidget,
    QLabel, QApplication)
from PyQt5.QtCore import QDate
 
class Calendar(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
 
    def initUI(self):
        calendar = QCalendarWidget(self)
        calendar.setGridVisible(True)
        calendar.move(0, 15)
        calendar.clicked[QDate].connect(self.showDate)
        calendar.currentPageChanged[int, int].connect(self.currentPageChanged)
 
        self.lbl = QLabel(self)
        date = calendar.selectedDate()
        self.lbl.setText(date.toString())
        self.lbl.move(0, 0)
 
        self.setGeometry(300, 300, 300, 300)
        self.setWindowTitle('Calendar')
        self.show()
 
    def showDate(self, date):
        self.lbl.setText(date.toString())
 
    def currentPageChanged(self, year, month):
        print(year, month)
 
if __name__ == '__main__':
    app = QApplication(sys.argv)
    calendar_test = Calendar()
    sys.exit(app.exec_())
The result of this script is:

Saturday, March 17, 2018

The Google Cloud SDK - part 003 .

The webapp2 is a lightweight Python web framework compatible with Google App Engine’s.
The webapp2 project, by Rodrigo Moraes, started as a fork of the App Engine web app framework.
The webapp2 includes a number of features such as improved support for URI routing, session management and localization.
You can see google documentation about this python module this link.
They say:
"webapp2 is compatible with the WSGI standard for Python web applications. You don't have to use webapp2 to write Python applications for App Engine. Other web application frameworks, such as Django, work with App Engine, and App Engine supports any Python code that uses the CGI standard. "
This is default start python example from Google Cloud SDK tested in the last tutorial.
import webapp2

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Hello, World!')

app = webapp2.WSGIApplication([
    ('/', MainPage),
], debug=True)
Remember how to deploy your project to google:
C:\Python27>cd python-docs-samples\appengine\standard\hello_world

C:\Python27\python-docs-samples\appengine\standard\hello_world>gcloud app deploy app.yaml
Services to deploy:

descriptor:      [C:\Python27\python-docs-samples\appengine\standard\hello_world\app.yaml]
source:          [C:\Python27\python-docs-samples\appengine\standard\hello_world]
target project:  [xxxxxx]
target service:  [default]
target version:  [xxxxxxxxxxxxx]
target url:      [https://xxxxxx.appspot.com]


Do you want to continue (Y/n)?  y

Beginning deployment of service [default]...
Now I make some changes into main.py file to show you how easy is to use it.
This file: main.py is set into setting file app.yaml like the script: main.app.
Let's make some changes.

The default project is set with --promote true the result is: after a number of uploads you got this error:
ERROR: (gcloud.app.deploy) Error Response: [400] Your app may not have more than 15 versions.
Please delete one of the existing versions before trying to create a new version.
...
To fix go to App Engine - Versions with selected versions and press Delete button.
Then you can make the upload with the command :
gcloud app deploy app.yaml
Also, you can use this:
gcloud app deploy app.yaml --stop-previous-version
Some info about your project can be seen with this command:
gcloud config list
You can see the gcloud versions with:
gcloud version
I tested also with python version 3.6.4 :
C:\Python364\Scripts>pip install webapp2
Requirement already satisfied: webapp2 in c:\python364\lib\site-packages
      2 python-dateutil-2.7.0 setuptools-39.0.0 

Wednesday, March 14, 2018

The regex online tool for python and any programming languages.

Today I tested this online tool.
Is a tool for a regular expression (regex or regexp for short) for many programming languages.
These programming languages are php, javascript, golang and python.
The tool is easy to use it.
First, you need to select the programming language that is used for regular expression.
The next step is to put the regular expression into the edit box and add your text to be parsed by this regular expression.
For example, if you use this inputs for a regular expression:
([a-zA-Z]+) \d+
and this text example:
March 7 1976, June 1, August 9, Dec 25
the result output will be this:
March , June , August , Dec

Sunday, March 11, 2018

Python 3.6.4 : Testing OpenCV default GrabCut algorithm.

The main goal for me was to test the new install of python 3.6.4 and python modules with Windows operating system version 8.1.
For this tutorial, I chose these python modules: cv2, numpy and matplotlib .
I have tested the GrabCut algorithm article from here.
The article comes with a python script that includes the modules I tested in this programming language.
They tell us:
User inputs the rectangle. Everything outside this rectangle will be taken as sure background (That is the reason it is mentioned before that your rectangle should include all the objects). Everything inside rectangle is unknown. Similarly any user input specifying foreground and background are considered as hard-labelling which means they won't change in the process.
From my point of view, it is not a very successful algorithm to crop off the background but is working well.
import numpy as np
import cv2
from matplotlib import pyplot as plt

img = cv2.imread('test_python_opencv.jpg')
mask = np.zeros(img.shape[:2],np.uint8)

bgdModel = np.zeros((1,65),np.float64)
fgdModel = np.zeros((1,65),np.float64)

rect = (57,58,476,741)
cv2.grabCut(img,mask,rect,bgdModel,fgdModel,5,cv2.GC_INIT_WITH_RECT)

mask2 = np.where((mask==2)|(mask==0),0,1).astype('uint8')
img = img*mask2[:,:,np.newaxis]

plt.imshow(img),plt.colorbar(),plt.show()
The intersection areas are eliminated exactly as in the documentation.
See my first test on an image taken from the internet.

Saturday, March 3, 2018

News: The Spyder IDE - new release .

Many python users use the Spyder IDE.
This IDE comes with many features and is easy to use, see Wikipedia page:
Spyder (formerly Pydee[3]) is an open-source cross-platform integrated development environment (IDE) for scientific programming in the Python language. Spyder integrates NumPy, SciPy, Matplotlib and IPython, as well as other open source software.[4][5] It is released under the MIT license.[6]
Six days ago, a release of this IDE with version 3.2.7 was announced.
This IDE can be download from GitHub page.