Friday 8 June 2018

Classes

My favourite subject, seriously!


A simple class

class MyClass(): pass

There are two types of class variables, class variables and Instance variables.




Class variables

class MyClass:
    # class variable
    var = 0         def __init__():
    # instance variable created at initialization.     self.var = 1 # not the same variable as class variable
        def method(self):
        # access a class variable from a class method.
        self.__class__.var1 = 1

Class variables are accessible to instance methods using the __class__ 

Kivy

I hold a real passion for developing GUI's using Kivy, its ability to be truly multi platform. I have used Ubuntu, Windows and Mac to develop code for Raspberry Pi that just works on the other platforms.

Where Kivy really lacks is its dependency on other packages with specific version such as Cython (love Cython) All of these programs can be overcome with a little persistence.

A simple 'Hello World' Kivy example:

import kivy

from kivy.app import App
from kivy.uix.label import Label

class MyApp(App):

    def build(self):
        return Label(text='Hello world')

if __name__ == '__main__':
    MyApp().run()

Go on give it a go!




Thursday 7 June 2018

Profile small code snippets

Had a requirement to test some code that was causing timing problems, so looked at a few ways that this may be achieved and decided on timeit a default python language package.

import timeit
     
t = timeit.Timer("def test(): print("def test()", "print('setup')")

print(t.timeit(10000))

print(t.repeat(3,10000))
       

In my code I use the following no requirement for setup so empty, just call the API method that I want to time.

import timeit

t = timeit.Timer("def example(): x10i.CachedReadAndResetSecuritySwitchFlags()", "")
print(t.timeit(10000))
print(t.repeat(3,10000))
       

And that's it simple!

Friday 25 May 2018

Kivy Default Theme

I was looking at changing the default action_group icon, a small insignificant taskbar icon that can represent the presence of a popup menu.

Kivy 1.10 is lacking in functionality here as you have to replace the default graphical theme to enable you to use a new image.

After using Google to search for a solution I came across the normal problems... t.b.c

The Holy Grail

Not sure there is one, but always worth looking for that illusive goal.

My adventures in Python started when I realised how mature this language had become. I love OOP and the python implementation is clear and easy to follow. My preference in software development lies in GUI’s and I have experience in Qt, wxWidgets and Kivy the soon to be released PySide2 will allow all of these toolkit’s to be accessible from Python.

Classes

My favourite subject, seriously! A simple class class MyClass(): pass There are two types of class variables, class variables and Inst...