Wednesday, June 5, 2019

TIM-Another Update-V1.70

TIM-The Insult Machine. Update V1.70

python-TIM-The Insult Machine Update V1.70-tim-logo-sml


Download Tim v1.70 Freeware. Source and .exe.


I just couldn’t let it lie

Although I did quite well with updating TIM last time, it still left me feeling like I had failed on too many issues. The main one being I wanted a single cross platform source code file for Windows, Linux and possibly Mac.

Almost as soon as I finished the last update I started work on the next version. My first task was to make it properly cross-platform, and then add another good feature, but first there were several issues to overcome to achieve this.

Here is my personal log of what I changed and \or fixed in TIM, read from bottom to top:

Updated help file
Improved logo a bit.
Added contact me and donate me in menu
Tim says ‘accent selected’
Updated gold label to show accent in use
Added dialects (accents) menu and 12 options
Tim now says clean or rude insults selected
Added tim_says() function
Fixed capitalized linux word gaff, in what_platform().
Added different file slashes for platforms when playing mp3
Added diff window geometry sizes dependent on platform
Use win explorer to view mp3 files only if on windows, else text view.
Added what_platform() function
Changed fav insults viewer to webbrowser view
Changed saved insults viewer to webbrowser view
Changed startfile to webbrowser to play mp3s
Added root.quit after root.destroy otherwise continues to next def
Fixed line lengths on message boxes
Spelling error, vicious, fixed
The word knicker mis-spelt in word file fixed
Improved error check msgbox on help txt
Changed help text from my viewer to webbrowser way
Fixed y\n msgbox on rude folder check

The first thing to do was to use my latest discovery about the webbrowser module trick to open Tim’s text files and play Mp3’s. This was really quick and easy to implement. It worked like a charm on Windows and then Linux, and cut out some large chunks of code that were now no longer needed.

Example code:

webbrowser.open("saved_insults.txt")
fname = full_insult+".mp3"
play_mp3 = "saved_mp3s\\"+fname
webbrowser.open(play_mp3)

I Got Over Excited Again

I was very happy with that, so happy that I got over-excited and wrote the Python secret post, for which I got slagged off  by a few people for click baiting. Old habits die hard I suppose. Next time, shall I keep my discoveries to myself?

Just An Aside

The following is just an aside, something I need to get off my chest, just skip over it:

I once owned three computer shops selling used computers and games in the 1990s. It didn’t matter that I made everything as cheap as possible and paid out good cash to buy in stuff from skint people, (about 4x more than cash converters would pay nowadays), people still complained and thought they were being ripped off.

I learnt then that most people are selfish assholes with no understanding of how the world works or any ability to wear the other persons shoes (so to speak) . When I got mild jip for the secret post, those awkward customers that used to give me nightmares in my shops came to mind.

Once I got rid of those shops I vowed never to work with, or for, the general public again.  The point I am trying to make in a rather laboured way is that I give everything away in this blog.

I share everything for free, and I am spending about 90% of my remaining life-span, (I am 58), writing or coding for this blog, for zero reward, and I still get criticised. 🙂  Humans, who’d want to be one of them, eh!

 

And Back To Reality

I’m sorry about that, back to TIM.

The only problem I didn’t solve was to view mp3s in a file explorer type program for Linux. It’s Easy to do on Windows of course, but I couldn’t do it on Linux, so I had to stick with my rubbishy text viewer for that task.

I’m sure I can suss it out over time, or get help, so it will be done in the next update. The next update will probably be a long way off anyway, maybe next year.

The first major problem I managed to fix was the crazy window width debacle. If you look at the last TIM update, I posted screenshots of this.

I asked for help on Reddit, but I couldn’t use the answers for various reasons, but they did remind me of a code snippet in my collection that detected what platform the code was running on, code snippet #19.

''' 19-determine system platform '''
import sys

if sys.platform.startswith('win'):
    PLAT = 'windows'
elif sys.platform.startswith('linux'):
    PLAT = 'linux'
elif sys.platform.startswith('darwin'):
    PLAT = 'mac'
else:
    print('This platform is not supported.')
    sys.exit(1)

print(PLAT)

This worked as expected. So I just set up separate geometries for Windows and Linux and it worked, luverly jubberly.

python-tim-cross-platform-the-insult-machine-v170

TIM Say’s

