(free) Version Check Script

Hello PythonHeads,

Introduction
I’m unknown when it comes to programming so I’ll just give a short summary of what I’ve tried to do with Python already:

  • Make a small RPG game (Python console, no MMO offcourse)
  • Install the ‘Mouse Look’ script from the Blender documentation onto a camera, it didn’t work out that well but it worked!
  • Install and modify a re-written camera collision script based on a tutorial by Blending-Online.co.uk
  • Create a version check script!The script
    I’ve made the script using the Python IDLE and it’s not using Blender. I’ve used Tkinter for the interface/application window. Tkinter runs on almost all platforms (I read that) .
    I hope you like it.

    Download here

    Source:

#Made using the Tkinter "Hello" tutorial and Introduction to Tkinter online version.
#http://docs.python.org/lib/node689.html
#modified by Christiaan "AniCator" Bakker
#http://www.anicator.com
#version 0.8.2
#Do not change the version.txt file, if you do there is a lot of chance you can't connect to the server.

from urllib2 import Request, urlopen, URLError, HTTPError
from Tkinter import *
import os
import time

root = Tk()
frame = Frame(width=300, height=100, borderwidth=1)
print 'This version checker was programmed by Christiaan "AniCator" Bakker.'
print 'Version: 0.8.2'

#exit code
def exitnow():
    root.destroy()
    exit()
#application code
class Application(Frame):
    def check(self):
        frame.checker = Label(frame, width=40, relief=SUNKEN)
        frame.checker["text"]='Downloading versionfile.txt'
        frame.checker.grid(row=1)
        #request the file
        request = urlopen("http://uploader.polorix.net/files/114/versionfile.txt")
        try:
            #read the file
            readremote = request.read()
            print 'File downloaded.'
            print 'Remote version: ' ,readremote
            frame.checker["text"]= 'Remote version: ', readremote
            frame.checker.grid(row=1)
        except URLError, e:
            #if an error occurs this code will be executed
            print e.code
            print e.read()
            print 'Unable to download file!'
            frame.checker["text"]='Unable to download the file.'
            frame.checker.grid(row=1)
        frame.localcheck = Label(frame, width=40, relief=SUNKEN)
        frame.localcheck.grid(row=2)
        print "Requesting local 'version.txt'"
        #request the local file
        requestlocal = open('version.txt', 'r')
        readlocal = requestlocal.read()
        print 'Local version: ', readlocal
        frame.localcheck["text"]='Local version: ', readlocal
        frame.matchcheck = Label(frame, width=45, relief=SUNKEN)
        frame.matchcheck.grid(row=3)
        if (readlocal==readremote):
            print "It's a MATCH!"
            frame.matchcheck["text"]='You have the right version!'
            time.sleep(5)
            print "Initiating the game!"
            print os.system('Area1_fix05.blend')
            os.system('Area1_fix05.blend')
        else:
            print "You're game is old...zzz..or ur a hacker! that tried to change the version.txt, bad thing that is"
            frame.matchcheck["text"]='You got an older version.'
    def createWidget(self):
        #'Check and Play' button
        self.check1 = Button(frame, width=40, height=4)
        self.check1["text"] ='Check & Play'
        self.check1["command"] = self.check
        print 'Check button initiated.'
        self.check1.grid(row=0, columnspan=2)

    def __init__(self, master=None):
        #initiate the widget
        Frame.__init__(self, master)
        self.createWidget()
        self.check
        self.grid(row=0)

#menu code
menu = Menu(root)
root.config(menu=menu)

filemenu = Menu(menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="Exit", command=exitnow)

#initialize the program
app = Application(master=root)
frame.grid()
app.master.title("Kalith Version Checker v0.8.2")

app.mainloop()


Bugs
I haven’t spend much time on optimizing. I’ve debugged a lot of my own mistakes but I haven’t encountered a lot of bugs since version 0.6. The only bug I noticed is that when you use the version checker to startup an application made with a certain line Python ‘quit code’, the application will startup everytime you quit it. I have tried to avoid this but the Python application runs on the process of the version checker. I almost forgot to mention that I couldn’t get the application to sleep for a few seconds so only the console shows the results but the Tkinter interface can’t keep up. It’s probably because of the line containing ‘time.sleep(5)’. Remove this line if possible. This script is still not complete but it’s almost done. It works! Partially.

Copyright
This script was programmed by Christiaan “AniCator” Bakker, do not re-use this script.
You may only use this script when you’ve modified it. Do not remove the comments that exist in the script.

Have Fun!
- AniCator

No comments?