# Programming

## February 12, 2021

Tilde – text editor

Tilde is a nice, curses based text editor. It is useful for if you are at the console or terminal in Linux and want a menu driven editor.

While other tools are more command driven (nano, emacs, vi, vim and joe to name a few). Tilde is being mentioned for those of you who may find it useful

As you would expect with a modern editor, tilde has support for syntax highlighting.

Which is really useful for programming or editing website code for example.

REFERENCES

TAGS

## January 30, 2021

Ansi Weather

Getting weather information is really useful. What happens if you're at the command line in Linux? I found a really little application that can help

ansiweather

apt install ansiweather

ansiweather -l Plymouth, UK

So what else can we do with this

1. Send the output to Mastodon with toot post

This is a two step process

1. ansiweather -l Plymouth, UK > weather.txt
2. toot post < weather.txt

Will send the weather info to Mastodon.

However this does not include any date info

We can fix this with

1. date > weatherinfo.txt
2. ansiweather -l Plymouth, UK >> weatherinfo.txt

then send the whole lot to Mastodon with

1. toot post < weatherinfo.txt

So, if we put this in to a final shell script we need:-

#send weather info to Mastodon
# current date
date > weatherinfo.txt
# current weather
ansiweather -l Plymouth, UK >> weatherinfo.txt
#send to Mastodon
toot post < weatherinfo.txt
# done
echo done



Again released under GPLv3

I tried to get festival to speak the weather, it is not perfect but this sort of works, you will need to direct to weather.txt first.

festival —tts < weather.txt

Looking in to this further, the issue is the brackets etc, so this stackoverflow post

strips out the colour formatting

sed 's/\x1b[[^\x1b]*m//g' weatherinfo.txt

Therefore

sed 's/\x1b[[^\x1b]*m//g' weatherinfo.txt > weatherinfo2.txt

Sends the newly formatted text to weatherinfo2.txt

So running back through festival

festival —tts < weather.txt

Is perhaps a little better, but not perfect

So going back to what we wrote earlier to send to Mastodon, the new script

  1 #send weather info to Mastodon
2 # current date
3 date > weatherinfo.txt
4 # current weather
5 ansiweather -l Plymouth, UK >> weatherinfo.txt
6 # clean up output with sed
7 sed 's/\x1b\[[^\x1b]*m//g' weatherinfo.txt > weatherinfo2.txt
8 #send to Mastodon
9 toot post < weatherinfo2.txt
10 # done
11 echo done



Produces much nicer output. The top bottom part of this illustrates what was sent before we stripped out the colour formatting

However it still isn't perfect, as it removes part some of the wording, but it is hopefully getting there.

REFERENCES

TAGS

## January 6, 2021

Site Index

2. Scroll to bottom of page.
• Any posts / pages within this blog will be displayed.

## Y

#YearOfTheFediverse

#Zoo

## December 21, 2020

Contribute to f-droid

This was originally shared on Mastodon, so am sharing here for any of my followers who may be interested.

• F-droid is looking for project contributors. There is a good article here with some more information.

The contribution page is also here

Looks like lots of opportunities to get involved. If you are interested you can also get in touch with IzzyOnDroid.

You can join Mastodon here then connect with IssyOnDroid and ask how to get involved.

I am on Mastodon here

## November 20, 2020

Scratch projects 20/11/2020

Still occasionally create simple Scratch projects to add to my portfolio. Mostly simple stuff, that can be built upon.

Resources

## August 3, 2020

New Repl.it course 3/8/2020

New course – How to teach yourself coding with Quizlet Founder Andrew Sutherland.

This may complement Paignton Code Club nicely. You can find more details here

I still need to complete the FreeCodeCamp course I am undertaking, I am also undertaking Teaching Primary Science : Chemistry With futurelearn.

Hopefully however, this is useful. I have shared on with Paignton Library on Twitter and with the Local Children and Young People partnership.

## July 15, 2020

Free Virtual Summer camps – from Microsoft

Just sharing this, in case anyone is interested

## May 21, 2020

I have added a few more maths functions to the application and also provided a clear function. There are still a few items to add to help improve debugging but the application is starting to take shape.

Notes

window = Tk()
window.title('Maths Application')
window.geometry("570x150") # w x h
window.resizable(0,0)

1. The above code is being modified as I go. So I am changing the window size depending on what is being displayed.

2. I have also made the Window title reflect the purpose of the application.

3. That the source code now has 'result' as a label rather than output. This will show up future screenshots.

The code for the above is as follows.

#!/usr/bin/env python
import Tkinter # note use of caps
from Tkinter import *

window = Tk()
window.title('Maths Application')
window.geometry("570x150") # w x h
window.resizable(0,0)

#define button actions
def btn1():
#convert box text in to integers
ent1 = int(entrytext.get())
ent2 = int(entrytext2.get())

#insert value of variable add in	to box outtext

def btn2():
#print("subtraction")
ent1 = int(entrytext.get())
ent2 = int(entrytext2.get())

#subtract the 2 integers and store in variable sub
sub = (ent1 - ent2)

#insert value of variable sub in	to box outtext
outtext1.insert(0,str(sub)) # insert response

def btn3():
#print("multiply")
ent1 = int(entrytext.get())
ent2 = int(entrytext2.get())

#multiply the 2 integers and store in variable mul
mul = (ent1 * ent2)

#insert value of variable mul in	to box outtext
outtext1.insert(0,str(mul)) # insert response

def btn4():
#print("divide")
ent1 = int(entrytext.get())
ent2 = int(entrytext2.get())

#multiply the 2 integers and store in variable div
div = (ent1 / ent2)

#insert value of variable mul in	to box outtext
outtext1.insert(0,str(div)) # insert response

