Skip to content

Commit

Permalink
Added checkForUpdates function
Browse files Browse the repository at this point in the history
  • Loading branch information
grze2000 committed Jul 7, 2019
1 parent 67901e6 commit 1ddefff
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pyCalc3/locales/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<translation text="16ns">hexa decimal</translation>
<translation text="2ns">binary</translation>
<translation text="8ns">octal</translation>
<translation text="actual version">Actual version:</translation>
<translation text="available version">Available version:</translation>
<translation text="calculate">Calculate</translation>
<translation text="celsius">Celsius</translation>
<translation text="centimeters">Centimeters</translation>
Expand All @@ -13,6 +15,7 @@
<translation text="decimeters">Decimeters</translation>
<translation text="degree">degrees</translation>
<translation text="diagonal">Diagonal:</translation>
<translation text="download update">Do you want to download new version?</translation>
<translation text="err1">Cannot divide by zero!</translation>
<translation text="err2">Incorrect value</translation>
<translation text="err3">File not found!</translation>
Expand Down Expand Up @@ -50,11 +53,13 @@
<translation text="menu3.1.2">English</translation>
<translation text="menu4">Help</translation>
<translation text="menu4.1">pyCalc - Informations</translation>
<translation text="menu4.2">Check for updates</translation>
<translation text="meters">Meters</translation>
<translation text="miles">Miles</translation>
<translation text="millimeters">Millimeters</translation>
<translation text="nautical miles">Nautical miles</translation>
<translation text="number">Number:</translation>
<translation text="no">No</translation>
<translation text="parallelogram">Parallelogram</translation>
<translation text="radian">radians</translation>
<translation text="ratio">Aspect Ratio:</translation>
Expand All @@ -69,7 +74,9 @@
<translation text="trapezoid">Trapezoid</translation>
<translation text="triangle">Triangle</translation>
<translation text="unit">Unit:</translation>
<translation text="update available">Update is available</translation>
<translation text="value">Value:</translation>
<translation text="width">Width:</translation>
<translation text="yards">Yards</translation>
<translation text="yes">Yes</translation>
</lang>
7 changes: 7 additions & 0 deletions pyCalc3/locales/pl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<translation text="16ns">szesnastkowy</translation>
<translation text="2ns">dwójkowy</translation>
<translation text="8ns">ósemkowy</translation>
<translation text="actual version">Aktualna wersja:</translation>
<translation text="available version">Dostępna wersja:</translation>
<translation text="calculate">Oblicz</translation>
<translation text="celsius">Celcjusz</translation>
<translation text="centimeters">Centymetry</translation>
Expand All @@ -13,6 +15,7 @@
<translation text="decimeters">Decymetry</translation>
<translation text="degree">stopnie</translation>
<translation text="diagonal">Przekątna:</translation>
<translation text="download update">Czy chcesz pobrać nową wersję?</translation>
<translation text="err1">Nie można dzielić przez zero</translation>
<translation text="err2">Nieprawidłowa wartość</translation>
<translation text="err3">Nie odnaleziono pliku!</translation>
Expand Down Expand Up @@ -50,11 +53,13 @@
<translation text="menu3.1.2">Angielski</translation>
<translation text="menu4">Pomoc</translation>
<translation text="menu4.1">pyCalc - Informacje</translation>
<translation text="menu4.2">Sprawdź dostępność aktualizacji</translation>
<translation text="meters">Metry</translation>
<translation text="miles">Mile</translation>
<translation text="millimeters">Milimetry</translation>
<translation text="nautical miles">Mile morskie</translation>
<translation text="number">Liczba:</translation>
<translation text="no">Nie</translation>
<translation text="parallelogram">Równoległobok</translation>
<translation text="radian">radiany</translation>
<translation text="ratio">Proporcje:</translation>
Expand All @@ -69,7 +74,9 @@
<translation text="trapezoid">Trapez</translation>
<translation text="triangle">Trójkąt</translation>
<translation text="unit">Jednostka:</translation>
<translation text="update available">Dostępna aktualizacja</translation>
<translation text="value">Wartość:</translation>
<translation text="width">Szerokość:</translation>
<translation text="yards">Jardy</translation>
<translation text="yes">Tak</translation>
</lang>
25 changes: 25 additions & 0 deletions pyCalc3/pyCalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import urllib.request as urllib
import json
from PIL import Image, ImageTk
from bs4 import BeautifulSoup
import threading
import webbrowser
import lang
_ = lang.get

Expand Down Expand Up @@ -440,6 +443,8 @@ def __init__(self):
self.languages = ['pl','en']
self.lang = "pl"
self.end = False
check = threading.Thread(target=self.checkForUpdates)
check.start()
self.checkSettings()
self.startGui()

Expand Down Expand Up @@ -534,6 +539,7 @@ def startGui(self):
menuOptions.add_checkbutton(label=_("menu3.4"), onvalue=True, offvalue=False, variable=vShowHistory, command=lambda: self.changeSettings('history', vShowHistory.get()))
menuOptions.add_checkbutton(label=_("menu3.5"), onvalue=True, offvalue=False, variable=self.vContinuity, command=lambda: self.changeSettings('continuity', self.vContinuity.get()))
menuHelp.add_command(label=_("menu4.1"), command=self.info)
menuHelp.add_command(label=_("menu4.2"), command=self.checkForUpdates)
menuFunctionsItems = {
_("menu1.1"): 'screenSize',
_("menu1.2"): 'trigonometricFunc',
Expand Down Expand Up @@ -893,4 +899,23 @@ def createDefaultSettingsFile(self):
config.write(cfgfile)
cfgfile.close()

def checkForUpdates(self):
latest = urllib.urlopen('https://github.com/Programista3/pyCalc/releases/latest')
parse = BeautifulSoup(latest, 'html.parser')
version = parse.select_one('div.release-header > div > div > a').text
if(version > self.version):
window = Toplevel(self.root, padx=20, pady=10)
window.resizable(False, False)
window.transient(self.root)
window.title(_("update available"))
window.iconbitmap('pycalc.ico')
label = Label(window, text=_("actual version")+' '+self.version+'\n'+_("available version")+' '+version+'\r\n'+_("download update"), justify=LEFT)
label.pack(pady=(0, 10))
buttons = ttk.Frame(window)
buttons.pack()
btnYes = ttk.Button(buttons, text=_("yes"), command=lambda: (webbrowser.open('https://github.com/Programista3/pyCalc/releases/latest'), window.destroy))
btnYes.pack(side=LEFT, padx=(0, 10))
btnNo = ttk.Button(buttons, text=_("no"), command=window.destroy)
btnNo.pack(side=LEFT)

calc = pyCalc()

0 comments on commit 1ddefff

Please sign in to comment.