Next up I wanted to add a simple feature exploiting the fact that we were using computer speech, why not have TIM speak out a bit more, other than just insults?  How about when you change insults or when you change accents?

So I knocked a quick and surprisingly easy function that can be called with the text to be spoken by TIM as a parameter, here it is:

def tim_says(tim_message):
    '''tim speaks message passed to this function'''
    tts = gTTS(text=str(tim_message), lang=tim_lang)
    tim_message = tim_message+".mp3"
    tts.save(tim_message)
    #play the message
    webbrowser.open(tim_message)

Pretty neat for me, and it works perfectly.

Next up I wanted to add the option to change dialects. Gtts supports this, so it wasn’t that difficult.

This feature adds a little bit more fun, and is sometimes very funny when used on certain insults.

I can’t say more than that as it may be construed as racist in today’s politically correct climate, and as I am a “1970s cave man“, as my female neighbour once called me, I am not taking any chances of pissing off even more people than I already have!

TIM’s Not Racist

So I created a separate menu for the accents. I added 12 accents. Not all of Googles accents seem to be supported for some reason, e.g I wanted to add Chinese, but it said it was not supported.

tim-v170-accents-menu

Now I came up against an old problem. Each menu option would need to call a seperate function when selected, that’s 12 new functions that would all look almost identical, that is extremely un-Pythonic even to my glaringly incompetent brain, and then, ding, I remembered another code snippet, the one that used lambdas to solve exactly this problem, it was snippet #60, pass parameter from callback.

We Have Lambda

I won’t reproduce the whole code here again as it is fairly long. But here is a sample so you can see what I mean:

def change_lang(clang):
    '''change accent'''
    tim_lang = clang
    tim_says("Accent selected")

#the menu set up here
insults_menu.add_command(label="Englisgh UK en-uk", command=lambda: change_lang("en-uk"))
insults_menu.add_command(label="Austrailian en-au", command=lambda: change_lang("en-au"))

#etc....

So by using lambda to call the same function with a different parameter saved making 11 more functions.

If anyone had any doubt about how useful having a code snippet collection is to me, then here is a good example of time saving and loss of hair saved from my head.

Donation Option

I came to the conclusion that I would probably never sell any of my software directly. It wouldn’t sell anyway of course, but I know from personal experience that I have rewarded free software that I loved with the odd fiver, just to say thanks, and if I do it occasionally then I’m sure there must be the odd one in 20 million people that do it, so I am just going to slap a “donate me” menu option on some of my programs.

tim-v170-donate-menu

I did it in Auto Photo Colourizer, and I have decided to do it in TIM. I don’t expect I will get a single donation, but the option is there just in case someone like Elon Musk uses TIM, loves it, and donates £1, way cool. Thanks Elon.

330px-Elon_Musk_Royal_Society

I set up the donation link using my PayPal account. Unfortunately PayPal only allows a single pay.me address, which I had named photo colourizer, now I can’t change it, but it will just have to do for all my programs in the future.

There’s Always Something!

Two somethings actually.  As mentioned earlier I have to work out how to get the Linux file explorer up and opened into the saved mp3s folder.

The second is a new problem, which I am amazed I have never noticed before. A check mark on the menu option selected.

Most right minded people would of thought that feature would be built into Tkinter as a default which could be changed, nope, it seems not, and after a few hours of research I cannot find a clear and sensible explanation of how to implement it. How ludicrous, it reminds me of the missing right-click menu support problem in Tkinter as well, solved in code snippet 39.

So those two will have to wait for the next update, assuming there is one. I can’t predict what I am going to do next, yet alone in months to come, so who knows?

That’s It For Now

And that is about it. There were other bits and bobs that I improved, fixed, or made worse, but most of those are trivial and hardly worth a mention.

I hope these TIM posts haven’t been too long and\or boring and that some newbs will pick up a few tips from me, whilst I randomly thrash about in my code editor.

What was that saying about a monkey with a code editor? Given enough time, he would end up writing Photoshop!

monkies-computer

Or was it the infinite monkey therom where givinen enough time a monkey could randomly write all of shakespears plays.


Download Tim v1.70 Freeware. Source and .exe.


Using Python V3.6.5 32bit, on Windows 7 64bit

and Python V3.67 on Linux Mint 19.1 Cinnamon 64bit

Home Page

Previous Post: A useful little Python secret ?





from Python Coder
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...