#clear boxes
def clear():
#print("clear boxes") # leave in for legacy testing
entrytext.delete(0, END) # clear input box
entrytext2.delete(0, END) # clear input box2
outtext1.delete(0, END) # clear output box

btn_tog2 = Button( window, text ='+', command=btn1) # add
btn_tog3 = Button( window, text ='-', command=btn2)  # subtract
btn_tog4 = Button( window, text ='x', command=btn3) #multiply
btn_tog5 = Button( window, text ='/', command=btn4) #divide
btn_tog6 = Button( window, text ='Clear', command=clear) #clear
btn_exit = Button( window, text ='Exit',command=exit)	 #exit

# define some labels
box1 = Label(window, text="1st Value")
box2 = Label(window, text="2nd Value")
box3 = Label(window, text="Result")

#define entry box
entry1 = StringVar() # this is our entry box
entry2 = StringVar()
entrytext = Entry(window, textvariable=entry1) # this is our entry box
entrytext2 = Entry(window, textvariable=entry2) # this is our second entry box

#define out box

entry2 = StringVar() # this is our output box
outtext1 = Entry(window, textvariable=entry2) # this is our output box

#display boxes
entrytext.grid(row = 3, column = 2,)  #display entry box
entrytext2.grid(row = 3, column = 3,)  #display entry box
outtext1.grid(row = 3, column = 4,) #display output box

#place labels
box1.grid(row = 1	, column = 2, padx = 5, pady = 5)
box2.grid(row = 1	, column = 3, padx = 5, pady = 5)
box3.grid(row = 1	, column = 4, padx = 5, pady = 5)

#buttons
btn_tog3.grid(row = 4, column = 3, padx = 1, pady = 1) # subtraction button
btn_tog4.grid(row = 5, column = 2, padx = 1, pady = 1) # multiply button
btn_tog5.grid(row = 5, column = 3, padx = 1, pady = 1) # divide button
btn_tog6.grid(row = 4, column = 6, padx = 1, pady = 1) # clear button
btn_exit.grid(row = 3, column = 6, padx = 1, pady = 1) # exit button

window.mainloop()



The code that I used for a previous application to detect if numerical values have been used is below but provided 'as is' for now.

def response():

msg = "error : must be a text value"

i = circletext.get()
y = i.isdigit()
l = len(circletext.get())
#print l
if y == True or l == 0:
circletext.insert(0,(msg))

else:
x = random.choice(RESPONSES)
circletext2.delete(0, END) # clear prev output
circletext2.insert(0,str(x)) # insert response


I will integrate a version of this in to the main code.

Happy to provide help and support via decentralised social media. I can be contacted on Mastodon here. You can get a free account on the http://qoto.org instance by following this link.

Licenced under Attribution 4.0 International (CC BY 4.0)

## May 20, 2020

So following on from the previous posts, I am how sharing a small application, that makes use of what we have been learning.

This presents 2 input boxes and an output box, any values entered in to the first two, the sum is placed in to the last box.

This is not perfect, but getting there slowly.

We need to:-

• Fix the name of the button from button1
• Detect if the user has entered numerical values
• Detect for empty boxes
• Make labels more useful

The code for the above is as follows.

#!/usr/bin/env python
import Tkinter # note use of caps
from Tkinter import *

window = Tk()
window.title('App 1')
window.geometry("650x125") # w x h
window.resizable(0,0)

#define button actions
def btn1():
#convert box text in to integers
ent1 = int(entrytext.get())
ent2 = int(entrytext2.get())

#instert value add in	to box outtext

btn_tog2 = Button( window, text ='button1', command=btn1)
btn_exit = Button( window, text ='exit',command=exit)

# define some labels
box1 = Label(window, text="Entry 1: ")
box2 = Label(window, text="Entry 2: ")
box3 = Label(window, text="Ouput1: ")

#define entry box
entry1 = StringVar() # this is our entry box
entry2 = StringVar()
entrytext = Entry(window, textvariable=entry1) # this is our entry box
entrytext2 = Entry(window, textvariable=entry2) # this is our second entry box

#define out box

entry2 = StringVar() # this is our output box
outtext1 = Entry(window, textvariable=entry2) # this is our output box

#display boxes
entrytext.grid(row = 3, column = 2,)  #display entry box
entrytext2.grid(row = 3, column = 3,)  #display entry box
outtext1.grid(row = 3, column = 4,) #display output box

#place labels
box1.grid(row = 1	, column = 2, padx = 5, pady = 5)
box2.grid(row = 1	, column = 3, padx = 5, pady = 5)
box3.grid(row = 1	, column = 4, padx = 5, pady = 5)

#buttons
btn_tog2.grid(row = 3, column = 5, padx = 5, pady = 5)
btn_exit.grid(row = 3, column = 6, padx = 5, pady = 5)

window.mainloop()



Happy to provide help and support via decentralised social media. I can be contacted on Mastodon here. You can get a free account on the http://qoto.org instance by following this link.

Licenced under Attribution 4.0 International (CC BY 4.0)

## May 19, 2020

More improvements

So last time we added some text boxes and made the application a little more presentable. Now we are going to do is add some labels above the boxes to help describe what they do.

Add this above were we define the entry boxes

# define some labels
box1 = Label(window, text="Entry 1: ")
box2 = Label(window, text="Entry 2: ")
box3 = Label(window, text="Ouput1: ")



Now add this below where we place the entry boxes but above window.mainloop()

#place labels
box1.grid(row = 1	, column = 2, padx = 5, pady = 5)
box2.grid(row = 1	, column = 3, padx = 5, pady = 5)
box3.grid(row = 1	, column = 4, padx = 5, pady = 5)


So here we have a window, with three text boxes.

So again we have something that looks a little more like an application.